| OLD | NEW |
| 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" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
| 11 #include "chrome/browser/api/infobars/infobar_service.h" | 11 #include "chrome/browser/api/infobars/infobar_service.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 18 #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" | 19 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
| 20 #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" | 21 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
| 22 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 22 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 23 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 23 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
| 24 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" | 24 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" |
| 25 #include "chrome/browser/ui/search/search.h" | 25 #include "chrome/browser/ui/search/search.h" |
| 26 #include "chrome/browser/ui/search/search_model.h" | 26 #include "chrome/browser/ui/search/search_model.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/test/base/in_process_browser_test.h" | 28 #include "chrome/test/base/in_process_browser_test.h" |
| 29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 30 #import "testing/gtest_mac.h" | 30 #import "testing/gtest_mac.h" |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 34 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 247 |
| 248 // Make sure the visual order of the buttons is correct and that they don't | 248 // Make sure the visual order of the buttons is correct and that they don't |
| 249 // overlap. | 249 // overlap. |
| 250 NSRect avatar_frame = [avatar frame]; | 250 NSRect avatar_frame = [avatar frame]; |
| 251 NSRect fullscreen_frame = [fullscreen_button frame]; | 251 NSRect fullscreen_frame = [fullscreen_button frame]; |
| 252 | 252 |
| 253 EXPECT_LT(NSMinX(fullscreen_frame), NSMinX(avatar_frame)); | 253 EXPECT_LT(NSMinX(fullscreen_frame), NSMinX(avatar_frame)); |
| 254 EXPECT_LT(NSMaxX(fullscreen_frame), NSMinX(avatar_frame)); | 254 EXPECT_LT(NSMaxX(fullscreen_frame), NSMinX(avatar_frame)); |
| 255 } | 255 } |
| 256 | 256 |
| 257 // Verify that in non-instant normal mode that the find bar and download shelf | 257 // Verify that in non-Instant normal mode that the find bar and download shelf |
| 258 // are above the content area. Everything else should be below it. | 258 // are above the content area. Everything else should be below it. |
| 259 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormal) { | 259 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormal) { |
| 260 browser()->GetFindBarController(); // add find bar | 260 browser()->GetFindBarController(); // add find bar |
| 261 | 261 |
| 262 std::vector<ViewID> view_list; | 262 std::vector<ViewID> view_list; |
| 263 view_list.push_back(VIEW_ID_BOOKMARK_BAR); | 263 view_list.push_back(VIEW_ID_BOOKMARK_BAR); |
| 264 view_list.push_back(VIEW_ID_TOOLBAR); | 264 view_list.push_back(VIEW_ID_TOOLBAR); |
| 265 view_list.push_back(VIEW_ID_INFO_BAR); | 265 view_list.push_back(VIEW_ID_INFO_BAR); |
| 266 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); | 266 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); |
| 267 view_list.push_back(VIEW_ID_FIND_BAR); | 267 view_list.push_back(VIEW_ID_FIND_BAR); |
| 268 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); | 268 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); |
| 269 VerifyZOrder(view_list); | 269 VerifyZOrder(view_list); |
| 270 } | 270 } |
| 271 | 271 |
| 272 // Verify that in non-instant presentation mode that the info bar is below the | 272 // Verify that in non-Instant presentation mode that the info bar is below the |
| 273 // content are and everything else is above it. | 273 // content are and everything else is above it. |
| 274 // DISABLED due to flaky failures on trybots. http://crbug.com/178778 | 274 // DISABLED due to flaky failures on trybots. http://crbug.com/178778 |
| 275 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, | 275 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| 276 DISABLED_ZOrderPresentationMode) { | 276 DISABLED_ZOrderPresentationMode) { |
| 277 chrome::ToggleFullscreenMode(browser()); | 277 chrome::ToggleFullscreenMode(browser()); |
| 278 browser()->GetFindBarController(); // add find bar | 278 browser()->GetFindBarController(); // add find bar |
| 279 | 279 |
| 280 std::vector<ViewID> view_list; | 280 std::vector<ViewID> view_list; |
| 281 view_list.push_back(VIEW_ID_INFO_BAR); | 281 view_list.push_back(VIEW_ID_INFO_BAR); |
| 282 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); | 282 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); |
| 283 view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR); | 283 view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR); |
| 284 view_list.push_back(VIEW_ID_BOOKMARK_BAR); | 284 view_list.push_back(VIEW_ID_BOOKMARK_BAR); |
| 285 view_list.push_back(VIEW_ID_TOOLBAR); | 285 view_list.push_back(VIEW_ID_TOOLBAR); |
| 286 view_list.push_back(VIEW_ID_FIND_BAR); | 286 view_list.push_back(VIEW_ID_FIND_BAR); |
| 287 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); | 287 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); |
| 288 VerifyZOrder(view_list); | 288 VerifyZOrder(view_list); |
| 289 } | 289 } |
| 290 | 290 |
| 291 // Normal mode with instant results showing. Should be same z-order as normal | 291 // Normal mode with Instant results showing. Should be same z-order as normal |
| 292 // mode except find bar is below content area. | 292 // mode except find bar is below content area. |
| 293 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormalInstant) { | 293 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormalInstant) { |
| 294 ShowInstantResults(); | 294 ShowInstantResults(); |
| 295 browser()->GetFindBarController(); // add find bar | 295 browser()->GetFindBarController(); // add find bar |
| 296 | 296 |
| 297 std::vector<ViewID> view_list; | 297 std::vector<ViewID> view_list; |
| 298 view_list.push_back(VIEW_ID_BOOKMARK_BAR); | 298 view_list.push_back(VIEW_ID_BOOKMARK_BAR); |
| 299 view_list.push_back(VIEW_ID_TOOLBAR); | 299 view_list.push_back(VIEW_ID_TOOLBAR); |
| 300 view_list.push_back(VIEW_ID_INFO_BAR); | 300 view_list.push_back(VIEW_ID_INFO_BAR); |
| 301 view_list.push_back(VIEW_ID_FIND_BAR); | 301 view_list.push_back(VIEW_ID_FIND_BAR); |
| 302 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); | 302 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); |
| 303 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); | 303 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); |
| 304 VerifyZOrder(view_list); | 304 VerifyZOrder(view_list); |
| 305 } | 305 } |
| 306 | 306 |
| 307 // Presentation mode with instant results showing. Should be exact same as | 307 // Presentation mode with Instant results showing. Should be exact same as |
| 308 // non-instant presentation mode. | 308 // non-Instant presentation mode. |
| 309 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, | 309 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| 310 ZOrderInstantPresentationMode) { | 310 ZOrderInstantPresentationMode) { |
| 311 chrome::ToggleFullscreenMode(browser()); | 311 chrome::ToggleFullscreenMode(browser()); |
| 312 ShowInstantResults(); | 312 ShowInstantResults(); |
| 313 browser()->GetFindBarController(); // add find bar | 313 browser()->GetFindBarController(); // add find bar |
| 314 | 314 |
| 315 std::vector<ViewID> view_list; | 315 std::vector<ViewID> view_list; |
| 316 view_list.push_back(VIEW_ID_INFO_BAR); | 316 view_list.push_back(VIEW_ID_INFO_BAR); |
| 317 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); | 317 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); |
| 318 view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR); | 318 view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 340 std::vector<ViewID> view_list; | 340 std::vector<ViewID> view_list; |
| 341 view_list.push_back(VIEW_ID_INFO_BAR); | 341 view_list.push_back(VIEW_ID_INFO_BAR); |
| 342 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); | 342 view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); |
| 343 view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR); | 343 view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR); |
| 344 view_list.push_back(VIEW_ID_BOOKMARK_BAR); | 344 view_list.push_back(VIEW_ID_BOOKMARK_BAR); |
| 345 view_list.push_back(VIEW_ID_TOOLBAR); | 345 view_list.push_back(VIEW_ID_TOOLBAR); |
| 346 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); | 346 view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); |
| 347 VerifyZOrder(view_list); | 347 VerifyZOrder(view_list); |
| 348 } | 348 } |
| 349 | 349 |
| 350 // Verify that in non-instant presentation mode the content area is beneath | 350 // Verify that in non-Instant presentation mode the content area is beneath |
| 351 // the bookmark bar and info bar. | 351 // the bookmark bar and info bar. |
| 352 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffset) { | 352 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffset) { |
| 353 PreviewableContentsController* preview = | 353 OverlayableContentsController* overlay = |
| 354 [controller() previewableContentsController]; | 354 [controller() overlayableContentsController]; |
| 355 | 355 |
| 356 // Just toolbar. | 356 // Just toolbar. |
| 357 EXPECT_EQ(0, [preview activeContainerOffset]); | 357 EXPECT_EQ(0, [overlay activeContainerOffset]); |
| 358 | 358 |
| 359 // Plus bookmark bar. | 359 // Plus bookmark bar. |
| 360 browser()->window()->ToggleBookmarkBar(); | 360 browser()->window()->ToggleBookmarkBar(); |
| 361 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR), | 361 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR), |
| 362 [preview activeContainerOffset]); | 362 [overlay activeContainerOffset]); |
| 363 | 363 |
| 364 // Plus info bar. | 364 // Plus info bar. |
| 365 ShowInfoBar(); | 365 ShowInfoBar(); |
| 366 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) + | 366 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) + |
| 367 GetViewHeight(VIEW_ID_INFO_BAR), | 367 GetViewHeight(VIEW_ID_INFO_BAR), |
| 368 [preview activeContainerOffset]); | 368 [overlay activeContainerOffset]); |
| 369 | 369 |
| 370 // Minus bookmark bar. | 370 // Minus bookmark bar. |
| 371 browser()->window()->ToggleBookmarkBar(); | 371 browser()->window()->ToggleBookmarkBar(); |
| 372 EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]); | 372 EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [overlay activeContainerOffset]); |
| 373 } | 373 } |
| 374 | 374 |
| 375 // Verify that in non-instant presentation mode the content area is beneath | 375 // Verify that in non-Instant presentation mode the content area is beneath |
| 376 // the info bar. | 376 // the info bar. |
| 377 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, | 377 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| 378 ContentOffsetPresentationMode) { | 378 ContentOffsetPresentationMode) { |
| 379 chrome::ToggleFullscreenMode(browser()); | 379 chrome::ToggleFullscreenMode(browser()); |
| 380 PreviewableContentsController* preview = | 380 OverlayableContentsController* overlay = |
| 381 [controller() previewableContentsController]; | 381 [controller() overlayableContentsController]; |
| 382 | 382 |
| 383 // Just toolbar. | 383 // Just toolbar. |
| 384 EXPECT_EQ(0, [preview activeContainerOffset]); | 384 EXPECT_EQ(0, [overlay activeContainerOffset]); |
| 385 | 385 |
| 386 // Plus bookmark bar. | 386 // Plus bookmark bar. |
| 387 browser()->window()->ToggleBookmarkBar(); | 387 browser()->window()->ToggleBookmarkBar(); |
| 388 EXPECT_EQ(0, [preview activeContainerOffset]); | 388 EXPECT_EQ(0, [overlay activeContainerOffset]); |
| 389 | 389 |
| 390 // Plus info bar. | 390 // Plus info bar. |
| 391 ShowInfoBar(); | 391 ShowInfoBar(); |
| 392 EXPECT_EQ(0, [preview activeContainerOffset]); | 392 EXPECT_EQ(0, [overlay activeContainerOffset]); |
| 393 | 393 |
| 394 // Minus bookmark bar. | 394 // Minus bookmark bar. |
| 395 browser()->window()->ToggleBookmarkBar(); | 395 browser()->window()->ToggleBookmarkBar(); |
| 396 EXPECT_EQ(0, [preview activeContainerOffset]); | 396 EXPECT_EQ(0, [overlay activeContainerOffset]); |
| 397 } | 397 } |
| 398 | 398 |
| 399 // Verify that when showing instant results the content area overlaps the | 399 // Verify that when showing Instant results the content area overlaps the |
| 400 // bookmark bar and info bar. | 400 // bookmark bar and info bar. |
| 401 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstant) { | 401 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstant) { |
| 402 ShowInstantResults(); | 402 ShowInstantResults(); |
| 403 PreviewableContentsController* preview = | 403 OverlayableContentsController* overlay = |
| 404 [controller() previewableContentsController]; | 404 [controller() overlayableContentsController]; |
| 405 | 405 |
| 406 // Just toolbar. | 406 // Just toolbar. |
| 407 EXPECT_EQ(0, [preview activeContainerOffset]); | 407 EXPECT_EQ(0, [overlay activeContainerOffset]); |
| 408 | 408 |
| 409 // Plus bookmark bar. | 409 // Plus bookmark bar. |
| 410 browser()->window()->ToggleBookmarkBar(); | 410 browser()->window()->ToggleBookmarkBar(); |
| 411 EXPECT_EQ(0, [preview activeContainerOffset]); | 411 EXPECT_EQ(0, [overlay activeContainerOffset]); |
| 412 | 412 |
| 413 // Plus info bar. | 413 // Plus info bar. |
| 414 ShowInfoBar(); | 414 ShowInfoBar(); |
| 415 EXPECT_EQ(0, [preview activeContainerOffset]); | 415 EXPECT_EQ(0, [overlay activeContainerOffset]); |
| 416 | 416 |
| 417 // Minus bookmark bar. | 417 // Minus bookmark bar. |
| 418 browser()->window()->ToggleBookmarkBar(); | 418 browser()->window()->ToggleBookmarkBar(); |
| 419 EXPECT_EQ(0, [preview activeContainerOffset]); | 419 EXPECT_EQ(0, [overlay activeContainerOffset]); |
| 420 } | 420 } |
| 421 | 421 |
| 422 // The instant NTP case is same as normal case except that the preview is | 422 // The Instant NTP case is same as normal case except that the overlay is |
| 423 // also shifted down. | 423 // also shifted down. |
| 424 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstantNPT) { | 424 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstantNPT) { |
| 425 ShowInstantNTP(); | 425 ShowInstantNTP(); |
| 426 PreviewableContentsController* preview = | 426 OverlayableContentsController* overlay = |
| 427 [controller() previewableContentsController]; | 427 [controller() overlayableContentsController]; |
| 428 | 428 |
| 429 // Just toolbar. | 429 // Just toolbar. |
| 430 EXPECT_EQ(0, [preview activeContainerOffset]); | 430 EXPECT_EQ(0, [overlay activeContainerOffset]); |
| 431 | 431 |
| 432 // Plus bookmark bar. | 432 // Plus bookmark bar. |
| 433 browser()->window()->ToggleBookmarkBar(); | 433 browser()->window()->ToggleBookmarkBar(); |
| 434 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR), | 434 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR), |
| 435 [preview activeContainerOffset]); | 435 [overlay activeContainerOffset]); |
| 436 | 436 |
| 437 // Plus info bar. | 437 // Plus info bar. |
| 438 ShowInfoBar(); | 438 ShowInfoBar(); |
| 439 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) + | 439 EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) + |
| 440 GetViewHeight(VIEW_ID_INFO_BAR), | 440 GetViewHeight(VIEW_ID_INFO_BAR), |
| 441 [preview activeContainerOffset]); | 441 [overlay activeContainerOffset]); |
| 442 | 442 |
| 443 // Minus bookmark bar. | 443 // Minus bookmark bar. |
| 444 browser()->window()->ToggleBookmarkBar(); | 444 browser()->window()->ToggleBookmarkBar(); |
| 445 EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]); | 445 EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [overlay activeContainerOffset]); |
| 446 } | 446 } |
| 447 | 447 |
| 448 // Verify that if bookmark bar is underneath instant search results then | 448 // Verify that if bookmark bar is underneath Instant search results then |
| 449 // clicking on instant search results still works. | 449 // clicking on Instant search results still works. |
| 450 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, | 450 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| 451 InstantSearchResultsHitTest) { | 451 InstantSearchResultsHitTest) { |
| 452 browser()->window()->ToggleBookmarkBar(); | 452 browser()->window()->ToggleBookmarkBar(); |
| 453 ShowInstantResults(); | 453 ShowInstantResults(); |
| 454 | 454 |
| 455 NSView* bookmarkView = [[controller() bookmarkBarController] view]; | 455 NSView* bookmarkView = [[controller() bookmarkBarController] view]; |
| 456 NSView* contentView = [[controller() window] contentView]; | 456 NSView* contentView = [[controller() window] contentView]; |
| 457 NSPoint point = [bookmarkView convertPoint:NSMakePoint(1, 1) | 457 NSPoint point = [bookmarkView convertPoint:NSMakePoint(1, 1) |
| 458 toView:[contentView superview]]; | 458 toView:[contentView superview]]; |
| 459 | 459 |
| 460 EXPECT_FALSE([[contentView hitTest:point] isDescendantOf:bookmarkView]); | 460 EXPECT_FALSE([[contentView hitTest:point] isDescendantOf:bookmarkView]); |
| 461 EXPECT_TRUE([[contentView hitTest:point] | 461 EXPECT_TRUE([[contentView hitTest:point] |
| 462 isDescendantOf:[controller() tabContentArea]]); | 462 isDescendantOf:[controller() tabContentArea]]); |
| 463 } | 463 } |
| OLD | NEW |