OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| 6 |
| 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_window.h" |
| 9 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 10 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
| 11 #include "chrome/browser/ui/search/search.h" |
| 12 #include "chrome/browser/ui/search/search_ui.h" |
| 13 #include "chrome/common/url_constants.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "content/public/test/test_utils.h" |
| 16 #include "googleurl/src/gurl.h" |
| 17 |
| 18 class BottomBookmarkBarControllerTest : public InProcessBrowserTest { |
| 19 public: |
| 20 BottomBookmarkBarControllerTest() { |
| 21 chrome::search::EnableInstantExtendedAPIForTesting(); |
| 22 } |
| 23 |
| 24 virtual void SetUpOnMainThread() OVERRIDE { |
| 25 AddTabAtIndex(1, |
| 26 GURL(chrome::kChromeUINewTabURL), |
| 27 content::PAGE_TRANSITION_LINK); |
| 28 EXPECT_TRUE([GetBookmarkBarController() shouldShowAtBottomWhenDetached]); |
| 29 EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]); |
| 30 } |
| 31 |
| 32 BrowserWindowController* GetBrowserWindowController() const { |
| 33 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 34 return [BrowserWindowController browserWindowControllerForWindow:window]; |
| 35 } |
| 36 |
| 37 BookmarkBarController* GetBookmarkBarController() const { |
| 38 return [GetBrowserWindowController() bookmarkBarController]; |
| 39 } |
| 40 |
| 41 private: |
| 42 DISALLOW_COPY_AND_ASSIGN(BottomBookmarkBarControllerTest); |
| 43 }; |
| 44 |
| 45 // Verify that the bookmark bar is positioned correctly when detached and |
| 46 // attached. |
| 47 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, Position) { |
| 48 // Verify detached bookmark bar is at the bottom of content area. |
| 49 NSRect bookmark_bar_frame = [[GetBookmarkBarController() view] frame]; |
| 50 EXPECT_EQ(0, NSMinY(bookmark_bar_frame)); |
| 51 |
| 52 // Attach the bookmark bar and verify it's above the content area. |
| 53 browser()->window()->ToggleBookmarkBar(); |
| 54 content::RunAllPendingInMessageLoop(); |
| 55 NSRect content_frame = [[GetBrowserWindowController() tabContentArea] frame]; |
| 56 bookmark_bar_frame = [[GetBookmarkBarController() view] frame]; |
| 57 EXPECT_EQ(NSMinX(content_frame), NSMinX(bookmark_bar_frame)); |
| 58 EXPECT_EQ(NSMaxY(content_frame), NSMinY(bookmark_bar_frame)); |
| 59 } |
| 60 |
| 61 // Test that detached bookmark bar is positioned correctly when the download |
| 62 // shelf is visible. |
| 63 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, PositionWithDownloads) { |
| 64 // Show the download shelf. |
| 65 DownloadShelfController* download_shelf_controller = |
| 66 [GetBrowserWindowController() downloadShelf]; |
| 67 [download_shelf_controller show:nil]; |
| 68 EXPECT_FALSE([[download_shelf_controller view] isHidden]); |
| 69 |
| 70 // Verify that the bookmark bar is at the bottom of the content area but above |
| 71 // the download shelf. |
| 72 NSRect content_frame = [[GetBrowserWindowController() tabContentArea] frame]; |
| 73 NSRect bookmark_bar_frame = [[GetBookmarkBarController() view] frame]; |
| 74 EXPECT_EQ(NSMinY(content_frame), NSMinY(bookmark_bar_frame)); |
| 75 EXPECT_NE(0, NSMinY(bookmark_bar_frame)); |
| 76 EXPECT_EQ(NSMinY(content_frame), NSMinY(bookmark_bar_frame)); |
| 77 } |
| 78 |
| 79 // Verify that the bookmark bar shrinks when the window is narrow. |
| 80 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, NarrowWindow) { |
| 81 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 82 NSRect window_frame = [window frame]; |
| 83 CGFloat expected_width = |
| 84 roundf(chrome::search::kMaxWidthForBottomBookmarkBar / 2.0); |
| 85 window_frame.size.width = expected_width + |
| 86 chrome::search::kHorizontalPaddingForBottomBookmarkBar * 2; |
| 87 [window setFrame:window_frame display:YES]; |
| 88 EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]); |
| 89 |
| 90 NSRect frame = [[GetBookmarkBarController() view] frame]; |
| 91 EXPECT_EQ(chrome::search::kHorizontalPaddingForBottomBookmarkBar, |
| 92 NSMinX(frame)); |
| 93 EXPECT_EQ(expected_width, NSWidth(frame)); |
| 94 } |
| 95 |
| 96 // Verify that the bookmark bar's width doesn't go above its maximum value. |
| 97 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, WideWindow) { |
| 98 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 99 NSRect window_frame = [window frame]; |
| 100 window_frame.size.width = chrome::search::kMaxWidthForBottomBookmarkBar + |
| 101 chrome::search::kHorizontalPaddingForBottomBookmarkBar * 2 + 100; |
| 102 [window setFrame:window_frame display:YES]; |
| 103 EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]); |
| 104 |
| 105 NSRect frame = [[GetBookmarkBarController() view] frame]; |
| 106 EXPECT_EQ(roundf((NSWidth(window_frame) - NSWidth(frame)) / 2.0), |
| 107 NSMinX(frame)); |
| 108 EXPECT_EQ(chrome::search::kMaxWidthForBottomBookmarkBar, NSWidth(frame)); |
| 109 } |
| 110 |
| 111 // Verify that the bookmark bar is hidden if the content area height falls |
| 112 // below a minimum value. |
| 113 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, MinContentHeight) { |
| 114 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 115 NSRect window_frame = [window frame]; |
| 116 window_frame.size.height = |
| 117 chrome::search::kMinContentHeightForBottomBookmarkBar; |
| 118 [window setFrame:window_frame display:YES]; |
| 119 EXPECT_TRUE([[GetBookmarkBarController() view] isHidden]); |
| 120 } |
OLD | NEW |