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

Side by Side Diff: chrome/browser/ui/views/frame/browser_view_browsertest.cc

Issue 13684002: cros: Instant extended support for immersive fullscreen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added one test for immersive instant extended Created 7 years, 8 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 #include "chrome/browser/ui/views/frame/browser_view.h" 5 #include "chrome/browser/ui/views/frame/browser_view.h"
6 6
7 #include "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 9 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
10 #include "chrome/browser/ui/views/frame/browser_view_layout.h"
11 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
10 #include "chrome/browser/ui/views/frame/top_container_view.h" 12 #include "chrome/browser/ui/views/frame/top_container_view.h"
11 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" 13 #include "chrome/browser/ui/views/infobars/infobar_container_view.h"
12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
13 #include "chrome/browser/ui/views/tabs/tab_strip.h" 15 #include "chrome/browser/ui/views/tabs/tab_strip.h"
14 #include "chrome/browser/ui/views/toolbar_view.h" 16 #include "chrome/browser/ui/views/toolbar_view.h"
15 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
16 #include "chrome/test/base/in_process_browser_test.h" 18 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
20 #include "ui/views/controls/single_split_view.h"
21 #include "ui/views/controls/webview/webview.h"
18 #include "ui/views/focus/focus_manager.h" 22 #include "ui/views/focus/focus_manager.h"
23 #include "ui/views/window/non_client_view.h"
24
25 #if defined(OS_CHROMEOS)
26 #include "chrome/browser/search/search.h"
27 #include "chrome/browser/ui/search/instant_test_utils.h"
28 #include "chrome/browser/ui/views/frame/contents_container.h"
29 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
30 #endif
19 31
20 using views::FocusManager; 32 using views::FocusManager;
21 33
34 namespace {
35
36 // Tab strip bounds depend on the window frame sizes.
37 gfx::Point ExpectedTabStripOrigin(BrowserView* browser_view) {
38 gfx::Rect tabstrip_bounds(
39 browser_view->frame()->GetBoundsForTabStrip(browser_view->tabstrip()));
40 gfx::Point tabstrip_origin(tabstrip_bounds.origin());
41 views::View::ConvertPointToTarget(browser_view->parent(),
42 browser_view,
43 &tabstrip_origin);
44 return tabstrip_origin;
45 }
46
47 // Returns the bounds of |view| in widget coordinates.
48 gfx::Rect GetRectInWidget(views::View* view) {
49 return view->ConvertRectToWidget(view->GetLocalBounds());
50 }
51
52 }
53
22 typedef InProcessBrowserTest BrowserViewTest; 54 typedef InProcessBrowserTest BrowserViewTest;
23 55
24 IN_PROC_BROWSER_TEST_F(BrowserViewTest, BrowserView) { 56 IN_PROC_BROWSER_TEST_F(BrowserViewTest, BrowserView) {
25 BookmarkBarView::DisableAnimationsForTesting(true); 57 BookmarkBarView::DisableAnimationsForTesting(true);
26 58
27 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); 59 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
28 TopContainerView* top_container = browser_view->top_container(); 60 TopContainerView* top_container = browser_view->top_container();
61 TabStrip* tabstrip = browser_view->tabstrip();
62 ToolbarView* toolbar = browser_view->toolbar();
63 views::SingleSplitView* contents_split =
64 browser_view->GetContentsSplitForTest();
65 views::WebView* contents_web_view =
66 browser_view->GetContentsWebViewForTest();
29 67
30 // Verify the view hierarchy. 68 // Verify the view hierarchy.
31 EXPECT_EQ(top_container, browser_view->tabstrip()->parent()); 69 EXPECT_EQ(top_container, browser_view->tabstrip()->parent());
32 EXPECT_EQ(top_container, browser_view->toolbar()->parent()); 70 EXPECT_EQ(top_container, browser_view->toolbar()->parent());
33 EXPECT_EQ(top_container, browser_view->GetBookmarkBarView()->parent()); 71 EXPECT_EQ(top_container, browser_view->GetBookmarkBarView()->parent());
34 EXPECT_EQ(browser_view, browser_view->infobar_container()->parent()); 72 EXPECT_EQ(browser_view, browser_view->infobar_container()->parent());
35 73
36 // Top container is at the front of the view hierarchy. 74 // Top container is at the front of the view hierarchy.
37 EXPECT_EQ(browser_view->child_count() - 1, 75 EXPECT_EQ(browser_view->child_count() - 1,
38 browser_view->GetIndexOf(top_container)); 76 browser_view->GetIndexOf(top_container));
39 77
40 // Verify basic layout. 78 // Verify basic layout.
41 EXPECT_EQ(0, top_container->x()); 79 EXPECT_EQ(0, top_container->x());
42 EXPECT_EQ(0, top_container->y()); 80 EXPECT_EQ(0, top_container->y());
43 EXPECT_EQ(browser_view->width(), top_container->width()); 81 EXPECT_EQ(browser_view->width(), top_container->width());
82 // Tabstrip layout varies based on window frame sizes.
83 gfx::Point expected_tabstrip_origin = ExpectedTabStripOrigin(browser_view);
84 EXPECT_EQ(expected_tabstrip_origin.x(), tabstrip->x());
85 EXPECT_EQ(expected_tabstrip_origin.y(), tabstrip->y());
86 EXPECT_EQ(0, toolbar->x());
87 EXPECT_EQ(
88 tabstrip->bounds().bottom() -
89 BrowserViewLayout::kToolbarTabStripVerticalOverlap,
90 toolbar->y());
91 EXPECT_EQ(0, contents_split->x());
92 EXPECT_EQ(toolbar->bounds().bottom(), contents_split->y());
93 EXPECT_EQ(0, contents_web_view->x());
94 EXPECT_EQ(0, contents_web_view->y());
44 95
45 // Verify bookmark bar visibility. 96 // Verify bookmark bar visibility.
46 BookmarkBarView* bookmark_bar = browser_view->GetBookmarkBarView(); 97 BookmarkBarView* bookmark_bar = browser_view->GetBookmarkBarView();
47 EXPECT_FALSE(bookmark_bar->visible()); 98 EXPECT_FALSE(bookmark_bar->visible());
48 EXPECT_FALSE(bookmark_bar->IsDetached()); 99 EXPECT_FALSE(bookmark_bar->IsDetached());
49 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR); 100 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR);
50 EXPECT_TRUE(bookmark_bar->visible()); 101 EXPECT_TRUE(bookmark_bar->visible());
51 EXPECT_FALSE(bookmark_bar->IsDetached()); 102 EXPECT_FALSE(bookmark_bar->IsDetached());
52 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR); 103 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR);
53 EXPECT_FALSE(bookmark_bar->visible()); 104 EXPECT_FALSE(bookmark_bar->visible());
54 EXPECT_FALSE(bookmark_bar->IsDetached()); 105 EXPECT_FALSE(bookmark_bar->IsDetached());
55 106
56 // Bookmark bar is reparented to BrowserView on NTP. 107 // Bookmark bar is reparented to BrowserView on NTP.
57 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); 108 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
58 EXPECT_TRUE(bookmark_bar->visible()); 109 EXPECT_TRUE(bookmark_bar->visible());
59 EXPECT_TRUE(bookmark_bar->IsDetached()); 110 EXPECT_TRUE(bookmark_bar->IsDetached());
60 EXPECT_EQ(browser_view, bookmark_bar->parent()); 111 EXPECT_EQ(browser_view, bookmark_bar->parent());
61 // Top container is still in front. 112 // Top container is still in front.
62 EXPECT_EQ(browser_view->child_count() - 1, 113 EXPECT_EQ(browser_view->child_count() - 1,
63 browser_view->GetIndexOf(top_container)); 114 browser_view->GetIndexOf(top_container));
64 115
116 // Bookmark bar layout on NTP.
117 EXPECT_EQ(0, bookmark_bar->x());
118 EXPECT_EQ(
119 tabstrip->bounds().bottom() +
120 toolbar->height() -
121 BrowserViewLayout::kToolbarTabStripVerticalOverlap -
122 views::NonClientFrameView::kClientEdgeThickness,
123 bookmark_bar->y());
124 EXPECT_EQ(toolbar->bounds().bottom(), contents_split->y());
125 // Contents view has a "top margin" pushing it below the bookmark bar.
126 EXPECT_EQ(bookmark_bar->height() -
127 views::NonClientFrameView::kClientEdgeThickness,
128 contents_web_view->y());
129
65 // Bookmark bar is parented back to top container on normal page. 130 // Bookmark bar is parented back to top container on normal page.
66 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 131 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
67 EXPECT_FALSE(bookmark_bar->visible()); 132 EXPECT_FALSE(bookmark_bar->visible());
68 EXPECT_FALSE(bookmark_bar->IsDetached()); 133 EXPECT_FALSE(bookmark_bar->IsDetached());
69 EXPECT_EQ(top_container, bookmark_bar->parent()); 134 EXPECT_EQ(top_container, bookmark_bar->parent());
70 // Top container is still in front. 135 // Top container is still in front.
71 EXPECT_EQ(browser_view->child_count() - 1, 136 EXPECT_EQ(browser_view->child_count() - 1,
72 browser_view->GetIndexOf(top_container)); 137 browser_view->GetIndexOf(top_container));
73 138
74 BookmarkBarView::DisableAnimationsForTesting(false); 139 BookmarkBarView::DisableAnimationsForTesting(false);
(...skipping 13 matching lines...) Expand all
88 153
89 // Focus starts in the location bar or one of its children. 154 // Focus starts in the location bar or one of its children.
90 EXPECT_TRUE(location_bar_view->Contains(focus_manager->GetFocusedView())); 155 EXPECT_TRUE(location_bar_view->Contains(focus_manager->GetFocusedView()));
91 156
92 chrome::ToggleFullscreenMode(browser()); 157 chrome::ToggleFullscreenMode(browser());
93 EXPECT_TRUE(browser_view->IsFullscreen()); 158 EXPECT_TRUE(browser_view->IsFullscreen());
94 159
95 // Focus is released from the location bar. 160 // Focus is released from the location bar.
96 EXPECT_FALSE(location_bar_view->Contains(focus_manager->GetFocusedView())); 161 EXPECT_FALSE(location_bar_view->Contains(focus_manager->GetFocusedView()));
97 } 162 }
163
164 //////////////////////////////////////////////////////////////////////////////
165
166 // Immersive fullscreen is currently enabled only on Chrome OS.
167 #if defined(OS_CHROMEOS)
168
169 class BrowserViewImmersiveInstantExtendedTest : public InProcessBrowserTest,
170 public InstantTestBase {
171 public:
172 BrowserViewImmersiveInstantExtendedTest() {}
173 virtual ~BrowserViewImmersiveInstantExtendedTest() {}
174
175 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
176 chrome::EnableImmersiveFullscreenForTest();
177 chrome::EnableInstantExtendedAPIForTesting();
178 ASSERT_TRUE(https_test_server().Start());
179 GURL instant_url = https_test_server().GetURL(
180 "files/instant_extended.html?strk=1&");
181 InstantTestBase::Init(instant_url);
182 }
183
184 private:
185 DISALLOW_COPY_AND_ASSIGN(BrowserViewImmersiveInstantExtendedTest);
186 };
187
188 IN_PROC_BROWSER_TEST_F(BrowserViewImmersiveInstantExtendedTest,
189 ImmersiveInstantExtended) {
190 ui::ScopedAnimationDurationScaleMode zero_duration_mode(
191 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
192 BookmarkBarView::DisableAnimationsForTesting(true);
193
194 // Cache some pointers we'll need below.
195 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
196 ToolbarView* toolbar = browser_view->toolbar();
197
198 // Start up both instant and immersive fullscreen.
199 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
200 ASSERT_TRUE(chrome::UseImmersiveFullscreen());
201 chrome::ToggleFullscreenMode(browser());
202 ASSERT_TRUE(browser_view->IsFullscreen());
203 ASSERT_TRUE(browser_view->immersive_mode_controller()->IsEnabled());
204
205 // Focus omnibox, which constructs an overlay web contents.
206 FocusOmniboxAndWaitForInstantExtendedSupport();
207 EXPECT_TRUE(instant()->model()->mode().is_default());
208 // The above testing code doesn't trigger the views location bar focus path,
209 // so force it to happen explicitly.
210 browser_view->SetFocusToLocationBar(false);
211 EXPECT_TRUE(browser_view->immersive_mode_controller()->IsRevealed());
212 // Content area is immediately below the tab indicators.
213 views::WebView* contents_web_view =
214 browser_view->GetContentsWebViewForTest();
215 EXPECT_EQ(GetRectInWidget(browser_view).y() + Tab::GetImmersiveHeight(),
216 GetRectInWidget(contents_web_view).y());
217
218 // Typing in the omnibox should show suggestions in an overlay view.
219 SetOmniboxTextAndWaitForOverlayToShow("query");
220 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions());
221 // Content area is still immediately below the tab indicators.
222 EXPECT_EQ(GetRectInWidget(browser_view).y() + Tab::GetImmersiveHeight(),
223 GetRectInWidget(contents_web_view).y());
224 // Overlay web view (with suggestions) aligns with the bottom of the omnibox.
225 gfx::Rect overlay_rect_in_widget = GetRectInWidget(
226 browser_view->GetContentsContainerForTest()->GetOverlayWebViewForTest());
227 EXPECT_EQ(GetRectInWidget(toolbar).bottom(), overlay_rect_in_widget.y());
228
229 // TODO(jamescook): Add a test similar to InstantExtendedTest
230 // EscapeClearsOmnibox that navigates to NTP, does a search that puts
231 // suggestions in the active contents, then checks active web contents
232 // location.
233
234 BookmarkBarView::DisableAnimationsForTesting(false);
235 }
236
237 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698