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

Side by Side Diff: chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm

Issue 7694014: Reland: Implement correct Panel closing sequence for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed random result of CreateClose unittest caused by using a freed object. Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/panels/panel_browser_window_cocoa.h" 5 #import "chrome/browser/ui/panels/panel_browser_window_cocoa.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/debugger.h" 10 #include "base/debug/debugger.h"
11 #include "base/mac/scoped_nsautorelease_pool.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "chrome/app/chrome_command_ids.h" // IDC_* 13 #include "chrome/app/chrome_command_ids.h" // IDC_*
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_list.h"
13 #import "chrome/browser/ui/cocoa/browser_test_helper.h" 16 #import "chrome/browser/ui/cocoa/browser_test_helper.h"
14 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 17 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
15 #include "chrome/browser/ui/panels/panel.h" 18 #include "chrome/browser/ui/panels/panel.h"
16 #include "chrome/browser/ui/panels/panel_manager.h" 19 #include "chrome/browser/ui/panels/panel_manager.h"
17 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" 20 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h"
18 #import "chrome/browser/ui/panels/panel_window_controller_cocoa.h" 21 #import "chrome/browser/ui/panels/panel_window_controller_cocoa.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
23 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/browser/tab_contents/test_tab_contents.h" 26 #include "content/browser/tab_contents/test_tab_contents.h"
22 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
23 28
24 // Main test class. 29 // Main test class.
25 class PanelBrowserWindowCocoaTest : public CocoaTest { 30 class PanelBrowserWindowCocoaTest : public CocoaTest {
26 public: 31 public:
27 virtual void SetUp() { 32 virtual void SetUp() {
28 CocoaTest::SetUp(); 33 CocoaTest::SetUp();
29 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePanels); 34 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePanels);
30 } 35 }
31 36
32 Panel* CreateTestPanel(const std::string& panel_name) { 37 Panel* CreateTestPanel(const std::string& panel_name) {
38 // Opening panels on a Mac causes NSWindowController of the Panel window
39 // to be autoreleased. We need a pool drained after it's done so the test
40 // can close correctly.
41 base::mac::ScopedNSAutoreleasePool autorelease_pool;
42
43 PanelManager* manager = PanelManager::GetInstance();
44 int panels_count = manager->num_panels();
45
33 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, 46 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL,
34 panel_name, 47 panel_name,
35 gfx::Rect(), 48 gfx::Rect(),
36 browser_helper_.profile()); 49 browser_helper_.profile());
37 50
38 TabContentsWrapper* tab_contents = new TabContentsWrapper( 51 TabContentsWrapper* tab_contents = new TabContentsWrapper(
39 new TestTabContents(browser_helper_.profile(), NULL)); 52 new TestTabContents(browser_helper_.profile(), NULL));
40 panel_browser->AddTab(tab_contents, PageTransition::LINK); 53 panel_browser->AddTab(tab_contents, PageTransition::LINK);
41 54
42 return static_cast<Panel*>(panel_browser->window()); 55 // We just created one new panel.
56 EXPECT_EQ(panels_count + 1, manager->num_panels());
57
58 Panel* panel = static_cast<Panel*>(panel_browser->window());
59 EXPECT_TRUE(panel);
60 EXPECT_TRUE(panel->native_panel()); // Native panel is created right away.
61 PanelBrowserWindowCocoa* native_window =
62 static_cast<PanelBrowserWindowCocoa*>(panel->native_panel());
63 EXPECT_EQ(panel, native_window->panel_); // Back pointer initialized.
64
65 // Window should not load before Show().
66 // Note: Loading the wnidow causes Cocoa to autorelease a few objects.
67 // This is the reason we do this within the scope of the
68 // ScopedNSAutoreleasePool.
69 EXPECT_FALSE([native_window->controller_ isWindowLoaded]);
70 panel->Show();
71 EXPECT_TRUE([native_window->controller_ isWindowLoaded]);
72 EXPECT_TRUE([native_window->controller_ window]);
73
74 return panel;
43 } 75 }
44 76
45 void VerifyTitlebarLocation(NSView* contentView, NSView* titlebar) { 77 void VerifyTitlebarLocation(NSView* contentView, NSView* titlebar) {
46 NSRect content_frame = [contentView frame]; 78 NSRect content_frame = [contentView frame];
47 NSRect titlebar_frame = [titlebar frame]; 79 NSRect titlebar_frame = [titlebar frame];
48 // Since contentView and titlebar are both children of window's root view, 80 // Since contentView and titlebar are both children of window's root view,
49 // we can compare their frames since they are in the same coordinate system. 81 // we can compare their frames since they are in the same coordinate system.
50 EXPECT_EQ(NSMinX(content_frame), NSMinX(titlebar_frame)); 82 EXPECT_EQ(NSMinX(content_frame), NSMinX(titlebar_frame));
51 EXPECT_EQ(NSWidth(content_frame), NSWidth(titlebar_frame)); 83 EXPECT_EQ(NSWidth(content_frame), NSWidth(titlebar_frame));
52 EXPECT_EQ(NSMaxY(content_frame), NSMinY(titlebar_frame)); 84 EXPECT_EQ(NSMaxY(content_frame), NSMinY(titlebar_frame));
53 EXPECT_EQ(NSHeight([[titlebar superview] bounds]), NSMaxY(titlebar_frame)); 85 EXPECT_EQ(NSHeight([[titlebar superview] bounds]), NSMaxY(titlebar_frame));
54 } 86 }
55 87
88 void ClosePanelAndWait(Browser* browser) {
89 EXPECT_TRUE(browser);
90 // Closing a browser window may involve several async tasks. Need to use
91 // message pump and wait for the notification.
92 size_t browser_count = BrowserList::size();
93 ui_test_utils::WindowedNotificationObserver signal(
94 chrome::NOTIFICATION_BROWSER_CLOSED,
95 Source<Browser>(browser));
96 browser->CloseWindow();
97 signal.Wait();
98 // Now we have one less browser instance.
99 EXPECT_EQ(browser_count - 1, BrowserList::size());
100 }
101
56 NSMenuItem* CreateMenuItem(NSMenu* menu, int command_id) { 102 NSMenuItem* CreateMenuItem(NSMenu* menu, int command_id) {
57 NSMenuItem* item = 103 NSMenuItem* item =
58 [menu addItemWithTitle:@"" 104 [menu addItemWithTitle:@""
59 action:@selector(commandDispatch:) 105 action:@selector(commandDispatch:)
60 keyEquivalent:@""]; 106 keyEquivalent:@""];
61 [item setTag:command_id]; 107 [item setTag:command_id];
62 return item; 108 return item;
63 } 109 }
64 110
65 private: 111 private:
66 BrowserTestHelper browser_helper_; 112 BrowserTestHelper browser_helper_;
67 }; 113 };
68 114
69 TEST_F(PanelBrowserWindowCocoaTest, CreateClose) { 115 TEST_F(PanelBrowserWindowCocoaTest, CreateClose) {
70 PanelManager* manager = PanelManager::GetInstance(); 116 PanelManager* manager = PanelManager::GetInstance();
71 EXPECT_EQ(0, manager->num_panels()); // No panels initially. 117 EXPECT_EQ(0, manager->num_panels()); // No panels initially.
72 118
73 Panel* panel = CreateTestPanel("Test Panel"); 119 Panel* panel = CreateTestPanel("Test Panel");
74 EXPECT_TRUE(panel); 120 ASSERT_TRUE(panel);
75 EXPECT_TRUE(panel->native_panel()); // Native panel is created right away.
76 PanelBrowserWindowCocoa* native_window =
77 static_cast<PanelBrowserWindowCocoa*>(panel->native_panel());
78
79 EXPECT_EQ(panel, native_window->panel_); // Back pointer initialized.
80 EXPECT_EQ(1, manager->num_panels());
81
82 // Window should not load before Show()
83 EXPECT_FALSE([native_window->controller_ isWindowLoaded]);
84 panel->Show();
85 EXPECT_TRUE([native_window->controller_ isWindowLoaded]);
86 EXPECT_TRUE([native_window->controller_ window]);
87 121
88 gfx::Rect bounds = panel->GetBounds(); 122 gfx::Rect bounds = panel->GetBounds();
89 EXPECT_TRUE(bounds.width() > 0); 123 EXPECT_TRUE(bounds.width() > 0);
90 EXPECT_TRUE(bounds.height() > 0); 124 EXPECT_TRUE(bounds.height() > 0);
91 125
126 PanelBrowserWindowCocoa* native_window =
127 static_cast<PanelBrowserWindowCocoa*>(panel->native_panel());
128 ASSERT_TRUE(native_window);
92 // NSWindows created by NSWindowControllers don't have this bit even if 129 // NSWindows created by NSWindowControllers don't have this bit even if
93 // their NIB has it. The controller's lifetime is the window's lifetime. 130 // their NIB has it. The controller's lifetime is the window's lifetime.
94 EXPECT_EQ(NO, [[native_window->controller_ window] isReleasedWhenClosed]); 131 EXPECT_EQ(NO, [[native_window->controller_ window] isReleasedWhenClosed]);
95 132
96 panel->Close(); 133 ASSERT_TRUE(panel->browser());
134 ClosePanelAndWait(panel->browser());
97 EXPECT_EQ(0, manager->num_panels()); 135 EXPECT_EQ(0, manager->num_panels());
98 // Close() destroys the controller, which destroys the NSWindow. CocoaTest
99 // base class verifies that there is no remaining open windows after the test.
100 EXPECT_FALSE(native_window->controller_);
101 } 136 }
102 137
103 TEST_F(PanelBrowserWindowCocoaTest, AssignedBounds) { 138 TEST_F(PanelBrowserWindowCocoaTest, AssignedBounds) {
104 PanelManager* manager = PanelManager::GetInstance();
105 Panel* panel1 = CreateTestPanel("Test Panel 1"); 139 Panel* panel1 = CreateTestPanel("Test Panel 1");
106 Panel* panel2 = CreateTestPanel("Test Panel 2"); 140 Panel* panel2 = CreateTestPanel("Test Panel 2");
107 Panel* panel3 = CreateTestPanel("Test Panel 3"); 141 Panel* panel3 = CreateTestPanel("Test Panel 3");
108 EXPECT_EQ(3, manager->num_panels());
109
110 panel1->Show();
111 panel2->Show();
112 panel3->Show();
113 142
114 gfx::Rect bounds1 = panel1->GetBounds(); 143 gfx::Rect bounds1 = panel1->GetBounds();
115 gfx::Rect bounds2 = panel2->GetBounds(); 144 gfx::Rect bounds2 = panel2->GetBounds();
116 gfx::Rect bounds3 = panel3->GetBounds(); 145 gfx::Rect bounds3 = panel3->GetBounds();
117 146
118 // This checks panelManager calculating and assigning bounds right. 147 // This checks panelManager calculating and assigning bounds right.
119 // Panels should stack on the bottom right to left. 148 // Panels should stack on the bottom right to left.
120 EXPECT_LT(bounds3.x() + bounds3.width(), bounds2.x()); 149 EXPECT_LT(bounds3.x() + bounds3.width(), bounds2.x());
121 EXPECT_LT(bounds2.x() + bounds2.width(), bounds1.x()); 150 EXPECT_LT(bounds2.x() + bounds2.width(), bounds1.x());
122 EXPECT_EQ(bounds1.y(), bounds2.y()); 151 EXPECT_EQ(bounds1.y(), bounds2.y());
123 EXPECT_EQ(bounds2.y(), bounds3.y()); 152 EXPECT_EQ(bounds2.y(), bounds3.y());
124 153
125 // After panel2 is closed, panel3 should take its place. 154 // After panel2 is closed, panel3 should take its place.
126 panel2->Close(); 155 ClosePanelAndWait(panel2->browser());
127 bounds3 = panel3->GetBounds(); 156 bounds3 = panel3->GetBounds();
128 EXPECT_EQ(bounds2, bounds3); 157 EXPECT_EQ(bounds2, bounds3);
129 EXPECT_EQ(2, manager->num_panels());
130 158
131 // After panel1 is closed, panel3 should take its place. 159 // After panel1 is closed, panel3 should take its place.
132 panel1->Close(); 160 ClosePanelAndWait(panel1->browser());
133 EXPECT_EQ(bounds1, panel3->GetBounds()); 161 EXPECT_EQ(bounds1, panel3->GetBounds());
134 EXPECT_EQ(1, manager->num_panels());
135 162
136 panel3->Close(); 163 ClosePanelAndWait(panel3->browser());
137 EXPECT_EQ(0, manager->num_panels());
138 } 164 }
139 165
140 // Same test as AssignedBounds, but checks actual bounds on native OS windows. 166 // Same test as AssignedBounds, but checks actual bounds on native OS windows.
141 TEST_F(PanelBrowserWindowCocoaTest, NativeBounds) { 167 TEST_F(PanelBrowserWindowCocoaTest, NativeBounds) {
142 PanelManager* manager = PanelManager::GetInstance();
143 Panel* panel1 = CreateTestPanel("Test Panel 1"); 168 Panel* panel1 = CreateTestPanel("Test Panel 1");
144 Panel* panel2 = CreateTestPanel("Test Panel 2"); 169 Panel* panel2 = CreateTestPanel("Test Panel 2");
145 Panel* panel3 = CreateTestPanel("Test Panel 3"); 170 Panel* panel3 = CreateTestPanel("Test Panel 3");
146 EXPECT_EQ(3, manager->num_panels());
147
148 panel1->Show();
149 panel2->Show();
150 panel3->Show();
151 171
152 PanelBrowserWindowCocoa* native_window1 = 172 PanelBrowserWindowCocoa* native_window1 =
153 static_cast<PanelBrowserWindowCocoa*>(panel1->native_panel()); 173 static_cast<PanelBrowserWindowCocoa*>(panel1->native_panel());
154 PanelBrowserWindowCocoa* native_window2 = 174 PanelBrowserWindowCocoa* native_window2 =
155 static_cast<PanelBrowserWindowCocoa*>(panel2->native_panel()); 175 static_cast<PanelBrowserWindowCocoa*>(panel2->native_panel());
156 PanelBrowserWindowCocoa* native_window3 = 176 PanelBrowserWindowCocoa* native_window3 =
157 static_cast<PanelBrowserWindowCocoa*>(panel3->native_panel()); 177 static_cast<PanelBrowserWindowCocoa*>(panel3->native_panel());
158 178
159 NSRect bounds1 = [[native_window1->controller_ window] frame]; 179 NSRect bounds1 = [[native_window1->controller_ window] frame];
160 NSRect bounds2 = [[native_window2->controller_ window] frame]; 180 NSRect bounds2 = [[native_window2->controller_ window] frame];
161 NSRect bounds3 = [[native_window3->controller_ window] frame]; 181 NSRect bounds3 = [[native_window3->controller_ window] frame];
162 182
163 EXPECT_LT(bounds3.origin.x + bounds3.size.width, bounds2.origin.x); 183 EXPECT_LT(bounds3.origin.x + bounds3.size.width, bounds2.origin.x);
164 EXPECT_LT(bounds2.origin.x + bounds2.size.width, bounds1.origin.x); 184 EXPECT_LT(bounds2.origin.x + bounds2.size.width, bounds1.origin.x);
165 EXPECT_EQ(bounds1.origin.y, bounds2.origin.y); 185 EXPECT_EQ(bounds1.origin.y, bounds2.origin.y);
166 EXPECT_EQ(bounds2.origin.y, bounds3.origin.y); 186 EXPECT_EQ(bounds2.origin.y, bounds3.origin.y);
167 187
168 // After panel2 is closed, panel3 should take its place. 188 // After panel2 is closed, panel3 should take its place.
169 panel2->Close(); 189 ClosePanelAndWait(panel2->browser());
170 bounds3 = [[native_window3->controller_ window] frame]; 190 bounds3 = [[native_window3->controller_ window] frame];
171 EXPECT_EQ(bounds2.origin.x, bounds3.origin.x); 191 EXPECT_EQ(bounds2.origin.x, bounds3.origin.x);
172 EXPECT_EQ(bounds2.origin.y, bounds3.origin.y); 192 EXPECT_EQ(bounds2.origin.y, bounds3.origin.y);
173 EXPECT_EQ(bounds2.size.width, bounds3.size.width); 193 EXPECT_EQ(bounds2.size.width, bounds3.size.width);
174 EXPECT_EQ(bounds2.size.height, bounds3.size.height); 194 EXPECT_EQ(bounds2.size.height, bounds3.size.height);
175 EXPECT_EQ(2, manager->num_panels());
176 195
177 // After panel1 is closed, panel3 should take its place. 196 // After panel1 is closed, panel3 should take its place.
178 panel1->Close(); 197 ClosePanelAndWait(panel1->browser());
179 bounds3 = [[native_window3->controller_ window] frame]; 198 bounds3 = [[native_window3->controller_ window] frame];
180 EXPECT_EQ(bounds1.origin.x, bounds3.origin.x); 199 EXPECT_EQ(bounds1.origin.x, bounds3.origin.x);
181 EXPECT_EQ(bounds1.origin.y, bounds3.origin.y); 200 EXPECT_EQ(bounds1.origin.y, bounds3.origin.y);
182 EXPECT_EQ(bounds1.size.width, bounds3.size.width); 201 EXPECT_EQ(bounds1.size.width, bounds3.size.width);
183 EXPECT_EQ(bounds1.size.height, bounds3.size.height); 202 EXPECT_EQ(bounds1.size.height, bounds3.size.height);
184 EXPECT_EQ(1, manager->num_panels());
185 203
186 panel3->Close(); 204 ClosePanelAndWait(panel3->browser());
187 EXPECT_EQ(0, manager->num_panels());
188 } 205 }
189 206
190 // Verify the titlebar is being created. 207 // Verify the titlebar is being created.
191 TEST_F(PanelBrowserWindowCocoaTest, TitlebarViewCreate) { 208 TEST_F(PanelBrowserWindowCocoaTest, TitlebarViewCreate) {
192 Panel* panel = CreateTestPanel("Test Panel"); 209 Panel* panel = CreateTestPanel("Test Panel");
193 panel->Show();
194 210
195 PanelBrowserWindowCocoa* native_window = 211 PanelBrowserWindowCocoa* native_window =
196 static_cast<PanelBrowserWindowCocoa*>(panel->native_panel()); 212 static_cast<PanelBrowserWindowCocoa*>(panel->native_panel());
197 213
198 PanelTitlebarViewCocoa* titlebar = [native_window->controller_ titlebarView]; 214 PanelTitlebarViewCocoa* titlebar = [native_window->controller_ titlebarView];
199 EXPECT_TRUE(titlebar); 215 EXPECT_TRUE(titlebar);
200 EXPECT_EQ(native_window->controller_, [titlebar controller]); 216 EXPECT_EQ(native_window->controller_, [titlebar controller]);
201 217
202 panel->Close(); 218 ClosePanelAndWait(panel->browser());
203 } 219 }
204 220
205 // Verify the sizing of titlebar - should be affixed on top of regular titlebar. 221 // Verify the sizing of titlebar - should be affixed on top of regular titlebar.
206 TEST_F(PanelBrowserWindowCocoaTest, TitlebarViewSizing) { 222 TEST_F(PanelBrowserWindowCocoaTest, TitlebarViewSizing) {
207 Panel* panel = CreateTestPanel("Test Panel"); 223 Panel* panel = CreateTestPanel("Test Panel");
208 panel->Show();
209 224
210 PanelBrowserWindowCocoa* native_window = 225 PanelBrowserWindowCocoa* native_window =
211 static_cast<PanelBrowserWindowCocoa*>(panel->native_panel()); 226 static_cast<PanelBrowserWindowCocoa*>(panel->native_panel());
212 PanelTitlebarViewCocoa* titlebar = [native_window->controller_ titlebarView]; 227 PanelTitlebarViewCocoa* titlebar = [native_window->controller_ titlebarView];
213 228
214 NSView* contentView = [[native_window->controller_ window] contentView]; 229 NSView* contentView = [[native_window->controller_ window] contentView];
215 VerifyTitlebarLocation(contentView, titlebar); 230 VerifyTitlebarLocation(contentView, titlebar);
216 231
217 // In local coordinate system, width of titlebar should match width of 232 // In local coordinate system, width of titlebar should match width of
218 // content view of the window. They both use the same scale factor. 233 // content view of the window. They both use the same scale factor.
(...skipping 10 matching lines...) Expand all
229 native_window->SetPanelBounds(bounds); 244 native_window->SetPanelBounds(bounds);
230 245
231 // Verify the panel resized. 246 // Verify the panel resized.
232 NSRect window_frame = [[native_window->controller_ window] frame]; 247 NSRect window_frame = [[native_window->controller_ window] frame];
233 EXPECT_EQ(NSWidth(window_frame), bounds.width()); 248 EXPECT_EQ(NSWidth(window_frame), bounds.width());
234 EXPECT_EQ(NSHeight(window_frame), bounds.height()); 249 EXPECT_EQ(NSHeight(window_frame), bounds.height());
235 250
236 // Verify the titlebar is still on top of regular titlebar. 251 // Verify the titlebar is still on top of regular titlebar.
237 VerifyTitlebarLocation(contentView, titlebar); 252 VerifyTitlebarLocation(contentView, titlebar);
238 253
239 panel->Close(); 254 ClosePanelAndWait(panel->browser());
240 } 255 }
241 256
242 // Verify closing behavior of titlebar close button. 257 // Verify closing behavior of titlebar close button.
243 TEST_F(PanelBrowserWindowCocoaTest, TitlebarViewClose) { 258 TEST_F(PanelBrowserWindowCocoaTest, TitlebarViewClose) {
244 PanelManager* manager = PanelManager::GetInstance();
245 Panel* panel = CreateTestPanel("Test Panel"); 259 Panel* panel = CreateTestPanel("Test Panel");
246 panel->Show();
247 260
248 PanelBrowserWindowCocoa* native_window = 261 PanelBrowserWindowCocoa* native_window =
249 static_cast<PanelBrowserWindowCocoa*>(panel->native_panel()); 262 static_cast<PanelBrowserWindowCocoa*>(panel->native_panel());
250 263
251 PanelTitlebarViewCocoa* titlebar = [native_window->controller_ titlebarView]; 264 PanelTitlebarViewCocoa* titlebar = [native_window->controller_ titlebarView];
252 EXPECT_TRUE(titlebar); 265 EXPECT_TRUE(titlebar);
253 266
267 PanelManager* manager = PanelManager::GetInstance();
254 EXPECT_EQ(1, manager->num_panels()); 268 EXPECT_EQ(1, manager->num_panels());
255 // Simulate clicking Close Button. This should close the Panel as well. 269 // Simulate clicking Close Button and wait until the Panel closes.
270 ui_test_utils::WindowedNotificationObserver signal(
271 chrome::NOTIFICATION_BROWSER_CLOSED,
272 Source<Browser>(panel->browser()));
256 [titlebar simulateCloseButtonClick]; 273 [titlebar simulateCloseButtonClick];
274 signal.Wait();
257 EXPECT_EQ(0, manager->num_panels()); 275 EXPECT_EQ(0, manager->num_panels());
258 } 276 }
259 277
260 // Verify some menu items being properly enabled/disabled for panels. 278 // Verify some menu items being properly enabled/disabled for panels.
261 TEST_F(PanelBrowserWindowCocoaTest, MenuItems) { 279 TEST_F(PanelBrowserWindowCocoaTest, MenuItems) {
262 Panel* panel = CreateTestPanel("Test Panel"); 280 Panel* panel = CreateTestPanel("Test Panel");
263 panel->Show();
264 281
265 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); 282 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]);
266 NSMenuItem* close_tab_menu_item = CreateMenuItem(menu, IDC_CLOSE_TAB); 283 NSMenuItem* close_tab_menu_item = CreateMenuItem(menu, IDC_CLOSE_TAB);
267 NSMenuItem* close_window_menu_item = CreateMenuItem(menu, IDC_CLOSE_WINDOW); 284 NSMenuItem* close_window_menu_item = CreateMenuItem(menu, IDC_CLOSE_WINDOW);
268 NSMenuItem* find_menu_item = CreateMenuItem(menu, IDC_FIND); 285 NSMenuItem* find_menu_item = CreateMenuItem(menu, IDC_FIND);
269 NSMenuItem* find_previous_menu_item = CreateMenuItem(menu, IDC_FIND_PREVIOUS); 286 NSMenuItem* find_previous_menu_item = CreateMenuItem(menu, IDC_FIND_PREVIOUS);
270 NSMenuItem* find_next_menu_item = CreateMenuItem(menu, IDC_FIND_NEXT); 287 NSMenuItem* find_next_menu_item = CreateMenuItem(menu, IDC_FIND_NEXT);
271 NSMenuItem* fullscreen_menu_item = CreateMenuItem(menu, IDC_FULLSCREEN); 288 NSMenuItem* fullscreen_menu_item = CreateMenuItem(menu, IDC_FULLSCREEN);
272 NSMenuItem* presentation_menu_item = 289 NSMenuItem* presentation_menu_item =
273 CreateMenuItem(menu, IDC_PRESENTATION_MODE); 290 CreateMenuItem(menu, IDC_PRESENTATION_MODE);
274 NSMenuItem* bookmarks_menu_item = CreateMenuItem(menu, IDC_SYNC_BOOKMARKS); 291 NSMenuItem* bookmarks_menu_item = CreateMenuItem(menu, IDC_SYNC_BOOKMARKS);
275 292
276 PanelBrowserWindowCocoa* native_window = 293 PanelBrowserWindowCocoa* native_window =
277 static_cast<PanelBrowserWindowCocoa*>(panel->native_panel()); 294 static_cast<PanelBrowserWindowCocoa*>(panel->native_panel());
278 PanelWindowControllerCocoa* panel_controller = native_window->controller_; 295 PanelWindowControllerCocoa* panel_controller = native_window->controller_;
279 for (NSMenuItem *item in [menu itemArray]) 296 for (NSMenuItem *item in [menu itemArray])
280 [item setTarget:panel_controller]; 297 [item setTarget:panel_controller];
281 298
282 [menu update]; // Trigger validation of menu items. 299 [menu update]; // Trigger validation of menu items.
283 EXPECT_FALSE([close_tab_menu_item isEnabled]); 300 EXPECT_FALSE([close_tab_menu_item isEnabled]);
284 EXPECT_TRUE([close_window_menu_item isEnabled]); 301 EXPECT_TRUE([close_window_menu_item isEnabled]);
285 EXPECT_TRUE([find_menu_item isEnabled]); 302 EXPECT_TRUE([find_menu_item isEnabled]);
286 EXPECT_TRUE([find_previous_menu_item isEnabled]); 303 EXPECT_TRUE([find_previous_menu_item isEnabled]);
287 EXPECT_TRUE([find_next_menu_item isEnabled]); 304 EXPECT_TRUE([find_next_menu_item isEnabled]);
288 EXPECT_FALSE([fullscreen_menu_item isEnabled]); 305 EXPECT_FALSE([fullscreen_menu_item isEnabled]);
289 EXPECT_FALSE([presentation_menu_item isEnabled]); 306 EXPECT_FALSE([presentation_menu_item isEnabled]);
290 EXPECT_FALSE([bookmarks_menu_item isEnabled]); 307 EXPECT_FALSE([bookmarks_menu_item isEnabled]);
291 308
292 panel->Close(); 309 ClosePanelAndWait(panel->browser());
293 } 310 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_window_cocoa.mm ('k') | chrome/browser/ui/panels/panel_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698