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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm

Issue 11876036: Alternate NTP: Don't hide bookmark bar on instant (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more test Created 7 years, 11 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) 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 "chrome/browser/ui/cocoa/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #import "base/mac/mac_util.h" 7 #import "base/mac/mac_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
11 #include "chrome/browser/api/infobars/infobar_service.h"
10 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/ui/browser_tabstrip.h"
11 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" 18 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
19 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
16 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" 20 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h"
21 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
22 #import "chrome/browser/ui/cocoa/nsview_additions.h"
23 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h"
24 #include "chrome/browser/ui/search/search.h"
25 #include "chrome/browser/ui/search/search_model.h"
17 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
27 #include "content/public/browser/web_contents.h"
28 #import "testing/gtest_mac.h"
29
30 namespace {
18 31
19 #if !defined(MAC_OS_X_VERSION_10_7) || \ 32 #if !defined(MAC_OS_X_VERSION_10_7) || \
20 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 33 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
21 enum { 34 enum {
22 NSWindowDocumentVersionsButton = 6, 35 NSWindowDocumentVersionsButton = 6,
23 NSWindowFullScreenButton 36 NSWindowFullScreenButton
24 }; 37 };
25 #endif // MAC_OS_X_VERSION_10_7 38 #endif // MAC_OS_X_VERSION_10_7
26 39
27 typedef InProcessBrowserTest BrowserWindowControllerTest;
28
29 void CreateProfileCallback(const base::Closure& quit_closure, 40 void CreateProfileCallback(const base::Closure& quit_closure,
30 Profile* profile, 41 Profile* profile,
31 Profile::CreateStatus status) { 42 Profile::CreateStatus status) {
32 EXPECT_TRUE(profile); 43 EXPECT_TRUE(profile);
33 EXPECT_NE(Profile::CREATE_STATUS_FAIL, status); 44 EXPECT_NE(Profile::CREATE_STATUS_FAIL, status);
34 // This will be called multiple times. Wait until the profile is initialized 45 // This will be called multiple times. Wait until the profile is initialized
35 // fully to quit the loop. 46 // fully to quit the loop.
36 if (status == Profile::CREATE_STATUS_INITIALIZED) 47 if (status == Profile::CREATE_STATUS_INITIALIZED)
37 quit_closure.Run(); 48 quit_closure.Run();
38 } 49 }
39 50
51 enum ViewID {
52 VIEW_ID_TOOLBAR, // 0
dhollowa 2013/01/18 00:55:11 I'm not a fan of the numbers in the comments. I'd
sail 2013/01/18 01:37:09 Done. Oops, that was just for debugging. Removed.
53 VIEW_ID_BOOKMARK_BAR, // 1
54 VIEW_ID_INFO_BAR, // 2
55 VIEW_ID_FIND_BAR, // 3
56 VIEW_ID_DOWNLOAD_SHELF, // 4
57 VIEW_ID_TAB_CONTENT_AREA, // 5
58 VIEW_ID_FULLSCREEN_FLOATING_BAR, // 6
59 VIEW_ID_COUNT,
60 };
61
62 class DummyInfoBar : public ConfirmInfoBarDelegate {
dhollowa 2013/01/18 00:55:11 Small doc please.
sail 2013/01/18 01:37:09 Done.
63 public:
64 DummyInfoBar(InfoBarService* service) : ConfirmInfoBarDelegate(service) {
dhollowa 2013/01/18 00:55:11 explicit
sail 2013/01/18 01:37:09 Done.
65 }
66
67 virtual ~DummyInfoBar() {
68 }
69
70 virtual string16 GetMessageText() const OVERRIDE {
71 return string16();
72 }
73 };
dhollowa 2013/01/18 00:55:11 DISALLOW_...
sail 2013/01/18 01:37:09 Done.
74
75 } // namespace
76
77 class BrowserWindowControllerTest : public InProcessBrowserTest {
78 public:
79 BrowserWindowControllerTest() : InProcessBrowserTest() {
80 }
81
82 virtual void SetUpOnMainThread() OVERRIDE {
83 [[controller() bookmarkBarController] setStateAnimationsEnabled:NO];
84 [[controller() bookmarkBarController] setInnerContentAnimationsEnabled:NO];
85 }
86
87 virtual void CleanUpOnMainThread() OVERRIDE {
88 if (web_contents_)
89 browser()->search_model()->set_web_contents(NULL);
90 }
91
92 BrowserWindowController* controller() const {
93 return [BrowserWindowController browserWindowControllerForWindow:
94 browser()->window()->GetNativeWindow()];
95 }
96
97 void ShowInstantResults() {
98 chrome::search::EnableInstantExtendedAPIForTesting();
99 web_contents_.reset(content::WebContents::Create(
100 content::WebContents::CreateParams(browser()->profile())));
101 browser()->search_model()->set_web_contents(web_contents_.get());
102 chrome::search::Mode mode(chrome::search::Mode::MODE_SEARCH_SUGGESTIONS,
103 chrome::search::Mode::ORIGIN_SEARCH);
104 browser()->search_model()->SetMode(mode);
105 EXPECT_TRUE(browser()->search_model()->mode().is_search_suggestions());
106 EXPECT_TRUE([controller() isShowingInstantResults]);
107 }
108
109 void ShowInstantNTP() {
110 chrome::search::EnableInstantExtendedAPIForTesting();
111 web_contents_.reset(content::WebContents::Create(
112 content::WebContents::CreateParams(browser()->profile())));
113 browser()->search_model()->set_web_contents(web_contents_.get());
114 chrome::search::Mode mode(chrome::search::Mode::MODE_NTP,
115 chrome::search::Mode::ORIGIN_NTP);
116 browser()->search_model()->SetMode(mode);
117 EXPECT_TRUE(browser()->search_model()->mode().is_ntp());
118 EXPECT_FALSE([controller() isShowingInstantResults]);
119 }
120
121 void ShowInfoBar() {
122 content::WebContents* web_contents =
123 chrome::GetActiveWebContents(browser());
124 InfoBarService* service =
125 InfoBarService::FromWebContents(web_contents);
126 service->AddInfoBar(scoped_ptr<InfoBarDelegate>(new DummyInfoBar(service)));
127 }
128
129 NSView* GetViewWithID(ViewID view_id) const {
130 switch (view_id) {
131 case VIEW_ID_FULLSCREEN_FLOATING_BAR:
132 return [controller() floatingBarBackingView];
133 case VIEW_ID_TOOLBAR:
134 return [[controller() toolbarController] view];
135 case VIEW_ID_BOOKMARK_BAR:
136 return [[controller() bookmarkBarController] view];
137 case VIEW_ID_INFO_BAR:
138 return [[controller() infoBarContainerController] view];
139 case VIEW_ID_FIND_BAR:
140 return [[controller() findBarCocoaController] view];
141 case VIEW_ID_DOWNLOAD_SHELF:
142 return [[controller() downloadShelf] view];
143 case VIEW_ID_TAB_CONTENT_AREA:
144 return [controller() tabContentArea];
145 default:
146 NOTREACHED();
147 return nil;
148 }
149 }
150
151 void VerifyZOrder(const std::vector<ViewID>& view_list) const {
152 for (size_t i = 0; i < view_list.size() - 1; ++i) {
153 NSView* bottom_view = GetViewWithID(view_list[i]);
154 NSView* top_view = GetViewWithID(view_list[i + 1]);
155 EXPECT_NSEQ([bottom_view superview], [top_view superview]);
156 EXPECT_TRUE([bottom_view cr_isBelowView:top_view]);
157 }
158
159 // Views not in |view_list| must either be nil or not parented.
160 for (size_t i = 0; i < VIEW_ID_COUNT; ++i) {
161 if (std::find(view_list.begin(), view_list.end(), i) == view_list.end()) {
162 NSView* view = GetViewWithID(static_cast<ViewID>(i));
163 EXPECT_TRUE(!view || ![view superview]);
164 }
165 }
166 }
167
168 CGFloat GetViewHeight(ViewID viewID) const {
169 return NSHeight([GetViewWithID(viewID) frame]);
170 }
171
172 private:
173 scoped_ptr<content::WebContents> web_contents_;
174
175 DISALLOW_COPY_AND_ASSIGN(BrowserWindowControllerTest);
176 };
177
40 // Tests that adding the first profile moves the Lion fullscreen button over 178 // Tests that adding the first profile moves the Lion fullscreen button over
41 // correctly. 179 // correctly.
42 // DISABLED_ because it regularly times out: http://crbug.com/159002. 180 // DISABLED_ because it regularly times out: http://crbug.com/159002.
43 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, 181 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
44 DISABLED_ProfileAvatarFullscreenButton) { 182 DISABLED_ProfileAvatarFullscreenButton) {
45 if (base::mac::IsOSSnowLeopard()) 183 if (base::mac::IsOSSnowLeopard())
46 return; 184 return;
47 185
48 // Initialize the locals. 186 // Initialize the locals.
49 ProfileManager* profile_manager = g_browser_process->profile_manager(); 187 ProfileManager* profile_manager = g_browser_process->profile_manager();
50 ASSERT_TRUE(profile_manager); 188 ASSERT_TRUE(profile_manager);
51 189
52 NSWindow* window = browser()->window()->GetNativeWindow(); 190 NSWindow* window = browser()->window()->GetNativeWindow();
53 ASSERT_TRUE(window); 191 ASSERT_TRUE(window);
54 192
55 BrowserWindowController* controller =
56 static_cast<BrowserWindowCocoa*>(browser()->window())->cocoa_controller();
57
58 // With only one profile, the fullscreen button should be visible, but the 193 // With only one profile, the fullscreen button should be visible, but the
59 // avatar button should not. 194 // avatar button should not.
60 EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles()); 195 EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles());
61 196
62 NSButton* fullscreen_button = 197 NSButton* fullscreen_button =
63 [window standardWindowButton:NSWindowFullScreenButton]; 198 [window standardWindowButton:NSWindowFullScreenButton];
64 EXPECT_TRUE(fullscreen_button); 199 EXPECT_TRUE(fullscreen_button);
65 EXPECT_FALSE([fullscreen_button isHidden]); 200 EXPECT_FALSE([fullscreen_button isHidden]);
66 201
67 AvatarButtonController* avatar_controller = 202 AvatarButtonController* avatar_controller =
68 [controller avatarButtonController]; 203 [controller() avatarButtonController];
69 NSView* avatar = [avatar_controller view]; 204 NSView* avatar = [avatar_controller view];
70 EXPECT_TRUE(avatar); 205 EXPECT_TRUE(avatar);
71 EXPECT_TRUE([avatar isHidden]); 206 EXPECT_TRUE([avatar isHidden]);
72 207
73 // Create a profile asynchronously and run the loop until its creation 208 // Create a profile asynchronously and run the loop until its creation
74 // is complete. 209 // is complete.
75 base::RunLoop run_loop; 210 base::RunLoop run_loop;
76 211
77 ProfileManager::CreateCallback create_callback = 212 ProfileManager::CreateCallback create_callback =
78 base::Bind(&CreateProfileCallback, run_loop.QuitClosure()); 213 base::Bind(&CreateProfileCallback, run_loop.QuitClosure());
(...skipping 14 matching lines...) Expand all
93 EXPECT_EQ([avatar window], [fullscreen_button window]); 228 EXPECT_EQ([avatar window], [fullscreen_button window]);
94 229
95 // Make sure the visual order of the buttons is correct and that they don't 230 // Make sure the visual order of the buttons is correct and that they don't
96 // overlap. 231 // overlap.
97 NSRect avatar_frame = [avatar frame]; 232 NSRect avatar_frame = [avatar frame];
98 NSRect fullscreen_frame = [fullscreen_button frame]; 233 NSRect fullscreen_frame = [fullscreen_button frame];
99 234
100 EXPECT_LT(NSMinX(fullscreen_frame), NSMinX(avatar_frame)); 235 EXPECT_LT(NSMinX(fullscreen_frame), NSMinX(avatar_frame));
101 EXPECT_LT(NSMaxX(fullscreen_frame), NSMinX(avatar_frame)); 236 EXPECT_LT(NSMaxX(fullscreen_frame), NSMinX(avatar_frame));
102 } 237 }
238
239 // Verify that in non-instant normal mode that the find bar and download shelf
240 // are above the content area. Everything else should be below it.
241 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormal) {
242 browser()->GetFindBarController(); // add find bar
243
244 std::vector<ViewID> view_list;
245 view_list.push_back(VIEW_ID_BOOKMARK_BAR);
246 view_list.push_back(VIEW_ID_TOOLBAR);
247 view_list.push_back(VIEW_ID_INFO_BAR);
248 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA);
249 view_list.push_back(VIEW_ID_FIND_BAR);
250 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF);
251 VerifyZOrder(view_list);
252 }
253
254 // Verify that in non-instant presentation mode that the info bar is below the
255 // content are and everything else is above it.
256 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderPresentationMode) {
257 browser()->TogglePresentationMode();
258 browser()->GetFindBarController(); // add find bar
259
260 std::vector<ViewID> view_list;
261 view_list.push_back(VIEW_ID_INFO_BAR);
262 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA);
263 view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR);
264 view_list.push_back(VIEW_ID_BOOKMARK_BAR);
265 view_list.push_back(VIEW_ID_TOOLBAR);
266 view_list.push_back(VIEW_ID_FIND_BAR);
267 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF);
268 VerifyZOrder(view_list);
269 }
270
271 // Normal mode with instant results showing. Should be same zorder as normal
272 // mode except find bar is below content area.
273 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormalInstant) {
274 ShowInstantResults();
275 browser()->GetFindBarController(); // add find bar
276
277 std::vector<ViewID> view_list;
278 view_list.push_back(VIEW_ID_BOOKMARK_BAR);
279 view_list.push_back(VIEW_ID_TOOLBAR);
280 view_list.push_back(VIEW_ID_INFO_BAR);
281 view_list.push_back(VIEW_ID_FIND_BAR);
282 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA);
283 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF);
284 VerifyZOrder(view_list);
285 }
286
287 // Presentation mode with instant results showing. Should be exact same as
288 // non-instant presentation mode.
289 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
290 ZOrderInstantPresentationMode) {
291 browser()->TogglePresentationMode();
292 ShowInstantResults();
293 browser()->GetFindBarController(); // add find bar
294
295 std::vector<ViewID> view_list;
296 view_list.push_back(VIEW_ID_INFO_BAR);
297 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA);
298 view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR);
299 view_list.push_back(VIEW_ID_BOOKMARK_BAR);
300 view_list.push_back(VIEW_ID_TOOLBAR);
301 view_list.push_back(VIEW_ID_FIND_BAR);
302 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF);
303 VerifyZOrder(view_list);
304 }
305
306 // Verify that in non-instant presentation mode the content area is beneath
307 // the bookmark bar and info bar.
308 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffset) {
309 PreviewableContentsController* preview =
310 [controller() previewableContentsController];
311
312 // Just toolbar.
313 EXPECT_EQ(0, [preview previewOffset]);
314 EXPECT_EQ(0, [preview activeContainerOffset]);
315
316 // Plus bookmark bar.
317 browser()->window()->ToggleBookmarkBar();
318 EXPECT_EQ(0, [preview previewOffset]);
319 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR),
320 [preview activeContainerOffset]);
321
322 // Plus info bar.
323 ShowInfoBar();
324 EXPECT_EQ(0, [preview previewOffset]);
325 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) +
326 GetViewHeight(VIEW_ID_INFO_BAR),
327 [preview activeContainerOffset]);
328
329 // Minus bookmark bar.
330 browser()->window()->ToggleBookmarkBar();
331 EXPECT_EQ(0, [preview previewOffset]);
332 EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]);
333 }
334
335 // Verify that in non-instant presentation mode the content area is beneath
336 // the info bar.
337 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
338 ContentOffsetPresentationMode) {
339 browser()->TogglePresentationMode();
340 PreviewableContentsController* preview =
341 [controller() previewableContentsController];
342
343 // Just toolbar.
344 EXPECT_EQ(0, [preview previewOffset]);
345 EXPECT_EQ(0, [preview activeContainerOffset]);
346
347 // Plus bookmark bar.
348 browser()->window()->ToggleBookmarkBar();
349 EXPECT_EQ(0, [preview previewOffset]);
350 EXPECT_EQ(0, [preview activeContainerOffset]);
351
352 // Plus info bar.
353 ShowInfoBar();
354 EXPECT_EQ(0, [preview previewOffset]);
355 EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]);
356
357 // Minus bookmark bar.
358 browser()->window()->ToggleBookmarkBar();
359 EXPECT_EQ(0, [preview previewOffset]);
360 EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]);
361 }
362
363 // Verify that when showing instant results the content area overlaps the
364 // bookmark bar and info bar.
365 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstant) {
366 ShowInstantResults();
367 PreviewableContentsController* preview =
368 [controller() previewableContentsController];
369
370 // Just toolbar.
371 EXPECT_EQ(0, [preview previewOffset]);
372 EXPECT_EQ(0, [preview activeContainerOffset]);
373
374 // Plus bookmark bar.
375 browser()->window()->ToggleBookmarkBar();
376 EXPECT_EQ(0, [preview previewOffset]);
377 EXPECT_EQ(0, [preview activeContainerOffset]);
378
379 // Plus info bar.
380 ShowInfoBar();
381 EXPECT_EQ(0, [preview previewOffset]);
382 EXPECT_EQ(0, [preview activeContainerOffset]);
383
384 // Minus bookmark bar.
385 browser()->window()->ToggleBookmarkBar();
386 EXPECT_EQ(0, [preview previewOffset]);
387 EXPECT_EQ(0, [preview activeContainerOffset]);
388 }
389
390 // The instant NTP case is same as normal case except that the preview is
391 // also shifted down.
392 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstantNPT) {
393 ShowInstantNTP();
394 PreviewableContentsController* preview =
395 [controller() previewableContentsController];
396
397 // Just toolbar.
398 EXPECT_EQ(0, [preview previewOffset]);
399 EXPECT_EQ(0, [preview activeContainerOffset]);
400
401 // Plus bookmark bar.
402 browser()->window()->ToggleBookmarkBar();
403 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR),
404 [preview previewOffset]);
405 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR),
406 [preview activeContainerOffset]);
407
408 // Plus info bar.
409 ShowInfoBar();
410 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) +
411 GetViewHeight(VIEW_ID_INFO_BAR),
412 [preview previewOffset]);
413 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) +
414 GetViewHeight(VIEW_ID_INFO_BAR),
415 [preview activeContainerOffset]);
416
417 // Minus bookmark bar.
418 browser()->window()->ToggleBookmarkBar();
419 EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview previewOffset]);
420 EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]);
421 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698