Commit 437d1c7f authored by johnnyg@chromium.org's avatar johnnyg@chromium.org

Fix memory leaks in the balloon controller unit test by loading the NIB in the...

Fix memory leaks in the balloon controller unit test by loading the NIB in the correct test-friendly way, which allows the windows to be closed correctly and the cleanup code to run as expected.

BUG=49590
TEST=unittests

Review URL: http://codereview.chromium.org/2825073

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54018 0039d316-1c4b-4281-b951-d872f2087c98
parent 09f89648
......@@ -7,6 +7,7 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#import "base/cocoa_protocols_mac.h"
#include "base/mac_util.h"
#import "base/scoped_nsobject.h"
#include "base/utf_string_conversions.h"
#import "chrome/browser/cocoa/menu_controller.h"
......@@ -33,7 +34,10 @@ const int kRightMargin = 1;
@implementation BalloonController
- (id)initWithBalloon:(Balloon*)balloon {
if ((self = [super initWithWindowNibName:@"Notification"])) {
NSString* nibpath =
[mac_util::MainAppBundle() pathForResource:@"Notification"
ofType:@"nib"];
if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
balloon_ = balloon;
[self initializeHost];
menuModel_.reset(new NotificationOptionsMenuModel(balloon));
......@@ -57,11 +61,14 @@ const int kRightMargin = 1;
WideToUTF16(balloon_->notification().display_source()));
[originLabel_ setStringValue:sourceLabelText];
gfx::NativeView contents = htmlContents_->native_view();
[contents setFrame:NSMakeRect(kLeftMargin, kTopMargin, 0, 0)];
[[htmlContainer_ superview] addSubview:contents
positioned:NSWindowBelow
relativeTo:nil];
// This condition is false in unit tests which have no RVH.
if (htmlContents_.get()) {
gfx::NativeView contents = htmlContents_->native_view();
[contents setFrame:NSMakeRect(kLeftMargin, kTopMargin, 0, 0)];
[[htmlContainer_ superview] addSubview:contents
positioned:NSWindowBelow
relativeTo:nil];
}
}
- (IBAction)optionsButtonPressed:(id)sender {
......@@ -104,7 +111,9 @@ const int kRightMargin = 1;
int w = [self desiredTotalWidth];
int h = [self desiredTotalHeight];
htmlContents_->UpdateActualSize(balloon_->content_size());
if (htmlContents_.get())
htmlContents_->UpdateActualSize(balloon_->content_size());
[[self window] setFrame:NSMakeRect(x, y, w, h)
display:YES
animate:YES];
......
......@@ -13,6 +13,16 @@
#include "chrome/test/testing_profile.h"
#import "third_party/ocmock/OCMock/OCMock.h"
// Subclass balloon controller and mock out the initialization of the RVH.
@interface TestBalloonController : BalloonController {
}
- (void)initializeHost;
@end
@implementation TestBalloonController
- (void)initializeHost {}
@end
namespace {
// Use a dummy balloon collection for testing.
......@@ -67,18 +77,14 @@ TEST_F(BalloonControllerTest, ShowAndCloseTest) {
new NotificationObjectProxy(-1, -1, -1, false));
scoped_ptr<Balloon> balloon(
new Balloon(n, profile_.get(), collection_.get()));
balloon->SetPosition(gfx::Point(1, 1), false);
balloon->set_content_size(gfx::Size(100, 100));
BalloonController* controller = [BalloonController alloc];
id mock = [OCMockObject partialMockForObject:controller];
[[mock expect] initializeHost];
BalloonController* controller =
[[TestBalloonController alloc] initWithBalloon:balloon.get()];
[controller initWithBalloon:balloon.get()];
[controller showWindow:nil];
[controller closeBalloon:YES];
[mock verify];
[controller release];
}
TEST_F(BalloonControllerTest, SizesTest) {
......@@ -87,19 +93,19 @@ TEST_F(BalloonControllerTest, SizesTest) {
new NotificationObjectProxy(-1, -1, -1, false));
scoped_ptr<Balloon> balloon(
new Balloon(n, profile_.get(), collection_.get()));
balloon->SetPosition(gfx::Point(1, 1), false);
balloon->set_content_size(gfx::Size(100, 100));
BalloonController* controller = [BalloonController alloc];
id mock = [OCMockObject partialMockForObject:controller];
[[mock expect] initializeHost];
BalloonController* controller =
[[TestBalloonController alloc] initWithBalloon:balloon.get()];
[controller initWithBalloon:balloon.get()];
[controller showWindow:nil];
EXPECT_TRUE([controller desiredTotalWidth] > 100);
EXPECT_TRUE([controller desiredTotalHeight] > 100);
[mock verify];
[controller release];
[controller closeBalloon:YES];
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment