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

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

Issue 2690563005: cros: Disable the auto management logic for v1app browser window (Closed)
Patch Set: scope tests to OS_CHROMEOS Created 3 years, 10 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
OLDNEW
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/ui/browser_commands.h" 9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 10 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 namespace { 53 namespace {
54 54
55 class BrowserViewTestParam : public BrowserViewTest, 55 class BrowserViewTestParam : public BrowserViewTest,
56 public testing::WithParamInterface<bool> { 56 public testing::WithParamInterface<bool> {
57 public: 57 public:
58 bool TestApp() { return GetParam(); } 58 bool TestApp() { return GetParam(); }
59 }; 59 };
60 60
61 } // namespace 61 } // namespace
62 62
63 #if defined(OS_CHROMEOS)
64 // Test that in Chrome OS, for app browser (v1app) windows, the auto management
65 // logic is disabled while for tabbed browser windows, it is enabled.
66 IN_PROC_BROWSER_TEST_P(BrowserViewTestParam,
sky 2017/02/13 17:43:03 Why does this need to be in interactive tests?
Qiang(Joe) Xu 2017/02/13 22:39:34 It doesn't need. I moved it to browser_browsertest
67 TabbedOrAppBrowserWindowAutoManagementTest) {
68 // Default |browser()| is not used by this test.
69 browser()->window()->Close();
70
71 // Open a new browser window (app or tabbed depending on a parameter).
72 bool test_app = TestApp();
73 Browser::CreateParams params =
74 test_app ? Browser::CreateParams::CreateForApp(
75 "test_browser_app", true /* trusted_source */, gfx::Rect(),
76 browser()->profile())
77 : Browser::CreateParams(browser()->profile());
78 params.initial_show_state = ui::SHOW_STATE_DEFAULT;
79 Browser* browser = new Browser(params);
80 ASSERT_TRUE(browser);
sky 2017/02/13 17:43:03 We don't assert that new returns non-null. If new
Qiang(Joe) Xu 2017/02/13 22:39:34 Done.
81 gfx::NativeWindow window = browser->window()->GetNativeWindow();
82 gfx::Rect original_bounds(gfx::Rect(150, 250, 400, 100));
83 window->SetBounds(original_bounds);
84 window->Show();
85
86 // For tabbed browser window, it will be centered to work area by auto window
87 // mangement logic; for app browser window, it will remain the given bounds.
88 gfx::Rect work_area = display::Screen::GetScreen()
89 ->GetDisplayNearestPoint(window->bounds().origin())
90 .work_area();
91 gfx::Rect tabbed_expected_bounds = work_area;
92 tabbed_expected_bounds.ClampToCenteredSize(original_bounds.size());
93 tabbed_expected_bounds.set_y(original_bounds.y());
94 if (test_app)
95 EXPECT_EQ(original_bounds.ToString(), window->bounds().ToString());
96 else
97 EXPECT_EQ(tabbed_expected_bounds.ToString(), window->bounds().ToString());
98
99 // Close the browser and re-create the browser window with the same app name.
100 browser->window()->Close();
101 browser = new Browser(params);
102 ASSERT_TRUE(browser);
sky 2017/02/13 17:43:03 Same comment about checking return value from new.
Qiang(Joe) Xu 2017/02/13 22:39:34 Done.
103 browser->window()->Show();
104
105 // The newly created browser window should remain the same bounds for each.
106 window = browser->window()->GetNativeWindow();
107 if (test_app)
108 EXPECT_EQ(original_bounds.ToString(), window->bounds().ToString());
109 else
110 EXPECT_EQ(tabbed_expected_bounds.ToString(), window->bounds().ToString());
111 }
112 #endif // defined(OS_CHROMEOS)
113
63 // Test that docked state is remembered for app browser windows and not 114 // Test that docked state is remembered for app browser windows and not
64 // remembered for tabbed browser windows. 115 // remembered for tabbed browser windows.
65 IN_PROC_BROWSER_TEST_P(BrowserViewTestParam, BrowserRemembersDockedState) { 116 IN_PROC_BROWSER_TEST_P(BrowserViewTestParam, BrowserRemembersDockedState) {
66 #if defined(USE_ASH) 117 #if defined(USE_ASH)
67 // Enable window docking for this test. 118 // Enable window docking for this test.
68 base::CommandLine::ForCurrentProcess()->AppendSwitch( 119 base::CommandLine::ForCurrentProcess()->AppendSwitch(
69 ash::switches::kAshEnableDockedWindows); 120 ash::switches::kAshEnableDockedWindows);
70 const bool kIsAsh = true; 121 const bool kIsAsh = true;
71 #else 122 #else
72 const bool kIsAsh = false; 123 const bool kIsAsh = false;
(...skipping 12 matching lines...) Expand all
85 browser()->window()->Close(); 136 browser()->window()->Close();
86 137
87 // Create a new app browser 138 // Create a new app browser
88 Browser* browser = new Browser(params); 139 Browser* browser = new Browser(params);
89 ASSERT_TRUE(browser); 140 ASSERT_TRUE(browser);
90 gfx::NativeWindow window = browser->window()->GetNativeWindow(); 141 gfx::NativeWindow window = browser->window()->GetNativeWindow();
91 gfx::Rect original_bounds(gfx::Rect(150, 250, 400, 100)); 142 gfx::Rect original_bounds(gfx::Rect(150, 250, 400, 100));
92 window->SetBounds(original_bounds); 143 window->SetBounds(original_bounds);
93 window->Show(); 144 window->Show();
94 // Dock the browser window using |kShowStateKey| property. 145 // Dock the browser window using |kShowStateKey| property.
95 gfx::Rect work_area = display::Screen::GetScreen()
96 ->GetDisplayNearestPoint(window->bounds().origin())
97 .work_area();
98 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_DOCKED); 146 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_DOCKED);
99 147
100 // Saved placement should reflect docked state (for app windows only in Ash). 148 // Saved placement should reflect docked state (for app windows only in Ash).
101 gfx::Rect bounds; 149 gfx::Rect bounds;
102 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; 150 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT;
103 const views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 151 const views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
104 widget->widget_delegate()->GetSavedWindowPlacement(widget, &bounds, 152 widget->widget_delegate()->GetSavedWindowPlacement(widget, &bounds,
105 &show_state); 153 &show_state);
106 EXPECT_EQ(kIsAsh && test_app ? ui::SHOW_STATE_DOCKED : ui::SHOW_STATE_DEFAULT, 154 EXPECT_EQ(kIsAsh && test_app ? ui::SHOW_STATE_DOCKED : ui::SHOW_STATE_DEFAULT,
107 show_state); 155 show_state);
108 // Docking is only relevant on Ash desktop. 156 // Docking is only relevant on Ash desktop.
109 if (!kIsAsh) 157 if (!kIsAsh)
110 return; 158 return;
111 159
112 // Saved placement should reflect restore bounds.
113 ASSERT_NE(nullptr, window->GetProperty(aura::client::kRestoreBoundsKey));
114 original_bounds = *window->GetProperty(aura::client::kRestoreBoundsKey);
115 gfx::Rect expected_bounds = work_area;
116 expected_bounds.ClampToCenteredSize(original_bounds.size());
117 expected_bounds.set_y(original_bounds.y());
118 EXPECT_EQ(expected_bounds.ToString(), bounds.ToString());
119 EXPECT_EQ(expected_bounds.ToString(), original_bounds.ToString());
120
121 // Browser window should be docked.
122 int width = 250; // same as DockedWindowLayoutManager::kIdealWidth.
123 if (window->delegate() && window->delegate()->GetMinimumSize().width() != 0)
124 width = std::max(width, window->delegate()->GetMinimumSize().width());
125 expected_bounds = work_area;
126 expected_bounds.set_width(width);
127 expected_bounds.set_x(work_area.right() - expected_bounds.width());
128 EXPECT_EQ(expected_bounds.ToString(), window->GetTargetBounds().ToString());
129 EXPECT_EQ(ui::SHOW_STATE_DOCKED,
130 window->GetProperty(aura::client::kShowStateKey));
131 browser->window()->Close();
132
133 // Newly created browser with the same app name should retain docked state 160 // Newly created browser with the same app name should retain docked state
134 // for app browser window but leave it as normal for a tabbed browser. 161 // for app browser window but leave it as normal for a tabbed browser.
135 browser = new Browser(params); 162 browser = new Browser(params);
136 ASSERT_TRUE(browser); 163 ASSERT_TRUE(browser);
137 browser->window()->Show(); 164 browser->window()->Show();
138 window = browser->window()->GetNativeWindow(); 165 window = browser->window()->GetNativeWindow();
139 EXPECT_EQ(test_app ? expected_bounds.ToString() : original_bounds.ToString(),
140 window->GetTargetBounds().ToString());
141 EXPECT_EQ(test_app ? ui::SHOW_STATE_DOCKED : ui::SHOW_STATE_NORMAL, 166 EXPECT_EQ(test_app ? ui::SHOW_STATE_DOCKED : ui::SHOW_STATE_NORMAL,
142 window->GetProperty(aura::client::kShowStateKey)); 167 window->GetProperty(aura::client::kShowStateKey));
143 168
144 // Undocking the browser window should restore original size and vertical 169 // Undocking the browser window.
145 // offset while centering the window horizontally.
146 // Tabbed window is already not docked.
147 expected_bounds = work_area;
148 expected_bounds.ClampToCenteredSize(original_bounds.size());
149 expected_bounds.set_y(original_bounds.y());
150 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 170 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
151 EXPECT_EQ(expected_bounds.ToString(), window->GetTargetBounds().ToString());
152 EXPECT_EQ(ui::SHOW_STATE_NORMAL, 171 EXPECT_EQ(ui::SHOW_STATE_NORMAL,
153 window->GetProperty(aura::client::kShowStateKey)); 172 window->GetProperty(aura::client::kShowStateKey));
154 browser->window()->Close(); 173 browser->window()->Close();
155 174
156 // Re-create the browser window with the same app name. 175 // Re-create the browser window with the same app name.
157 browser = new Browser(params); 176 browser = new Browser(params);
158 ASSERT_TRUE(browser); 177 ASSERT_TRUE(browser);
159 browser->window()->Show(); 178 browser->window()->Show();
160 179
161 // Newly created browser should retain undocked state and bounds. 180 // Newly created browser should retain undocked state.
162 window = browser->window()->GetNativeWindow(); 181 window = browser->window()->GetNativeWindow();
163 EXPECT_EQ(expected_bounds.ToString(), window->GetTargetBounds().ToString());
164 EXPECT_EQ(ui::SHOW_STATE_NORMAL, 182 EXPECT_EQ(ui::SHOW_STATE_NORMAL,
165 window->GetProperty(aura::client::kShowStateKey)); 183 window->GetProperty(aura::client::kShowStateKey));
166 } 184 }
167 185
168 INSTANTIATE_TEST_CASE_P(BrowserViewTestTabbedOrApp, 186 INSTANTIATE_TEST_CASE_P(BrowserViewTestTabbedOrApp,
169 BrowserViewTestParam, 187 BrowserViewTestParam,
170 testing::Bool()); 188 testing::Bool());
171 #endif 189 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_frame_ash.cc ('k') | chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698