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 class BrowserViewTestP : public BrowserViewTest, | |
oshima
2015/07/10 17:43:56
nit: please put this in anonymous namespace to avo
varkha
2015/07/10 19:38:26
Done.
| |
47 public testing::WithParamInterface<bool> { | |
48 public: | |
49 bool TestApp() { return GetParam(); } | |
50 }; | |
51 | |
52 // Test that docked state is remembered for app browser windows and not | |
53 // remembered for tabbed browser windows. | |
54 IN_PROC_BROWSER_TEST_P(BrowserViewTestP, BrowserRemembersDockedState) { | |
55 // Open a new browser window (app or tabbed depending on a parameter). | |
56 bool test_app = TestApp(); | |
57 LOG(INFO) << "test: " << (test_app ? "APP" : "TABBED"); | |
Peter Kasting
2015/07/10 16:40:56
Try to avoid LOG statements, even in tests.
varkha
2015/07/10 19:38:26
Done. Leftover that presubmit doesn't catch.
| |
58 Browser::CreateParams params = | |
59 test_app ? Browser::CreateParams::CreateForApp( | |
60 "test_browser_app", true /* trusted_source */, gfx::Rect(), | |
61 browser()->profile(), browser()->host_desktop_type()) | |
62 : Browser::CreateParams(browser()->profile(), | |
63 browser()->host_desktop_type()); | |
64 params.initial_show_state = ui::SHOW_STATE_NORMAL; | |
65 bool is_ash = browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH; | |
66 // Default |browser()| is not used by this test. | |
67 browser()->window()->Close(); | |
68 | |
69 // Create a new app browser | |
70 Browser* browser = new Browser(params); | |
71 ASSERT_TRUE(browser); | |
72 gfx::NativeWindow window = browser->window()->GetNativeWindow(); | |
73 gfx::Rect original_bounds(gfx::Rect(150, 250, 350, 100)); | |
74 window->SetBounds(original_bounds); | |
75 window->Show(); | |
76 // Dock the browser window using |kShowStateKey| property. | |
77 gfx::Rect work_area = gfx::Screen::GetScreenFor(window) | |
78 ->GetDisplayNearestPoint(window->bounds().origin()) | |
79 .work_area(); | |
80 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_DOCKED); | |
81 | |
82 // Saved placement should reflect docked state (for app windows only in Ash). | |
83 gfx::Rect bounds; | |
84 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; | |
85 const views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | |
86 widget->widget_delegate()->GetSavedWindowPlacement(widget, &bounds, | |
87 &show_state); | |
88 EXPECT_EQ(is_ash && test_app ? ui::SHOW_STATE_DOCKED : ui::SHOW_STATE_NORMAL, | |
89 show_state); | |
90 // Docking is only relevant on Ash desktop. | |
91 if (!is_ash) | |
92 return; | |
93 | |
94 // Saved placement should reflect restore bounds. | |
95 ASSERT_NE(nullptr, window->GetProperty(aura::client::kRestoreBoundsKey)); | |
96 original_bounds = *window->GetProperty(aura::client::kRestoreBoundsKey); | |
97 gfx::Rect expected_bounds = work_area; | |
98 expected_bounds.ClampToCenteredSize(original_bounds.size()); | |
99 expected_bounds.set_y(original_bounds.y()); | |
100 EXPECT_EQ(expected_bounds.ToString(), bounds.ToString()); | |
101 EXPECT_EQ(expected_bounds.ToString(), original_bounds.ToString()); | |
102 | |
103 // Browser window should be docked. | |
104 int width = 250; // same as DockedWindowLayoutManager::kIdealWidth. | |
105 if (window->delegate() && window->delegate()->GetMinimumSize().width() != 0) | |
106 width = std::max(width, window->delegate()->GetMinimumSize().width()); | |
107 expected_bounds = work_area; | |
108 expected_bounds.set_width(width); | |
109 expected_bounds.set_x(work_area.right() - expected_bounds.width()); | |
110 EXPECT_EQ(expected_bounds.ToString(), window->GetTargetBounds().ToString()); | |
111 EXPECT_EQ(ui::SHOW_STATE_DOCKED, | |
112 window->GetProperty(aura::client::kShowStateKey)); | |
113 browser->window()->Close(); | |
114 | |
115 // Newly created browser with the same app name should retain docked state | |
116 // for app browser window but leave it as normal for a tabbed browser. | |
117 browser = new Browser(params); | |
118 ASSERT_TRUE(browser); | |
119 browser->window()->Show(); | |
120 window = browser->window()->GetNativeWindow(); | |
121 EXPECT_EQ(test_app ? expected_bounds.ToString() : original_bounds.ToString(), | |
122 window->GetTargetBounds().ToString()); | |
123 EXPECT_EQ(test_app ? ui::SHOW_STATE_DOCKED : ui::SHOW_STATE_NORMAL, | |
124 window->GetProperty(aura::client::kShowStateKey)); | |
125 | |
126 // Undocking the browser window should restore original size and vertical | |
127 // offset while centering the window horizontally. | |
128 // Tabbed window is already not docked. | |
129 expected_bounds = work_area; | |
130 expected_bounds.ClampToCenteredSize(original_bounds.size()); | |
131 expected_bounds.set_y(original_bounds.y()); | |
132 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
133 EXPECT_EQ(expected_bounds.ToString(), window->GetTargetBounds().ToString()); | |
134 EXPECT_EQ(ui::SHOW_STATE_NORMAL, | |
135 window->GetProperty(aura::client::kShowStateKey)); | |
136 browser->window()->Close(); | |
137 | |
138 // Re-create the browser window with the same app name. | |
139 browser = new Browser(params); | |
140 ASSERT_TRUE(browser); | |
141 browser->window()->Show(); | |
142 | |
143 // Newly created browser should retain undocked state and bounds. | |
144 window = browser->window()->GetNativeWindow(); | |
145 EXPECT_EQ(expected_bounds.ToString(), window->GetTargetBounds().ToString()); | |
146 EXPECT_EQ(ui::SHOW_STATE_NORMAL, | |
147 window->GetProperty(aura::client::kShowStateKey)); | |
148 } | |
149 | |
150 INSTANTIATE_TEST_CASE_P(BrowserViewTestTabbedOrApp, | |
151 BrowserViewTestP, | |
152 testing::Bool()); | |
153 #endif | |
OLD | NEW |