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

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

Powered by Google App Engine
This is Rietveld 408576698