OLD | NEW |
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/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
8 #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" |
9 #include "chrome/browser/ui/views/frame/immersive_mode_controller.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" |
10 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
11 #include "chrome/browser/ui/views/tabs/tab.h" | 15 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
12 #include "chrome/browser/ui/views/toolbar_view.h" | 16 #include "chrome/browser/ui/views/toolbar_view.h" |
13 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
15 #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" |
16 #include "ui/views/controls/webview/webview.h" | 21 #include "ui/views/controls/webview/webview.h" |
17 #include "ui/views/focus/focus_manager.h" | 22 #include "ui/views/focus/focus_manager.h" |
18 #include "ui/views/window/non_client_view.h" | 23 #include "ui/views/window/non_client_view.h" |
19 | 24 |
20 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
21 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 26 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
22 #include "chrome/browser/search/search.h" | 27 #include "chrome/browser/search/search.h" |
23 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 28 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
24 #include "chrome/browser/ui/search/instant_test_utils.h" | 29 #include "chrome/browser/ui/search/instant_test_utils.h" |
25 #include "chrome/browser/ui/views/frame/contents_container.h" | 30 #include "chrome/browser/ui/views/frame/contents_container.h" |
26 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
27 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
28 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 33 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
29 #endif | 34 #endif |
30 | 35 |
31 using views::FocusManager; | 36 using views::FocusManager; |
32 | 37 |
33 namespace { | 38 namespace { |
34 | 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 |
35 // Returns the bounds of |view| in widget coordinates. | 51 // Returns the bounds of |view| in widget coordinates. |
36 gfx::Rect GetRectInWidget(views::View* view) { | 52 gfx::Rect GetRectInWidget(views::View* view) { |
37 return view->ConvertRectToWidget(view->GetLocalBounds()); | 53 return view->ConvertRectToWidget(view->GetLocalBounds()); |
38 } | 54 } |
39 | 55 |
40 } | 56 } |
41 | 57 |
42 typedef InProcessBrowserTest BrowserViewTest; | 58 typedef InProcessBrowserTest BrowserViewTest; |
43 | 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 |
44 // Active window and focus testing is not reliable on Windows crbug.com/79493 | 146 // Active window and focus testing is not reliable on Windows crbug.com/79493 |
45 // TODO(linux_aura) http://crbug.com/163931 | 147 // TODO(linux_aura) http://crbug.com/163931 |
46 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US
E_AURA)) | 148 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(US
E_AURA)) |
47 #define MAYBE_FullscreenClearsFocus DISABLED_FullscreenClearsFocus | 149 #define MAYBE_FullscreenClearsFocus DISABLED_FullscreenClearsFocus |
48 #else | 150 #else |
49 #define MAYBE_FullscreenClearsFocus FullscreenClearsFocus | 151 #define MAYBE_FullscreenClearsFocus FullscreenClearsFocus |
50 #endif | 152 #endif |
51 IN_PROC_BROWSER_TEST_F(BrowserViewTest, MAYBE_FullscreenClearsFocus) { | 153 IN_PROC_BROWSER_TEST_F(BrowserViewTest, MAYBE_FullscreenClearsFocus) { |
52 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); | 154 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); |
53 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); | 155 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 EXPECT_TRUE(browser_view->immersive_mode_controller()->IsRevealed()); | 271 EXPECT_TRUE(browser_view->immersive_mode_controller()->IsRevealed()); |
170 // The active web contents are aligned with the toolbar. | 272 // The active web contents are aligned with the toolbar. |
171 gfx::Rect web_view_rect_in_widget = GetRectInWidget( | 273 gfx::Rect web_view_rect_in_widget = GetRectInWidget( |
172 browser_view->GetContentsContainerForTest()->GetActiveWebViewForTest()); | 274 browser_view->GetContentsContainerForTest()->GetActiveWebViewForTest()); |
173 EXPECT_EQ(GetRectInWidget(toolbar).bottom(), web_view_rect_in_widget.y()); | 275 EXPECT_EQ(GetRectInWidget(toolbar).bottom(), web_view_rect_in_widget.y()); |
174 | 276 |
175 BookmarkBarView::DisableAnimationsForTesting(false); | 277 BookmarkBarView::DisableAnimationsForTesting(false); |
176 } | 278 } |
177 | 279 |
178 #endif // defined(OS_CHROMEOS) | 280 #endif // defined(OS_CHROMEOS) |
OLD | NEW |