Chromium Code Reviews| 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 ASSERT_TRUE(chrome::search::IsInstantExtendedAPIEnabled(NULL)); | |
| 23 } | |
| 24 | |
| 25 virtual void SetUpOnMainThread() OVERRIDE { | |
| 26 AddTabAtIndex(1, | |
| 27 GURL(chrome::kChromeUINewTabURL), | |
| 28 content::PAGE_TRANSITION_LINK); | |
| 29 EXPECT_TRUE([GetBookmarkBarController() shouldShowAtBottomWhenDetached]); | |
| 30 EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]); | |
| 31 } | |
| 32 | |
| 33 BrowserWindowController* GetBrowserWindowController() const { | |
| 34 NSWindow* window = browser()->window()->GetNativeWindow(); | |
| 35 return [BrowserWindowController browserWindowControllerForWindow:window]; | |
| 36 } | |
| 37 | |
| 38 BookmarkBarController* GetBookmarkBarController() const { | |
| 39 return [GetBrowserWindowController() bookmarkBarController]; | |
| 40 } | |
| 41 }; | |
|
dhollowa
2012/12/04 01:24:49
nit: DISALLOW_COPY_AND_ASSIGN()
sail
2012/12/04 01:41:12
Done.
| |
| 42 | |
| 43 // Verify that the bookmark bar is positioned correctly when detached and | |
| 44 // attached. | |
| 45 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, Position) { | |
| 46 // Verify detached bookmark bar is at the bottom of content area. | |
| 47 NSRect bookmark_bar_frame = [[GetBookmarkBarController() view] frame]; | |
| 48 EXPECT_EQ(0, NSMinY(bookmark_bar_frame)); | |
| 49 | |
| 50 // Attach the bookmark bar and verify it's above the content area. | |
| 51 browser()->window()->ToggleBookmarkBar(); | |
| 52 content::RunAllPendingInMessageLoop(); | |
| 53 NSRect content_frame = [[GetBrowserWindowController() tabContentArea] frame]; | |
| 54 bookmark_bar_frame = [[GetBookmarkBarController() view] frame]; | |
| 55 EXPECT_EQ(NSMinX(content_frame), NSMinX(bookmark_bar_frame)); | |
| 56 EXPECT_EQ(NSMaxY(content_frame), NSMinY(bookmark_bar_frame)); | |
| 57 } | |
| 58 | |
| 59 // Test that detached bookmark bar is positioned correctly when the download | |
| 60 // shelf is visible. | |
| 61 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, PositionWithDownloads) { | |
| 62 // Show the download shelf. | |
| 63 DownloadShelfController* download_shelf_controller = | |
| 64 [GetBrowserWindowController() downloadShelf]; | |
| 65 [download_shelf_controller show:nil]; | |
| 66 EXPECT_FALSE([[download_shelf_controller view] isHidden]); | |
| 67 | |
| 68 // Verify that the bookmark bar is at the bottom of the content area but above | |
| 69 // the download shelf. | |
| 70 NSRect content_frame = [[GetBrowserWindowController() tabContentArea] frame]; | |
| 71 NSRect bookmark_bar_frame = [[GetBookmarkBarController() view] frame]; | |
| 72 EXPECT_EQ(NSMinY(content_frame), NSMinY(bookmark_bar_frame)); | |
| 73 EXPECT_NE(0, NSMinY(bookmark_bar_frame)); | |
| 74 EXPECT_EQ(NSMinY(content_frame), NSMinY(bookmark_bar_frame)); | |
| 75 } | |
| 76 | |
| 77 // Verify that the bookmark bar shrinks when the window is narrow. | |
| 78 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, NarrowWindow) { | |
| 79 NSWindow* window = browser()->window()->GetNativeWindow(); | |
| 80 NSRect window_frame = [window frame]; | |
| 81 CGFloat expected_width = | |
| 82 roundf(chrome::search::kMaxWidthForBottomBookmarkBar / 2.0); | |
| 83 window_frame.size.width = expected_width + | |
| 84 chrome::search::kHorizontalPaddingForBottomBookmarkBar * 2; | |
| 85 [window setFrame:window_frame display:YES]; | |
| 86 EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]); | |
| 87 | |
| 88 NSRect frame = [[GetBookmarkBarController() view] frame]; | |
| 89 EXPECT_EQ(chrome::search::kHorizontalPaddingForBottomBookmarkBar, | |
| 90 NSMinX(frame)); | |
| 91 EXPECT_EQ(expected_width, NSWidth(frame)); | |
| 92 } | |
| 93 | |
| 94 // Verify that the bookmark bar's width doesn't go above its maximum value. | |
| 95 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, WideWindow) { | |
| 96 NSWindow* window = browser()->window()->GetNativeWindow(); | |
| 97 NSRect window_frame = [window frame]; | |
| 98 window_frame.size.width = chrome::search::kMaxWidthForBottomBookmarkBar + | |
| 99 chrome::search::kHorizontalPaddingForBottomBookmarkBar * 2 + 100; | |
| 100 [window setFrame:window_frame display:YES]; | |
| 101 EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]); | |
| 102 | |
| 103 NSRect frame = [[GetBookmarkBarController() view] frame]; | |
| 104 EXPECT_EQ(roundf((NSWidth(window_frame) - NSWidth(frame)) / 2.0), | |
| 105 NSMinX(frame)); | |
| 106 EXPECT_EQ(chrome::search::kMaxWidthForBottomBookmarkBar, NSWidth(frame)); | |
| 107 } | |
| 108 | |
| 109 // Verify that the bookmark bar is hidden if the content area height falls | |
| 110 // below a minimum value. | |
| 111 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, MinContentHeight) { | |
| 112 NSWindow* window = browser()->window()->GetNativeWindow(); | |
| 113 NSRect window_frame = [window frame]; | |
| 114 window_frame.size.height = | |
| 115 chrome::search::kMinContentHeightForBottomBookmarkBar; | |
| 116 [window setFrame:window_frame display:YES]; | |
| 117 EXPECT_TRUE([[GetBookmarkBarController() view] isHidden]); | |
| 118 } | |
| OLD | NEW |