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

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

Issue 261163004: Lock Rotation when screen is manually rotated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
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/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 EXPECT_TRUE(IsMaximizeModeStarted()); 141 EXPECT_TRUE(IsMaximizeModeStarted());
142 142
143 // Open 90 degrees. 143 // Open 90 degrees.
144 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 144 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
145 EXPECT_FALSE(IsMaximizeModeStarted()); 145 EXPECT_FALSE(IsMaximizeModeStarted());
146 } 146 }
147 147
148 // Tests that when the hinge is nearly vertically aligned, the current state 148 // Tests that when the hinge is nearly vertically aligned, the current state
149 // persists as the computed angle is highly inaccurate in this orientation. 149 // persists as the computed angle is highly inaccurate in this orientation.
150 TEST_F(MaximizeModeControllerTest, HingeAligned) { 150 TEST_F(MaximizeModeControllerTest, HingeAligned) {
151 // Laptop in normal orientation lid open 90 degrees. 151 // Laptop in normal orientation lid open 90 degrees.
152 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 152 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
153 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 153 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
154 EXPECT_FALSE(IsMaximizeModeStarted()); 154 EXPECT_FALSE(IsMaximizeModeStarted());
155 155
156 // Completely vertical. 156 // Completely vertical.
157 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f), 157 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f),
158 gfx::Vector3dF(0.0f, -1.0f, 0.0f)); 158 gfx::Vector3dF(0.0f, -1.0f, 0.0f));
159 EXPECT_FALSE(IsMaximizeModeStarted()); 159 EXPECT_FALSE(IsMaximizeModeStarted());
160 160
161 // Close to vertical but with hinge appearing to be open 270 degrees. 161 // Close to vertical but with hinge appearing to be open 270 degrees.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // Open up 270 degrees. 302 // Open up 270 degrees.
303 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 303 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
304 gfx::Vector3dF(1.0f, 0.0f, 0.0f)); 304 gfx::Vector3dF(1.0f, 0.0f, 0.0f));
305 ASSERT_TRUE(IsMaximizeModeStarted()); 305 ASSERT_TRUE(IsMaximizeModeStarted());
306 306
307 event_generator.PressKey(ui::VKEY_ESCAPE, 0); 307 event_generator.PressKey(ui::VKEY_ESCAPE, 0);
308 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0); 308 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0);
309 EXPECT_EQ(0u, counter.event_count()); 309 EXPECT_EQ(0u, counter.event_count());
310 counter.reset(); 310 counter.reset();
311 311
312 // Touch should not be blocked. 312 // Touch should not be blocked.
313 event_generator.PressTouch(); 313 event_generator.PressTouch();
314 event_generator.ReleaseTouch(); 314 event_generator.ReleaseTouch();
315 EXPECT_GT(counter.event_count(), 0u); 315 EXPECT_GT(counter.event_count(), 0u);
316 counter.reset(); 316 counter.reset();
317 317
318 gfx::Vector3dF base; 318 gfx::Vector3dF base;
319 319
320 // Lid open 90 degrees. 320 // Lid open 90 degrees.
321 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 321 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
322 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 322 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
323 323
324 event_generator.PressKey(ui::VKEY_ESCAPE, 0); 324 event_generator.PressKey(ui::VKEY_ESCAPE, 0);
325 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0); 325 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0);
326 EXPECT_GT(counter.event_count(), 0u); 326 EXPECT_GT(counter.event_count(), 0u);
327 counter.reset(); 327 counter.reset();
328 } 328 }
329 329
330 TEST_F(MaximizeModeControllerTest, LaptopTest) { 330 TEST_F(MaximizeModeControllerTest, LaptopTest) {
331 // Feeds in sample accelerometer data and verifies that there are no 331 // Feeds in sample accelerometer data and verifies that there are no
332 // transitions into touchview / maximize mode while shaking the device around 332 // transitions into touchview / maximize mode while shaking the device around
333 // with the hinge at less than 180 degrees. 333 // with the hinge at less than 180 degrees.
334 ASSERT_TRUE(kAccelerometerLaptopModeTestDataLength % 6 == 0); 334 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6);
335 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) { 335 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) {
336 gfx::Vector3dF base(kAccelerometerLaptopModeTestData[i * 6], 336 gfx::Vector3dF base(kAccelerometerLaptopModeTestData[i * 6],
337 kAccelerometerLaptopModeTestData[i * 6 + 1], 337 kAccelerometerLaptopModeTestData[i * 6 + 1],
338 kAccelerometerLaptopModeTestData[i * 6 + 2]); 338 kAccelerometerLaptopModeTestData[i * 6 + 2]);
339 gfx::Vector3dF lid(kAccelerometerLaptopModeTestData[i * 6 + 3], 339 gfx::Vector3dF lid(kAccelerometerLaptopModeTestData[i * 6 + 3],
340 kAccelerometerLaptopModeTestData[i * 6 + 4], 340 kAccelerometerLaptopModeTestData[i * 6 + 4],
341 kAccelerometerLaptopModeTestData[i * 6 + 5]); 341 kAccelerometerLaptopModeTestData[i * 6 + 5]);
342 TriggerAccelerometerUpdate(base, lid); 342 TriggerAccelerometerUpdate(base, lid);
343 // There are a lot of samples, so ASSERT rather than EXPECT to only generate 343 // There are a lot of samples, so ASSERT rather than EXPECT to only generate
344 // one failure rather than potentially hundreds. 344 // one failure rather than potentially hundreds.
345 ASSERT_FALSE(IsMaximizeModeStarted()); 345 ASSERT_FALSE(IsMaximizeModeStarted());
346 } 346 }
347 } 347 }
348 348
349 TEST_F(MaximizeModeControllerTest, MaximizeModeTest) { 349 TEST_F(MaximizeModeControllerTest, MaximizeModeTest) {
350 // Trigger maximize mode by opening to 270 to begin the test in maximize mode. 350 // Trigger maximize mode by opening to 270 to begin the test in maximize mode.
351 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), 351 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
352 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 352 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
353 ASSERT_TRUE(IsMaximizeModeStarted()); 353 ASSERT_TRUE(IsMaximizeModeStarted());
354 354
355 // Feeds in sample accelerometer data and verifies that there are no 355 // Feeds in sample accelerometer data and verifies that there are no
356 // transitions out of touchview / maximize mode while shaking the device 356 // transitions out of touchview / maximize mode while shaking the device
357 // around. 357 // around.
358 ASSERT_TRUE(kAccelerometerFullyOpenTestDataLength % 6 == 0); 358 ASSERT_EQ(0u, kAccelerometerFullyOpenTestDataLength % 6);
359 for (size_t i = 0; i < kAccelerometerFullyOpenTestDataLength / 6; ++i) { 359 for (size_t i = 0; i < kAccelerometerFullyOpenTestDataLength / 6; ++i) {
360 gfx::Vector3dF base(kAccelerometerFullyOpenTestData[i * 6], 360 gfx::Vector3dF base(kAccelerometerFullyOpenTestData[i * 6],
361 kAccelerometerFullyOpenTestData[i * 6 + 1], 361 kAccelerometerFullyOpenTestData[i * 6 + 1],
362 kAccelerometerFullyOpenTestData[i * 6 + 2]); 362 kAccelerometerFullyOpenTestData[i * 6 + 2]);
363 gfx::Vector3dF lid(kAccelerometerFullyOpenTestData[i * 6 + 3], 363 gfx::Vector3dF lid(kAccelerometerFullyOpenTestData[i * 6 + 3],
364 kAccelerometerFullyOpenTestData[i * 6 + 4], 364 kAccelerometerFullyOpenTestData[i * 6 + 4],
365 kAccelerometerFullyOpenTestData[i * 6 + 5]); 365 kAccelerometerFullyOpenTestData[i * 6 + 5]);
366 TriggerAccelerometerUpdate(base, lid); 366 TriggerAccelerometerUpdate(base, lid);
367 // There are a lot of samples, so ASSERT rather than EXPECT to only generate 367 // There are a lot of samples, so ASSERT rather than EXPECT to only generate
368 // one failure rather than potentially hundreds. 368 // one failure rather than potentially hundreds.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 409
410 // Open 90 degrees. 410 // Open 90 degrees.
411 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 411 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
412 EXPECT_FALSE(IsMaximizeModeStarted()); 412 EXPECT_FALSE(IsMaximizeModeStarted());
413 413
414 // Send an update that would not relaunch MaximizeMode. 90 degrees. 414 // Send an update that would not relaunch MaximizeMode. 90 degrees.
415 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 415 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
416 EXPECT_FALSE(maximize_mode_controller()->rotation_locked()); 416 EXPECT_FALSE(maximize_mode_controller()->rotation_locked());
417 } 417 }
418 418
419 // Tests that if the display was rotated before entering maximize mode that
420 // rotation becomes locked.
421 TEST_F(MaximizeModeControllerTest,
422 RotatedDisplayLocksRotationUponEnteringMaximizeMode) {
423 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
424 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
425 gfx::Display::ROTATE_90);
426 // Trigger maximize mode by opening to 270.
427 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
428 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
429 ASSERT_TRUE(IsMaximizeModeStarted());
430 EXPECT_TRUE(maximize_mode_controller()->rotation_locked());
flackr 2014/05/05 20:53:56 Maybe also expect the rotation not to have been to
jonross 2014/05/06 15:07:54 Done.
431 }
432
419 } // namespace ash 433 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698