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

Side by Side Diff: ash/wm/tablet_mode/tablet_mode_controller_unittest.cc

Issue 2906803002: Rename MaximizeMode to TabletMode (Closed)
Patch Set: updated filter Created 3 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
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/tablet_mode/tablet_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
11 #include "ash/ash_switches.h" 11 #include "ash/ash_switches.h"
12 #include "ash/display/screen_orientation_controller_chromeos.h" 12 #include "ash/display/screen_orientation_controller_chromeos.h"
13 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "ash/system/tray/system_tray_delegate.h" 14 #include "ash/system/tray/system_tray_delegate.h"
15 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 // Test accelerometer data taken with the lid open 360 degrees while the device 65 // Test accelerometer data taken with the lid open 360 degrees while the device
66 // hinge was nearly vertical, while shaking the device around. The data is to be 66 // hinge was nearly vertical, while shaking the device around. The data is to be
67 // interpreted in groups of 6 where each 6 values corresponds to the X, Y, and Z 67 // interpreted in groups of 6 where each 6 values corresponds to the X, Y, and Z
68 // readings from the base and lid accelerometers in this order. 68 // readings from the base and lid accelerometers in this order.
69 extern const float kAccelerometerVerticalHingeTestData[]; 69 extern const float kAccelerometerVerticalHingeTestData[];
70 extern const size_t kAccelerometerVerticalHingeTestDataLength; 70 extern const size_t kAccelerometerVerticalHingeTestDataLength;
71 extern const float kAccelerometerVerticalHingeUnstableAnglesTestData[]; 71 extern const float kAccelerometerVerticalHingeUnstableAnglesTestData[];
72 extern const size_t kAccelerometerVerticalHingeUnstableAnglesTestDataLength; 72 extern const size_t kAccelerometerVerticalHingeUnstableAnglesTestDataLength;
73 73
74 class MaximizeModeControllerTest : public test::AshTestBase { 74 class TabletModeControllerTest : public test::AshTestBase {
75 public: 75 public:
76 MaximizeModeControllerTest() {} 76 TabletModeControllerTest() {}
77 ~MaximizeModeControllerTest() override {} 77 ~TabletModeControllerTest() override {}
78 78
79 void SetUp() override { 79 void SetUp() override {
80 base::CommandLine::ForCurrentProcess()->AppendSwitch( 80 base::CommandLine::ForCurrentProcess()->AppendSwitch(
81 switches::kAshEnableTouchView); 81 switches::kAshEnableTouchView);
82 test::AshTestBase::SetUp(); 82 test::AshTestBase::SetUp();
83 chromeos::AccelerometerReader::GetInstance()->RemoveObserver( 83 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(
84 maximize_mode_controller()); 84 tablet_mode_controller());
85 85
86 // Set the first display to be the internal display for the accelerometer 86 // Set the first display to be the internal display for the accelerometer
87 // screen rotation tests. 87 // screen rotation tests.
88 display::test::DisplayManagerTestApi(Shell::Get()->display_manager()) 88 display::test::DisplayManagerTestApi(Shell::Get()->display_manager())
89 .SetFirstDisplayAsInternalDisplay(); 89 .SetFirstDisplayAsInternalDisplay();
90 } 90 }
91 91
92 void TearDown() override { 92 void TearDown() override {
93 chromeos::AccelerometerReader::GetInstance()->AddObserver( 93 chromeos::AccelerometerReader::GetInstance()->AddObserver(
94 maximize_mode_controller()); 94 tablet_mode_controller());
95 test::AshTestBase::TearDown(); 95 test::AshTestBase::TearDown();
96 } 96 }
97 97
98 MaximizeModeController* maximize_mode_controller() { 98 TabletModeController* tablet_mode_controller() {
99 return Shell::Get()->maximize_mode_controller(); 99 return Shell::Get()->tablet_mode_controller();
100 } 100 }
101 101
102 void TriggerLidUpdate(const gfx::Vector3dF& lid) { 102 void TriggerLidUpdate(const gfx::Vector3dF& lid) {
103 scoped_refptr<chromeos::AccelerometerUpdate> update( 103 scoped_refptr<chromeos::AccelerometerUpdate> update(
104 new chromeos::AccelerometerUpdate()); 104 new chromeos::AccelerometerUpdate());
105 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(), 105 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(),
106 lid.z()); 106 lid.z());
107 maximize_mode_controller()->OnAccelerometerUpdated(update); 107 tablet_mode_controller()->OnAccelerometerUpdated(update);
108 } 108 }
109 109
110 void TriggerBaseAndLidUpdate(const gfx::Vector3dF& base, 110 void TriggerBaseAndLidUpdate(const gfx::Vector3dF& base,
111 const gfx::Vector3dF& lid) { 111 const gfx::Vector3dF& lid) {
112 scoped_refptr<chromeos::AccelerometerUpdate> update( 112 scoped_refptr<chromeos::AccelerometerUpdate> update(
113 new chromeos::AccelerometerUpdate()); 113 new chromeos::AccelerometerUpdate());
114 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, base.x(), 114 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, base.x(),
115 base.y(), base.z()); 115 base.y(), base.z());
116 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(), 116 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(),
117 lid.z()); 117 lid.z());
118 maximize_mode_controller()->OnAccelerometerUpdated(update); 118 tablet_mode_controller()->OnAccelerometerUpdated(update);
119 } 119 }
120 120
121 bool IsMaximizeModeStarted() { 121 bool IsTabletModeStarted() {
122 return maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled(); 122 return tablet_mode_controller()->IsTabletModeWindowManagerEnabled();
123 } 123 }
124 124
125 // Attaches a SimpleTestTickClock to the MaximizeModeController with a non 125 // Attaches a SimpleTestTickClock to the TabletModeController with a non
126 // null value initial value. 126 // null value initial value.
127 void AttachTickClockForTest() { 127 void AttachTickClockForTest() {
128 std::unique_ptr<base::TickClock> tick_clock( 128 std::unique_ptr<base::TickClock> tick_clock(
129 test_tick_clock_ = new base::SimpleTestTickClock()); 129 test_tick_clock_ = new base::SimpleTestTickClock());
130 test_tick_clock_->Advance(base::TimeDelta::FromSeconds(1)); 130 test_tick_clock_->Advance(base::TimeDelta::FromSeconds(1));
131 maximize_mode_controller()->SetTickClockForTest(std::move(tick_clock)); 131 tablet_mode_controller()->SetTickClockForTest(std::move(tick_clock));
132 } 132 }
133 133
134 void AdvanceTickClock(const base::TimeDelta& delta) { 134 void AdvanceTickClock(const base::TimeDelta& delta) {
135 DCHECK(test_tick_clock_); 135 DCHECK(test_tick_clock_);
136 test_tick_clock_->Advance(delta); 136 test_tick_clock_->Advance(delta);
137 } 137 }
138 138
139 void OpenLidToAngle(float degrees) { 139 void OpenLidToAngle(float degrees) {
140 DCHECK(degrees >= 0.0f); 140 DCHECK(degrees >= 0.0f);
141 DCHECK(degrees <= 360.0f); 141 DCHECK(degrees <= 360.0f);
142 142
143 float radians = degrees * kDegreesToRadians; 143 float radians = degrees * kDegreesToRadians;
144 gfx::Vector3dF base_vector(0.0f, -kMeanGravity, 0.0f); 144 gfx::Vector3dF base_vector(0.0f, -kMeanGravity, 0.0f);
145 gfx::Vector3dF lid_vector(0.0f, kMeanGravity * cos(radians), 145 gfx::Vector3dF lid_vector(0.0f, kMeanGravity * cos(radians),
146 kMeanGravity * sin(radians)); 146 kMeanGravity * sin(radians));
147 TriggerBaseAndLidUpdate(base_vector, lid_vector); 147 TriggerBaseAndLidUpdate(base_vector, lid_vector);
148 } 148 }
149 149
150 void HoldDeviceVertical() { 150 void HoldDeviceVertical() {
151 gfx::Vector3dF base_vector(9.8f, 0.0f, 0.0f); 151 gfx::Vector3dF base_vector(9.8f, 0.0f, 0.0f);
152 gfx::Vector3dF lid_vector(9.8f, 0.0f, 0.0f); 152 gfx::Vector3dF lid_vector(9.8f, 0.0f, 0.0f);
153 TriggerBaseAndLidUpdate(base_vector, lid_vector); 153 TriggerBaseAndLidUpdate(base_vector, lid_vector);
154 } 154 }
155 155
156 void OpenLid() { 156 void OpenLid() {
157 maximize_mode_controller()->LidEventReceived( 157 tablet_mode_controller()->LidEventReceived(
158 chromeos::PowerManagerClient::LidState::OPEN, 158 chromeos::PowerManagerClient::LidState::OPEN,
159 maximize_mode_controller()->tick_clock_->NowTicks()); 159 tablet_mode_controller()->tick_clock_->NowTicks());
160 } 160 }
161 161
162 void CloseLid() { 162 void CloseLid() {
163 maximize_mode_controller()->LidEventReceived( 163 tablet_mode_controller()->LidEventReceived(
164 chromeos::PowerManagerClient::LidState::CLOSED, 164 chromeos::PowerManagerClient::LidState::CLOSED,
165 maximize_mode_controller()->tick_clock_->NowTicks()); 165 tablet_mode_controller()->tick_clock_->NowTicks());
166 } 166 }
167 167
168 bool WasLidOpenedRecently() { 168 bool WasLidOpenedRecently() {
169 return maximize_mode_controller()->WasLidOpenedRecently(); 169 return tablet_mode_controller()->WasLidOpenedRecently();
170 } 170 }
171 171
172 void SetTabletMode(bool on) { 172 void SetTabletMode(bool on) {
173 maximize_mode_controller()->TabletModeEventReceived( 173 tablet_mode_controller()->TabletModeEventReceived(
174 on ? chromeos::PowerManagerClient::TabletMode::ON 174 on ? chromeos::PowerManagerClient::TabletMode::ON
175 : chromeos::PowerManagerClient::TabletMode::OFF, 175 : chromeos::PowerManagerClient::TabletMode::OFF,
176 maximize_mode_controller()->tick_clock_->NowTicks()); 176 tablet_mode_controller()->tick_clock_->NowTicks());
177 } 177 }
178 178
179 bool AreEventsBlocked() { 179 bool AreEventsBlocked() {
180 return !!maximize_mode_controller()->event_blocker_.get(); 180 return !!tablet_mode_controller()->event_blocker_.get();
181 } 181 }
182 182
183 MaximizeModeController::ForceTabletMode forced_tablet_mode() { 183 TabletModeController::ForceTabletMode forced_tablet_mode() {
184 return maximize_mode_controller()->force_tablet_mode_; 184 return tablet_mode_controller()->force_tablet_mode_;
185 } 185 }
186 186
187 base::UserActionTester* user_action_tester() { return &user_action_tester_; } 187 base::UserActionTester* user_action_tester() { return &user_action_tester_; }
188 188
189 private: 189 private:
190 base::SimpleTestTickClock* test_tick_clock_; 190 base::SimpleTestTickClock* test_tick_clock_;
191 191
192 // Tracks user action counts. 192 // Tracks user action counts.
193 base::UserActionTester user_action_tester_; 193 base::UserActionTester user_action_tester_;
194 194
195 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest); 195 DISALLOW_COPY_AND_ASSIGN(TabletModeControllerTest);
196 }; 196 };
197 197
198 // Verify TouchView enabled/disabled user action metrics are recorded. 198 // Verify TouchView enabled/disabled user action metrics are recorded.
199 TEST_F(MaximizeModeControllerTest, VerifyTouchViewEnabledDisabledCounts) { 199 TEST_F(TabletModeControllerTest, VerifyTouchViewEnabledDisabledCounts) {
200 ASSERT_EQ(1, 200 ASSERT_EQ(1,
201 user_action_tester()->GetActionCount(kTouchViewInitiallyDisabled)); 201 user_action_tester()->GetActionCount(kTouchViewInitiallyDisabled));
202 ASSERT_EQ(0, user_action_tester()->GetActionCount(kTouchViewEnabled)); 202 ASSERT_EQ(0, user_action_tester()->GetActionCount(kTouchViewEnabled));
203 ASSERT_EQ(0, user_action_tester()->GetActionCount(kTouchViewDisabled)); 203 ASSERT_EQ(0, user_action_tester()->GetActionCount(kTouchViewDisabled));
204 204
205 user_action_tester()->ResetCounts(); 205 user_action_tester()->ResetCounts();
206 maximize_mode_controller()->EnableMaximizeModeWindowManager(true); 206 tablet_mode_controller()->EnableTabletModeWindowManager(true);
207 EXPECT_EQ(1, user_action_tester()->GetActionCount(kTouchViewEnabled)); 207 EXPECT_EQ(1, user_action_tester()->GetActionCount(kTouchViewEnabled));
208 EXPECT_EQ(0, user_action_tester()->GetActionCount(kTouchViewDisabled)); 208 EXPECT_EQ(0, user_action_tester()->GetActionCount(kTouchViewDisabled));
209 maximize_mode_controller()->EnableMaximizeModeWindowManager(true); 209 tablet_mode_controller()->EnableTabletModeWindowManager(true);
210 EXPECT_EQ(1, user_action_tester()->GetActionCount(kTouchViewEnabled)); 210 EXPECT_EQ(1, user_action_tester()->GetActionCount(kTouchViewEnabled));
211 EXPECT_EQ(0, user_action_tester()->GetActionCount(kTouchViewDisabled)); 211 EXPECT_EQ(0, user_action_tester()->GetActionCount(kTouchViewDisabled));
212 212
213 user_action_tester()->ResetCounts(); 213 user_action_tester()->ResetCounts();
214 maximize_mode_controller()->EnableMaximizeModeWindowManager(false); 214 tablet_mode_controller()->EnableTabletModeWindowManager(false);
215 EXPECT_EQ(0, user_action_tester()->GetActionCount(kTouchViewEnabled)); 215 EXPECT_EQ(0, user_action_tester()->GetActionCount(kTouchViewEnabled));
216 EXPECT_EQ(1, user_action_tester()->GetActionCount(kTouchViewDisabled)); 216 EXPECT_EQ(1, user_action_tester()->GetActionCount(kTouchViewDisabled));
217 maximize_mode_controller()->EnableMaximizeModeWindowManager(false); 217 tablet_mode_controller()->EnableTabletModeWindowManager(false);
218 EXPECT_EQ(0, user_action_tester()->GetActionCount(kTouchViewEnabled)); 218 EXPECT_EQ(0, user_action_tester()->GetActionCount(kTouchViewEnabled));
219 EXPECT_EQ(1, user_action_tester()->GetActionCount(kTouchViewDisabled)); 219 EXPECT_EQ(1, user_action_tester()->GetActionCount(kTouchViewDisabled));
220 } 220 }
221 221
222 // Verify that closing the lid will exit maximize mode. 222 // Verify that closing the lid will exit tablet mode.
223 TEST_F(MaximizeModeControllerTest, CloseLidWhileInMaximizeMode) { 223 TEST_F(TabletModeControllerTest, CloseLidWhileInTabletMode) {
224 OpenLidToAngle(315.0f); 224 OpenLidToAngle(315.0f);
225 ASSERT_TRUE(IsMaximizeModeStarted()); 225 ASSERT_TRUE(IsTabletModeStarted());
226 226
227 CloseLid(); 227 CloseLid();
228 EXPECT_FALSE(IsMaximizeModeStarted()); 228 EXPECT_FALSE(IsTabletModeStarted());
229 } 229 }
230 230
231 // Verify that maximize mode will not be entered when the lid is closed. 231 // Verify that tablet mode will not be entered when the lid is closed.
232 TEST_F(MaximizeModeControllerTest, HingeAnglesWithLidClosed) { 232 TEST_F(TabletModeControllerTest, HingeAnglesWithLidClosed) {
233 AttachTickClockForTest(); 233 AttachTickClockForTest();
234 234
235 CloseLid(); 235 CloseLid();
236 236
237 OpenLidToAngle(270.0f); 237 OpenLidToAngle(270.0f);
238 EXPECT_FALSE(IsMaximizeModeStarted()); 238 EXPECT_FALSE(IsTabletModeStarted());
239 239
240 OpenLidToAngle(315.0f); 240 OpenLidToAngle(315.0f);
241 EXPECT_FALSE(IsMaximizeModeStarted()); 241 EXPECT_FALSE(IsTabletModeStarted());
242 242
243 OpenLidToAngle(355.0f); 243 OpenLidToAngle(355.0f);
244 EXPECT_FALSE(IsMaximizeModeStarted()); 244 EXPECT_FALSE(IsTabletModeStarted());
245 } 245 }
246 246
247 // Verify the maximize mode state for unstable hinge angles when the lid was 247 // Verify the tablet mode state for unstable hinge angles when the lid was
248 // recently open. 248 // recently open.
249 TEST_F(MaximizeModeControllerTest, UnstableHingeAnglesWhenLidRecentlyOpened) { 249 TEST_F(TabletModeControllerTest, UnstableHingeAnglesWhenLidRecentlyOpened) {
250 AttachTickClockForTest(); 250 AttachTickClockForTest();
251 251
252 OpenLid(); 252 OpenLid();
253 ASSERT_TRUE(WasLidOpenedRecently()); 253 ASSERT_TRUE(WasLidOpenedRecently());
254 254
255 OpenLidToAngle(5.0f); 255 OpenLidToAngle(5.0f);
256 EXPECT_FALSE(IsMaximizeModeStarted()); 256 EXPECT_FALSE(IsTabletModeStarted());
257 257
258 OpenLidToAngle(355.0f); 258 OpenLidToAngle(355.0f);
259 EXPECT_FALSE(IsMaximizeModeStarted()); 259 EXPECT_FALSE(IsTabletModeStarted());
260 260
261 // This is a stable reading and should clear the last lid opened time. 261 // This is a stable reading and should clear the last lid opened time.
262 OpenLidToAngle(45.0f); 262 OpenLidToAngle(45.0f);
263 EXPECT_FALSE(IsMaximizeModeStarted()); 263 EXPECT_FALSE(IsTabletModeStarted());
264 EXPECT_FALSE(WasLidOpenedRecently()); 264 EXPECT_FALSE(WasLidOpenedRecently());
265 265
266 OpenLidToAngle(355.0f); 266 OpenLidToAngle(355.0f);
267 EXPECT_TRUE(IsMaximizeModeStarted()); 267 EXPECT_TRUE(IsTabletModeStarted());
268 } 268 }
269 269
270 // Verify the WasLidOpenedRecently signal with respect to time. 270 // Verify the WasLidOpenedRecently signal with respect to time.
271 TEST_F(MaximizeModeControllerTest, WasLidOpenedRecentlyOverTime) { 271 TEST_F(TabletModeControllerTest, WasLidOpenedRecentlyOverTime) {
272 AttachTickClockForTest(); 272 AttachTickClockForTest();
273 273
274 // No lid open time initially. 274 // No lid open time initially.
275 ASSERT_FALSE(WasLidOpenedRecently()); 275 ASSERT_FALSE(WasLidOpenedRecently());
276 276
277 CloseLid(); 277 CloseLid();
278 EXPECT_FALSE(WasLidOpenedRecently()); 278 EXPECT_FALSE(WasLidOpenedRecently());
279 279
280 OpenLid(); 280 OpenLid();
281 EXPECT_TRUE(WasLidOpenedRecently()); 281 EXPECT_TRUE(WasLidOpenedRecently());
282 282
283 // 1 second after lid open. 283 // 1 second after lid open.
284 AdvanceTickClock(base::TimeDelta::FromSeconds(1)); 284 AdvanceTickClock(base::TimeDelta::FromSeconds(1));
285 EXPECT_TRUE(WasLidOpenedRecently()); 285 EXPECT_TRUE(WasLidOpenedRecently());
286 286
287 // 3 seconds after lid open. 287 // 3 seconds after lid open.
288 AdvanceTickClock(base::TimeDelta::FromSeconds(2)); 288 AdvanceTickClock(base::TimeDelta::FromSeconds(2));
289 EXPECT_FALSE(WasLidOpenedRecently()); 289 EXPECT_FALSE(WasLidOpenedRecently());
290 } 290 }
291 291
292 TEST_F(MaximizeModeControllerTest, TabletModeTransition) { 292 TEST_F(TabletModeControllerTest, TabletModeTransition) {
293 OpenLidToAngle(90.0f); 293 OpenLidToAngle(90.0f);
294 EXPECT_FALSE(IsMaximizeModeStarted()); 294 EXPECT_FALSE(IsTabletModeStarted());
295 295
296 // Unstable reading. This should not trigger maximize mode. 296 // Unstable reading. This should not trigger tablet mode.
297 HoldDeviceVertical(); 297 HoldDeviceVertical();
298 EXPECT_FALSE(IsMaximizeModeStarted()); 298 EXPECT_FALSE(IsTabletModeStarted());
299 299
300 // When tablet mode switch is on it should force maximize mode even if the 300 // When tablet mode switch is on it should force tablet mode even if the
301 // reading is not stable. 301 // reading is not stable.
302 SetTabletMode(true); 302 SetTabletMode(true);
303 EXPECT_TRUE(IsMaximizeModeStarted()); 303 EXPECT_TRUE(IsTabletModeStarted());
304 304
305 // After tablet mode switch is off it should stay in maximize mode if the 305 // After tablet mode switch is off it should stay in tablet mode if the
306 // reading is not stable. 306 // reading is not stable.
307 SetTabletMode(false); 307 SetTabletMode(false);
308 EXPECT_TRUE(IsMaximizeModeStarted()); 308 EXPECT_TRUE(IsTabletModeStarted());
309 309
310 // Should leave maximize mode when the lid angle is small enough. 310 // Should leave tablet mode when the lid angle is small enough.
311 OpenLidToAngle(90.0f); 311 OpenLidToAngle(90.0f);
312 EXPECT_FALSE(IsMaximizeModeStarted()); 312 EXPECT_FALSE(IsTabletModeStarted());
313 313
314 OpenLidToAngle(300.0f); 314 OpenLidToAngle(300.0f);
315 EXPECT_TRUE(IsMaximizeModeStarted()); 315 EXPECT_TRUE(IsTabletModeStarted());
316 } 316 }
317 317
318 // When there is no keyboard accelerometer available maximize mode should solely 318 // When there is no keyboard accelerometer available tablet mode should solely
319 // rely on the tablet mode switch. 319 // rely on the tablet mode switch.
320 TEST_F(MaximizeModeControllerTest, 320 TEST_F(TabletModeControllerTest, TabletModeTransitionNoKeyboardAccelerometer) {
321 TabletModeTransitionNoKeyboardAccelerometer) { 321 ASSERT_FALSE(IsTabletModeStarted());
322 ASSERT_FALSE(IsMaximizeModeStarted());
323 TriggerLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity)); 322 TriggerLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity));
324 ASSERT_FALSE(IsMaximizeModeStarted()); 323 ASSERT_FALSE(IsTabletModeStarted());
325 324
326 SetTabletMode(true); 325 SetTabletMode(true);
327 EXPECT_TRUE(IsMaximizeModeStarted()); 326 EXPECT_TRUE(IsTabletModeStarted());
328 327
329 // Single sensor reading should not change mode. 328 // Single sensor reading should not change mode.
330 TriggerLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity)); 329 TriggerLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity));
331 EXPECT_TRUE(IsMaximizeModeStarted()); 330 EXPECT_TRUE(IsTabletModeStarted());
332 331
333 // With a single sensor we should exit immediately on the tablet mode switch 332 // With a single sensor we should exit immediately on the tablet mode switch
334 // rather than waiting for stabilized accelerometer readings. 333 // rather than waiting for stabilized accelerometer readings.
335 SetTabletMode(false); 334 SetTabletMode(false);
336 EXPECT_FALSE(IsMaximizeModeStarted()); 335 EXPECT_FALSE(IsTabletModeStarted());
337 } 336 }
338 337
339 // Verify the maximize mode enter/exit thresholds for stable angles. 338 // Verify the tablet mode enter/exit thresholds for stable angles.
340 TEST_F(MaximizeModeControllerTest, StableHingeAnglesWithLidOpened) { 339 TEST_F(TabletModeControllerTest, StableHingeAnglesWithLidOpened) {
341 ASSERT_FALSE(IsMaximizeModeStarted()); 340 ASSERT_FALSE(IsTabletModeStarted());
342 ASSERT_FALSE(WasLidOpenedRecently()); 341 ASSERT_FALSE(WasLidOpenedRecently());
343 342
344 OpenLidToAngle(180.0f); 343 OpenLidToAngle(180.0f);
345 EXPECT_FALSE(IsMaximizeModeStarted()); 344 EXPECT_FALSE(IsTabletModeStarted());
346 345
347 OpenLidToAngle(315.0f); 346 OpenLidToAngle(315.0f);
348 EXPECT_TRUE(IsMaximizeModeStarted()); 347 EXPECT_TRUE(IsTabletModeStarted());
349 348
350 OpenLidToAngle(180.0f); 349 OpenLidToAngle(180.0f);
351 EXPECT_TRUE(IsMaximizeModeStarted()); 350 EXPECT_TRUE(IsTabletModeStarted());
352 351
353 OpenLidToAngle(45.0f); 352 OpenLidToAngle(45.0f);
354 EXPECT_FALSE(IsMaximizeModeStarted()); 353 EXPECT_FALSE(IsTabletModeStarted());
355 354
356 OpenLidToAngle(270.0f); 355 OpenLidToAngle(270.0f);
357 EXPECT_TRUE(IsMaximizeModeStarted()); 356 EXPECT_TRUE(IsTabletModeStarted());
358 357
359 OpenLidToAngle(90.0f); 358 OpenLidToAngle(90.0f);
360 EXPECT_FALSE(IsMaximizeModeStarted()); 359 EXPECT_FALSE(IsTabletModeStarted());
361 } 360 }
362 361
363 // Verify the maximize mode state for unstable hinge angles when the lid is open 362 // Verify the tablet mode state for unstable hinge angles when the lid is open
364 // but not recently. 363 // but not recently.
365 TEST_F(MaximizeModeControllerTest, UnstableHingeAnglesWithLidOpened) { 364 TEST_F(TabletModeControllerTest, UnstableHingeAnglesWithLidOpened) {
366 AttachTickClockForTest(); 365 AttachTickClockForTest();
367 366
368 ASSERT_FALSE(WasLidOpenedRecently()); 367 ASSERT_FALSE(WasLidOpenedRecently());
369 ASSERT_FALSE(IsMaximizeModeStarted()); 368 ASSERT_FALSE(IsTabletModeStarted());
370 369
371 OpenLidToAngle(5.0f); 370 OpenLidToAngle(5.0f);
372 EXPECT_FALSE(IsMaximizeModeStarted()); 371 EXPECT_FALSE(IsTabletModeStarted());
373 372
374 OpenLidToAngle(355.0f); 373 OpenLidToAngle(355.0f);
375 EXPECT_TRUE(IsMaximizeModeStarted()); 374 EXPECT_TRUE(IsTabletModeStarted());
376 375
377 OpenLidToAngle(5.0f); 376 OpenLidToAngle(5.0f);
378 EXPECT_TRUE(IsMaximizeModeStarted()); 377 EXPECT_TRUE(IsTabletModeStarted());
379 } 378 }
380 379
381 // Tests that when the hinge is nearly vertically aligned, the current state 380 // Tests that when the hinge is nearly vertically aligned, the current state
382 // persists as the computed angle is highly inaccurate in this orientation. 381 // persists as the computed angle is highly inaccurate in this orientation.
383 TEST_F(MaximizeModeControllerTest, HingeAligned) { 382 TEST_F(TabletModeControllerTest, HingeAligned) {
384 // Laptop in normal orientation lid open 90 degrees. 383 // Laptop in normal orientation lid open 90 degrees.
385 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, -kMeanGravity), 384 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, -kMeanGravity),
386 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 385 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
387 EXPECT_FALSE(IsMaximizeModeStarted()); 386 EXPECT_FALSE(IsTabletModeStarted());
388 387
389 // Completely vertical. 388 // Completely vertical.
390 TriggerBaseAndLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f), 389 TriggerBaseAndLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f),
391 gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 390 gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
392 EXPECT_FALSE(IsMaximizeModeStarted()); 391 EXPECT_FALSE(IsTabletModeStarted());
393 392
394 // Close to vertical but with hinge appearing to be open 270 degrees. 393 // Close to vertical but with hinge appearing to be open 270 degrees.
395 TriggerBaseAndLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, -0.1f), 394 TriggerBaseAndLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, -0.1f),
396 gfx::Vector3dF(kMeanGravity, 0.1f, 0.0f)); 395 gfx::Vector3dF(kMeanGravity, 0.1f, 0.0f));
397 EXPECT_FALSE(IsMaximizeModeStarted()); 396 EXPECT_FALSE(IsTabletModeStarted());
398 397
399 // Flat and open 270 degrees should start maximize mode. 398 // Flat and open 270 degrees should start tablet mode.
400 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, -kMeanGravity), 399 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, -kMeanGravity),
401 gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 400 gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
402 EXPECT_TRUE(IsMaximizeModeStarted()); 401 EXPECT_TRUE(IsTabletModeStarted());
403 402
404 // Normal 90 degree orientation but near vertical should stay in maximize 403 // Normal 90 degree orientation but near vertical should stay in maximize
405 // mode. 404 // mode.
406 TriggerBaseAndLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, -0.1f), 405 TriggerBaseAndLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, -0.1f),
407 gfx::Vector3dF(kMeanGravity, -0.1f, 0.0f)); 406 gfx::Vector3dF(kMeanGravity, -0.1f, 0.0f));
408 EXPECT_TRUE(IsMaximizeModeStarted()); 407 EXPECT_TRUE(IsTabletModeStarted());
409 } 408 }
410 409
411 TEST_F(MaximizeModeControllerTest, LaptopTest) { 410 TEST_F(TabletModeControllerTest, LaptopTest) {
412 // Feeds in sample accelerometer data and verifies that there are no 411 // Feeds in sample accelerometer data and verifies that there are no
413 // transitions into touchview / maximize mode while shaking the device around 412 // transitions into touchview / tablet mode while shaking the device around
414 // with the hinge at less than 180 degrees. Note the conversion from device 413 // with the hinge at less than 180 degrees. Note the conversion from device
415 // data to accelerometer updates consistent with accelerometer_reader.cc. 414 // data to accelerometer updates consistent with accelerometer_reader.cc.
416 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6); 415 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6);
417 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) { 416 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) {
418 gfx::Vector3dF base(-kAccelerometerLaptopModeTestData[i * 6 + 1], 417 gfx::Vector3dF base(-kAccelerometerLaptopModeTestData[i * 6 + 1],
419 -kAccelerometerLaptopModeTestData[i * 6], 418 -kAccelerometerLaptopModeTestData[i * 6],
420 -kAccelerometerLaptopModeTestData[i * 6 + 2]); 419 -kAccelerometerLaptopModeTestData[i * 6 + 2]);
421 base.Scale(kMeanGravity); 420 base.Scale(kMeanGravity);
422 gfx::Vector3dF lid(-kAccelerometerLaptopModeTestData[i * 6 + 4], 421 gfx::Vector3dF lid(-kAccelerometerLaptopModeTestData[i * 6 + 4],
423 kAccelerometerLaptopModeTestData[i * 6 + 3], 422 kAccelerometerLaptopModeTestData[i * 6 + 3],
424 kAccelerometerLaptopModeTestData[i * 6 + 5]); 423 kAccelerometerLaptopModeTestData[i * 6 + 5]);
425 lid.Scale(kMeanGravity); 424 lid.Scale(kMeanGravity);
426 TriggerBaseAndLidUpdate(base, lid); 425 TriggerBaseAndLidUpdate(base, lid);
427 // There are a lot of samples, so ASSERT rather than EXPECT to only generate 426 // There are a lot of samples, so ASSERT rather than EXPECT to only generate
428 // one failure rather than potentially hundreds. 427 // one failure rather than potentially hundreds.
429 ASSERT_FALSE(IsMaximizeModeStarted()); 428 ASSERT_FALSE(IsTabletModeStarted());
430 } 429 }
431 } 430 }
432 431
433 TEST_F(MaximizeModeControllerTest, MaximizeModeTest) { 432 TEST_F(TabletModeControllerTest, TabletModeTest) {
434 // Trigger maximize mode by opening to 270 to begin the test in maximize mode. 433 // Trigger tablet mode by opening to 270 to begin the test in tablet mode.
435 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), 434 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
436 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 435 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
437 ASSERT_TRUE(IsMaximizeModeStarted()); 436 ASSERT_TRUE(IsTabletModeStarted());
438 437
439 // Feeds in sample accelerometer data and verifies that there are no 438 // Feeds in sample accelerometer data and verifies that there are no
440 // transitions out of touchview / maximize mode while shaking the device 439 // transitions out of touchview / tablet mode while shaking the device
441 // around. Note the conversion from device data to accelerometer updates 440 // around. Note the conversion from device data to accelerometer updates
442 // consistent with accelerometer_reader.cc. 441 // consistent with accelerometer_reader.cc.
443 ASSERT_EQ(0u, kAccelerometerFullyOpenTestDataLength % 6); 442 ASSERT_EQ(0u, kAccelerometerFullyOpenTestDataLength % 6);
444 for (size_t i = 0; i < kAccelerometerFullyOpenTestDataLength / 6; ++i) { 443 for (size_t i = 0; i < kAccelerometerFullyOpenTestDataLength / 6; ++i) {
445 gfx::Vector3dF base(-kAccelerometerFullyOpenTestData[i * 6 + 1], 444 gfx::Vector3dF base(-kAccelerometerFullyOpenTestData[i * 6 + 1],
446 -kAccelerometerFullyOpenTestData[i * 6], 445 -kAccelerometerFullyOpenTestData[i * 6],
447 -kAccelerometerFullyOpenTestData[i * 6 + 2]); 446 -kAccelerometerFullyOpenTestData[i * 6 + 2]);
448 base.Scale(kMeanGravity); 447 base.Scale(kMeanGravity);
449 gfx::Vector3dF lid(-kAccelerometerFullyOpenTestData[i * 6 + 4], 448 gfx::Vector3dF lid(-kAccelerometerFullyOpenTestData[i * 6 + 4],
450 kAccelerometerFullyOpenTestData[i * 6 + 3], 449 kAccelerometerFullyOpenTestData[i * 6 + 3],
451 kAccelerometerFullyOpenTestData[i * 6 + 5]); 450 kAccelerometerFullyOpenTestData[i * 6 + 5]);
452 lid.Scale(kMeanGravity); 451 lid.Scale(kMeanGravity);
453 TriggerBaseAndLidUpdate(base, lid); 452 TriggerBaseAndLidUpdate(base, lid);
454 // There are a lot of samples, so ASSERT rather than EXPECT to only generate 453 // There are a lot of samples, so ASSERT rather than EXPECT to only generate
455 // one failure rather than potentially hundreds. 454 // one failure rather than potentially hundreds.
456 ASSERT_TRUE(IsMaximizeModeStarted()); 455 ASSERT_TRUE(IsTabletModeStarted());
457 } 456 }
458 } 457 }
459 458
460 TEST_F(MaximizeModeControllerTest, VerticalHingeTest) { 459 TEST_F(TabletModeControllerTest, VerticalHingeTest) {
461 // Feeds in sample accelerometer data and verifies that there are no 460 // Feeds in sample accelerometer data and verifies that there are no
462 // transitions out of touchview / maximize mode while shaking the device 461 // transitions out of touchview / tablet mode while shaking the device
463 // around, while the hinge is nearly vertical. The data was captured from 462 // around, while the hinge is nearly vertical. The data was captured from
464 // maxmimize_mode_controller.cc and does not require conversion. 463 // maxmimize_mode_controller.cc and does not require conversion.
465 ASSERT_EQ(0u, kAccelerometerVerticalHingeTestDataLength % 6); 464 ASSERT_EQ(0u, kAccelerometerVerticalHingeTestDataLength % 6);
466 for (size_t i = 0; i < kAccelerometerVerticalHingeTestDataLength / 6; ++i) { 465 for (size_t i = 0; i < kAccelerometerVerticalHingeTestDataLength / 6; ++i) {
467 gfx::Vector3dF base(kAccelerometerVerticalHingeTestData[i * 6], 466 gfx::Vector3dF base(kAccelerometerVerticalHingeTestData[i * 6],
468 kAccelerometerVerticalHingeTestData[i * 6 + 1], 467 kAccelerometerVerticalHingeTestData[i * 6 + 1],
469 kAccelerometerVerticalHingeTestData[i * 6 + 2]); 468 kAccelerometerVerticalHingeTestData[i * 6 + 2]);
470 gfx::Vector3dF lid(kAccelerometerVerticalHingeTestData[i * 6 + 3], 469 gfx::Vector3dF lid(kAccelerometerVerticalHingeTestData[i * 6 + 3],
471 kAccelerometerVerticalHingeTestData[i * 6 + 4], 470 kAccelerometerVerticalHingeTestData[i * 6 + 4],
472 kAccelerometerVerticalHingeTestData[i * 6 + 5]); 471 kAccelerometerVerticalHingeTestData[i * 6 + 5]);
473 TriggerBaseAndLidUpdate(base, lid); 472 TriggerBaseAndLidUpdate(base, lid);
474 // There are a lot of samples, so ASSERT rather than EXPECT to only generate 473 // There are a lot of samples, so ASSERT rather than EXPECT to only generate
475 // one failure rather than potentially hundreds. 474 // one failure rather than potentially hundreds.
476 ASSERT_TRUE(IsMaximizeModeStarted()); 475 ASSERT_TRUE(IsTabletModeStarted());
477 } 476 }
478 } 477 }
479 478
480 // Test if this case does not crash. See http://crbug.com/462806 479 // Test if this case does not crash. See http://crbug.com/462806
481 TEST_F(MaximizeModeControllerTest, DisplayDisconnectionDuringOverview) { 480 TEST_F(TabletModeControllerTest, DisplayDisconnectionDuringOverview) {
482 UpdateDisplay("800x600,800x600"); 481 UpdateDisplay("800x600,800x600");
483 std::unique_ptr<aura::Window> w1( 482 std::unique_ptr<aura::Window> w1(
484 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 100, 100))); 483 CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 100, 100)));
485 std::unique_ptr<aura::Window> w2( 484 std::unique_ptr<aura::Window> w2(
486 CreateTestWindowInShellWithBounds(gfx::Rect(800, 0, 100, 100))); 485 CreateTestWindowInShellWithBounds(gfx::Rect(800, 0, 100, 100)));
487 ASSERT_NE(w1->GetRootWindow(), w2->GetRootWindow()); 486 ASSERT_NE(w1->GetRootWindow(), w2->GetRootWindow());
488 487
489 maximize_mode_controller()->EnableMaximizeModeWindowManager(true); 488 tablet_mode_controller()->EnableTabletModeWindowManager(true);
490 EXPECT_TRUE(Shell::Get()->window_selector_controller()->ToggleOverview()); 489 EXPECT_TRUE(Shell::Get()->window_selector_controller()->ToggleOverview());
491 490
492 UpdateDisplay("800x600"); 491 UpdateDisplay("800x600");
493 EXPECT_FALSE(Shell::Get()->window_selector_controller()->IsSelecting()); 492 EXPECT_FALSE(Shell::Get()->window_selector_controller()->IsSelecting());
494 EXPECT_EQ(w1->GetRootWindow(), w2->GetRootWindow()); 493 EXPECT_EQ(w1->GetRootWindow(), w2->GetRootWindow());
495 } 494 }
496 495
497 // Test that the disabling of the internal display exits maximize mode, and that 496 // Test that the disabling of the internal display exits tablet mode, and that
498 // while disabled we do not re-enter maximize mode. 497 // while disabled we do not re-enter tablet mode.
499 TEST_F(MaximizeModeControllerTest, NoMaximizeModeWithDisabledInternalDisplay) { 498 TEST_F(TabletModeControllerTest, NoTabletModeWithDisabledInternalDisplay) {
500 UpdateDisplay("200x200, 200x200"); 499 UpdateDisplay("200x200, 200x200");
501 const int64_t internal_display_id = 500 const int64_t internal_display_id =
502 display::test::DisplayManagerTestApi(display_manager()) 501 display::test::DisplayManagerTestApi(display_manager())
503 .SetFirstDisplayAsInternalDisplay(); 502 .SetFirstDisplayAsInternalDisplay();
504 ASSERT_FALSE(IsMaximizeModeStarted()); 503 ASSERT_FALSE(IsTabletModeStarted());
505 504
506 OpenLidToAngle(270.0f); 505 OpenLidToAngle(270.0f);
507 EXPECT_TRUE(IsMaximizeModeStarted()); 506 EXPECT_TRUE(IsTabletModeStarted());
508 EXPECT_TRUE(AreEventsBlocked()); 507 EXPECT_TRUE(AreEventsBlocked());
509 508
510 // Deactivate internal display to simulate Docked Mode. 509 // Deactivate internal display to simulate Docked Mode.
511 std::vector<display::ManagedDisplayInfo> secondary_only; 510 std::vector<display::ManagedDisplayInfo> secondary_only;
512 secondary_only.push_back(display_manager()->GetDisplayInfo( 511 secondary_only.push_back(display_manager()->GetDisplayInfo(
513 display_manager()->GetDisplayAt(1).id())); 512 display_manager()->GetDisplayAt(1).id()));
514 display_manager()->OnNativeDisplaysChanged(secondary_only); 513 display_manager()->OnNativeDisplaysChanged(secondary_only);
515 ASSERT_FALSE(display_manager()->IsActiveDisplayId(internal_display_id)); 514 ASSERT_FALSE(display_manager()->IsActiveDisplayId(internal_display_id));
516 EXPECT_FALSE(IsMaximizeModeStarted()); 515 EXPECT_FALSE(IsTabletModeStarted());
517 EXPECT_FALSE(AreEventsBlocked()); 516 EXPECT_FALSE(AreEventsBlocked());
518 517
519 OpenLidToAngle(270.0f); 518 OpenLidToAngle(270.0f);
520 EXPECT_FALSE(IsMaximizeModeStarted()); 519 EXPECT_FALSE(IsTabletModeStarted());
521 EXPECT_FALSE(AreEventsBlocked()); 520 EXPECT_FALSE(AreEventsBlocked());
522 521
523 // Tablet mode signal should also be ignored. 522 // Tablet mode signal should also be ignored.
524 SetTabletMode(true); 523 SetTabletMode(true);
525 EXPECT_FALSE(IsMaximizeModeStarted()); 524 EXPECT_FALSE(IsTabletModeStarted());
526 EXPECT_FALSE(AreEventsBlocked()); 525 EXPECT_FALSE(AreEventsBlocked());
527 } 526 }
528 527
529 // Tests that is a tablet mode signal is received while docked, that maximize 528 // Tests that is a tablet mode signal is received while docked, that maximize
530 // mode is enabled upon exiting docked mode. 529 // mode is enabled upon exiting docked mode.
531 TEST_F(MaximizeModeControllerTest, MaximizeModeAfterExitingDockedMode) { 530 TEST_F(TabletModeControllerTest, TabletModeAfterExitingDockedMode) {
532 UpdateDisplay("200x200, 200x200"); 531 UpdateDisplay("200x200, 200x200");
533 const int64_t internal_display_id = 532 const int64_t internal_display_id =
534 display::test::DisplayManagerTestApi(display_manager()) 533 display::test::DisplayManagerTestApi(display_manager())
535 .SetFirstDisplayAsInternalDisplay(); 534 .SetFirstDisplayAsInternalDisplay();
536 ASSERT_FALSE(IsMaximizeModeStarted()); 535 ASSERT_FALSE(IsTabletModeStarted());
537 536
538 // Deactivate internal display to simulate Docked Mode. 537 // Deactivate internal display to simulate Docked Mode.
539 std::vector<display::ManagedDisplayInfo> all_displays; 538 std::vector<display::ManagedDisplayInfo> all_displays;
540 all_displays.push_back(display_manager()->GetDisplayInfo( 539 all_displays.push_back(display_manager()->GetDisplayInfo(
541 display_manager()->GetDisplayAt(0).id())); 540 display_manager()->GetDisplayAt(0).id()));
542 std::vector<display::ManagedDisplayInfo> secondary_only; 541 std::vector<display::ManagedDisplayInfo> secondary_only;
543 display::ManagedDisplayInfo secondary_display = 542 display::ManagedDisplayInfo secondary_display =
544 display_manager()->GetDisplayInfo( 543 display_manager()->GetDisplayInfo(
545 display_manager()->GetDisplayAt(1).id()); 544 display_manager()->GetDisplayAt(1).id());
546 all_displays.push_back(secondary_display); 545 all_displays.push_back(secondary_display);
547 secondary_only.push_back(secondary_display); 546 secondary_only.push_back(secondary_display);
548 display_manager()->OnNativeDisplaysChanged(secondary_only); 547 display_manager()->OnNativeDisplaysChanged(secondary_only);
549 ASSERT_FALSE(display_manager()->IsActiveDisplayId(internal_display_id)); 548 ASSERT_FALSE(display_manager()->IsActiveDisplayId(internal_display_id));
550 549
551 // Tablet mode signal should also be ignored. 550 // Tablet mode signal should also be ignored.
552 SetTabletMode(true); 551 SetTabletMode(true);
553 EXPECT_FALSE(IsMaximizeModeStarted()); 552 EXPECT_FALSE(IsTabletModeStarted());
554 EXPECT_FALSE(AreEventsBlocked()); 553 EXPECT_FALSE(AreEventsBlocked());
555 554
556 // Exiting docked state 555 // Exiting docked state
557 display_manager()->OnNativeDisplaysChanged(all_displays); 556 display_manager()->OnNativeDisplaysChanged(all_displays);
558 display::test::DisplayManagerTestApi(display_manager()) 557 display::test::DisplayManagerTestApi(display_manager())
559 .SetFirstDisplayAsInternalDisplay(); 558 .SetFirstDisplayAsInternalDisplay();
560 EXPECT_TRUE(IsMaximizeModeStarted()); 559 EXPECT_TRUE(IsTabletModeStarted());
561 } 560 }
562 561
563 // Verify that the device won't exit touchview / maximize mode for unstable 562 // Verify that the device won't exit touchview / tablet mode for unstable
564 // angles when hinge is nearly vertical 563 // angles when hinge is nearly vertical
565 TEST_F(MaximizeModeControllerTest, VerticalHingeUnstableAnglesTest) { 564 TEST_F(TabletModeControllerTest, VerticalHingeUnstableAnglesTest) {
566 // Trigger maximize mode by opening to 270 to begin the test in maximize mode. 565 // Trigger tablet mode by opening to 270 to begin the test in tablet mode.
567 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity), 566 TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
568 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 567 gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
569 ASSERT_TRUE(IsMaximizeModeStarted()); 568 ASSERT_TRUE(IsTabletModeStarted());
570 569
571 // Feeds in sample accelerometer data and verifies that there are no 570 // Feeds in sample accelerometer data and verifies that there are no
572 // transitions out of touchview / maximize mode while shaking the device 571 // transitions out of touchview / tablet mode while shaking the device
573 // around, while the hinge is nearly vertical. The data was captured 572 // around, while the hinge is nearly vertical. The data was captured
574 // from maxmimize_mode_controller.cc and does not require conversion. 573 // from maxmimize_mode_controller.cc and does not require conversion.
575 ASSERT_EQ(0u, kAccelerometerVerticalHingeUnstableAnglesTestDataLength % 6); 574 ASSERT_EQ(0u, kAccelerometerVerticalHingeUnstableAnglesTestDataLength % 6);
576 for (size_t i = 0; 575 for (size_t i = 0;
577 i < kAccelerometerVerticalHingeUnstableAnglesTestDataLength / 6; ++i) { 576 i < kAccelerometerVerticalHingeUnstableAnglesTestDataLength / 6; ++i) {
578 gfx::Vector3dF base( 577 gfx::Vector3dF base(
579 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6], 578 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6],
580 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6 + 1], 579 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6 + 1],
581 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6 + 2]); 580 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6 + 2]);
582 gfx::Vector3dF lid( 581 gfx::Vector3dF lid(
583 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6 + 3], 582 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6 + 3],
584 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6 + 4], 583 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6 + 4],
585 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6 + 5]); 584 kAccelerometerVerticalHingeUnstableAnglesTestData[i * 6 + 5]);
586 TriggerBaseAndLidUpdate(base, lid); 585 TriggerBaseAndLidUpdate(base, lid);
587 // There are a lot of samples, so ASSERT rather than EXPECT to only generate 586 // There are a lot of samples, so ASSERT rather than EXPECT to only generate
588 // one failure rather than potentially hundreds. 587 // one failure rather than potentially hundreds.
589 ASSERT_TRUE(IsMaximizeModeStarted()); 588 ASSERT_TRUE(IsTabletModeStarted());
590 } 589 }
591 } 590 }
592 591
593 // Tests that when a MaximizeModeController is created that cached tablet mode 592 // Tests that when a TabletModeController is created that cached tablet mode
594 // state will trigger a mode update. 593 // state will trigger a mode update.
595 TEST_F(MaximizeModeControllerTest, InitializedWhileTabletModeSwitchOn) { 594 TEST_F(TabletModeControllerTest, InitializedWhileTabletModeSwitchOn) {
596 base::RunLoop().RunUntilIdle(); 595 base::RunLoop().RunUntilIdle();
597 // FakePowerManagerClient is always installed for tests 596 // FakePowerManagerClient is always installed for tests
598 chromeos::FakePowerManagerClient* power_manager_client = 597 chromeos::FakePowerManagerClient* power_manager_client =
599 static_cast<chromeos::FakePowerManagerClient*>( 598 static_cast<chromeos::FakePowerManagerClient*>(
600 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()); 599 chromeos::DBusThreadManager::Get()->GetPowerManagerClient());
601 power_manager_client->set_tablet_mode( 600 power_manager_client->set_tablet_mode(
602 chromeos::PowerManagerClient::TabletMode::ON); 601 chromeos::PowerManagerClient::TabletMode::ON);
603 MaximizeModeController controller; 602 TabletModeController controller;
604 EXPECT_FALSE(controller.IsMaximizeModeWindowManagerEnabled()); 603 EXPECT_FALSE(controller.IsTabletModeWindowManagerEnabled());
605 // PowerManagerClient callback is a posted task. 604 // PowerManagerClient callback is a posted task.
606 base::RunLoop().RunUntilIdle(); 605 base::RunLoop().RunUntilIdle();
607 EXPECT_TRUE(controller.IsMaximizeModeWindowManagerEnabled()); 606 EXPECT_TRUE(controller.IsTabletModeWindowManagerEnabled());
608 } 607 }
609 608
610 // Verify when the force clamshell mode flag is turned on, opening the lid past 609 // Verify when the force clamshell mode flag is turned on, opening the lid past
611 // 180 degrees or setting tablet mode to true will no turn on maximize mode. 610 // 180 degrees or setting tablet mode to true will no turn on tablet mode.
612 TEST_F(MaximizeModeControllerTest, ForceClamshellModeTest) { 611 TEST_F(TabletModeControllerTest, ForceClamshellModeTest) {
613 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 612 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
614 switches::kAshForceTabletMode, switches::kAshForceTabletModeClamshell); 613 switches::kAshForceTabletMode, switches::kAshForceTabletModeClamshell);
615 maximize_mode_controller()->OnShellInitialized(); 614 tablet_mode_controller()->OnShellInitialized();
616 EXPECT_EQ(MaximizeModeController::ForceTabletMode::CLAMSHELL, 615 EXPECT_EQ(TabletModeController::ForceTabletMode::CLAMSHELL,
617 forced_tablet_mode()); 616 forced_tablet_mode());
618 EXPECT_FALSE(IsMaximizeModeStarted()); 617 EXPECT_FALSE(IsTabletModeStarted());
619 618
620 OpenLidToAngle(300.0f); 619 OpenLidToAngle(300.0f);
621 EXPECT_FALSE(IsMaximizeModeStarted()); 620 EXPECT_FALSE(IsTabletModeStarted());
622 EXPECT_FALSE(AreEventsBlocked()); 621 EXPECT_FALSE(AreEventsBlocked());
623 622
624 SetTabletMode(true); 623 SetTabletMode(true);
625 EXPECT_FALSE(IsMaximizeModeStarted()); 624 EXPECT_FALSE(IsTabletModeStarted());
626 EXPECT_FALSE(AreEventsBlocked()); 625 EXPECT_FALSE(AreEventsBlocked());
627 } 626 }
628 627
629 // Verify when the force touch view mode flag is turned on, maximize mode is on 628 // Verify when the force touch view mode flag is turned on, tablet mode is on
630 // intially, and opening the lid to less than 180 degress or setting tablet mode 629 // intially, and opening the lid to less than 180 degress or setting tablet mode
631 // to off will not turn off maximize mode. 630 // to off will not turn off tablet mode.
632 TEST_F(MaximizeModeControllerTest, ForceTouchViewModeTest) { 631 TEST_F(TabletModeControllerTest, ForceTouchViewModeTest) {
633 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 632 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
634 switches::kAshForceTabletMode, switches::kAshForceTabletModeTouchView); 633 switches::kAshForceTabletMode, switches::kAshForceTabletModeTouchView);
635 maximize_mode_controller()->OnShellInitialized(); 634 tablet_mode_controller()->OnShellInitialized();
636 EXPECT_EQ(MaximizeModeController::ForceTabletMode::TOUCHVIEW, 635 EXPECT_EQ(TabletModeController::ForceTabletMode::TOUCHVIEW,
637 forced_tablet_mode()); 636 forced_tablet_mode());
638 EXPECT_TRUE(IsMaximizeModeStarted()); 637 EXPECT_TRUE(IsTabletModeStarted());
639 EXPECT_TRUE(AreEventsBlocked()); 638 EXPECT_TRUE(AreEventsBlocked());
640 639
641 OpenLidToAngle(30.0f); 640 OpenLidToAngle(30.0f);
642 EXPECT_TRUE(IsMaximizeModeStarted()); 641 EXPECT_TRUE(IsTabletModeStarted());
643 EXPECT_TRUE(AreEventsBlocked()); 642 EXPECT_TRUE(AreEventsBlocked());
644 643
645 SetTabletMode(false); 644 SetTabletMode(false);
646 EXPECT_TRUE(IsMaximizeModeStarted()); 645 EXPECT_TRUE(IsTabletModeStarted());
647 EXPECT_TRUE(AreEventsBlocked()); 646 EXPECT_TRUE(AreEventsBlocked());
648 } 647 }
649 648
650 TEST_F(MaximizeModeControllerTest, RestoreAfterExit) { 649 TEST_F(TabletModeControllerTest, RestoreAfterExit) {
651 UpdateDisplay("1000x600"); 650 UpdateDisplay("1000x600");
652 std::unique_ptr<aura::Window> w1( 651 std::unique_ptr<aura::Window> w1(
653 CreateTestWindowInShellWithBounds(gfx::Rect(10, 10, 900, 300))); 652 CreateTestWindowInShellWithBounds(gfx::Rect(10, 10, 900, 300)));
654 maximize_mode_controller()->EnableMaximizeModeWindowManager(true); 653 tablet_mode_controller()->EnableTabletModeWindowManager(true);
655 Shell::Get()->screen_orientation_controller()->SetLockToRotation( 654 Shell::Get()->screen_orientation_controller()->SetLockToRotation(
656 display::Display::ROTATE_90); 655 display::Display::ROTATE_90);
657 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); 656 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
658 EXPECT_EQ(display::Display::ROTATE_90, display.rotation()); 657 EXPECT_EQ(display::Display::ROTATE_90, display.rotation());
659 EXPECT_LT(display.size().width(), display.size().height()); 658 EXPECT_LT(display.size().width(), display.size().height());
660 maximize_mode_controller()->EnableMaximizeModeWindowManager(false); 659 tablet_mode_controller()->EnableTabletModeWindowManager(false);
661 display = display::Screen::GetScreen()->GetPrimaryDisplay(); 660 display = display::Screen::GetScreen()->GetPrimaryDisplay();
662 // Sanity checks. 661 // Sanity checks.
663 EXPECT_EQ(display::Display::ROTATE_0, display.rotation()); 662 EXPECT_EQ(display::Display::ROTATE_0, display.rotation());
664 EXPECT_GT(display.size().width(), display.size().height()); 663 EXPECT_GT(display.size().width(), display.size().height());
665 664
666 // The bounds should be restored to the original bounds, and 665 // The bounds should be restored to the original bounds, and
667 // should not be clamped by the portrait display in touch view. 666 // should not be clamped by the portrait display in touch view.
668 EXPECT_EQ(gfx::Rect(10, 10, 900, 300), w1->bounds()); 667 EXPECT_EQ(gfx::Rect(10, 10, 900, 300), w1->bounds());
669 } 668 }
670 669
671 } // namespace ash 670 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698