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

Side by Side Diff: ash/wm/workspace/workspace_event_handler_unittest.cc

Issue 222203006: Prevents double-clicks on a tab close button from aslo maximizing the browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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) 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 "ash/wm/workspace/workspace_event_handler.h" 5 #include "ash/wm/workspace/workspace_event_handler.h"
6 6
7 #include "ash/screen_util.h" 7 #include "ash/screen_util.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h" 9 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/window_state.h" 10 #include "ash/wm/window_state.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 aura::Window* window_; 78 aura::Window* window_;
79 std::vector<const void*> properties_changed_; 79 std::vector<const void*> properties_changed_;
80 80
81 DISALLOW_COPY_AND_ASSIGN(WindowPropertyObserver); 81 DISALLOW_COPY_AND_ASSIGN(WindowPropertyObserver);
82 }; 82 };
83 83
84 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) { 84 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
85 // Double clicking the vertical resize edge of a window should maximize it 85 // Double clicking the vertical resize edge of a window should maximize it
86 // vertically. 86 // vertically.
87 gfx::Rect restored_bounds(10, 10, 50, 50); 87 gfx::Rect restored_bounds(10, 10, 50, 50);
88 aura::test::TestWindowDelegate wd; 88 aura::test::TestWindowDelegate delegate;
89 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds)); 89 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
90 90
91 wm::ActivateWindow(window.get()); 91 wm::ActivateWindow(window.get());
92 92
93 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( 93 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
94 window.get()).work_area(); 94 window.get()).work_area();
95 95
96 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 96 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
97 window.get()); 97 window.get());
98 98
99 // Double-click the top resize edge. 99 // Double-click the top resize edge.
100 wd.set_window_component(HTTOP); 100 delegate.set_window_component(HTTOP);
101 // On X a double click actually generates a drag between each press/release. 101 // On X a double click actually generates a drag between each press/release.
102 // Explicitly trigger this path since we had bugs in dealing with it 102 // Explicitly trigger this path since we had bugs in dealing with it
103 // correctly. 103 // correctly.
104 generator.PressLeftButton(); 104 generator.PressLeftButton();
105 generator.ReleaseLeftButton(); 105 generator.ReleaseLeftButton();
106 generator.set_flags(ui::EF_IS_DOUBLE_CLICK); 106 generator.set_flags(ui::EF_IS_DOUBLE_CLICK);
107 generator.PressLeftButton(); 107 generator.PressLeftButton();
108 generator.MoveMouseTo(generator.current_location(), 1); 108 generator.MoveMouseTo(generator.current_location(), 1);
109 generator.ReleaseLeftButton(); 109 generator.ReleaseLeftButton();
110 gfx::Rect bounds_in_screen = window->GetBoundsInScreen(); 110 gfx::Rect bounds_in_screen = window->GetBoundsInScreen();
111 EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x()); 111 EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x());
112 EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width()); 112 EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width());
113 EXPECT_EQ(work_area.y(), bounds_in_screen.y()); 113 EXPECT_EQ(work_area.y(), bounds_in_screen.y());
114 EXPECT_EQ(work_area.height(), bounds_in_screen.height()); 114 EXPECT_EQ(work_area.height(), bounds_in_screen.height());
115 115
116 wm::WindowState* window_state = wm::GetWindowState(window.get()); 116 wm::WindowState* window_state = wm::GetWindowState(window.get());
117 // Single-axis maximization is not considered real maximization. 117 // Single-axis maximization is not considered real maximization.
118 EXPECT_FALSE(window_state->IsMaximized()); 118 EXPECT_FALSE(window_state->IsMaximized());
119 119
120 // Restore. 120 // Restore.
121 generator.DoubleClickLeftButton(); 121 generator.DoubleClickLeftButton();
122 bounds_in_screen = window->GetBoundsInScreen(); 122 bounds_in_screen = window->GetBoundsInScreen();
123 EXPECT_EQ(restored_bounds.ToString(), bounds_in_screen.ToString()); 123 EXPECT_EQ(restored_bounds.ToString(), bounds_in_screen.ToString());
124 // Note that it should not even be restored at this point, it should have 124 // Note that it should not even be restored at this point, it should have
125 // also cleared the restore rectangle. 125 // also cleared the restore rectangle.
126 EXPECT_FALSE(window_state->HasRestoreBounds()); 126 EXPECT_FALSE(window_state->HasRestoreBounds());
127 127
128 // Double clicking the left resize edge should maximize horizontally. 128 // Double clicking the left resize edge should maximize horizontally.
129 wd.set_window_component(HTLEFT); 129 delegate.set_window_component(HTLEFT);
130 generator.DoubleClickLeftButton(); 130 generator.DoubleClickLeftButton();
131 bounds_in_screen = window->GetBoundsInScreen(); 131 bounds_in_screen = window->GetBoundsInScreen();
132 EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y()); 132 EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y());
133 EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height()); 133 EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height());
134 EXPECT_EQ(work_area.x(), bounds_in_screen.x()); 134 EXPECT_EQ(work_area.x(), bounds_in_screen.x());
135 EXPECT_EQ(work_area.width(), bounds_in_screen.width()); 135 EXPECT_EQ(work_area.width(), bounds_in_screen.width());
136 // Single-axis maximization is not considered real maximization. 136 // Single-axis maximization is not considered real maximization.
137 EXPECT_FALSE(window_state->IsMaximized()); 137 EXPECT_FALSE(window_state->IsMaximized());
138 138
139 // Restore. 139 // Restore.
140 generator.DoubleClickLeftButton(); 140 generator.DoubleClickLeftButton();
141 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); 141 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString());
142 142
143 #if defined(OS_WIN) 143 #if defined(OS_WIN)
144 // Multi display test does not run on Win8 bot. crbug.com/247427. 144 // Multi display test does not run on Win8 bot. crbug.com/247427.
145 if (base::win::GetVersion() >= base::win::VERSION_WIN8) 145 if (base::win::GetVersion() >= base::win::VERSION_WIN8)
146 return; 146 return;
147 #endif 147 #endif
148 148
149 // Verify the double clicking the resize edge works on 2nd display too. 149 // Verify the double clicking the resize edge works on 2nd display too.
150 UpdateDisplay("200x200,400x300"); 150 UpdateDisplay("200x200,400x300");
151 gfx::Rect work_area2 = ScreenUtil::GetSecondaryDisplay().work_area(); 151 gfx::Rect work_area2 = ScreenUtil::GetSecondaryDisplay().work_area();
152 restored_bounds.SetRect(220,20, 50, 50); 152 restored_bounds.SetRect(220, 20, 50, 50);
153 window->SetBoundsInScreen(restored_bounds, ScreenUtil::GetSecondaryDisplay()); 153 window->SetBoundsInScreen(restored_bounds, ScreenUtil::GetSecondaryDisplay());
154 aura::Window* second_root = Shell::GetAllRootWindows()[1]; 154 aura::Window* second_root = Shell::GetAllRootWindows()[1];
155 EXPECT_EQ(second_root, window->GetRootWindow()); 155 EXPECT_EQ(second_root, window->GetRootWindow());
156 aura::test::EventGenerator generator2(second_root, window.get()); 156 aura::test::EventGenerator generator2(second_root, window.get());
157 157
158 // Y-axis maximization. 158 // Y-axis maximization.
159 wd.set_window_component(HTTOP); 159 delegate.set_window_component(HTTOP);
160 generator2.PressLeftButton(); 160 generator2.PressLeftButton();
161 generator2.ReleaseLeftButton(); 161 generator2.ReleaseLeftButton();
162 generator2.set_flags(ui::EF_IS_DOUBLE_CLICK); 162 generator2.set_flags(ui::EF_IS_DOUBLE_CLICK);
163 generator2.PressLeftButton(); 163 generator2.PressLeftButton();
164 generator2.MoveMouseTo(generator.current_location(), 1); 164 generator2.MoveMouseTo(generator.current_location(), 1);
165 generator2.ReleaseLeftButton(); 165 generator2.ReleaseLeftButton();
166 generator.DoubleClickLeftButton(); 166 generator.DoubleClickLeftButton();
167 bounds_in_screen = window->GetBoundsInScreen(); 167 bounds_in_screen = window->GetBoundsInScreen();
168 EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x()); 168 EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x());
169 EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width()); 169 EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width());
170 EXPECT_EQ(work_area2.y(), bounds_in_screen.y()); 170 EXPECT_EQ(work_area2.y(), bounds_in_screen.y());
171 EXPECT_EQ(work_area2.height(), bounds_in_screen.height()); 171 EXPECT_EQ(work_area2.height(), bounds_in_screen.height());
172 EXPECT_FALSE(window_state->IsMaximized()); 172 EXPECT_FALSE(window_state->IsMaximized());
173 173
174 // Restore. 174 // Restore.
175 generator2.DoubleClickLeftButton(); 175 generator2.DoubleClickLeftButton();
176 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); 176 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString());
177 177
178 // X-axis maximization. 178 // X-axis maximization.
179 wd.set_window_component(HTLEFT); 179 delegate.set_window_component(HTLEFT);
180 generator2.DoubleClickLeftButton(); 180 generator2.DoubleClickLeftButton();
181 bounds_in_screen = window->GetBoundsInScreen(); 181 bounds_in_screen = window->GetBoundsInScreen();
182 EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y()); 182 EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y());
183 EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height()); 183 EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height());
184 EXPECT_EQ(work_area2.x(), bounds_in_screen.x()); 184 EXPECT_EQ(work_area2.x(), bounds_in_screen.x());
185 EXPECT_EQ(work_area2.width(), bounds_in_screen.width()); 185 EXPECT_EQ(work_area2.width(), bounds_in_screen.width());
186 EXPECT_FALSE(window_state->IsMaximized()); 186 EXPECT_FALSE(window_state->IsMaximized());
187 187
188 // Restore. 188 // Restore.
189 generator2.DoubleClickLeftButton(); 189 generator2.DoubleClickLeftButton();
190 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); 190 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString());
191 } 191 }
192 192
193 // Tests the behavior when double clicking the border of a side snapped window. 193 // Tests the behavior when double clicking the border of a side snapped window.
194 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisWhenSideSnapped) { 194 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisWhenSideSnapped) {
195 gfx::Rect restored_bounds(10, 10, 50, 50); 195 gfx::Rect restored_bounds(10, 10, 50, 50);
196 aura::test::TestWindowDelegate wd; 196 aura::test::TestWindowDelegate delegate;
197 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds)); 197 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
198 198
199 gfx::Rect work_area_in_screen = Shell::GetScreen()->GetDisplayNearestWindow( 199 gfx::Rect work_area_in_screen = Shell::GetScreen()->GetDisplayNearestWindow(
200 window.get()).work_area(); 200 window.get()).work_area();
201 201
202 wm::WindowState* window_state = wm::GetWindowState(window.get()); 202 wm::WindowState* window_state = wm::GetWindowState(window.get());
203 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT); 203 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
204 window_state->OnWMEvent(&snap_event); 204 window_state->OnWMEvent(&snap_event);
205 205
206 gfx::Rect snapped_bounds_in_screen = window->GetBoundsInScreen(); 206 gfx::Rect snapped_bounds_in_screen = window->GetBoundsInScreen();
207 EXPECT_EQ(work_area_in_screen.x(), snapped_bounds_in_screen.x()); 207 EXPECT_EQ(work_area_in_screen.x(), snapped_bounds_in_screen.x());
208 EXPECT_EQ(work_area_in_screen.y(), snapped_bounds_in_screen.y()); 208 EXPECT_EQ(work_area_in_screen.y(), snapped_bounds_in_screen.y());
209 EXPECT_GT(work_area_in_screen.width(), snapped_bounds_in_screen.width()); 209 EXPECT_GT(work_area_in_screen.width(), snapped_bounds_in_screen.width());
210 EXPECT_EQ(work_area_in_screen.height(), snapped_bounds_in_screen.height()); 210 EXPECT_EQ(work_area_in_screen.height(), snapped_bounds_in_screen.height());
211 211
212 // Double clicking the top border should not do anything for side snapped 212 // Double clicking the top border should not do anything for side snapped
213 // windows. (They already take up the entire workspace height and reverting 213 // windows. (They already take up the entire workspace height and reverting
214 // to the restored bounds would be weird). 214 // to the restored bounds would be weird).
215 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 215 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
216 window.get()); 216 window.get());
217 wd.set_window_component(HTTOP); 217 delegate.set_window_component(HTTOP);
218 generator.DoubleClickLeftButton(); 218 generator.DoubleClickLeftButton();
219 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); 219 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
220 EXPECT_EQ(snapped_bounds_in_screen.ToString(), 220 EXPECT_EQ(snapped_bounds_in_screen.ToString(),
221 window->GetBoundsInScreen().ToString()); 221 window->GetBoundsInScreen().ToString());
222 222
223 // Double clicking the right border should exit the side snapped state and 223 // Double clicking the right border should exit the side snapped state and
224 // make the window take up the entire work area. 224 // make the window take up the entire work area.
225 wd.set_window_component(HTRIGHT); 225 delegate.set_window_component(HTRIGHT);
226 generator.DoubleClickLeftButton(); 226 generator.DoubleClickLeftButton();
227 EXPECT_TRUE(window_state->IsNormalStateType()); 227 EXPECT_TRUE(window_state->IsNormalStateType());
228 EXPECT_EQ(work_area_in_screen.ToString(), 228 EXPECT_EQ(work_area_in_screen.ToString(),
229 window->GetBoundsInScreen().ToString()); 229 window->GetBoundsInScreen().ToString());
230 } 230 }
231 231
232 TEST_F(WorkspaceEventHandlerTest, 232 TEST_F(WorkspaceEventHandlerTest,
233 DoubleClickSingleAxisDoesntResizeVerticalEdgeIfConstrained) { 233 DoubleClickSingleAxisDoesntResizeVerticalEdgeIfConstrained) {
234 gfx::Rect restored_bounds(10, 10, 50, 50); 234 gfx::Rect restored_bounds(10, 10, 50, 50);
235 aura::test::TestWindowDelegate wd; 235 aura::test::TestWindowDelegate delegate;
236 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds)); 236 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
237 237
238 wm::ActivateWindow(window.get()); 238 wm::ActivateWindow(window.get());
239 239
240 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( 240 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
241 window.get()).work_area(); 241 window.get()).work_area();
242 242
243 wd.set_maximum_size(gfx::Size(0, 100)); 243 delegate.set_maximum_size(gfx::Size(0, 100));
244 244
245 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 245 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
246 window.get()); 246 window.get());
247 // Double-click the top resize edge. 247 // Double-click the top resize edge.
248 wd.set_window_component(HTTOP); 248 delegate.set_window_component(HTTOP);
249 generator.DoubleClickLeftButton(); 249 generator.DoubleClickLeftButton();
250 250
251 // The size of the window should be unchanged. 251 // The size of the window should be unchanged.
252 EXPECT_EQ(restored_bounds.y(), window->bounds().y()); 252 EXPECT_EQ(restored_bounds.y(), window->bounds().y());
253 EXPECT_EQ(restored_bounds.height(), window->bounds().height()); 253 EXPECT_EQ(restored_bounds.height(), window->bounds().height());
254 } 254 }
255 255
256 TEST_F(WorkspaceEventHandlerTest, 256 TEST_F(WorkspaceEventHandlerTest,
257 DoubleClickSingleAxisDoesntResizeHorizontalEdgeIfConstrained) { 257 DoubleClickSingleAxisDoesntResizeHorizontalEdgeIfConstrained) {
258 gfx::Rect restored_bounds(10, 10, 50, 50); 258 gfx::Rect restored_bounds(10, 10, 50, 50);
259 aura::test::TestWindowDelegate wd; 259 aura::test::TestWindowDelegate delegate;
260 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds)); 260 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
261 261
262 wm::ActivateWindow(window.get()); 262 wm::ActivateWindow(window.get());
263 263
264 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( 264 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
265 window.get()).work_area(); 265 window.get()).work_area();
266 266
267 wd.set_maximum_size(gfx::Size(100, 0)); 267 delegate.set_maximum_size(gfx::Size(100, 0));
268 268
269 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 269 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
270 window.get()); 270 window.get());
271 // Double-click the top resize edge. 271 // Double-click the top resize edge.
272 wd.set_window_component(HTRIGHT); 272 delegate.set_window_component(HTRIGHT);
273 generator.DoubleClickLeftButton(); 273 generator.DoubleClickLeftButton();
274 274
275 // The size of the window should be unchanged. 275 // The size of the window should be unchanged.
276 EXPECT_EQ(restored_bounds.x(), window->bounds().x()); 276 EXPECT_EQ(restored_bounds.x(), window->bounds().x());
277 EXPECT_EQ(restored_bounds.width(), window->bounds().width()); 277 EXPECT_EQ(restored_bounds.width(), window->bounds().width());
278 } 278 }
279 279
280 TEST_F(WorkspaceEventHandlerTest, 280 TEST_F(WorkspaceEventHandlerTest,
281 DoubleClickOrTapWithModalChildDoesntMaximize) { 281 DoubleClickOrTapWithModalChildDoesntMaximize) {
282 aura::test::TestWindowDelegate wd1; 282 aura::test::TestWindowDelegate delegate1;
283 aura::test::TestWindowDelegate wd2; 283 aura::test::TestWindowDelegate delegate2;
284 scoped_ptr<aura::Window> window( 284 scoped_ptr<aura::Window> window(
285 CreateTestWindow(&wd1, gfx::Rect(10, 20, 30, 40))); 285 CreateTestWindow(&delegate1, gfx::Rect(10, 20, 30, 40)));
286 scoped_ptr<aura::Window> child( 286 scoped_ptr<aura::Window> child(
287 CreateTestWindow(&wd2, gfx::Rect(0, 0, 1, 1))); 287 CreateTestWindow(&delegate2, gfx::Rect(0, 0, 1, 1)));
288 window->SetProperty(aura::client::kCanMaximizeKey, true); 288 window->SetProperty(aura::client::kCanMaximizeKey, true);
289 wd1.set_window_component(HTCAPTION); 289 delegate1.set_window_component(HTCAPTION);
290 290
291 child->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); 291 child->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
292 ::wm::AddTransientChild(window.get(), child.get()); 292 ::wm::AddTransientChild(window.get(), child.get());
293 293
294 wm::WindowState* window_state = wm::GetWindowState(window.get()); 294 wm::WindowState* window_state = wm::GetWindowState(window.get());
295 EXPECT_FALSE(window_state->IsMaximized()); 295 EXPECT_FALSE(window_state->IsMaximized());
296 aura::Window* root = Shell::GetPrimaryRootWindow(); 296 aura::Window* root = Shell::GetPrimaryRootWindow();
297 aura::test::EventGenerator generator(root, window.get()); 297 aura::test::EventGenerator generator(root, window.get());
298 generator.DoubleClickLeftButton(); 298 generator.DoubleClickLeftButton();
299 EXPECT_EQ("10,20 30x40", window->bounds().ToString()); 299 EXPECT_EQ("10,20 30x40", window->bounds().ToString());
300 EXPECT_FALSE(window_state->IsMaximized()); 300 EXPECT_FALSE(window_state->IsMaximized());
301 301
302 generator.GestureTapAt(gfx::Point(25, 25)); 302 generator.GestureTapAt(gfx::Point(25, 25));
303 generator.GestureTapAt(gfx::Point(25, 25)); 303 generator.GestureTapAt(gfx::Point(25, 25));
304 RunAllPendingInMessageLoop(); 304 RunAllPendingInMessageLoop();
305 EXPECT_EQ("10,20 30x40", window->bounds().ToString()); 305 EXPECT_EQ("10,20 30x40", window->bounds().ToString());
306 EXPECT_FALSE(window_state->IsMaximized()); 306 EXPECT_FALSE(window_state->IsMaximized());
307 } 307 }
308 308
309 // Test the behavior as a result of double clicking the window header. 309 // Test the behavior as a result of double clicking the window header.
310 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) { 310 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) {
311 aura::test::TestWindowDelegate wd; 311 aura::test::TestWindowDelegate delegate;
312 scoped_ptr<aura::Window> window( 312 scoped_ptr<aura::Window> window(
313 CreateTestWindow(&wd, gfx::Rect(1, 2, 30, 40))); 313 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
314 window->SetProperty(aura::client::kCanMaximizeKey, true); 314 window->SetProperty(aura::client::kCanMaximizeKey, true);
315 315
316 wm::WindowState* window_state = wm::GetWindowState(window.get()); 316 wm::WindowState* window_state = wm::GetWindowState(window.get());
317 gfx::Rect restore_bounds = window->bounds(); 317 gfx::Rect restore_bounds = window->bounds();
318 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent( 318 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
319 window.get()); 319 window.get());
320 320
321 EXPECT_FALSE(window_state->IsMaximized()); 321 EXPECT_FALSE(window_state->IsMaximized());
322 322
323 // 1) Double clicking a normal window should maximize. 323 // 1) Double clicking a normal window should maximize.
324 wd.set_window_component(HTCAPTION); 324 delegate.set_window_component(HTCAPTION);
325 aura::Window* root = Shell::GetPrimaryRootWindow(); 325 aura::Window* root = Shell::GetPrimaryRootWindow();
326 aura::test::EventGenerator generator(root, window.get()); 326 aura::test::EventGenerator generator(root, window.get());
327 generator.ClickLeftButton();
327 generator.DoubleClickLeftButton(); 328 generator.DoubleClickLeftButton();
328 EXPECT_NE(restore_bounds.ToString(), window->bounds().ToString()); 329 EXPECT_NE(restore_bounds.ToString(), window->bounds().ToString());
329 EXPECT_TRUE(window_state->IsMaximized()); 330 EXPECT_TRUE(window_state->IsMaximized());
330 331
332 generator.ClickLeftButton();
331 generator.DoubleClickLeftButton(); 333 generator.DoubleClickLeftButton();
332 EXPECT_TRUE(window_state->IsNormalStateType()); 334 EXPECT_TRUE(window_state->IsNormalStateType());
333 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString()); 335 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
334 336
335 // 2) Double clicking a horizontally maximized window should maximize. 337 // 2) Double clicking a horizontally maximized window should maximize.
336 wd.set_window_component(HTLEFT); 338 delegate.set_window_component(HTLEFT);
339 generator.ClickLeftButton();
337 generator.DoubleClickLeftButton(); 340 generator.DoubleClickLeftButton();
338 EXPECT_TRUE(window_state->IsNormalStateType()); 341 EXPECT_TRUE(window_state->IsNormalStateType());
339 EXPECT_EQ(work_area_in_parent.x(), window->bounds().x()); 342 EXPECT_EQ(work_area_in_parent.x(), window->bounds().x());
340 EXPECT_EQ(restore_bounds.y(), window->bounds().y()); 343 EXPECT_EQ(restore_bounds.y(), window->bounds().y());
341 EXPECT_EQ(work_area_in_parent.width(), window->bounds().width()); 344 EXPECT_EQ(work_area_in_parent.width(), window->bounds().width());
342 EXPECT_EQ(restore_bounds.height(), window->bounds().height()); 345 EXPECT_EQ(restore_bounds.height(), window->bounds().height());
343 346
344 wd.set_window_component(HTCAPTION); 347 delegate.set_window_component(HTCAPTION);
348 generator.ClickLeftButton();
345 generator.DoubleClickLeftButton(); 349 generator.DoubleClickLeftButton();
346 EXPECT_TRUE(window_state->IsMaximized()); 350 EXPECT_TRUE(window_state->IsMaximized());
347 351
352 generator.ClickLeftButton();
348 generator.DoubleClickLeftButton(); 353 generator.DoubleClickLeftButton();
349 EXPECT_TRUE(window_state->IsNormalStateType()); 354 EXPECT_TRUE(window_state->IsNormalStateType());
350 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString()); 355 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
351 356
352 // 3) Double clicking a snapped window should maximize. 357 // 3) Double clicking a snapped window should maximize.
353 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT); 358 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
354 window_state->OnWMEvent(&snap_event); 359 window_state->OnWMEvent(&snap_event);
355 EXPECT_TRUE(window_state->IsSnapped()); 360 EXPECT_TRUE(window_state->IsSnapped());
356 generator.MoveMouseTo(window->GetBoundsInRootWindow().CenterPoint()); 361 generator.MoveMouseTo(window->GetBoundsInRootWindow().CenterPoint());
362 generator.ClickLeftButton();
357 generator.DoubleClickLeftButton(); 363 generator.DoubleClickLeftButton();
358 EXPECT_TRUE(window_state->IsMaximized()); 364 EXPECT_TRUE(window_state->IsMaximized());
359 365
366 generator.ClickLeftButton();
360 generator.DoubleClickLeftButton(); 367 generator.DoubleClickLeftButton();
361 EXPECT_TRUE(window_state->IsNormalStateType()); 368 EXPECT_TRUE(window_state->IsNormalStateType());
362 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString()); 369 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
363 } 370 }
364 371
365 // Test that double clicking the middle button on the window header does not 372 // Test that double clicking the middle button on the window header does not
366 // toggle the maximized state. 373 // toggle the maximized state.
367 TEST_F(WorkspaceEventHandlerTest, 374 TEST_F(WorkspaceEventHandlerTest,
368 DoubleClickMiddleButtonDoesNotToggleMaximize) { 375 DoubleClickMiddleButtonDoesNotToggleMaximize) {
369 aura::test::TestWindowDelegate wd; 376 aura::test::TestWindowDelegate delegate;
370 scoped_ptr<aura::Window> window( 377 scoped_ptr<aura::Window> window(
371 CreateTestWindow(&wd, gfx::Rect(1, 2, 30, 40))); 378 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
372 window->SetProperty(aura::client::kCanMaximizeKey, true); 379 window->SetProperty(aura::client::kCanMaximizeKey, true);
373 wd.set_window_component(HTCAPTION); 380 delegate.set_window_component(HTCAPTION);
374 aura::Window* root = Shell::GetPrimaryRootWindow(); 381 aura::Window* root = Shell::GetPrimaryRootWindow();
375 aura::test::EventGenerator generator(root, window.get()); 382 aura::test::EventGenerator generator(root, window.get());
376 383
377 WindowPropertyObserver observer(window.get()); 384 WindowPropertyObserver observer(window.get());
378 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, generator.current_location(), 385 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, generator.current_location(),
379 generator.current_location(), 386 generator.current_location(),
380 ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, 387 ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK,
381 ui::EF_MIDDLE_MOUSE_BUTTON); 388 ui::EF_MIDDLE_MOUSE_BUTTON);
382 ui::EventProcessor* dispatcher = root->GetHost()->event_processor(); 389 ui::EventProcessor* dispatcher = root->GetHost()->event_processor();
383 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); 390 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press);
384 ASSERT_FALSE(details.dispatcher_destroyed); 391 ASSERT_FALSE(details.dispatcher_destroyed);
385 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, generator.current_location(), 392 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, generator.current_location(),
386 generator.current_location(), 393 generator.current_location(),
387 ui::EF_IS_DOUBLE_CLICK, 394 ui::EF_IS_DOUBLE_CLICK,
388 ui::EF_MIDDLE_MOUSE_BUTTON); 395 ui::EF_MIDDLE_MOUSE_BUTTON);
389 details = dispatcher->OnEventFromSource(&release); 396 details = dispatcher->OnEventFromSource(&release);
390 ASSERT_FALSE(details.dispatcher_destroyed); 397 ASSERT_FALSE(details.dispatcher_destroyed);
391 398
392 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); 399 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
393 EXPECT_EQ("1,2 30x40", window->bounds().ToString()); 400 EXPECT_EQ("1,2 30x40", window->bounds().ToString());
394 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey)); 401 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey));
395 } 402 }
396 403
397 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) { 404 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) {
398 aura::test::TestWindowDelegate wd; 405 aura::test::TestWindowDelegate delegate;
399 gfx::Rect bounds(10, 20, 30, 40); 406 gfx::Rect bounds(10, 20, 30, 40);
400 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds)); 407 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
401 window->SetProperty(aura::client::kCanMaximizeKey, true); 408 window->SetProperty(aura::client::kCanMaximizeKey, true);
402 wd.set_window_component(HTCAPTION); 409 delegate.set_window_component(HTCAPTION);
403 410
404 wm::WindowState* window_state = wm::GetWindowState(window.get()); 411 wm::WindowState* window_state = wm::GetWindowState(window.get());
405 EXPECT_FALSE(window_state->IsMaximized()); 412 EXPECT_FALSE(window_state->IsMaximized());
406 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 413 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
407 window.get()); 414 window.get());
408 generator.GestureTapAt(gfx::Point(25, 25)); 415 generator.GestureTapAt(gfx::Point(25, 25));
409 generator.GestureTapAt(gfx::Point(25, 25)); 416 generator.GestureTapAt(gfx::Point(25, 25));
410 RunAllPendingInMessageLoop(); 417 RunAllPendingInMessageLoop();
411 EXPECT_NE(bounds.ToString(), window->bounds().ToString()); 418 EXPECT_NE(bounds.ToString(), window->bounds().ToString());
412 EXPECT_TRUE(window_state->IsMaximized()); 419 EXPECT_TRUE(window_state->IsMaximized());
413 420
414 generator.GestureTapAt(gfx::Point(5, 5)); 421 generator.GestureTapAt(gfx::Point(5, 5));
415 generator.GestureTapAt(gfx::Point(10, 10)); 422 generator.GestureTapAt(gfx::Point(10, 10));
416 423
417 EXPECT_FALSE(window_state->IsMaximized()); 424 EXPECT_FALSE(window_state->IsMaximized());
418 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); 425 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
419 } 426 }
420 427
421 // Verifies deleting the window while dragging doesn't crash. 428 // Verifies deleting the window while dragging doesn't crash.
422 TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) { 429 TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) {
423 // Create a large window in the background. This is necessary so that when we 430 // Create a large window in the background. This is necessary so that when we
424 // delete |window| WorkspaceEventHandler is still the active event handler. 431 // delete |window| WorkspaceEventHandler is still the active event handler.
425 aura::test::TestWindowDelegate wd2; 432 aura::test::TestWindowDelegate delegate2;
426 scoped_ptr<aura::Window> window2( 433 scoped_ptr<aura::Window> window2(
427 CreateTestWindow(&wd2, gfx::Rect(0, 0, 500, 500))); 434 CreateTestWindow(&delegate2, gfx::Rect(0, 0, 500, 500)));
428 435
429 aura::test::TestWindowDelegate wd; 436 aura::test::TestWindowDelegate delegate;
430 const gfx::Rect bounds(10, 20, 30, 40); 437 const gfx::Rect bounds(10, 20, 30, 40);
431 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds)); 438 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
432 wd.set_window_component(HTCAPTION); 439 delegate.set_window_component(HTCAPTION);
433 aura::test::EventGenerator generator(window->GetRootWindow()); 440 aura::test::EventGenerator generator(window->GetRootWindow());
434 generator.MoveMouseToCenterOf(window.get()); 441 generator.MoveMouseToCenterOf(window.get());
435 generator.PressLeftButton(); 442 generator.PressLeftButton();
436 generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50)); 443 generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50));
437 DCHECK_NE(bounds.origin().ToString(), window->bounds().origin().ToString()); 444 DCHECK_NE(bounds.origin().ToString(), window->bounds().origin().ToString());
438 window.reset(); 445 window.reset();
439 generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50)); 446 generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50));
440 } 447 }
441 448
442 // Verifies deleting the window while in a run loop doesn't crash. 449 // Verifies deleting the window while in a run loop doesn't crash.
443 TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) { 450 TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) {
444 aura::test::TestWindowDelegate wd; 451 aura::test::TestWindowDelegate delegate;
445 const gfx::Rect bounds(10, 20, 30, 40); 452 const gfx::Rect bounds(10, 20, 30, 40);
446 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds)); 453 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
447 wd.set_window_component(HTCAPTION); 454 delegate.set_window_component(HTCAPTION);
448 455
449 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->GetRootWindow())); 456 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->GetRootWindow()));
450 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get()); 457 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get());
451 aura::client::GetWindowMoveClient(window->GetRootWindow()) 458 aura::client::GetWindowMoveClient(window->GetRootWindow())
452 ->RunMoveLoop(window.release(), 459 ->RunMoveLoop(window.release(),
453 gfx::Vector2d(), 460 gfx::Vector2d(),
454 aura::client::WINDOW_MOVE_SOURCE_MOUSE); 461 aura::client::WINDOW_MOVE_SOURCE_MOUSE);
455 } 462 }
456 463
464 // Verifies that double clicking in the header does not maximize if the target
465 // component has changed.
466 TEST_F(WorkspaceEventHandlerTest,
467 DoubleClickTwoDifferentTargetsDoesntMaximize) {
468 aura::test::TestWindowDelegate delegate;
469 scoped_ptr<aura::Window> window(
470 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
471 window->SetProperty(aura::client::kCanMaximizeKey, true);
472
473 wm::WindowState* window_state = wm::GetWindowState(window.get());
474 gfx::Rect restore_bounds = window->bounds();
475 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
476 window.get());
477
478 EXPECT_FALSE(window_state->IsMaximized());
479
480 // First click will go to a client
481 delegate.set_window_component(HTCLIENT);
482 aura::Window* root = Shell::GetPrimaryRootWindow();
483 aura::test::EventGenerator generator(root, window.get());
484 generator.ClickLeftButton();
485 EXPECT_FALSE(window_state->IsMaximized());
486
487 // Second click will go to the header
488 delegate.set_window_component(HTCAPTION);
489 generator.DoubleClickLeftButton();
490 EXPECT_FALSE(window_state->IsMaximized());
491 }
492
493 // Verifies that double tapping in the header does not maximize if the target
494 // component has changed.
495 TEST_F(WorkspaceEventHandlerTest, DoubleTapTwoDifferentTargetsDoesntMaximize) {
496 aura::test::TestWindowDelegate delegate;
497 scoped_ptr<aura::Window> window(
498 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
499 window->SetProperty(aura::client::kCanMaximizeKey, true);
500
501 wm::WindowState* window_state = wm::GetWindowState(window.get());
502 gfx::Rect restore_bounds = window->bounds();
503 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
504 window.get());
505
506 EXPECT_FALSE(window_state->IsMaximized());
507
508 // First tap will go to a client
509 delegate.set_window_component(HTCLIENT);
510 aura::Window* root = Shell::GetPrimaryRootWindow();
511 aura::test::EventGenerator generator(root, window.get());
512 generator.GestureTapAt(gfx::Point(25, 25));
513 EXPECT_FALSE(window_state->IsMaximized());
514
515 // Second tap will go to the header
516 delegate.set_window_component(HTCAPTION);
517 generator.GestureTapAt(gfx::Point(25, 25));
518 EXPECT_FALSE(window_state->IsMaximized());
519 }
520
521 TEST_F(WorkspaceEventHandlerTest,
522 RightClickDuringDoubleClickDoesntMaximize) {
523 aura::test::TestWindowDelegate delegate;
524 scoped_ptr<aura::Window> window(
525 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
526 window->SetProperty(aura::client::kCanMaximizeKey, true);
527
528 wm::WindowState* window_state = wm::GetWindowState(window.get());
529 gfx::Rect restore_bounds = window->bounds();
530 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
531 window.get());
532
533 EXPECT_FALSE(window_state->IsMaximized());
534
535 // First click will go to a client
536 delegate.set_window_component(HTCLIENT);
537 aura::Window* root = Shell::GetPrimaryRootWindow();
538 aura::test::EventGenerator generator(root, window.get());
539 generator.ClickLeftButton();
540 EXPECT_FALSE(window_state->IsMaximized());
541
542 // Second click will go to the header
543 delegate.set_window_component(HTCAPTION);
544 generator.PressRightButton();
545 generator.ReleaseRightButton();
546 EXPECT_FALSE(window_state->IsMaximized());
547 generator.DoubleClickLeftButton();
548 EXPECT_FALSE(window_state->IsMaximized());
549 }
550
457 } // namespace ash 551 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_event_handler.cc ('k') | ui/views/widget/desktop_aura/desktop_screen_x11_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698