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

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

Issue 2020553003: Hook up TABLET_MODE switch to maximize_mode_controller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Hook up TABLET_MODE switch to maximize_mode_controller Created 4 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
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.cc ('k') | chromeos/dbus/power_manager_client.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 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 <math.h> 7 #include <math.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 DCHECK(degrees <= 360.0f); 134 DCHECK(degrees <= 360.0f);
135 135
136 float radians = degrees * kDegreesToRadians; 136 float radians = degrees * kDegreesToRadians;
137 gfx::Vector3dF base_vector(0.0f, -kMeanGravity, 0.0f); 137 gfx::Vector3dF base_vector(0.0f, -kMeanGravity, 0.0f);
138 gfx::Vector3dF lid_vector(0.0f, 138 gfx::Vector3dF lid_vector(0.0f,
139 kMeanGravity * cos(radians), 139 kMeanGravity * cos(radians),
140 kMeanGravity * sin(radians)); 140 kMeanGravity * sin(radians));
141 TriggerBaseAndLidUpdate(base_vector, lid_vector); 141 TriggerBaseAndLidUpdate(base_vector, lid_vector);
142 } 142 }
143 143
144 void HoldDeviceVertical() {
145 gfx::Vector3dF base_vector(9.8f, 0.0f, 0.0f);
146 gfx::Vector3dF lid_vector(9.8f, 0.0f, 0.0f);
147 TriggerBaseAndLidUpdate(base_vector, lid_vector);
148 }
149
144 void OpenLid() { 150 void OpenLid() {
145 maximize_mode_controller()->LidEventReceived(true /* open */, 151 maximize_mode_controller()->LidEventReceived(true /* open */,
146 maximize_mode_controller()->tick_clock_->NowTicks()); 152 maximize_mode_controller()->tick_clock_->NowTicks());
147 } 153 }
148 154
149 void CloseLid() { 155 void CloseLid() {
150 maximize_mode_controller()->LidEventReceived(false /* open */, 156 maximize_mode_controller()->LidEventReceived(false /* open */,
151 maximize_mode_controller()->tick_clock_->NowTicks()); 157 maximize_mode_controller()->tick_clock_->NowTicks());
152 } 158 }
153 159
154 bool WasLidOpenedRecently() { 160 bool WasLidOpenedRecently() {
155 return maximize_mode_controller()->WasLidOpenedRecently(); 161 return maximize_mode_controller()->WasLidOpenedRecently();
156 } 162 }
157 163
164 void SetTabletMode(bool on) {
165 maximize_mode_controller()->TabletModeEventReceived(
166 on, maximize_mode_controller()->tick_clock_->NowTicks());
167 }
168
158 bool AreEventsBlocked() { 169 bool AreEventsBlocked() {
159 return !!maximize_mode_controller()->event_blocker_.get(); 170 return !!maximize_mode_controller()->event_blocker_.get();
160 } 171 }
161 172
162 base::UserActionTester* user_action_tester() { return &user_action_tester_; } 173 base::UserActionTester* user_action_tester() { return &user_action_tester_; }
163 174
164 private: 175 private:
165 base::SimpleTestTickClock* test_tick_clock_; 176 base::SimpleTestTickClock* test_tick_clock_;
166 177
167 // Tracks user action counts. 178 // Tracks user action counts.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 270
260 // 1 second after lid open. 271 // 1 second after lid open.
261 AdvanceTickClock(base::TimeDelta::FromSeconds(1)); 272 AdvanceTickClock(base::TimeDelta::FromSeconds(1));
262 EXPECT_TRUE(WasLidOpenedRecently()); 273 EXPECT_TRUE(WasLidOpenedRecently());
263 274
264 // 3 seconds after lid open. 275 // 3 seconds after lid open.
265 AdvanceTickClock(base::TimeDelta::FromSeconds(2)); 276 AdvanceTickClock(base::TimeDelta::FromSeconds(2));
266 EXPECT_FALSE(WasLidOpenedRecently()); 277 EXPECT_FALSE(WasLidOpenedRecently());
267 } 278 }
268 279
280 TEST_F(MaximizeModeControllerTest, TabletModeTransition) {
281 OpenLidToAngle(90.0f);
282 EXPECT_FALSE(IsMaximizeModeStarted());
283
284 // Unstable reading. This should not trigger maximize mode.
285 HoldDeviceVertical();
286 EXPECT_FALSE(IsMaximizeModeStarted());
287
288 // When tablet mode switch is on it should force maximize mode even if the
289 // reading is not stable.
290 SetTabletMode(true);
291 EXPECT_TRUE(IsMaximizeModeStarted());
292
293 // After tablet mode switch is off it should stay in maximize mode if the
294 // reading is not stable.
295 SetTabletMode(false);
296 EXPECT_TRUE(IsMaximizeModeStarted());
297
298 // Should leave maximize mode when the lid angle is small enough.
299 OpenLidToAngle(90.0f);
300 EXPECT_FALSE(IsMaximizeModeStarted());
301
302 OpenLidToAngle(300.0f);
303 EXPECT_TRUE(IsMaximizeModeStarted());
304 }
305
269 // Verify the maximize mode enter/exit thresholds for stable angles. 306 // Verify the maximize mode enter/exit thresholds for stable angles.
270 TEST_F(MaximizeModeControllerTest, StableHingeAnglesWithLidOpened) { 307 TEST_F(MaximizeModeControllerTest, StableHingeAnglesWithLidOpened) {
271 ASSERT_FALSE(IsMaximizeModeStarted()); 308 ASSERT_FALSE(IsMaximizeModeStarted());
272 ASSERT_FALSE(WasLidOpenedRecently()); 309 ASSERT_FALSE(WasLidOpenedRecently());
273 310
274 OpenLidToAngle(180.0f); 311 OpenLidToAngle(180.0f);
275 EXPECT_FALSE(IsMaximizeModeStarted()); 312 EXPECT_FALSE(IsMaximizeModeStarted());
276 313
277 OpenLidToAngle(315.0f); 314 OpenLidToAngle(315.0f);
278 EXPECT_TRUE(IsMaximizeModeStarted()); 315 EXPECT_TRUE(IsMaximizeModeStarted());
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 // accelerometer updates which would normally cause it to exit do not. 529 // accelerometer updates which would normally cause it to exit do not.
493 TEST_F(MaximizeModeControllerSwitchesTest, IgnoreHingeAngles) { 530 TEST_F(MaximizeModeControllerSwitchesTest, IgnoreHingeAngles) {
494 maximize_mode_controller()->EnableMaximizeModeWindowManager(true); 531 maximize_mode_controller()->EnableMaximizeModeWindowManager(true);
495 532
496 // Would normally trigger an exit from maximize mode. 533 // Would normally trigger an exit from maximize mode.
497 OpenLidToAngle(90.0f); 534 OpenLidToAngle(90.0f);
498 EXPECT_TRUE(IsMaximizeModeStarted()); 535 EXPECT_TRUE(IsMaximizeModeStarted());
499 } 536 }
500 537
501 } // namespace ash 538 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.cc ('k') | chromeos/dbus/power_manager_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698