OLD | NEW |
---|---|
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 12 matching lines...) Expand all Loading... | |
23 #include "ui/wm/core/window_util.h" | 23 #include "ui/wm/core/window_util.h" |
24 #include "ui/wm/public/window_move_client.h" | 24 #include "ui/wm/public/window_move_client.h" |
25 | 25 |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
28 #endif | 28 #endif |
29 | 29 |
30 namespace ash { | 30 namespace ash { |
31 namespace internal { | 31 namespace internal { |
32 | 32 |
33 namespace { | |
34 | |
35 // Simulates that a child of the window handled a given event. Allows for | |
36 // early exits from EventDispatch::ProcessEvent, which would otherwise | |
37 // dispatch the events a second time to the WorkspaceEventHandler. | |
38 class EventConsumingTestWindowDelegate | |
39 : public aura::test::TestWindowDelegate { | |
40 public: | |
41 EventConsumingTestWindowDelegate() {} | |
42 virtual ~EventConsumingTestWindowDelegate() {} | |
43 | |
44 // ui::EventHandler | |
45 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE { | |
46 event->SetHandled(); | |
47 } | |
48 | |
49 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | |
50 event->SetHandled(); | |
51 } | |
52 | |
53 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | |
54 event->SetHandled(); | |
55 } | |
56 | |
57 private: | |
58 DISALLOW_COPY_AND_ASSIGN(EventConsumingTestWindowDelegate); | |
59 }; | |
60 | |
61 } // namespace | |
62 | |
33 class WorkspaceEventHandlerTest : public test::AshTestBase { | 63 class WorkspaceEventHandlerTest : public test::AshTestBase { |
34 public: | 64 public: |
35 WorkspaceEventHandlerTest() {} | 65 WorkspaceEventHandlerTest() {} |
36 virtual ~WorkspaceEventHandlerTest() {} | 66 virtual ~WorkspaceEventHandlerTest() {} |
37 | 67 |
38 protected: | 68 protected: |
39 aura::Window* CreateTestWindow(aura::WindowDelegate* delegate, | 69 aura::Window* CreateTestWindow(aura::WindowDelegate* delegate, |
40 const gfx::Rect& bounds) { | 70 const gfx::Rect& bounds) { |
41 aura::Window* window = new aura::Window(delegate); | 71 aura::Window* window = new aura::Window(delegate); |
42 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 72 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 | 173 |
144 #if defined(OS_WIN) | 174 #if defined(OS_WIN) |
145 // Multi display test does not run on Win8 bot. crbug.com/247427. | 175 // Multi display test does not run on Win8 bot. crbug.com/247427. |
146 if (base::win::GetVersion() >= base::win::VERSION_WIN8) | 176 if (base::win::GetVersion() >= base::win::VERSION_WIN8) |
147 return; | 177 return; |
148 #endif | 178 #endif |
149 | 179 |
150 // Verify the double clicking the resize edge works on 2nd display too. | 180 // Verify the double clicking the resize edge works on 2nd display too. |
151 UpdateDisplay("200x200,400x300"); | 181 UpdateDisplay("200x200,400x300"); |
152 gfx::Rect work_area2 = ScreenUtil::GetSecondaryDisplay().work_area(); | 182 gfx::Rect work_area2 = ScreenUtil::GetSecondaryDisplay().work_area(); |
153 restored_bounds.SetRect(220,20, 50, 50); | 183 restored_bounds.SetRect(220, 20, 50, 50); |
154 window->SetBoundsInScreen(restored_bounds, ScreenUtil::GetSecondaryDisplay()); | 184 window->SetBoundsInScreen(restored_bounds, ScreenUtil::GetSecondaryDisplay()); |
155 aura::Window* second_root = Shell::GetAllRootWindows()[1]; | 185 aura::Window* second_root = Shell::GetAllRootWindows()[1]; |
156 EXPECT_EQ(second_root, window->GetRootWindow()); | 186 EXPECT_EQ(second_root, window->GetRootWindow()); |
157 aura::test::EventGenerator generator2(second_root, window.get()); | 187 aura::test::EventGenerator generator2(second_root, window.get()); |
158 | 188 |
159 // Y-axis maximization. | 189 // Y-axis maximization. |
160 wd.set_window_component(HTTOP); | 190 wd.set_window_component(HTTOP); |
161 generator2.PressLeftButton(); | 191 generator2.PressLeftButton(); |
162 generator2.ReleaseLeftButton(); | 192 generator2.ReleaseLeftButton(); |
163 generator2.set_flags(ui::EF_IS_DOUBLE_CLICK); | 193 generator2.set_flags(ui::EF_IS_DOUBLE_CLICK); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 wd.set_window_component(HTLEFT); | 367 wd.set_window_component(HTLEFT); |
338 generator.DoubleClickLeftButton(); | 368 generator.DoubleClickLeftButton(); |
339 EXPECT_TRUE(window_state->IsNormalStateType()); | 369 EXPECT_TRUE(window_state->IsNormalStateType()); |
340 EXPECT_EQ(work_area_in_parent.x(), window->bounds().x()); | 370 EXPECT_EQ(work_area_in_parent.x(), window->bounds().x()); |
341 EXPECT_EQ(restore_bounds.y(), window->bounds().y()); | 371 EXPECT_EQ(restore_bounds.y(), window->bounds().y()); |
342 EXPECT_EQ(work_area_in_parent.width(), window->bounds().width()); | 372 EXPECT_EQ(work_area_in_parent.width(), window->bounds().width()); |
343 EXPECT_EQ(restore_bounds.height(), window->bounds().height()); | 373 EXPECT_EQ(restore_bounds.height(), window->bounds().height()); |
344 | 374 |
345 wd.set_window_component(HTCAPTION); | 375 wd.set_window_component(HTCAPTION); |
346 generator.DoubleClickLeftButton(); | 376 generator.DoubleClickLeftButton(); |
347 EXPECT_TRUE(window_state->IsMaximized()); | 377 EXPECT_TRUE(window_state->IsMaximized()); |
varkha
2014/04/03 04:13:21
Does this test still work? Shouldn't it now requir
jonross
2014/04/07 15:49:30
It does, but it shouldn't.
Closer inspection show
| |
348 | 378 |
349 generator.DoubleClickLeftButton(); | 379 generator.DoubleClickLeftButton(); |
350 EXPECT_TRUE(window_state->IsNormalStateType()); | 380 EXPECT_TRUE(window_state->IsNormalStateType()); |
351 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString()); | 381 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString()); |
352 | 382 |
353 // 3) Double clicking a snapped window should maximize. | 383 // 3) Double clicking a snapped window should maximize. |
354 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT); | 384 const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT); |
355 window_state->OnWMEvent(&snap_event); | 385 window_state->OnWMEvent(&snap_event); |
356 EXPECT_TRUE(window_state->IsSnapped()); | 386 EXPECT_TRUE(window_state->IsSnapped()); |
357 generator.MoveMouseTo(window->GetBoundsInRootWindow().CenterPoint()); | 387 generator.MoveMouseTo(window->GetBoundsInRootWindow().CenterPoint()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 wd.set_window_component(HTCAPTION); | 478 wd.set_window_component(HTCAPTION); |
449 | 479 |
450 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->GetRootWindow())); | 480 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->GetRootWindow())); |
451 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get()); | 481 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get()); |
452 aura::client::GetWindowMoveClient(window->GetRootWindow()) | 482 aura::client::GetWindowMoveClient(window->GetRootWindow()) |
453 ->RunMoveLoop(window.release(), | 483 ->RunMoveLoop(window.release(), |
454 gfx::Vector2d(), | 484 gfx::Vector2d(), |
455 aura::client::WINDOW_MOVE_SOURCE_MOUSE); | 485 aura::client::WINDOW_MOVE_SOURCE_MOUSE); |
456 } | 486 } |
457 | 487 |
488 // Verifies that double clicking in the header does not maximize if the target | |
489 // component has changed. | |
490 TEST_F(WorkspaceEventHandlerTest, | |
491 DoubleClickTwoDifferentTargetsDoesntMaximize) { | |
492 EventConsumingTestWindowDelegate wd; | |
varkha
2014/04/03 04:13:21
nit: Maybe wd -> delegate, probably in the other m
jonross
2014/04/07 15:49:30
Done.
| |
493 scoped_ptr<aura::Window> window( | |
494 CreateTestWindow(&wd, gfx::Rect(1, 2, 30, 40))); | |
495 window->SetProperty(aura::client::kCanMaximizeKey, true); | |
496 | |
497 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
498 gfx::Rect restore_bounds = window->bounds(); | |
499 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent( | |
500 window.get()); | |
501 | |
502 EXPECT_FALSE(window_state->IsMaximized()); | |
503 | |
504 // First click will go to a client | |
505 wd.set_window_component(HTCLIENT); | |
506 aura::Window* root = Shell::GetPrimaryRootWindow(); | |
507 aura::test::EventGenerator generator(root, window.get()); | |
508 generator.ClickLeftButton(); | |
509 EXPECT_FALSE(window_state->IsMaximized()); | |
510 | |
511 // Second click will go to the header | |
512 wd.set_window_component(HTCAPTION); | |
513 generator.DoubleClickLeftButton(); | |
514 EXPECT_FALSE(window_state->IsMaximized()); | |
515 } | |
516 | |
517 // Verifies that double tapping in the header does not maximize if the target | |
518 // component has changed. | |
519 TEST_F(WorkspaceEventHandlerTest, DoubleTapTwoDifferentTargetsDoesntMaximize) { | |
520 EventConsumingTestWindowDelegate wd; | |
521 scoped_ptr<aura::Window> window( | |
522 CreateTestWindow(&wd, gfx::Rect(1, 2, 30, 40))); | |
523 window->SetProperty(aura::client::kCanMaximizeKey, true); | |
524 | |
525 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
526 gfx::Rect restore_bounds = window->bounds(); | |
527 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent( | |
528 window.get()); | |
529 | |
530 EXPECT_FALSE(window_state->IsMaximized()); | |
531 | |
532 // First click will go to a client | |
varkha
2014/04/03 04:13:21
s/click/tap
jonross
2014/04/07 15:49:30
Done.
| |
533 wd.set_window_component(HTCLIENT); | |
534 aura::Window* root = Shell::GetPrimaryRootWindow(); | |
535 aura::test::EventGenerator generator(root, window.get()); | |
536 generator.GestureTapAt(gfx::Point(25, 25)); | |
537 EXPECT_FALSE(window_state->IsMaximized()); | |
538 | |
539 // Second click will go to the header | |
varkha
2014/04/03 04:13:21
s/click/tap
jonross
2014/04/07 15:49:30
Done.
| |
540 wd.set_window_component(HTCAPTION); | |
541 generator.GestureTapAt(gfx::Point(25, 25)); | |
542 EXPECT_FALSE(window_state->IsMaximized()); | |
543 } | |
544 | |
545 | |
458 } // namespace internal | 546 } // namespace internal |
459 } // namespace ash | 547 } // namespace ash |
OLD | NEW |