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

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

Issue 10916221: Make ToplevelWindowEventFilter and WorkspaceEventFilter into event handlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ash/wm/workspace/workspace_event_handler_test_helper.cc ('k') | ash/wm/workspace_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_filter.h" 5 #include "ash/wm/workspace/workspace_event_handler.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/window_util.h" 9 #include "ash/wm/window_util.h"
10 #include "ash/wm/workspace_controller_test_helper.h" 10 #include "ash/wm/workspace_controller_test_helper.h"
11 #include "ash/wm/workspace/workspace_manager.h" 11 #include "ash/wm/workspace/workspace_manager.h"
12 #include "ash/wm/workspace_controller.h" 12 #include "ash/wm/workspace_controller.h"
13 #include "ui/aura/test/event_generator.h" 13 #include "ui/aura/test/event_generator.h"
14 #include "ui/aura/test/test_window_delegate.h" 14 #include "ui/aura/test/test_window_delegate.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/base/hit_test.h" 16 #include "ui/base/hit_test.h"
17 #include "ui/gfx/screen.h" 17 #include "ui/gfx/screen.h"
18 18
19 namespace ash { 19 namespace ash {
20 namespace internal { 20 namespace internal {
21 21
22 class WorkspaceEventFilterTest : public test::AshTestBase { 22 class WorkspaceEventHandlerTest : public test::AshTestBase {
23 public: 23 public:
24 WorkspaceEventFilterTest() {} 24 WorkspaceEventHandlerTest() {}
25 virtual ~WorkspaceEventFilterTest() {} 25 virtual ~WorkspaceEventHandlerTest() {}
26 26
27 protected: 27 protected:
28 aura::Window* CreateTestWindow(aura::WindowDelegate* delegate, 28 aura::Window* CreateTestWindow(aura::WindowDelegate* delegate,
29 const gfx::Rect& bounds) { 29 const gfx::Rect& bounds) {
30 aura::Window* window = new aura::Window(delegate); 30 aura::Window* window = new aura::Window(delegate);
31 window->SetType(aura::client::WINDOW_TYPE_NORMAL); 31 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
32 window->Init(ui::LAYER_TEXTURED); 32 window->Init(ui::LAYER_TEXTURED);
33 window->SetParent(NULL); 33 window->SetParent(NULL);
34 window->SetBounds(bounds); 34 window->SetBounds(bounds);
35 window->Show(); 35 window->Show();
36 return window; 36 return window;
37 } 37 }
38 38
39 private: 39 private:
40 DISALLOW_COPY_AND_ASSIGN(WorkspaceEventFilterTest); 40 DISALLOW_COPY_AND_ASSIGN(WorkspaceEventHandlerTest);
41 }; 41 };
42 42
43 TEST_F(WorkspaceEventFilterTest, DoubleClickSingleAxisResizeEdge) { 43 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
44 // Double clicking the vertical resize edge of a window should maximize it 44 // Double clicking the vertical resize edge of a window should maximize it
45 // vertically. 45 // vertically.
46 gfx::Rect restored_bounds(10, 10, 50, 50); 46 gfx::Rect restored_bounds(10, 10, 50, 50);
47 aura::test::TestWindowDelegate wd; 47 aura::test::TestWindowDelegate wd;
48 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds)); 48 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds));
49 49
50 wm::ActivateWindow(window.get()); 50 wm::ActivateWindow(window.get());
51 51
52 gfx::Rect work_area = 52 gfx::Rect work_area =
53 gfx::Screen::GetDisplayNearestWindow(window.get()).work_area(); 53 gfx::Screen::GetDisplayNearestWindow(window.get()).work_area();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 // Double clicking the left resize edge should maximize horizontally. 89 // Double clicking the left resize edge should maximize horizontally.
90 wd.set_window_component(HTLEFT); 90 wd.set_window_component(HTLEFT);
91 generator.DoubleClickLeftButton(); 91 generator.DoubleClickLeftButton();
92 EXPECT_EQ(work_area.x(), window->bounds().x()); 92 EXPECT_EQ(work_area.x(), window->bounds().x());
93 EXPECT_EQ(work_area.width(), window->bounds().width()); 93 EXPECT_EQ(work_area.width(), window->bounds().width());
94 // Single-axis maximization is not considered real maximization. 94 // Single-axis maximization is not considered real maximization.
95 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); 95 EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
96 } 96 }
97 97
98 TEST_F(WorkspaceEventFilterTest, DoubleClickCaptionTogglesMaximize) { 98 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) {
99 aura::test::TestWindowDelegate wd; 99 aura::test::TestWindowDelegate wd;
100 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, gfx::Rect(1, 2, 3, 4))); 100 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, gfx::Rect(1, 2, 3, 4)));
101 wd.set_window_component(HTCAPTION); 101 wd.set_window_component(HTCAPTION);
102 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); 102 EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
103 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 103 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
104 window.get()); 104 window.get());
105 generator.DoubleClickLeftButton(); 105 generator.DoubleClickLeftButton();
106 EXPECT_NE("1,2 3x4", window->bounds().ToString()); 106 EXPECT_NE("1,2 3x4", window->bounds().ToString());
107 107
108 EXPECT_TRUE(wm::IsWindowMaximized(window.get())); 108 EXPECT_TRUE(wm::IsWindowMaximized(window.get()));
109 generator.DoubleClickLeftButton(); 109 generator.DoubleClickLeftButton();
110 110
111 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); 111 EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
112 EXPECT_EQ("1,2 3x4", window->bounds().ToString()); 112 EXPECT_EQ("1,2 3x4", window->bounds().ToString());
113 } 113 }
114 114
115 TEST_F(WorkspaceEventFilterTest, DoubleTapCaptionTogglesMaximize) { 115 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) {
116 aura::test::TestWindowDelegate wd; 116 aura::test::TestWindowDelegate wd;
117 gfx::Rect bounds(10, 20, 30, 40); 117 gfx::Rect bounds(10, 20, 30, 40);
118 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds)); 118 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
119 wd.set_window_component(HTCAPTION); 119 wd.set_window_component(HTCAPTION);
120 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); 120 EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
121 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 121 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
122 window.get()); 122 window.get());
123 generator.GestureTapAt(gfx::Point(25, 25)); 123 generator.GestureTapAt(gfx::Point(25, 25));
124 generator.GestureTapAt(gfx::Point(25, 25)); 124 generator.GestureTapAt(gfx::Point(25, 25));
125 RunAllPendingInMessageLoop(); 125 RunAllPendingInMessageLoop();
126 EXPECT_NE(bounds.ToString(), window->bounds().ToString()); 126 EXPECT_NE(bounds.ToString(), window->bounds().ToString());
127 EXPECT_TRUE(wm::IsWindowMaximized(window.get())); 127 EXPECT_TRUE(wm::IsWindowMaximized(window.get()));
128 128
129 generator.GestureTapAt(gfx::Point(5, 5)); 129 generator.GestureTapAt(gfx::Point(5, 5));
130 generator.GestureTapAt(gfx::Point(10, 10)); 130 generator.GestureTapAt(gfx::Point(10, 10));
131 131
132 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); 132 EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
133 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); 133 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
134 } 134 }
135 135
136 // Verifies deleting the window while dragging doesn't crash. 136 // Verifies deleting the window while dragging doesn't crash.
137 TEST_F(WorkspaceEventFilterTest, DeleteWhenDragging) { 137 TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) {
138 // Create a large window in the background. This is necessary so that when we 138 // Create a large window in the background. This is necessary so that when we
139 // delete |window| WorkspaceEventFilter is still the active EventFilter. 139 // delete |window| WorkspaceEventHandler is still the active event handler.
140 aura::test::TestWindowDelegate wd2; 140 aura::test::TestWindowDelegate wd2;
141 scoped_ptr<aura::Window> window2( 141 scoped_ptr<aura::Window> window2(
142 CreateTestWindow(&wd2, gfx::Rect(0, 0, 500, 500))); 142 CreateTestWindow(&wd2, gfx::Rect(0, 0, 500, 500)));
143 143
144 aura::test::TestWindowDelegate wd; 144 aura::test::TestWindowDelegate wd;
145 const gfx::Rect bounds(10, 20, 30, 40); 145 const gfx::Rect bounds(10, 20, 30, 40);
146 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds)); 146 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
147 wd.set_window_component(HTCAPTION); 147 wd.set_window_component(HTCAPTION);
148 aura::test::EventGenerator generator(window->GetRootWindow()); 148 aura::test::EventGenerator generator(window->GetRootWindow());
149 generator.MoveMouseToCenterOf(window.get()); 149 generator.MoveMouseToCenterOf(window.get());
150 generator.PressLeftButton(); 150 generator.PressLeftButton();
151 generator.MoveMouseTo(generator.current_location().Add(gfx::Point(50, 50))); 151 generator.MoveMouseTo(generator.current_location().Add(gfx::Point(50, 50)));
152 DCHECK_NE(bounds.origin().ToString(), window->bounds().origin().ToString()); 152 DCHECK_NE(bounds.origin().ToString(), window->bounds().origin().ToString());
153 window.reset(); 153 window.reset();
154 generator.MoveMouseTo(generator.current_location().Add(gfx::Point(50, 50))); 154 generator.MoveMouseTo(generator.current_location().Add(gfx::Point(50, 50)));
155 } 155 }
156 156
157 // Verifies deleting the window while in a run loop doesn't crash. 157 // Verifies deleting the window while in a run loop doesn't crash.
158 TEST_F(WorkspaceEventFilterTest, DeleteWhileInRunLoop) { 158 TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) {
159 aura::test::TestWindowDelegate wd; 159 aura::test::TestWindowDelegate wd;
160 const gfx::Rect bounds(10, 20, 30, 40); 160 const gfx::Rect bounds(10, 20, 30, 40);
161 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds)); 161 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
162 wd.set_window_component(HTCAPTION); 162 wd.set_window_component(HTCAPTION);
163 163
164 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->parent())); 164 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->parent()));
165 MessageLoop::current()->DeleteSoon(FROM_HERE, window.get()); 165 MessageLoop::current()->DeleteSoon(FROM_HERE, window.get());
166 aura::client::GetWindowMoveClient(window->parent())->RunMoveLoop( 166 aura::client::GetWindowMoveClient(window->parent())->RunMoveLoop(
167 window.release(), gfx::Point()); 167 window.release(), gfx::Point());
168 } 168 }
169 169
170 } // namespace internal 170 } // namespace internal
171 } // namespace ash 171 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_event_handler_test_helper.cc ('k') | ash/wm/workspace_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698