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

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

Issue 22397002: ash: Process double-click event only for left-button clicks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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.cc ('k') | no next file » | 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_handler.h" 5 #include "ash/wm/workspace/workspace_event_handler.h"
6 6
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.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/property_util.h" 10 #include "ash/wm/property_util.h"
11 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
12 #include "ash/wm/workspace_controller.h" 12 #include "ash/wm/workspace_controller.h"
13 #include "ash/wm/workspace_controller_test_helper.h" 13 #include "ash/wm/workspace_controller_test_helper.h"
14 #include "ui/aura/client/aura_constants.h" 14 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/root_window.h"
15 #include "ui/aura/test/event_generator.h" 16 #include "ui/aura/test/event_generator.h"
16 #include "ui/aura/test/test_window_delegate.h" 17 #include "ui/aura/test/test_window_delegate.h"
17 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
19 #include "ui/aura/window_property.h"
18 #include "ui/base/hit_test.h" 20 #include "ui/base/hit_test.h"
19 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
20 22
21 #if defined(OS_WIN) 23 #if defined(OS_WIN)
22 #include "base/win/windows_version.h" 24 #include "base/win/windows_version.h"
23 #endif 25 #endif
24 26
25 namespace ash { 27 namespace ash {
26 namespace internal { 28 namespace internal {
27 29
(...skipping 11 matching lines...) Expand all
39 SetDefaultParentByPrimaryRootWindow(window); 41 SetDefaultParentByPrimaryRootWindow(window);
40 window->SetBounds(bounds); 42 window->SetBounds(bounds);
41 window->Show(); 43 window->Show();
42 return window; 44 return window;
43 } 45 }
44 46
45 private: 47 private:
46 DISALLOW_COPY_AND_ASSIGN(WorkspaceEventHandlerTest); 48 DISALLOW_COPY_AND_ASSIGN(WorkspaceEventHandlerTest);
47 }; 49 };
48 50
51 // Keeps track of the properties changed of a particular window.
52 class WindowPropertyObserver : public aura::WindowObserver {
53 public:
54 explicit WindowPropertyObserver(aura::Window* window)
55 : window_(window) {
56 window->AddObserver(this);
57 }
58
59 virtual ~WindowPropertyObserver() {
60 window_->RemoveObserver(this);
61 }
62
63 bool DidPropertyChange(const void* property) const {
64 return std::find(properties_changed_.begin(),
65 properties_changed_.end(),
66 property) != properties_changed_.end();
67 }
68
69 private:
70 virtual void OnWindowPropertyChanged(aura::Window* window,
71 const void* key,
72 intptr_t old) OVERRIDE {
73 properties_changed_.push_back(key);
74 }
75
76 aura::Window* window_;
77 std::vector<const void*> properties_changed_;
78
79 DISALLOW_COPY_AND_ASSIGN(WindowPropertyObserver);
80 };
81
49 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) { 82 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
50 // Double clicking the vertical resize edge of a window should maximize it 83 // Double clicking the vertical resize edge of a window should maximize it
51 // vertically. 84 // vertically.
52 gfx::Rect restored_bounds(10, 10, 50, 50); 85 gfx::Rect restored_bounds(10, 10, 50, 50);
53 aura::test::TestWindowDelegate wd; 86 aura::test::TestWindowDelegate wd;
54 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds)); 87 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds));
55 88
56 wm::ActivateWindow(window.get()); 89 wm::ActivateWindow(window.get());
57 90
58 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( 91 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 EXPECT_EQ(restored_bounds.x(), window->bounds().x()); 245 EXPECT_EQ(restored_bounds.x(), window->bounds().x());
213 EXPECT_EQ(restored_bounds.width(), window->bounds().width()); 246 EXPECT_EQ(restored_bounds.width(), window->bounds().width());
214 } 247 }
215 248
216 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) { 249 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) {
217 aura::test::TestWindowDelegate wd; 250 aura::test::TestWindowDelegate wd;
218 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, gfx::Rect(1, 2, 3, 4))); 251 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, gfx::Rect(1, 2, 3, 4)));
219 window->SetProperty(aura::client::kCanMaximizeKey, true); 252 window->SetProperty(aura::client::kCanMaximizeKey, true);
220 wd.set_window_component(HTCAPTION); 253 wd.set_window_component(HTCAPTION);
221 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); 254 EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
222 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 255 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
223 window.get()); 256 aura::test::EventGenerator generator(root, window.get());
224 generator.DoubleClickLeftButton(); 257 generator.DoubleClickLeftButton();
225 EXPECT_NE("1,2 3x4", window->bounds().ToString()); 258 EXPECT_NE("1,2 3x4", window->bounds().ToString());
226 259
227 EXPECT_TRUE(wm::IsWindowMaximized(window.get())); 260 EXPECT_TRUE(wm::IsWindowMaximized(window.get()));
228 generator.DoubleClickLeftButton(); 261 generator.DoubleClickLeftButton();
229 262
230 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); 263 EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
231 EXPECT_EQ("1,2 3x4", window->bounds().ToString()); 264 EXPECT_EQ("1,2 3x4", window->bounds().ToString());
265
266 // Double-clicking the middle button shouldn't toggle the maximized state.
267 WindowPropertyObserver observer(window.get());
268 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, generator.current_location(),
269 generator.current_location(),
270 ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK);
271 root->AsRootWindowHostDelegate()->OnHostMouseEvent(&press);
272 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, generator.current_location(),
273 generator.current_location(),
274 ui::EF_IS_DOUBLE_CLICK);
275 root->AsRootWindowHostDelegate()->OnHostMouseEvent(&release);
276
277 EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
278 EXPECT_EQ("1,2 3x4", window->bounds().ToString());
279 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey));
232 } 280 }
233 281
234 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) { 282 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) {
235 aura::test::TestWindowDelegate wd; 283 aura::test::TestWindowDelegate wd;
236 gfx::Rect bounds(10, 20, 30, 40); 284 gfx::Rect bounds(10, 20, 30, 40);
237 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds)); 285 scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
238 window->SetProperty(aura::client::kCanMaximizeKey, true); 286 window->SetProperty(aura::client::kCanMaximizeKey, true);
239 wd.set_window_component(HTCAPTION); 287 wd.set_window_component(HTCAPTION);
240 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); 288 EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
241 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 289 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->parent())); 332 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->parent()));
285 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get()); 333 base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get());
286 aura::client::GetWindowMoveClient(window->parent()) 334 aura::client::GetWindowMoveClient(window->parent())
287 ->RunMoveLoop(window.release(), 335 ->RunMoveLoop(window.release(),
288 gfx::Vector2d(), 336 gfx::Vector2d(),
289 aura::client::WINDOW_MOVE_SOURCE_MOUSE); 337 aura::client::WINDOW_MOVE_SOURCE_MOUSE);
290 } 338 }
291 339
292 } // namespace internal 340 } // namespace internal
293 } // namespace ash 341 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_event_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698