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

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller_unittest.cc

Issue 313913004: Block internal PlatformEvents before they are dispatched in touchview. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove obsolete comment and unnecessary includes. Created 6 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/maximize_mode/maximize_mode_controller.h" 5 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
6 6
7 #include "ash/accelerometer/accelerometer_controller.h" 7 #include "ash/accelerometer/accelerometer_controller.h"
8 #include "ash/display/display_manager.h" 8 #include "ash/display/display_manager.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
11 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/display_manager_test_api.h" 12 #include "ash/test/display_manager_test_api.h"
13 #include "ash/test/test_lock_state_controller_delegate.h" 13 #include "ash/test/test_lock_state_controller_delegate.h"
14 #include "ash/test/test_screenshot_delegate.h" 14 #include "ash/test/test_screenshot_delegate.h"
15 #include "ash/test/test_system_tray_delegate.h" 15 #include "ash/test/test_system_tray_delegate.h"
16 #include "ash/test/test_volume_control_delegate.h" 16 #include "ash/test/test_volume_control_delegate.h"
17 #include "ash/wm/maximize_mode/internal_input_device_list.h"
18 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h"
19 #include "ui/aura/test/event_generator.h" 17 #include "ui/aura/test/event_generator.h"
20 #include "ui/events/event_handler.h"
21 #include "ui/gfx/vector3d_f.h" 18 #include "ui/gfx/vector3d_f.h"
22 #include "ui/message_center/message_center.h" 19 #include "ui/message_center/message_center.h"
23 20
24 namespace ash { 21 namespace ash {
25 22
26 namespace { 23 namespace {
27 24
28 const float kDegreesToRadians = 3.14159265f / 180.0f; 25 const float kDegreesToRadians = 3.14159265f / 180.0f;
29 26
30 // Filter to count the number of events seen.
31 class EventCounter : public ui::EventHandler {
32 public:
33 EventCounter();
34 virtual ~EventCounter();
35
36 // Overridden from ui::EventHandler:
37 virtual void OnEvent(ui::Event* event) OVERRIDE;
38
39 void reset() {
40 event_count_ = 0;
41 }
42
43 size_t event_count() const { return event_count_; }
44
45 private:
46 size_t event_count_;
47
48 DISALLOW_COPY_AND_ASSIGN(EventCounter);
49 };
50
51 EventCounter::EventCounter() : event_count_(0) {
52 Shell::GetInstance()->AddPreTargetHandler(this);
53 }
54
55 EventCounter::~EventCounter() {
56 Shell::GetInstance()->RemovePreTargetHandler(this);
57 }
58
59 void EventCounter::OnEvent(ui::Event* event) {
60 event_count_++;
61 }
62
63 // A test internal input device list which pretends that all events are from
64 // internal devices to allow verifying that the event blocking works.
65 class TestInternalInputDeviceList : public InternalInputDeviceList {
66 public:
67 TestInternalInputDeviceList() {}
68 virtual ~TestInternalInputDeviceList() {}
69
70 virtual bool IsEventFromInternalDevice(const ui::Event* event) OVERRIDE {
71 return true;
72 }
73
74 private:
75 DISALLOW_COPY_AND_ASSIGN(TestInternalInputDeviceList);
76 };
77
78 } // namespace 27 } // namespace
79 28
80 // Test accelerometer data taken with the lid at less than 180 degrees while 29 // Test accelerometer data taken with the lid at less than 180 degrees while
81 // shaking the device around. The data is to be interpreted in groups of 6 where 30 // shaking the device around. The data is to be interpreted in groups of 6 where
82 // each 6 values corresponds to the X, Y, and Z readings from the base and lid 31 // each 6 values corresponds to the X, Y, and Z readings from the base and lid
83 // accelerometers in this order. 32 // accelerometers in this order.
84 extern const float kAccelerometerLaptopModeTestData[]; 33 extern const float kAccelerometerLaptopModeTestData[];
85 extern const size_t kAccelerometerLaptopModeTestDataLength; 34 extern const size_t kAccelerometerLaptopModeTestDataLength;
86 35
87 // Test accelerometer data taken with the lid open 360 degrees while 36 // Test accelerometer data taken with the lid open 360 degrees while
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 68
120 void TriggerAccelerometerUpdate(const gfx::Vector3dF& base, 69 void TriggerAccelerometerUpdate(const gfx::Vector3dF& base,
121 const gfx::Vector3dF& lid) { 70 const gfx::Vector3dF& lid) {
122 maximize_mode_controller()->OnAccelerometerUpdated(base, lid); 71 maximize_mode_controller()->OnAccelerometerUpdated(base, lid);
123 } 72 }
124 73
125 bool IsMaximizeModeStarted() const { 74 bool IsMaximizeModeStarted() const {
126 return Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); 75 return Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled();
127 } 76 }
128 77
129 // Overrides the internal input device list for the current event targeters
130 // with one which always returns true.
131 void InstallTestInternalDeviceList() {
132 maximize_mode_controller()->event_blocker_->internal_devices_.reset(
133 new TestInternalInputDeviceList);
134 }
135
136 gfx::Display::Rotation GetInternalDisplayRotation() const { 78 gfx::Display::Rotation GetInternalDisplayRotation() const {
137 return Shell::GetInstance()->display_manager()->GetDisplayInfo( 79 return Shell::GetInstance()->display_manager()->GetDisplayInfo(
138 gfx::Display::InternalDisplayId()).rotation(); 80 gfx::Display::InternalDisplayId()).rotation();
139 } 81 }
140 82
141 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) const { 83 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) const {
142 Shell::GetInstance()->display_manager()-> 84 Shell::GetInstance()->display_manager()->
143 SetDisplayRotation(gfx::Display::InternalDisplayId(), rotation); 85 SetDisplayRotation(gfx::Display::InternalDisplayId(), rotation);
144 } 86 }
145 87
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 ASSERT_TRUE(IsMaximizeModeStarted()); 251 ASSERT_TRUE(IsMaximizeModeStarted());
310 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 252 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
311 253
312 // Close lid back to 90, screen should rotate back. 254 // Close lid back to 90, screen should rotate back.
313 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.95f, 0.35f), 255 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.95f, 0.35f),
314 gfx::Vector3dF(-0.35f, 0.95f, 0.0f)); 256 gfx::Vector3dF(-0.35f, 0.95f, 0.0f));
315 ASSERT_FALSE(IsMaximizeModeStarted()); 257 ASSERT_FALSE(IsMaximizeModeStarted());
316 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 258 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
317 } 259 }
318 260
319 // Tests that maximize mode blocks keyboard and mouse events but not touch
320 // events.
321 TEST_F(MaximizeModeControllerTest, BlocksKeyboardAndMouse) {
322 aura::Window* root = Shell::GetPrimaryRootWindow();
323 aura::test::EventGenerator event_generator(root, root);
324 EventCounter counter;
325
326 event_generator.PressKey(ui::VKEY_ESCAPE, 0);
327 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0);
328 EXPECT_GT(counter.event_count(), 0u);
329 counter.reset();
330
331 event_generator.ClickLeftButton();
332 EXPECT_GT(counter.event_count(), 0u);
333 counter.reset();
334
335 event_generator.ScrollSequence(
336 gfx::Point(), base::TimeDelta::FromMilliseconds(5), 0, 100, 5, 2);
337 EXPECT_GT(counter.event_count(), 0u);
338 counter.reset();
339
340 event_generator.MoveMouseWheel(0, 10);
341 EXPECT_GT(counter.event_count(), 0u);
342 counter.reset();
343
344 event_generator.PressTouch();
345 event_generator.ReleaseTouch();
346 EXPECT_GT(counter.event_count(), 0u);
347 counter.reset();
348
349 // Open up 270 degrees.
350 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
351 gfx::Vector3dF(1.0f, 0.0f, 0.0f));
352 ASSERT_TRUE(IsMaximizeModeStarted());
353 InstallTestInternalDeviceList();
354
355 event_generator.PressKey(ui::VKEY_ESCAPE, 0);
356 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0);
357 EXPECT_EQ(0u, counter.event_count());
358 counter.reset();
359
360 event_generator.ClickLeftButton();
361 EXPECT_EQ(0u, counter.event_count());
362 counter.reset();
363
364 event_generator.ScrollSequence(
365 gfx::Point(), base::TimeDelta::FromMilliseconds(5), 0, 100, 5, 2);
366 EXPECT_EQ(0u, counter.event_count());
367 counter.reset();
368
369 event_generator.MoveMouseWheel(0, 10);
370 EXPECT_EQ(0u, counter.event_count());
371 counter.reset();
372
373 // Touch should not be blocked.
374 event_generator.PressTouch();
375 event_generator.ReleaseTouch();
376 EXPECT_GT(counter.event_count(), 0u);
377 counter.reset();
378
379 gfx::Vector3dF base;
380
381 // Lid open 90 degrees.
382 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
383 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
384
385 event_generator.PressKey(ui::VKEY_ESCAPE, 0);
386 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0);
387 EXPECT_GT(counter.event_count(), 0u);
388 counter.reset();
389 }
390
391 #if defined(OS_CHROMEOS) 261 #if defined(OS_CHROMEOS)
392 // Tests that a screenshot can be taken in maximize mode by holding volume down 262 // Tests that a screenshot can be taken in maximize mode by holding volume down
393 // and pressing power. 263 // and pressing power.
394 TEST_F(MaximizeModeControllerTest, Screenshot) { 264 TEST_F(MaximizeModeControllerTest, Screenshot) {
395 Shell::GetInstance()->lock_state_controller()->SetDelegate( 265 Shell::GetInstance()->lock_state_controller()->SetDelegate(
396 new test::TestLockStateControllerDelegate); 266 new test::TestLockStateControllerDelegate);
397 aura::Window* root = Shell::GetPrimaryRootWindow(); 267 aura::Window* root = Shell::GetPrimaryRootWindow();
398 aura::test::EventGenerator event_generator(root, root); 268 aura::test::EventGenerator event_generator(root, root);
399 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); 269 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate();
400 delegate->set_can_take_screenshot(true); 270 delegate->set_can_take_screenshot(true);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); 483 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
614 484
615 // Exit maximize mode 485 // Exit maximize mode
616 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 486 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
617 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 487 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
618 EXPECT_FALSE(IsMaximizeModeStarted()); 488 EXPECT_FALSE(IsMaximizeModeStarted());
619 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 489 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
620 } 490 }
621 491
622 } // namespace ash 492 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698