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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_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
(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 "base/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view.h"
13 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
14 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
15 #include "chrome/browser/ui/search/search.h"
16 #include "chrome/browser/ui/search/search_ui.h"
17 #include "chrome/common/url_constants.h"
18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "content/public/test/test_utils.h"
20 #include "googleurl/src/gurl.h"
21
22 class BottomBookmarkBarControllerTest : public InProcessBrowserTest {
23 public:
24 BottomBookmarkBarControllerTest() {
25 chrome::search::EnableInstantExtendedAPIForTesting();
26 }
27
28 virtual void SetUpOnMainThread() OVERRIDE {
29 AddTabAtIndex(1,
30 GURL(chrome::kChromeUINewTabURL),
31 content::PAGE_TRANSITION_LINK);
32 EXPECT_TRUE([GetBookmarkBarController() shouldShowAtBottomWhenDetached]);
33 EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]);
34 }
35
36 BrowserWindowController* GetBrowserWindowController() const {
37 NSWindow* window = browser()->window()->GetNativeWindow();
38 return [BrowserWindowController browserWindowControllerForWindow:window];
39 }
40
41 BookmarkBarController* GetBookmarkBarController() const {
42 return [GetBrowserWindowController() bookmarkBarController];
43 }
44
45 private:
46 DISALLOW_COPY_AND_ASSIGN(BottomBookmarkBarControllerTest);
47 };
48
49 // Verify that the bookmark bar is positioned correctly when detached and
50 // attached.
51 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, Position) {
52 // Verify detached bookmark bar is at the bottom of content area.
53 NSRect bookmark_bar_frame = [[GetBookmarkBarController() view] frame];
54 EXPECT_EQ(0, NSMinY(bookmark_bar_frame));
55
56 // Attach the bookmark bar and verify it's above the content area.
57 browser()->window()->ToggleBookmarkBar();
58 content::RunAllPendingInMessageLoop();
59 NSRect content_frame = [[GetBrowserWindowController() tabContentArea] frame];
60 bookmark_bar_frame = [[GetBookmarkBarController() view] frame];
61 EXPECT_EQ(NSMinX(content_frame), NSMinX(bookmark_bar_frame));
62 EXPECT_EQ(NSMaxY(content_frame), NSMinY(bookmark_bar_frame));
63 }
64
65 // Test that detached bookmark bar is positioned correctly when the download
66 // shelf is visible.
67 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, PositionWithDownloads) {
68 // Show the download shelf.
69 DownloadShelfController* download_shelf_controller =
70 [GetBrowserWindowController() downloadShelf];
71 [download_shelf_controller show:nil];
72 EXPECT_FALSE([[download_shelf_controller view] isHidden]);
73
74 // Verify that the bookmark bar is at the bottom of the content area but above
75 // the download shelf.
76 NSRect content_frame = [[GetBrowserWindowController() tabContentArea] frame];
77 NSRect bookmark_bar_frame = [[GetBookmarkBarController() view] frame];
78 EXPECT_EQ(NSMinY(content_frame), NSMinY(bookmark_bar_frame));
79 EXPECT_NE(0, NSMinY(bookmark_bar_frame));
80 EXPECT_EQ(NSMinY(content_frame), NSMinY(bookmark_bar_frame));
81 }
82
83 // Verify that the bookmark bar shrinks when the window is narrow.
84 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, NarrowWindow) {
85 NSWindow* window = browser()->window()->GetNativeWindow();
86 NSRect window_frame = [window frame];
87 CGFloat expected_width =
88 roundf(chrome::search::kMaxWidthForBottomBookmarkBar / 2.0);
89 window_frame.size.width = expected_width +
90 chrome::search::kHorizontalPaddingForBottomBookmarkBar * 2;
91 [window setFrame:window_frame display:YES];
92 EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]);
93
94 NSRect frame = [[GetBookmarkBarController() view] frame];
95 EXPECT_EQ(chrome::search::kHorizontalPaddingForBottomBookmarkBar,
96 NSMinX(frame));
97 EXPECT_EQ(expected_width, NSWidth(frame));
98 }
99
100 // Verify that the bookmark bar's width doesn't go above its maximum value.
101 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, WideWindow) {
102 NSWindow* window = browser()->window()->GetNativeWindow();
103 NSRect window_frame = [window frame];
104 window_frame.size.width = chrome::search::kMaxWidthForBottomBookmarkBar +
105 chrome::search::kHorizontalPaddingForBottomBookmarkBar * 2 + 100;
106 [window setFrame:window_frame display:YES];
107 EXPECT_FALSE([[GetBookmarkBarController() view] isHidden]);
108
109 NSRect frame = [[GetBookmarkBarController() view] frame];
110 EXPECT_EQ(roundf((NSWidth(window_frame) - NSWidth(frame)) / 2.0),
111 NSMinX(frame));
112 EXPECT_EQ(chrome::search::kMaxWidthForBottomBookmarkBar, NSWidth(frame));
113 }
114
115 // Verify that the bookmark bar is hidden if the content area height falls
116 // below a minimum value.
117 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, MinContentHeight) {
118 NSWindow* window = browser()->window()->GetNativeWindow();
119 NSRect window_frame = [window frame];
120 window_frame.size.height =
121 chrome::search::kMinContentHeightForBottomBookmarkBar;
122 [window setFrame:window_frame display:YES];
123 EXPECT_TRUE([[GetBookmarkBarController() view] isHidden]);
124 }
125
126 IN_PROC_BROWSER_TEST_F(BottomBookmarkBarControllerTest, NoItemContainer) {
127 EXPECT_TRUE([GetBookmarkBarController() isEmpty]);
128 BookmarkBarView* button_view = [GetBookmarkBarController() buttonView];
129 EXPECT_TRUE([[button_view noItemContainer] isHidden]);
130
131 // Add a bookmark.
132 BookmarkModel* model =
133 BookmarkModelFactory::GetForProfile(browser()->profile());
134 const BookmarkNode* node = model->bookmark_bar_node();
135 model->AddURL(node,
136 node->child_count(),
137 ASCIIToUTF16("title"),
138 GURL("http://www.google.com"));
139
140 // Item container should remain hidden.
141 EXPECT_FALSE([GetBookmarkBarController() isEmpty]);
142 EXPECT_TRUE([[button_view noItemContainer] isHidden]);
143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698