Put WeakPtrFactory member last in USBEventRouter
[chromium-blink-merge.git] / ash / wm / workspace / workspace_event_handler_unittest.cc
blobdde0be8fd6b95c63103ee1247585d5ddb503f3ff
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
3 // found in the LICENSE file.
5 #include "ash/wm/workspace/workspace_event_handler.h"
7 #include "ash/screen_util.h"
8 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/window_state.h"
11 #include "ash/wm/window_util.h"
12 #include "ash/wm/wm_event.h"
13 #include "ash/wm/workspace_controller.h"
14 #include "ash/wm/workspace_controller_test_helper.h"
15 #include "ui/aura/client/aura_constants.h"
16 #include "ui/aura/test/test_window_delegate.h"
17 #include "ui/aura/window.h"
18 #include "ui/aura/window_tree_host.h"
19 #include "ui/base/hit_test.h"
20 #include "ui/events/event_processor.h"
21 #include "ui/events/test/event_generator.h"
22 #include "ui/gfx/screen.h"
23 #include "ui/wm/core/window_util.h"
24 #include "ui/wm/public/window_move_client.h"
26 #if defined(OS_WIN)
27 #include "base/win/windows_version.h"
28 #endif
30 namespace ash {
32 namespace {
34 // Clicks |button| with |flags|.
35 void ClickButtonWithFlags(ui::test::EventGenerator* generator,
36 int button,
37 int flags) {
38 gfx::Point location = generator->current_location();
39 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, location, location,
40 button | flags, button);
41 generator->Dispatch(&press);
42 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, location, location,
43 button | flags, button);
44 generator->Dispatch(&release);
47 } // namespace
49 class WorkspaceEventHandlerTest : public test::AshTestBase {
50 public:
51 WorkspaceEventHandlerTest() {}
52 ~WorkspaceEventHandlerTest() override {}
54 protected:
55 aura::Window* CreateTestWindow(aura::WindowDelegate* delegate,
56 const gfx::Rect& bounds) {
57 aura::Window* window = new aura::Window(delegate);
58 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
59 window->Init(aura::WINDOW_LAYER_TEXTURED);
60 ParentWindowInPrimaryRootWindow(window);
61 window->SetBounds(bounds);
62 window->Show();
63 return window;
66 private:
67 DISALLOW_COPY_AND_ASSIGN(WorkspaceEventHandlerTest);
70 // Keeps track of the properties changed of a particular window.
71 class WindowPropertyObserver : public aura::WindowObserver {
72 public:
73 explicit WindowPropertyObserver(aura::Window* window)
74 : window_(window) {
75 window->AddObserver(this);
78 ~WindowPropertyObserver() override { window_->RemoveObserver(this); }
80 bool DidPropertyChange(const void* property) const {
81 return std::find(properties_changed_.begin(),
82 properties_changed_.end(),
83 property) != properties_changed_.end();
86 private:
87 void OnWindowPropertyChanged(aura::Window* window,
88 const void* key,
89 intptr_t old) override {
90 properties_changed_.push_back(key);
93 aura::Window* window_;
94 std::vector<const void*> properties_changed_;
96 DISALLOW_COPY_AND_ASSIGN(WindowPropertyObserver);
99 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
100 // Double clicking the vertical resize edge of a window should maximize it
101 // vertically.
102 gfx::Rect restored_bounds(10, 10, 50, 50);
103 aura::test::TestWindowDelegate delegate;
104 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
106 wm::ActivateWindow(window.get());
108 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
109 window.get()).work_area();
111 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
112 window.get());
114 // Double-click the top resize edge.
115 delegate.set_window_component(HTTOP);
116 // On X a double click actually generates a drag between each press/release.
117 // Explicitly trigger this path since we had bugs in dealing with it
118 // correctly.
119 generator.PressLeftButton();
120 generator.ReleaseLeftButton();
121 generator.set_flags(ui::EF_IS_DOUBLE_CLICK);
122 generator.PressLeftButton();
123 generator.MoveMouseTo(generator.current_location(), 1);
124 generator.ReleaseLeftButton();
125 gfx::Rect bounds_in_screen = window->GetBoundsInScreen();
126 EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x());
127 EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width());
128 EXPECT_EQ(work_area.y(), bounds_in_screen.y());
129 EXPECT_EQ(work_area.height(), bounds_in_screen.height());
131 wm::WindowState* window_state = wm::GetWindowState(window.get());
132 // Single-axis maximization is not considered real maximization.
133 EXPECT_FALSE(window_state->IsMaximized());
135 // Restore.
136 generator.DoubleClickLeftButton();
137 bounds_in_screen = window->GetBoundsInScreen();
138 EXPECT_EQ(restored_bounds.ToString(), bounds_in_screen.ToString());
139 // Note that it should not even be restored at this point, it should have
140 // also cleared the restore rectangle.
141 EXPECT_FALSE(window_state->HasRestoreBounds());
143 // Double clicking the left resize edge should maximize horizontally.
144 delegate.set_window_component(HTLEFT);
145 generator.DoubleClickLeftButton();
146 bounds_in_screen = window->GetBoundsInScreen();
147 EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y());
148 EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height());
149 EXPECT_EQ(work_area.x(), bounds_in_screen.x());
150 EXPECT_EQ(work_area.width(), bounds_in_screen.width());
151 // Single-axis maximization is not considered real maximization.
152 EXPECT_FALSE(window_state->IsMaximized());
154 // Restore.
155 generator.DoubleClickLeftButton();
156 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString());
158 #if defined(OS_WIN)
159 // Multi display test does not run on Win8 bot. crbug.com/247427.
160 if (!SupportsMultipleDisplays())
161 return;
162 #endif
164 // Verify the double clicking the resize edge works on 2nd display too.
165 UpdateDisplay("200x200,400x300");
166 gfx::Rect work_area2 = ScreenUtil::GetSecondaryDisplay().work_area();
167 restored_bounds.SetRect(220, 20, 50, 50);
168 window->SetBoundsInScreen(restored_bounds, ScreenUtil::GetSecondaryDisplay());
169 aura::Window* second_root = Shell::GetAllRootWindows()[1];
170 EXPECT_EQ(second_root, window->GetRootWindow());
171 ui::test::EventGenerator generator2(second_root, window.get());
173 // Y-axis maximization.
174 delegate.set_window_component(HTTOP);
175 generator2.PressLeftButton();
176 generator2.ReleaseLeftButton();
177 generator2.set_flags(ui::EF_IS_DOUBLE_CLICK);
178 generator2.PressLeftButton();
179 generator2.MoveMouseTo(generator.current_location(), 1);
180 generator2.ReleaseLeftButton();
181 generator.DoubleClickLeftButton();
182 bounds_in_screen = window->GetBoundsInScreen();
183 EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x());
184 EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width());
185 EXPECT_EQ(work_area2.y(), bounds_in_screen.y());
186 EXPECT_EQ(work_area2.height(), bounds_in_screen.height());
187 EXPECT_FALSE(window_state->IsMaximized());
189 // Restore.
190 generator2.DoubleClickLeftButton();
191 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString());
193 // X-axis maximization.
194 delegate.set_window_component(HTLEFT);
195 generator2.DoubleClickLeftButton();
196 bounds_in_screen = window->GetBoundsInScreen();
197 EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y());
198 EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height());
199 EXPECT_EQ(work_area2.x(), bounds_in_screen.x());
200 EXPECT_EQ(work_area2.width(), bounds_in_screen.width());
201 EXPECT_FALSE(window_state->IsMaximized());
203 // Restore.
204 generator2.DoubleClickLeftButton();
205 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString());
208 // Tests the behavior when double clicking the border of a side snapped window.
209 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisWhenSideSnapped) {
210 gfx::Rect restored_bounds(10, 10, 50, 50);
211 aura::test::TestWindowDelegate delegate;
212 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
214 gfx::Rect work_area_in_screen = Shell::GetScreen()->GetDisplayNearestWindow(
215 window.get()).work_area();
217 wm::WindowState* window_state = wm::GetWindowState(window.get());
218 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
219 window_state->OnWMEvent(&snap_event);
221 gfx::Rect snapped_bounds_in_screen = window->GetBoundsInScreen();
222 EXPECT_EQ(work_area_in_screen.x(), snapped_bounds_in_screen.x());
223 EXPECT_EQ(work_area_in_screen.y(), snapped_bounds_in_screen.y());
224 EXPECT_GT(work_area_in_screen.width(), snapped_bounds_in_screen.width());
225 EXPECT_EQ(work_area_in_screen.height(), snapped_bounds_in_screen.height());
227 // Double clicking the top border should not do anything for side snapped
228 // windows. (They already take up the entire workspace height and reverting
229 // to the restored bounds would be weird).
230 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
231 window.get());
232 delegate.set_window_component(HTTOP);
233 generator.DoubleClickLeftButton();
234 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
235 EXPECT_EQ(snapped_bounds_in_screen.ToString(),
236 window->GetBoundsInScreen().ToString());
238 // Double clicking the right border should exit the side snapped state and
239 // make the window take up the entire work area.
240 delegate.set_window_component(HTRIGHT);
241 generator.DoubleClickLeftButton();
242 EXPECT_TRUE(window_state->IsNormalStateType());
243 EXPECT_EQ(work_area_in_screen.ToString(),
244 window->GetBoundsInScreen().ToString());
247 TEST_F(WorkspaceEventHandlerTest,
248 DoubleClickSingleAxisDoesntResizeVerticalEdgeIfConstrained) {
249 gfx::Rect restored_bounds(10, 10, 50, 50);
250 aura::test::TestWindowDelegate delegate;
251 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
253 wm::ActivateWindow(window.get());
255 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
256 window.get()).work_area();
258 delegate.set_maximum_size(gfx::Size(0, 100));
260 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
261 window.get());
262 // Double-click the top resize edge.
263 delegate.set_window_component(HTTOP);
264 generator.DoubleClickLeftButton();
266 // The size of the window should be unchanged.
267 EXPECT_EQ(restored_bounds.y(), window->bounds().y());
268 EXPECT_EQ(restored_bounds.height(), window->bounds().height());
271 TEST_F(WorkspaceEventHandlerTest,
272 DoubleClickSingleAxisDoesntResizeHorizontalEdgeIfConstrained) {
273 gfx::Rect restored_bounds(10, 10, 50, 50);
274 aura::test::TestWindowDelegate delegate;
275 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
277 wm::ActivateWindow(window.get());
279 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
280 window.get()).work_area();
282 delegate.set_maximum_size(gfx::Size(100, 0));
284 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
285 window.get());
286 // Double-click the top resize edge.
287 delegate.set_window_component(HTRIGHT);
288 generator.DoubleClickLeftButton();
290 // The size of the window should be unchanged.
291 EXPECT_EQ(restored_bounds.x(), window->bounds().x());
292 EXPECT_EQ(restored_bounds.width(), window->bounds().width());
295 TEST_F(WorkspaceEventHandlerTest,
296 DoubleClickOrTapWithModalChildDoesntMaximize) {
297 aura::test::TestWindowDelegate delegate1;
298 aura::test::TestWindowDelegate delegate2;
299 scoped_ptr<aura::Window> window(
300 CreateTestWindow(&delegate1, gfx::Rect(10, 20, 30, 40)));
301 scoped_ptr<aura::Window> child(
302 CreateTestWindow(&delegate2, gfx::Rect(0, 0, 1, 1)));
303 window->SetProperty(aura::client::kCanMaximizeKey, true);
304 delegate1.set_window_component(HTCAPTION);
306 child->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
307 ::wm::AddTransientChild(window.get(), child.get());
309 wm::WindowState* window_state = wm::GetWindowState(window.get());
310 EXPECT_FALSE(window_state->IsMaximized());
311 aura::Window* root = Shell::GetPrimaryRootWindow();
312 ui::test::EventGenerator generator(root, window.get());
313 generator.DoubleClickLeftButton();
314 EXPECT_EQ("10,20 30x40", window->bounds().ToString());
315 EXPECT_FALSE(window_state->IsMaximized());
317 generator.GestureTapAt(gfx::Point(25, 25));
318 generator.GestureTapAt(gfx::Point(25, 25));
319 RunAllPendingInMessageLoop();
320 EXPECT_EQ("10,20 30x40", window->bounds().ToString());
321 EXPECT_FALSE(window_state->IsMaximized());
324 // Test the behavior as a result of double clicking the window header.
325 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) {
326 aura::test::TestWindowDelegate delegate;
327 scoped_ptr<aura::Window> window(
328 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
329 window->SetProperty(aura::client::kCanMaximizeKey, true);
331 wm::WindowState* window_state = wm::GetWindowState(window.get());
332 gfx::Rect restore_bounds = window->bounds();
333 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
334 window.get());
336 EXPECT_FALSE(window_state->IsMaximized());
338 // 1) Double clicking a normal window should maximize.
339 delegate.set_window_component(HTCAPTION);
340 aura::Window* root = Shell::GetPrimaryRootWindow();
341 ui::test::EventGenerator generator(root, window.get());
342 generator.DoubleClickLeftButton();
343 EXPECT_NE(restore_bounds.ToString(), window->bounds().ToString());
344 EXPECT_TRUE(window_state->IsMaximized());
346 generator.DoubleClickLeftButton();
347 EXPECT_TRUE(window_state->IsNormalStateType());
348 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
350 // 2) Double clicking a horizontally maximized window should maximize.
351 delegate.set_window_component(HTLEFT);
352 generator.DoubleClickLeftButton();
353 EXPECT_TRUE(window_state->IsNormalStateType());
354 EXPECT_EQ(work_area_in_parent.x(), window->bounds().x());
355 EXPECT_EQ(restore_bounds.y(), window->bounds().y());
356 EXPECT_EQ(work_area_in_parent.width(), window->bounds().width());
357 EXPECT_EQ(restore_bounds.height(), window->bounds().height());
359 delegate.set_window_component(HTCAPTION);
360 generator.DoubleClickLeftButton();
361 EXPECT_TRUE(window_state->IsMaximized());
363 generator.DoubleClickLeftButton();
364 EXPECT_TRUE(window_state->IsNormalStateType());
365 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
367 // 3) Double clicking a snapped window should maximize.
368 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
369 window_state->OnWMEvent(&snap_event);
370 EXPECT_TRUE(window_state->IsSnapped());
371 generator.MoveMouseTo(window->GetBoundsInRootWindow().CenterPoint());
372 generator.DoubleClickLeftButton();
373 EXPECT_TRUE(window_state->IsMaximized());
375 generator.DoubleClickLeftButton();
376 EXPECT_TRUE(window_state->IsNormalStateType());
377 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
380 // Test that double clicking the middle button on the window header does not
381 // toggle the maximized state.
382 TEST_F(WorkspaceEventHandlerTest,
383 DoubleClickMiddleButtonDoesNotToggleMaximize) {
384 aura::test::TestWindowDelegate delegate;
385 scoped_ptr<aura::Window> window(
386 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
387 window->SetProperty(aura::client::kCanMaximizeKey, true);
388 delegate.set_window_component(HTCAPTION);
389 aura::Window* root = Shell::GetPrimaryRootWindow();
390 ui::test::EventGenerator generator(root, window.get());
392 WindowPropertyObserver observer(window.get());
393 ClickButtonWithFlags(&generator, ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_NONE);
394 ClickButtonWithFlags(&generator, ui::EF_MIDDLE_MOUSE_BUTTON,
395 ui::EF_IS_DOUBLE_CLICK);
397 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
398 EXPECT_EQ("1,2 30x40", window->bounds().ToString());
399 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey));
402 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) {
403 aura::test::TestWindowDelegate delegate;
404 gfx::Rect bounds(10, 20, 30, 40);
405 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
406 window->SetProperty(aura::client::kCanMaximizeKey, true);
407 delegate.set_window_component(HTCAPTION);
409 wm::WindowState* window_state = wm::GetWindowState(window.get());
410 EXPECT_FALSE(window_state->IsMaximized());
411 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
412 window.get());
413 generator.GestureTapAt(gfx::Point(25, 25));
414 generator.GestureTapAt(gfx::Point(25, 25));
415 RunAllPendingInMessageLoop();
416 EXPECT_NE(bounds.ToString(), window->bounds().ToString());
417 EXPECT_TRUE(window_state->IsMaximized());
419 generator.GestureTapAt(gfx::Point(5, 5));
420 generator.GestureTapAt(gfx::Point(10, 10));
422 EXPECT_FALSE(window_state->IsMaximized());
423 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
426 // Verifies deleting the window while dragging doesn't crash.
427 TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) {
428 // Create a large window in the background. This is necessary so that when we
429 // delete |window| WorkspaceEventHandler is still the active event handler.
430 aura::test::TestWindowDelegate delegate2;
431 scoped_ptr<aura::Window> window2(
432 CreateTestWindow(&delegate2, gfx::Rect(0, 0, 500, 500)));
434 aura::test::TestWindowDelegate delegate;
435 const gfx::Rect bounds(10, 20, 30, 40);
436 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
437 delegate.set_window_component(HTCAPTION);
438 ui::test::EventGenerator generator(window->GetRootWindow());
439 generator.MoveMouseToCenterOf(window.get());
440 generator.PressLeftButton();
441 generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50));
442 DCHECK_NE(bounds.origin().ToString(), window->bounds().origin().ToString());
443 window.reset();
444 generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50));
447 // Verifies deleting the window while in a run loop doesn't crash.
448 TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) {
449 aura::test::TestWindowDelegate delegate;
450 const gfx::Rect bounds(10, 20, 30, 40);
451 scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
452 delegate.set_window_component(HTCAPTION);
454 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->GetRootWindow()));
455 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get());
456 aura::client::GetWindowMoveClient(window->GetRootWindow())
457 ->RunMoveLoop(window.release(),
458 gfx::Vector2d(),
459 aura::client::WINDOW_MOVE_SOURCE_MOUSE);
462 // Verifies that double clicking in the header does not maximize if the target
463 // component has changed.
464 TEST_F(WorkspaceEventHandlerTest,
465 DoubleClickTwoDifferentTargetsDoesntMaximize) {
466 aura::test::TestWindowDelegate delegate;
467 scoped_ptr<aura::Window> window(
468 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
469 window->SetProperty(aura::client::kCanMaximizeKey, true);
471 wm::WindowState* window_state = wm::GetWindowState(window.get());
472 gfx::Rect restore_bounds = window->bounds();
473 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
474 window.get());
476 EXPECT_FALSE(window_state->IsMaximized());
478 // First click will go to a client
479 delegate.set_window_component(HTCLIENT);
480 aura::Window* root = Shell::GetPrimaryRootWindow();
481 ui::test::EventGenerator generator(root, window.get());
482 generator.ClickLeftButton();
483 EXPECT_FALSE(window_state->IsMaximized());
485 // Second click will go to the header
486 delegate.set_window_component(HTCAPTION);
487 ClickButtonWithFlags(&generator, ui::EF_LEFT_MOUSE_BUTTON,
488 ui::EF_IS_DOUBLE_CLICK);
489 EXPECT_FALSE(window_state->IsMaximized());
492 // Verifies that double tapping in the header does not maximize if the target
493 // component has changed.
494 TEST_F(WorkspaceEventHandlerTest, DoubleTapTwoDifferentTargetsDoesntMaximize) {
495 aura::test::TestWindowDelegate delegate;
496 scoped_ptr<aura::Window> window(
497 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
498 window->SetProperty(aura::client::kCanMaximizeKey, true);
500 wm::WindowState* window_state = wm::GetWindowState(window.get());
501 gfx::Rect restore_bounds = window->bounds();
502 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
503 window.get());
505 EXPECT_FALSE(window_state->IsMaximized());
507 // First tap will go to a client
508 delegate.set_window_component(HTCLIENT);
509 aura::Window* root = Shell::GetPrimaryRootWindow();
510 ui::test::EventGenerator generator(root, window.get());
511 generator.GestureTapAt(gfx::Point(25, 25));
512 EXPECT_FALSE(window_state->IsMaximized());
514 // Second tap will go to the header
515 delegate.set_window_component(HTCAPTION);
516 generator.GestureTapAt(gfx::Point(25, 25));
517 EXPECT_FALSE(window_state->IsMaximized());
520 TEST_F(WorkspaceEventHandlerTest,
521 RightClickDuringDoubleClickDoesntMaximize) {
522 aura::test::TestWindowDelegate delegate;
523 scoped_ptr<aura::Window> window(
524 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
525 window->SetProperty(aura::client::kCanMaximizeKey, true);
527 wm::WindowState* window_state = wm::GetWindowState(window.get());
528 gfx::Rect restore_bounds = window->bounds();
529 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
530 window.get());
532 EXPECT_FALSE(window_state->IsMaximized());
534 // First click will go to a client
535 delegate.set_window_component(HTCLIENT);
536 aura::Window* root = Shell::GetPrimaryRootWindow();
537 ui::test::EventGenerator generator(root, window.get());
538 generator.ClickLeftButton();
539 EXPECT_FALSE(window_state->IsMaximized());
541 // Second click will go to the header
542 delegate.set_window_component(HTCAPTION);
543 generator.PressRightButton();
544 generator.ReleaseRightButton();
545 EXPECT_FALSE(window_state->IsMaximized());
546 ClickButtonWithFlags(&generator, ui::EF_LEFT_MOUSE_BUTTON,
547 ui::EF_IS_DOUBLE_CLICK);
548 EXPECT_FALSE(window_state->IsMaximized());
551 } // namespace ash