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

Side by Side Diff: chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm

Issue 1221173003: [Mac] Inform reference counted objects that hold a weak Browser* when the Browser is being destroye… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 5 months 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "base/mac/scoped_nsobject.h" 7 #import "base/mac/scoped_nsobject.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/command_updater.h" 11 #include "chrome/browser/command_updater.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_command_controller.h" 13 #include "chrome/browser/ui/browser_command_controller.h"
14 #include "chrome/browser/ui/browser_commands.h" 14 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/browser_list.h" 15 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/browser_list_observer.h" 16 #include "chrome/browser/ui/browser_list_observer.h"
17 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 17 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
18 #import "chrome/browser/ui/cocoa/image_button_cell.h" 18 #import "chrome/browser/ui/cocoa/image_button_cell.h"
19 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 19 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
20 #import "chrome/browser/ui/cocoa/view_resizer_pong.h"
21 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
23 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
24 #import "testing/gtest_mac.h" 23 #import "testing/gtest_mac.h"
25 #include "testing/platform_test.h" 24 #include "testing/platform_test.h"
26 25
27 // An NSView that fakes out hitTest:. 26 // An NSView that fakes out hitTest:.
28 @interface HitView : NSView { 27 @interface HitView : NSView {
29 id hitTestReturn_; 28 id hitTestReturn_;
30 } 29 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 void SetUp() override { 77 void SetUp() override {
79 CocoaProfileTest::SetUp(); 78 CocoaProfileTest::SetUp();
80 ASSERT_TRUE(browser()); 79 ASSERT_TRUE(browser());
81 80
82 CommandUpdater* updater = 81 CommandUpdater* updater =
83 browser()->command_controller()->command_updater(); 82 browser()->command_controller()->command_updater();
84 // The default state for the commands is true, set a couple to false to 83 // The default state for the commands is true, set a couple to false to
85 // ensure they get picked up correct on initialization 84 // ensure they get picked up correct on initialization
86 updater->UpdateCommandEnabled(IDC_BACK, false); 85 updater->UpdateCommandEnabled(IDC_BACK, false);
87 updater->UpdateCommandEnabled(IDC_FORWARD, false); 86 updater->UpdateCommandEnabled(IDC_FORWARD, false);
88 resizeDelegate_.reset([[ViewResizerPong alloc] init]);
89 bar_.reset([[TestToolbarController alloc] 87 bar_.reset([[TestToolbarController alloc]
90 initWithCommands:browser()->command_controller()->command_updater() 88 initWithCommands:browser()->command_controller()->command_updater()
91 profile:profile() 89 profile:profile()
92 browser:browser() 90 browser:browser()]);
93 resizeDelegate:resizeDelegate_.get()]);
94 EXPECT_TRUE([bar_ view]); 91 EXPECT_TRUE([bar_ view]);
95 NSView* parent = [test_window() contentView]; 92 NSView* parent = [test_window() contentView];
96 [parent addSubview:[bar_ view]]; 93 [parent addSubview:[bar_ view]];
97 } 94 }
98 95
99 void TearDown() override { 96 void TearDown() override {
100 bar_.reset(); // browser() must outlive the ToolbarController. 97 bar_.reset(); // browser() must outlive the ToolbarController.
101 CocoaProfileTest::TearDown(); 98 CocoaProfileTest::TearDown();
102 } 99 }
103 100
104 // Make sure the enabled state of the view is the same as the corresponding 101 // Make sure the enabled state of the view is the same as the corresponding
105 // command in the updater. The views are in the declaration order of outlets. 102 // command in the updater. The views are in the declaration order of outlets.
106 void CompareState(CommandUpdater* updater, NSArray* views) { 103 void CompareState(CommandUpdater* updater, NSArray* views) {
107 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK), 104 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK),
108 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false); 105 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false);
109 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD), 106 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD),
110 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false); 107 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false);
111 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD), 108 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD),
112 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false); 109 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false);
113 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME), 110 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME),
114 [[views objectAtIndex:kHomeIndex] isEnabled] ? true : false); 111 [[views objectAtIndex:kHomeIndex] isEnabled] ? true : false);
115 } 112 }
116 113
117 base::scoped_nsobject<ViewResizerPong> resizeDelegate_;
118 base::scoped_nsobject<TestToolbarController> bar_; 114 base::scoped_nsobject<TestToolbarController> bar_;
119 }; 115 };
120 116
121 TEST_VIEW(ToolbarControllerTest, [bar_ view]) 117 TEST_VIEW(ToolbarControllerTest, [bar_ view])
122 118
123 // Test the initial state that everything is sync'd up 119 // Test the initial state that everything is sync'd up
124 TEST_F(ToolbarControllerTest, InitialState) { 120 TEST_F(ToolbarControllerTest, InitialState) {
125 CommandUpdater* updater = browser()->command_controller()->command_updater(); 121 CommandUpdater* updater = browser()->command_controller()->command_updater();
126 CompareState(updater, [bar_ toolbarViews]); 122 CompareState(updater, [bar_ toolbarViews]);
127 } 123 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 private: 287 private:
292 base::RunLoop run_loop_; 288 base::RunLoop run_loop_;
293 289
294 DISALLOW_COPY_AND_ASSIGN(BrowserRemovedObserver); 290 DISALLOW_COPY_AND_ASSIGN(BrowserRemovedObserver);
295 }; 291 };
296 292
297 // Test that ToolbarController can be destroyed after the Browser. 293 // Test that ToolbarController can be destroyed after the Browser.
298 // This can happen because the ToolbarController is retained by both the 294 // This can happen because the ToolbarController is retained by both the
299 // BrowserWindowController and -[ToolbarController view], the latter of which is 295 // BrowserWindowController and -[ToolbarController view], the latter of which is
300 // autoreleased. 296 // autoreleased.
301 // TODO(nhiroki): This is disabled due to http://crbug.com/506745. 297 TEST_F(ToolbarControllerTest, ToolbarDestroyedAfterBrowser) {
302 TEST_F(ToolbarControllerTest, DISABLED_ToolbarDestroyedAfterBrowser) {
303 BrowserRemovedObserver observer; 298 BrowserRemovedObserver observer;
299 // This is normally called by BrowserWindowController, but since |bar_| is not
300 // owned by one, call it here.
301 [bar_ browserWillBeDestroyed];
304 CloseBrowserWindow(); 302 CloseBrowserWindow();
305 observer.WaitUntilBrowserRemoved(); 303 observer.WaitUntilBrowserRemoved();
306 // |bar_| is released in TearDown(). 304 // |bar_| is released in TearDown().
307 } 305 }
308 306
309 } // namespace 307 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm ('k') | chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698