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 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 6 |
| 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/ui/browser_commands.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" |
| 12 #include "chrome/browser/ui/views/frame/top_container_view.h" |
| 13 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" |
| 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 15 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 16 #include "chrome/browser/ui/views/toolbar_view.h" |
| 17 #include "chrome/common/url_constants.h" |
| 18 #include "chrome/test/base/in_process_browser_test.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" |
| 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/autocomplete/autocomplete_controller.h" |
| 27 #include "chrome/browser/search/search.h" |
| 28 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 29 #include "chrome/browser/ui/search/instant_test_utils.h" |
| 30 #include "chrome/browser/ui/views/frame/contents_container.h" |
| 31 #include "chrome/common/chrome_notification_types.h" |
| 32 #include "content/public/browser/notification_service.h" |
| 33 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 34 #endif |
| 35 |
| 36 using views::FocusManager; |
| 37 |
| 38 namespace { |
| 39 |
| 40 // Tab strip bounds depend on the window frame sizes. |
| 41 gfx::Point ExpectedTabStripOrigin(BrowserView* browser_view) { |
| 42 gfx::Rect tabstrip_bounds( |
| 43 browser_view->frame()->GetBoundsForTabStrip(browser_view->tabstrip())); |
| 44 gfx::Point tabstrip_origin(tabstrip_bounds.origin()); |
| 45 views::View::ConvertPointToTarget(browser_view->parent(), |
| 46 browser_view, |
| 47 &tabstrip_origin); |
| 48 return tabstrip_origin; |
| 49 } |
| 50 |
| 51 // Returns the bounds of |view| in widget coordinates. |
| 52 gfx::Rect GetRectInWidget(views::View* view) { |
| 53 return view->ConvertRectToWidget(view->GetLocalBounds()); |
| 54 } |
| 55 |
| 56 } |
| 57 |
| 58 typedef InProcessBrowserTest BrowserViewTest; |
| 59 |
| 60 IN_PROC_BROWSER_TEST_F(BrowserViewTest, BrowserView) { |
| 61 BookmarkBarView::DisableAnimationsForTesting(true); |
| 62 |
| 63 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); |
| 64 TopContainerView* top_container = browser_view->top_container(); |
| 65 TabStrip* tabstrip = browser_view->tabstrip(); |
| 66 ToolbarView* toolbar = browser_view->toolbar(); |
| 67 views::SingleSplitView* contents_split = |
| 68 browser_view->GetContentsSplitForTest(); |
| 69 views::WebView* contents_web_view = |
| 70 browser_view->GetContentsWebViewForTest(); |
| 71 |
| 72 // Verify the view hierarchy. |
| 73 EXPECT_EQ(top_container, browser_view->tabstrip()->parent()); |
| 74 EXPECT_EQ(top_container, browser_view->toolbar()->parent()); |
| 75 EXPECT_EQ(top_container, browser_view->GetBookmarkBarView()->parent()); |
| 76 EXPECT_EQ(browser_view, browser_view->infobar_container()->parent()); |
| 77 |
| 78 // Top container is at the front of the view hierarchy. |
| 79 EXPECT_EQ(browser_view->child_count() - 1, |
| 80 browser_view->GetIndexOf(top_container)); |
| 81 |
| 82 // Verify basic layout. |
| 83 EXPECT_EQ(0, top_container->x()); |
| 84 EXPECT_EQ(0, top_container->y()); |
| 85 EXPECT_EQ(browser_view->width(), top_container->width()); |
| 86 // Tabstrip layout varies based on window frame sizes. |
| 87 gfx::Point expected_tabstrip_origin = ExpectedTabStripOrigin(browser_view); |
| 88 EXPECT_EQ(expected_tabstrip_origin.x(), tabstrip->x()); |
| 89 EXPECT_EQ(expected_tabstrip_origin.y(), tabstrip->y()); |
| 90 EXPECT_EQ(0, toolbar->x()); |
| 91 EXPECT_EQ( |
| 92 tabstrip->bounds().bottom() - |
| 93 BrowserViewLayout::kToolbarTabStripVerticalOverlap, |
| 94 toolbar->y()); |
| 95 EXPECT_EQ(0, contents_split->x()); |
| 96 EXPECT_EQ(toolbar->bounds().bottom(), contents_split->y()); |
| 97 EXPECT_EQ(0, contents_web_view->x()); |
| 98 EXPECT_EQ(0, contents_web_view->y()); |
| 99 |
| 100 // Verify bookmark bar visibility. |
| 101 BookmarkBarView* bookmark_bar = browser_view->GetBookmarkBarView(); |
| 102 EXPECT_FALSE(bookmark_bar->visible()); |
| 103 EXPECT_FALSE(bookmark_bar->IsDetached()); |
| 104 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR); |
| 105 EXPECT_TRUE(bookmark_bar->visible()); |
| 106 EXPECT_FALSE(bookmark_bar->IsDetached()); |
| 107 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR); |
| 108 EXPECT_FALSE(bookmark_bar->visible()); |
| 109 EXPECT_FALSE(bookmark_bar->IsDetached()); |
| 110 |
| 111 // Bookmark bar is reparented to BrowserView on NTP. |
| 112 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
| 113 EXPECT_TRUE(bookmark_bar->visible()); |
| 114 EXPECT_TRUE(bookmark_bar->IsDetached()); |
| 115 EXPECT_EQ(browser_view, bookmark_bar->parent()); |
| 116 // Top container is still in front. |
| 117 EXPECT_EQ(browser_view->child_count() - 1, |
| 118 browser_view->GetIndexOf(top_container)); |
| 119 |
| 120 // Bookmark bar layout on NTP. |
| 121 EXPECT_EQ(0, bookmark_bar->x()); |
| 122 EXPECT_EQ( |
| 123 tabstrip->bounds().bottom() + |
| 124 toolbar->height() - |
| 125 BrowserViewLayout::kToolbarTabStripVerticalOverlap - |
| 126 views::NonClientFrameView::kClientEdgeThickness, |
| 127 bookmark_bar->y()); |
| 128 EXPECT_EQ(toolbar->bounds().bottom(), contents_split->y()); |
| 129 // Contents view has a "top margin" pushing it below the bookmark bar. |
| 130 EXPECT_EQ(bookmark_bar->height() - |
| 131 views::NonClientFrameView::kClientEdgeThickness, |
| 132 contents_web_view->y()); |
| 133 |
| 134 // Bookmark bar is parented back to top container on normal page. |
| 135 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 136 EXPECT_FALSE(bookmark_bar->visible()); |
| 137 EXPECT_FALSE(bookmark_bar->IsDetached()); |
| 138 EXPECT_EQ(top_container, bookmark_bar->parent()); |
| 139 // Top container is still in front. |
| 140 EXPECT_EQ(browser_view->child_count() - 1, |
| 141 browser_view->GetIndexOf(top_container)); |
| 142 |
| 143 BookmarkBarView::DisableAnimationsForTesting(false); |
| 144 } |
| 145 |
| 146 // Active window and focus testing is not reliable on Windows crbug.com/79493 |
| 147 // TODO(linux_aura) http://crbug.com/163931 |
| 148 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US
E_AURA)) |
| 149 #define MAYBE_FullscreenClearsFocus DISABLED_FullscreenClearsFocus |
| 150 #else |
| 151 #define MAYBE_FullscreenClearsFocus FullscreenClearsFocus |
| 152 #endif |
| 153 IN_PROC_BROWSER_TEST_F(BrowserViewTest, MAYBE_FullscreenClearsFocus) { |
| 154 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); |
| 155 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); |
| 156 FocusManager* focus_manager = browser_view->GetFocusManager(); |
| 157 |
| 158 // Focus starts in the location bar or one of its children. |
| 159 EXPECT_TRUE(location_bar_view->Contains(focus_manager->GetFocusedView())); |
| 160 |
| 161 chrome::ToggleFullscreenMode(browser()); |
| 162 EXPECT_TRUE(browser_view->IsFullscreen()); |
| 163 |
| 164 // Focus is released from the location bar. |
| 165 EXPECT_FALSE(location_bar_view->Contains(focus_manager->GetFocusedView())); |
| 166 } |
| 167 |
| 168 ////////////////////////////////////////////////////////////////////////////// |
| 169 |
| 170 // Immersive fullscreen is currently enabled only on Chrome OS. |
| 171 #if defined(OS_CHROMEOS) |
| 172 |
| 173 class BrowserViewImmersiveInstantExtendedTest : public InProcessBrowserTest, |
| 174 public InstantTestBase { |
| 175 public: |
| 176 BrowserViewImmersiveInstantExtendedTest() {} |
| 177 virtual ~BrowserViewImmersiveInstantExtendedTest() {} |
| 178 |
| 179 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 180 chrome::EnableImmersiveFullscreenForTest(); |
| 181 chrome::EnableInstantExtendedAPIForTesting(); |
| 182 ASSERT_TRUE(https_test_server().Start()); |
| 183 GURL instant_url = https_test_server().GetURL( |
| 184 "files/instant_extended.html?strk=1&"); |
| 185 InstantTestBase::Init(instant_url); |
| 186 } |
| 187 |
| 188 private: |
| 189 DISALLOW_COPY_AND_ASSIGN(BrowserViewImmersiveInstantExtendedTest); |
| 190 }; |
| 191 |
| 192 IN_PROC_BROWSER_TEST_F(BrowserViewImmersiveInstantExtendedTest, |
| 193 ImmersiveInstantExtended) { |
| 194 ui::ScopedAnimationDurationScaleMode zero_duration_mode( |
| 195 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| 196 BookmarkBarView::DisableAnimationsForTesting(true); |
| 197 |
| 198 // Cache some pointers we'll need below. |
| 199 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); |
| 200 ToolbarView* toolbar = browser_view->toolbar(); |
| 201 |
| 202 // Start up both instant and immersive fullscreen. |
| 203 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 204 ASSERT_TRUE(chrome::UseImmersiveFullscreen()); |
| 205 chrome::ToggleFullscreenMode(browser()); |
| 206 ASSERT_TRUE(browser_view->IsFullscreen()); |
| 207 ASSERT_TRUE(browser_view->immersive_mode_controller()->IsEnabled()); |
| 208 |
| 209 //////////////////////////////////////////////////////////////////////////// |
| 210 // Test suggestions on a normal web page, which are in an overlay. |
| 211 |
| 212 // Focus omnibox, which constructs an overlay web contents. |
| 213 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 214 EXPECT_TRUE(instant()->model()->mode().is_default()); |
| 215 // The above testing code doesn't trigger the views location bar focus path, |
| 216 // so force it to happen explicitly. |
| 217 browser_view->SetFocusToLocationBar(false); |
| 218 EXPECT_TRUE(browser_view->immersive_mode_controller()->IsRevealed()); |
| 219 // Content area is immediately below the tab indicators. |
| 220 views::WebView* contents_web_view = |
| 221 browser_view->GetContentsWebViewForTest(); |
| 222 EXPECT_EQ(GetRectInWidget(browser_view).y() + Tab::GetImmersiveHeight(), |
| 223 GetRectInWidget(contents_web_view).y()); |
| 224 |
| 225 // Typing in the omnibox should show suggestions in an overlay view. |
| 226 SetOmniboxTextAndWaitForOverlayToShow("santa"); |
| 227 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); |
| 228 // Content area is still immediately below the tab indicators. |
| 229 EXPECT_EQ(GetRectInWidget(browser_view).y() + Tab::GetImmersiveHeight(), |
| 230 GetRectInWidget(contents_web_view).y()); |
| 231 // Overlay web view (with suggestions) aligns with the bottom of the omnibox. |
| 232 gfx::Rect overlay_rect_in_widget = GetRectInWidget( |
| 233 browser_view->GetContentsContainerForTest()->GetOverlayWebViewForTest()); |
| 234 EXPECT_EQ(GetRectInWidget(toolbar).bottom(), overlay_rect_in_widget.y()); |
| 235 |
| 236 //////////////////////////////////////////////////////////////////////////// |
| 237 // Test suggestions on the NTP, which are not in an overlay. |
| 238 |
| 239 // Navigate to the Instant NTP, and wait for it to be recognized. |
| 240 content::WindowedNotificationObserver instant_tab_observer( |
| 241 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
| 242 content::NotificationService::AllSources()); |
| 243 ui_test_utils::NavigateToURLWithDisposition(browser(), |
| 244 GURL(chrome::kChromeUINewTabURL), |
| 245 CURRENT_TAB, |
| 246 ui_test_utils::BROWSER_TEST_NONE); |
| 247 instant_tab_observer.Wait(); |
| 248 |
| 249 // Type in the omnibox, which should generate suggestions in the main page |
| 250 // contents. |
| 251 SetOmniboxText("claus"); |
| 252 // The autocomplete controller isn't done until all the providers are done. |
| 253 // Though we don't care about the SearchProvider when we send autocomplete |
| 254 // results to the page, we do need to cause it to be "done" to make this test |
| 255 // work. Setting the suggestion calls SearchProvider::FinalizeInstantQuery(), |
| 256 // thus causing it to be done. |
| 257 omnibox()->model()->SetInstantSuggestion( |
| 258 InstantSuggestion(ASCIIToUTF16("query"), |
| 259 INSTANT_COMPLETE_NOW, |
| 260 INSTANT_SUGGESTION_SEARCH, |
| 261 ASCIIToUTF16("query"))); |
| 262 while (!omnibox()->model()->autocomplete_controller()->done()) { |
| 263 content::WindowedNotificationObserver autocomplete_observer( |
| 264 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, |
| 265 content::NotificationService::AllSources()); |
| 266 autocomplete_observer.Wait(); |
| 267 } |
| 268 // Ensure JavaScript has finished running by executing a blank script. |
| 269 EXPECT_TRUE(ExecuteScript(std::string())); |
| 270 // We're still revealed, since focus is in the omnibox. |
| 271 EXPECT_TRUE(browser_view->immersive_mode_controller()->IsRevealed()); |
| 272 // The active web contents are aligned with the toolbar. |
| 273 gfx::Rect web_view_rect_in_widget = GetRectInWidget( |
| 274 browser_view->GetContentsContainerForTest()->GetActiveWebViewForTest()); |
| 275 EXPECT_EQ(GetRectInWidget(toolbar).bottom(), web_view_rect_in_widget.y()); |
| 276 |
| 277 BookmarkBarView::DisableAnimationsForTesting(false); |
| 278 } |
| 279 |
| 280 #endif // defined(OS_CHROMEOS) |
OLD | NEW |