OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/browser/ui/browser_commands.h" | 7 #include "chrome/browser/ui/browser_commands.h" |
8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
10 #include "ui/views/focus/focus_manager.h" | 10 #include "ui/views/focus/focus_manager.h" |
11 | 11 |
| 12 #if defined(USE_AURA) |
| 13 #include "chrome/browser/ui/browser_window_state.h" |
| 14 #include "ui/aura/client/aura_constants.h" |
| 15 #include "ui/aura/window.h" |
| 16 #include "ui/aura/window_delegate.h" |
| 17 #include "ui/gfx/screen.h" |
| 18 #endif |
| 19 |
12 using views::FocusManager; | 20 using views::FocusManager; |
13 | 21 |
14 typedef InProcessBrowserTest BrowserViewTest; | 22 typedef InProcessBrowserTest BrowserViewTest; |
15 | 23 |
16 // Active window and focus testing is not reliable on Windows crbug.com/79493 | 24 // Active window and focus testing is not reliable on Windows crbug.com/79493 |
17 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
18 #define MAYBE_FullscreenClearsFocus DISABLED_FullscreenClearsFocus | 26 #define MAYBE_FullscreenClearsFocus DISABLED_FullscreenClearsFocus |
19 #else | 27 #else |
20 #define MAYBE_FullscreenClearsFocus FullscreenClearsFocus | 28 #define MAYBE_FullscreenClearsFocus FullscreenClearsFocus |
21 #endif | 29 #endif |
22 IN_PROC_BROWSER_TEST_F(BrowserViewTest, MAYBE_FullscreenClearsFocus) { | 30 IN_PROC_BROWSER_TEST_F(BrowserViewTest, MAYBE_FullscreenClearsFocus) { |
23 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); | 31 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); |
24 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); | 32 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); |
25 FocusManager* focus_manager = browser_view->GetFocusManager(); | 33 FocusManager* focus_manager = browser_view->GetFocusManager(); |
26 | 34 |
27 // Focus starts in the location bar or one of its children. | 35 // Focus starts in the location bar or one of its children. |
28 EXPECT_TRUE(location_bar_view->Contains(focus_manager->GetFocusedView())); | 36 EXPECT_TRUE(location_bar_view->Contains(focus_manager->GetFocusedView())); |
29 | 37 |
30 chrome::ToggleFullscreenMode(browser()); | 38 chrome::ToggleFullscreenMode(browser()); |
31 EXPECT_TRUE(browser_view->IsFullscreen()); | 39 EXPECT_TRUE(browser_view->IsFullscreen()); |
32 | 40 |
33 // Focus is released from the location bar. | 41 // Focus is released from the location bar. |
34 EXPECT_FALSE(location_bar_view->Contains(focus_manager->GetFocusedView())); | 42 EXPECT_FALSE(location_bar_view->Contains(focus_manager->GetFocusedView())); |
35 } | 43 } |
| 44 |
| 45 #if defined(USE_AURA) |
| 46 namespace { |
| 47 |
| 48 class BrowserViewTestParam : public BrowserViewTest, |
| 49 public testing::WithParamInterface<bool> { |
| 50 public: |
| 51 bool TestApp() { return GetParam(); } |
| 52 }; |
| 53 |
| 54 } // namespace |
| 55 |
| 56 // Test that docked state is remembered for app browser windows and not |
| 57 // remembered for tabbed browser windows. |
| 58 IN_PROC_BROWSER_TEST_P(BrowserViewTestParam, BrowserRemembersDockedState) { |
| 59 // Open a new browser window (app or tabbed depending on a parameter). |
| 60 bool test_app = TestApp(); |
| 61 Browser::CreateParams params = |
| 62 test_app ? Browser::CreateParams::CreateForApp( |
| 63 "test_browser_app", true /* trusted_source */, gfx::Rect(), |
| 64 browser()->profile(), browser()->host_desktop_type()) |
| 65 : Browser::CreateParams(browser()->profile(), |
| 66 browser()->host_desktop_type()); |
| 67 params.initial_show_state = ui::SHOW_STATE_NORMAL; |
| 68 bool is_ash = browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH; |
| 69 // Default |browser()| is not used by this test. |
| 70 browser()->window()->Close(); |
| 71 |
| 72 // Create a new app browser |
| 73 Browser* browser = new Browser(params); |
| 74 ASSERT_TRUE(browser); |
| 75 gfx::NativeWindow window = browser->window()->GetNativeWindow(); |
| 76 gfx::Rect original_bounds(gfx::Rect(150, 250, 350, 100)); |
| 77 window->SetBounds(original_bounds); |
| 78 window->Show(); |
| 79 // Dock the browser window using |kShowStateKey| property. |
| 80 gfx::Rect work_area = gfx::Screen::GetScreenFor(window) |
| 81 ->GetDisplayNearestPoint(window->bounds().origin()) |
| 82 .work_area(); |
| 83 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_DOCKED); |
| 84 |
| 85 // Saved placement should reflect docked state (for app windows only in Ash). |
| 86 gfx::Rect bounds; |
| 87 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; |
| 88 const views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 89 widget->widget_delegate()->GetSavedWindowPlacement(widget, &bounds, |
| 90 &show_state); |
| 91 EXPECT_EQ(is_ash && test_app ? ui::SHOW_STATE_DOCKED : ui::SHOW_STATE_NORMAL, |
| 92 show_state); |
| 93 // Docking is only relevant on Ash desktop. |
| 94 if (!is_ash) |
| 95 return; |
| 96 |
| 97 // Saved placement should reflect restore bounds. |
| 98 ASSERT_NE(nullptr, window->GetProperty(aura::client::kRestoreBoundsKey)); |
| 99 original_bounds = *window->GetProperty(aura::client::kRestoreBoundsKey); |
| 100 gfx::Rect expected_bounds = work_area; |
| 101 expected_bounds.ClampToCenteredSize(original_bounds.size()); |
| 102 expected_bounds.set_y(original_bounds.y()); |
| 103 EXPECT_EQ(expected_bounds.ToString(), bounds.ToString()); |
| 104 EXPECT_EQ(expected_bounds.ToString(), original_bounds.ToString()); |
| 105 |
| 106 // Browser window should be docked. |
| 107 int width = 250; // same as DockedWindowLayoutManager::kIdealWidth. |
| 108 if (window->delegate() && window->delegate()->GetMinimumSize().width() != 0) |
| 109 width = std::max(width, window->delegate()->GetMinimumSize().width()); |
| 110 expected_bounds = work_area; |
| 111 expected_bounds.set_width(width); |
| 112 expected_bounds.set_x(work_area.right() - expected_bounds.width()); |
| 113 EXPECT_EQ(expected_bounds.ToString(), window->GetTargetBounds().ToString()); |
| 114 EXPECT_EQ(ui::SHOW_STATE_DOCKED, |
| 115 window->GetProperty(aura::client::kShowStateKey)); |
| 116 browser->window()->Close(); |
| 117 |
| 118 // Newly created browser with the same app name should retain docked state |
| 119 // for app browser window but leave it as normal for a tabbed browser. |
| 120 browser = new Browser(params); |
| 121 ASSERT_TRUE(browser); |
| 122 browser->window()->Show(); |
| 123 window = browser->window()->GetNativeWindow(); |
| 124 EXPECT_EQ(test_app ? expected_bounds.ToString() : original_bounds.ToString(), |
| 125 window->GetTargetBounds().ToString()); |
| 126 EXPECT_EQ(test_app ? ui::SHOW_STATE_DOCKED : ui::SHOW_STATE_NORMAL, |
| 127 window->GetProperty(aura::client::kShowStateKey)); |
| 128 |
| 129 // Undocking the browser window should restore original size and vertical |
| 130 // offset while centering the window horizontally. |
| 131 // Tabbed window is already not docked. |
| 132 expected_bounds = work_area; |
| 133 expected_bounds.ClampToCenteredSize(original_bounds.size()); |
| 134 expected_bounds.set_y(original_bounds.y()); |
| 135 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 136 EXPECT_EQ(expected_bounds.ToString(), window->GetTargetBounds().ToString()); |
| 137 EXPECT_EQ(ui::SHOW_STATE_NORMAL, |
| 138 window->GetProperty(aura::client::kShowStateKey)); |
| 139 browser->window()->Close(); |
| 140 |
| 141 // Re-create the browser window with the same app name. |
| 142 browser = new Browser(params); |
| 143 ASSERT_TRUE(browser); |
| 144 browser->window()->Show(); |
| 145 |
| 146 // Newly created browser should retain undocked state and bounds. |
| 147 window = browser->window()->GetNativeWindow(); |
| 148 EXPECT_EQ(expected_bounds.ToString(), window->GetTargetBounds().ToString()); |
| 149 EXPECT_EQ(ui::SHOW_STATE_NORMAL, |
| 150 window->GetProperty(aura::client::kShowStateKey)); |
| 151 } |
| 152 |
| 153 INSTANTIATE_TEST_CASE_P(BrowserViewTestTabbedOrApp, |
| 154 BrowserViewTestParam, |
| 155 testing::Bool()); |
| 156 #endif |
OLD | NEW |