Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4841)

Unified Diff: chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm

Issue 1415743011: Call -browserWillBeDestroyed before releasing ToolbarController in unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bookmark-apps-location-bar
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm
diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm
index 9a976e5a0fd5fa6ad6a7bf4ad8f0c75fe21d58a7..0cd9275d685039f3344929f65fe45398a47be0a5 100644
--- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm
@@ -98,7 +98,14 @@ class ToolbarControllerTest : public CocoaProfileTest {
}
void TearDown() override {
- bar_.reset(); // browser() must outlive the ToolbarController.
+ // Releasing ToolbarController doesn't actually free it at this point, since
+ // the NSViewController retains a reference to it from the nib loading.
+ // As browser() is released in the superclass TearDown, call
+ // -[ToolbarController browserWillBeDestroyed] to prevent a use after free
+ // issue on the |browser_| pointer in LocationBarViewMac when
+ // ToolbarController is actually freed (some time after this method is run).
+ [bar_ browserWillBeDestroyed];
+ bar_.reset();
CocoaProfileTest::TearDown();
}
@@ -346,6 +353,7 @@ TEST_F(ToolbarControllerTest, TranslateBubblePoint) {
TEST_F(ToolbarControllerTest, HoverButtonForEvent) {
base::scoped_nsobject<HitView> view(
[[HitView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
+ NSView* toolbarView = [bar_ view];
[bar_ setView:view];
NSEvent* event = [NSEvent mouseEventWithType:NSMouseMoved
location:NSMakePoint(10,10)
@@ -371,6 +379,10 @@ TEST_F(ToolbarControllerTest, HoverButtonForEvent) {
[[ImageButtonCell alloc] init]);
[button setCell:cell.get()];
EXPECT_TRUE([bar_ hoverButtonForEvent:nil]);
+
+ // Restore the original view so that
+ // -[ToolbarController browserWillBeDestroyed] will run correctly.
+ [bar_ setView:toolbarView];
}
class BrowserRemovedObserver : public chrome::BrowserListObserver {
@@ -386,18 +398,4 @@ class BrowserRemovedObserver : public chrome::BrowserListObserver {
DISALLOW_COPY_AND_ASSIGN(BrowserRemovedObserver);
};
-// Test that ToolbarController can be destroyed after the Browser.
-// This can happen because the ToolbarController is retained by both the
-// BrowserWindowController and -[ToolbarController view], the latter of which is
-// autoreleased.
-TEST_F(ToolbarControllerTest, ToolbarDestroyedAfterBrowser) {
- BrowserRemovedObserver observer;
- // This is normally called by BrowserWindowController, but since |bar_| is not
- // owned by one, call it here.
- [bar_ browserWillBeDestroyed];
- CloseBrowserWindow();
- observer.WaitUntilBrowserRemoved();
- // |bar_| is released in TearDown().
-}
-
} // namespace
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698