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

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

Issue 239213003: Revert of 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 delegate; 88 aura::test::TestWindowDelegate wd;
89 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds)); 89 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, 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 delegate.set_window_component(HTTOP); 100 wd.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 delegate.set_window_component(HTLEFT); 129 wd.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 delegate.set_window_component(HTTOP); 159 wd.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 delegate.set_window_component(HTLEFT); 179 wd.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 delegate; 196 aura::test::TestWindowDelegate wd;
197 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds)); 197 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, 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 delegate.set_window_component(HTTOP); 217 wd.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 delegate.set_window_component(HTRIGHT); 225 wd.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 delegate; 235 aura::test::TestWindowDelegate wd;
236 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds)); 236 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, 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 delegate.set_maximum_size(gfx::Size(0, 100)); 243 wd.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 delegate.set_window_component(HTTOP); 248 wd.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 delegate; 259 aura::test::TestWindowDelegate wd;
260 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds)); 260 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, 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 delegate.set_maximum_size(gfx::Size(100, 0)); 267 wd.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 delegate.set_window_component(HTRIGHT); 272 wd.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 delegate1; 282 aura::test::TestWindowDelegate wd1;
283 aura::test::TestWindowDelegate delegate2; 283 aura::test::TestWindowDelegate wd2;
284 scoped_ptr<aura::Window> window( 284 scoped_ptr<aura::Window> window(
285 CreateTestWindow(&delegate1, gfx::Rect(10, 20, 30, 40))); 285 CreateTestWindow(&wd1, gfx::Rect(10, 20, 30, 40)));
286 scoped_ptr<aura::Window> child( 286 scoped_ptr<aura::Window> child(
287 CreateTestWindow(&delegate2, gfx::Rect(0, 0, 1, 1))); 287 CreateTestWindow(&wd2, gfx::Rect(0, 0, 1, 1)));
288 window->SetProperty(aura::client::kCanMaximizeKey, true); 288 window->SetProperty(aura::client::kCanMaximizeKey, true);
289 delegate1.set_window_component(HTCAPTION); 289 wd1.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 delegate; 311 aura::test::TestWindowDelegate wd;
312 scoped_ptr<aura::Window> window( 312 scoped_ptr<aura::Window> window(
313 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); 313 CreateTestWindow(&wd, 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 delegate.set_window_component(HTCAPTION); 324 wd.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();
328 generator.DoubleClickLeftButton(); 327 generator.DoubleClickLeftButton();
329 EXPECT_NE(restore_bounds.ToString(), window->bounds().ToString()); 328 EXPECT_NE(restore_bounds.ToString(), window->bounds().ToString());
330 EXPECT_TRUE(window_state->IsMaximized()); 329 EXPECT_TRUE(window_state->IsMaximized());
331 330
332 generator.ClickLeftButton();
333 generator.DoubleClickLeftButton(); 331 generator.DoubleClickLeftButton();
334 EXPECT_TRUE(window_state->IsNormalStateType()); 332 EXPECT_TRUE(window_state->IsNormalStateType());
335 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString()); 333 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
336 334
337 // 2) Double clicking a horizontally maximized window should maximize. 335 // 2) Double clicking a horizontally maximized window should maximize.
338 delegate.set_window_component(HTLEFT); 336 wd.set_window_component(HTLEFT);
339 generator.ClickLeftButton();
340 generator.DoubleClickLeftButton(); 337 generator.DoubleClickLeftButton();
341 EXPECT_TRUE(window_state->IsNormalStateType()); 338 EXPECT_TRUE(window_state->IsNormalStateType());
342 EXPECT_EQ(work_area_in_parent.x(), window->bounds().x()); 339 EXPECT_EQ(work_area_in_parent.x(), window->bounds().x());
343 EXPECT_EQ(restore_bounds.y(), window->bounds().y()); 340 EXPECT_EQ(restore_bounds.y(), window->bounds().y());
344 EXPECT_EQ(work_area_in_parent.width(), window->bounds().width()); 341 EXPECT_EQ(work_area_in_parent.width(), window->bounds().width());
345 EXPECT_EQ(restore_bounds.height(), window->bounds().height()); 342 EXPECT_EQ(restore_bounds.height(), window->bounds().height());
346 343
347 delegate.set_window_component(HTCAPTION); 344 wd.set_window_component(HTCAPTION);
348 generator.ClickLeftButton();
349 generator.DoubleClickLeftButton(); 345 generator.DoubleClickLeftButton();
350 EXPECT_TRUE(window_state->IsMaximized()); 346 EXPECT_TRUE(window_state->IsMaximized());
351 347
352 generator.ClickLeftButton();
353 generator.DoubleClickLeftButton(); 348 generator.DoubleClickLeftButton();
354 EXPECT_TRUE(window_state->IsNormalStateType()); 349 EXPECT_TRUE(window_state->IsNormalStateType());
355 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString()); 350 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
356 351
357 // 3) Double clicking a snapped window should maximize. 352 // 3) Double clicking a snapped window should maximize.
358 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT); 353 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
359 window_state->OnWMEvent(&snap_event); 354 window_state->OnWMEvent(&snap_event);
360 EXPECT_TRUE(window_state->IsSnapped()); 355 EXPECT_TRUE(window_state->IsSnapped());
361 generator.MoveMouseTo(window->GetBoundsInRootWindow().CenterPoint()); 356 generator.MoveMouseTo(window->GetBoundsInRootWindow().CenterPoint());
362 generator.ClickLeftButton();
363 generator.DoubleClickLeftButton(); 357 generator.DoubleClickLeftButton();
364 EXPECT_TRUE(window_state->IsMaximized()); 358 EXPECT_TRUE(window_state->IsMaximized());
365 359
366 generator.ClickLeftButton();
367 generator.DoubleClickLeftButton(); 360 generator.DoubleClickLeftButton();
368 EXPECT_TRUE(window_state->IsNormalStateType()); 361 EXPECT_TRUE(window_state->IsNormalStateType());
369 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString()); 362 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
370 } 363 }
371 364
372 // Test that double clicking the middle button on the window header does not 365 // Test that double clicking the middle button on the window header does not
373 // toggle the maximized state. 366 // toggle the maximized state.
374 TEST_F(WorkspaceEventHandlerTest, 367 TEST_F(WorkspaceEventHandlerTest,
375 DoubleClickMiddleButtonDoesNotToggleMaximize) { 368 DoubleClickMiddleButtonDoesNotToggleMaximize) {
376 aura::test::TestWindowDelegate delegate; 369 aura::test::TestWindowDelegate wd;
377 scoped_ptr<aura::Window> window( 370 scoped_ptr<aura::Window> window(
378 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); 371 CreateTestWindow(&wd, gfx::Rect(1, 2, 30, 40)));
379 window->SetProperty(aura::client::kCanMaximizeKey, true); 372 window->SetProperty(aura::client::kCanMaximizeKey, true);
380 delegate.set_window_component(HTCAPTION); 373 wd.set_window_component(HTCAPTION);
381 aura::Window* root = Shell::GetPrimaryRootWindow(); 374 aura::Window* root = Shell::GetPrimaryRootWindow();
382 aura::test::EventGenerator generator(root, window.get()); 375 aura::test::EventGenerator generator(root, window.get());
383 376
384 WindowPropertyObserver observer(window.get()); 377 WindowPropertyObserver observer(window.get());
385 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, generator.current_location(), 378 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, generator.current_location(),
386 generator.current_location(), 379 generator.current_location(),
387 ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, 380 ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK,
388 ui::EF_MIDDLE_MOUSE_BUTTON); 381 ui::EF_MIDDLE_MOUSE_BUTTON);
389 ui::EventProcessor* dispatcher = root->GetHost()->event_processor(); 382 ui::EventProcessor* dispatcher = root->GetHost()->event_processor();
390 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); 383 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press);
391 ASSERT_FALSE(details.dispatcher_destroyed); 384 ASSERT_FALSE(details.dispatcher_destroyed);
392 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, generator.current_location(), 385 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, generator.current_location(),
393 generator.current_location(), 386 generator.current_location(),
394 ui::EF_IS_DOUBLE_CLICK, 387 ui::EF_IS_DOUBLE_CLICK,
395 ui::EF_MIDDLE_MOUSE_BUTTON); 388 ui::EF_MIDDLE_MOUSE_BUTTON);
396 details = dispatcher->OnEventFromSource(&release); 389 details = dispatcher->OnEventFromSource(&release);
397 ASSERT_FALSE(details.dispatcher_destroyed); 390 ASSERT_FALSE(details.dispatcher_destroyed);
398 391
399 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); 392 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
400 EXPECT_EQ("1,2 30x40", window->bounds().ToString()); 393 EXPECT_EQ("1,2 30x40", window->bounds().ToString());
401 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey)); 394 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey));
402 } 395 }
403 396
404 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) { 397 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) {
405 aura::test::TestWindowDelegate delegate; 398 aura::test::TestWindowDelegate wd;
406 gfx::Rect bounds(10, 20, 30, 40); 399 gfx::Rect bounds(10, 20, 30, 40);
407 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds)); 400 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
408 window->SetProperty(aura::client::kCanMaximizeKey, true); 401 window->SetProperty(aura::client::kCanMaximizeKey, true);
409 delegate.set_window_component(HTCAPTION); 402 wd.set_window_component(HTCAPTION);
410 403
411 wm::WindowState* window_state = wm::GetWindowState(window.get()); 404 wm::WindowState* window_state = wm::GetWindowState(window.get());
412 EXPECT_FALSE(window_state->IsMaximized()); 405 EXPECT_FALSE(window_state->IsMaximized());
413 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 406 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
414 window.get()); 407 window.get());
415 generator.GestureTapAt(gfx::Point(25, 25)); 408 generator.GestureTapAt(gfx::Point(25, 25));
416 generator.GestureTapAt(gfx::Point(25, 25)); 409 generator.GestureTapAt(gfx::Point(25, 25));
417 RunAllPendingInMessageLoop(); 410 RunAllPendingInMessageLoop();
418 EXPECT_NE(bounds.ToString(), window->bounds().ToString()); 411 EXPECT_NE(bounds.ToString(), window->bounds().ToString());
419 EXPECT_TRUE(window_state->IsMaximized()); 412 EXPECT_TRUE(window_state->IsMaximized());
420 413
421 generator.GestureTapAt(gfx::Point(5, 5)); 414 generator.GestureTapAt(gfx::Point(5, 5));
422 generator.GestureTapAt(gfx::Point(10, 10)); 415 generator.GestureTapAt(gfx::Point(10, 10));
423 416
424 EXPECT_FALSE(window_state->IsMaximized()); 417 EXPECT_FALSE(window_state->IsMaximized());
425 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); 418 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
426 } 419 }
427 420
428 // Verifies deleting the window while dragging doesn't crash. 421 // Verifies deleting the window while dragging doesn't crash.
429 TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) { 422 TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) {
430 // Create a large window in the background. This is necessary so that when we 423 // Create a large window in the background. This is necessary so that when we
431 // delete |window| WorkspaceEventHandler is still the active event handler. 424 // delete |window| WorkspaceEventHandler is still the active event handler.
432 aura::test::TestWindowDelegate delegate2; 425 aura::test::TestWindowDelegate wd2;
433 scoped_ptr<aura::Window> window2( 426 scoped_ptr<aura::Window> window2(
434 CreateTestWindow(&delegate2, gfx::Rect(0, 0, 500, 500))); 427 CreateTestWindow(&wd2, gfx::Rect(0, 0, 500, 500)));
435 428
436 aura::test::TestWindowDelegate delegate; 429 aura::test::TestWindowDelegate wd;
437 const gfx::Rect bounds(10, 20, 30, 40); 430 const gfx::Rect bounds(10, 20, 30, 40);
438 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds)); 431 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
439 delegate.set_window_component(HTCAPTION); 432 wd.set_window_component(HTCAPTION);
440 aura::test::EventGenerator generator(window->GetRootWindow()); 433 aura::test::EventGenerator generator(window->GetRootWindow());
441 generator.MoveMouseToCenterOf(window.get()); 434 generator.MoveMouseToCenterOf(window.get());
442 generator.PressLeftButton(); 435 generator.PressLeftButton();
443 generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50)); 436 generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50));
444 DCHECK_NE(bounds.origin().ToString(), window->bounds().origin().ToString()); 437 DCHECK_NE(bounds.origin().ToString(), window->bounds().origin().ToString());
445 window.reset(); 438 window.reset();
446 generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50)); 439 generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50));
447 } 440 }
448 441
449 // Verifies deleting the window while in a run loop doesn't crash. 442 // Verifies deleting the window while in a run loop doesn't crash.
450 TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) { 443 TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) {
451 aura::test::TestWindowDelegate delegate; 444 aura::test::TestWindowDelegate wd;
452 const gfx::Rect bounds(10, 20, 30, 40); 445 const gfx::Rect bounds(10, 20, 30, 40);
453 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds)); 446 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
454 delegate.set_window_component(HTCAPTION); 447 wd.set_window_component(HTCAPTION);
455 448
456 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->GetRootWindow())); 449 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->GetRootWindow()));
457 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get()); 450 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get());
458 aura::client::GetWindowMoveClient(window->GetRootWindow()) 451 aura::client::GetWindowMoveClient(window->GetRootWindow())
459 ->RunMoveLoop(window.release(), 452 ->RunMoveLoop(window.release(),
460 gfx::Vector2d(), 453 gfx::Vector2d(),
461 aura::client::WINDOW_MOVE_SOURCE_MOUSE); 454 aura::client::WINDOW_MOVE_SOURCE_MOUSE);
462 } 455 }
463 456
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
551 } // namespace ash 457 } // 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