OLD | NEW |
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 "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 5 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
14 #include "chrome/browser/signin/easy_unlock_metrics.h" | 14 #include "chrome/browser/signin/easy_unlock_metrics.h" |
15 #include "chrome/browser/signin/easy_unlock_service.h" | 15 #include "chrome/browser/signin/easy_unlock_service.h" |
16 #include "chrome/browser/signin/screenlock_bridge.h" | 16 #include "chrome/browser/signin/easy_unlock_util.h" |
17 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 18 #include "components/proximity_auth/screenlock_bridge.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // Icons used by EasyUnlockScreenlockStateHandler. The icon id values are the | 24 // Icons used by EasyUnlockScreenlockStateHandler. The icon id values are the |
24 // same as the ones set by ScreenlockBridge. | 25 // same as the ones set by proximity_auth::ScreenlockBridge. |
25 const char kLockedIconId[] = "locked"; | 26 const char kLockedIconId[] = "locked"; |
26 const char kLockedToBeActivatedIconId[] = "locked-to-be-activated"; | 27 const char kLockedToBeActivatedIconId[] = "locked-to-be-activated"; |
27 const char kUnlockedIconId[] = "unlocked"; | 28 const char kUnlockedIconId[] = "unlocked"; |
28 const char kSpinnerIconId[] = "spinner"; | 29 const char kSpinnerIconId[] = "spinner"; |
29 const char kHardlockedIconId[] = "hardlocked"; | 30 const char kHardlockedIconId[] = "hardlocked"; |
30 | 31 |
31 // Checks if |input| string has any unreplaced placeholders. | 32 // Checks if |input| string has any unreplaced placeholders. |
32 bool StringHasPlaceholders(const base::string16& input) { | 33 bool StringHasPlaceholders(const base::string16& input) { |
33 std::vector<size_t> offsets; | 34 std::vector<size_t> offsets; |
34 std::vector<base::string16> subst; | 35 std::vector<base::string16> subst; |
35 subst.push_back(base::string16()); | 36 subst.push_back(base::string16()); |
36 | 37 |
37 base::string16 replaced = ReplaceStringPlaceholders(input, subst, &offsets); | 38 base::string16 replaced = ReplaceStringPlaceholders(input, subst, &offsets); |
38 return !offsets.empty(); | 39 return !offsets.empty(); |
39 } | 40 } |
40 | 41 |
41 // Fake lock handler to be used in these tests. | 42 // Fake lock handler to be used in these tests. |
42 class TestLockHandler : public ScreenlockBridge::LockHandler { | 43 class TestLockHandler : public proximity_auth::ScreenlockBridge::LockHandler { |
43 public: | 44 public: |
44 explicit TestLockHandler(const std::string& user_email) | 45 explicit TestLockHandler(const std::string& user_email) |
45 : user_email_(user_email), | 46 : user_email_(user_email), |
46 show_icon_count_(0u), | 47 show_icon_count_(0u), |
47 auth_type_(OFFLINE_PASSWORD) { | 48 auth_type_(OFFLINE_PASSWORD) { |
48 } | 49 } |
49 ~TestLockHandler() override {} | 50 ~TestLockHandler() override {} |
50 | 51 |
51 // ScreenlockBridge::LockHandler implementation: | 52 // proximity_auth::ScreenlockBridge::LockHandler implementation: |
52 void ShowBannerMessage(const base::string16& message) override { | 53 void ShowBannerMessage(const base::string16& message) override { |
53 ASSERT_FALSE(true) << "Should not be reached."; | 54 ASSERT_FALSE(true) << "Should not be reached."; |
54 } | 55 } |
55 | 56 |
56 void ShowUserPodCustomIcon( | 57 void ShowUserPodCustomIcon( |
57 const std::string& user_email, | 58 const std::string& user_email, |
58 const ScreenlockBridge::UserPodCustomIconOptions& icon) override { | 59 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& icon) |
| 60 override { |
59 ASSERT_EQ(user_email_, user_email); | 61 ASSERT_EQ(user_email_, user_email); |
60 ++show_icon_count_; | 62 ++show_icon_count_; |
61 last_custom_icon_ = icon.ToDictionaryValue().Pass(); | 63 last_custom_icon_ = icon.ToDictionaryValue().Pass(); |
62 ValidateCustomIcon(); | 64 ValidateCustomIcon(); |
63 } | 65 } |
64 | 66 |
65 void HideUserPodCustomIcon(const std::string& user_email) override { | 67 void HideUserPodCustomIcon(const std::string& user_email) override { |
66 ASSERT_EQ(user_email_, user_email); | 68 ASSERT_EQ(user_email_, user_email); |
67 last_custom_icon_.reset(); | 69 last_custom_icon_.reset(); |
68 } | 70 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 }; | 202 }; |
201 | 203 |
202 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { | 204 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { |
203 public: | 205 public: |
204 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {} | 206 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {} |
205 ~EasyUnlockScreenlockStateHandlerTest() override {} | 207 ~EasyUnlockScreenlockStateHandlerTest() override {} |
206 | 208 |
207 void SetUp() override { | 209 void SetUp() override { |
208 // Create and inject fake lock handler to the screenlock bridge. | 210 // Create and inject fake lock handler to the screenlock bridge. |
209 lock_handler_.reset(new TestLockHandler(user_email_)); | 211 lock_handler_.reset(new TestLockHandler(user_email_)); |
210 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get(); | 212 proximity_auth::ScreenlockBridge* screenlock_bridge = |
| 213 GetScreenlockBridgeInstance(); |
211 screenlock_bridge->SetLockHandler(lock_handler_.get()); | 214 screenlock_bridge->SetLockHandler(lock_handler_.get()); |
212 | 215 |
213 // Create the screenlock state handler object that will be tested. | 216 // Create the screenlock state handler object that will be tested. |
214 state_handler_.reset(new EasyUnlockScreenlockStateHandler( | 217 state_handler_.reset(new EasyUnlockScreenlockStateHandler( |
215 user_email_, | 218 user_email_, |
216 EasyUnlockScreenlockStateHandler::NO_HARDLOCK, | 219 EasyUnlockScreenlockStateHandler::NO_HARDLOCK, |
217 screenlock_bridge)); | 220 screenlock_bridge)); |
218 } | 221 } |
219 | 222 |
220 void TearDown() override { | 223 void TearDown() override { |
221 ScreenlockBridge::Get()->SetLockHandler(NULL); | 224 GetScreenlockBridgeInstance()->SetLockHandler(NULL); |
222 lock_handler_.reset(); | 225 lock_handler_.reset(); |
223 state_handler_.reset(); | 226 state_handler_.reset(); |
224 } | 227 } |
225 | 228 |
226 protected: | 229 protected: |
227 // The state handler that is being tested. | 230 // The state handler that is being tested. |
228 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; | 231 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; |
229 | 232 |
230 // The user associated with |state_handler_|. | 233 // The user associated with |state_handler_|. |
231 const std::string user_email_; | 234 const std::string user_email_; |
232 | 235 |
233 // Faked lock handler given to ScreenlockBridge during the test. Abstracts | 236 // Faked lock handler given to proximity_auth::ScreenlockBridge during the |
234 // the screen lock UI. | 237 // test. Abstracts the screen lock UI. |
235 scoped_ptr<TestLockHandler> lock_handler_; | 238 scoped_ptr<TestLockHandler> lock_handler_; |
236 }; | 239 }; |
237 | 240 |
238 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedTrialRun) { | 241 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedTrialRun) { |
239 state_handler_->SetTrialRun(); | 242 state_handler_->SetTrialRun(); |
240 state_handler_->ChangeState( | 243 state_handler_->ChangeState( |
241 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 244 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
242 | 245 |
243 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 246 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
244 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 247 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
245 lock_handler_->GetAuthType(user_email_)); | 248 lock_handler_->GetAuthType(user_email_)); |
246 | 249 |
247 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 250 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
248 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); | 251 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); |
249 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 252 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
250 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); | 253 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
251 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); | 254 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
252 | 255 |
253 state_handler_->ChangeState( | 256 state_handler_->ChangeState( |
254 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 257 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
255 // Duplicated state change should be ignored. | 258 // Duplicated state change should be ignored. |
256 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 259 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
257 } | 260 } |
258 | 261 |
259 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) { | 262 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) { |
260 state_handler_->ChangeState( | 263 state_handler_->ChangeState( |
261 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 264 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
262 | 265 |
263 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 266 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
264 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 267 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
265 lock_handler_->GetAuthType(user_email_)); | 268 lock_handler_->GetAuthType(user_email_)); |
266 | 269 |
267 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 270 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
268 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); | 271 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); |
269 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 272 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
270 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); | 273 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); |
271 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 274 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
272 } | 275 } |
273 | 276 |
274 TEST_F(EasyUnlockScreenlockStateHandlerTest, IsActive) { | 277 TEST_F(EasyUnlockScreenlockStateHandlerTest, IsActive) { |
275 EXPECT_FALSE(state_handler_->IsActive()); | 278 EXPECT_FALSE(state_handler_->IsActive()); |
276 state_handler_->ChangeState( | 279 state_handler_->ChangeState( |
277 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 280 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
278 EXPECT_TRUE(state_handler_->IsActive()); | 281 EXPECT_TRUE(state_handler_->IsActive()); |
279 state_handler_->ChangeState( | 282 state_handler_->ChangeState( |
280 EasyUnlockScreenlockStateHandler::STATE_INACTIVE); | 283 EasyUnlockScreenlockStateHandler::STATE_INACTIVE); |
281 EXPECT_FALSE(state_handler_->IsActive()); | 284 EXPECT_FALSE(state_handler_->IsActive()); |
282 } | 285 } |
283 | 286 |
284 TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) { | 287 TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) { |
285 state_handler_->ChangeState( | 288 state_handler_->ChangeState( |
286 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 289 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
287 EXPECT_TRUE(state_handler_->IsActive()); | 290 EXPECT_TRUE(state_handler_->IsActive()); |
288 | 291 |
289 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 292 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
290 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 293 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
291 lock_handler_->GetAuthType(user_email_)); | 294 lock_handler_->GetAuthType(user_email_)); |
292 | 295 |
293 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 296 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
294 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); | 297 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); |
295 EXPECT_FALSE(lock_handler_->CustomIconHasTooltip()); | 298 EXPECT_FALSE(lock_handler_->CustomIconHasTooltip()); |
296 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 299 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
297 | 300 |
298 state_handler_->ChangeState( | 301 state_handler_->ChangeState( |
299 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 302 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
300 // Duplicated state change should be ignored. | 303 // Duplicated state change should be ignored. |
301 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 304 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
302 } | 305 } |
303 | 306 |
304 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedState) { | 307 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedState) { |
305 state_handler_->ChangeState( | 308 state_handler_->ChangeState( |
306 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 309 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
307 | 310 |
308 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 311 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
309 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 312 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
310 lock_handler_->GetAuthType(user_email_)); | 313 lock_handler_->GetAuthType(user_email_)); |
311 | 314 |
312 state_handler_->SetHardlockState( | 315 state_handler_->SetHardlockState( |
313 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 316 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
314 | 317 |
315 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 318 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
316 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 319 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
317 lock_handler_->GetAuthType(user_email_)); | 320 lock_handler_->GetAuthType(user_email_)); |
318 | 321 |
319 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 322 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
320 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); | 323 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
321 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 324 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
322 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); | 325 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
323 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); | 326 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
324 | 327 |
325 state_handler_->SetHardlockState( | 328 state_handler_->SetHardlockState( |
326 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 329 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
327 | 330 |
328 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 331 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
329 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 332 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
330 } | 333 } |
331 | 334 |
332 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedStateNoPairing) { | 335 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedStateNoPairing) { |
333 state_handler_->ChangeState( | 336 state_handler_->ChangeState( |
334 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 337 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
335 | 338 |
336 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 339 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
337 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 340 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
338 lock_handler_->GetAuthType(user_email_)); | 341 lock_handler_->GetAuthType(user_email_)); |
339 | 342 |
340 state_handler_->SetHardlockState( | 343 state_handler_->SetHardlockState( |
341 EasyUnlockScreenlockStateHandler::NO_PAIRING); | 344 EasyUnlockScreenlockStateHandler::NO_PAIRING); |
342 | 345 |
343 EXPECT_FALSE(lock_handler_->HasCustomIcon()); | 346 EXPECT_FALSE(lock_handler_->HasCustomIcon()); |
344 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 347 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
345 lock_handler_->GetAuthType(user_email_)); | 348 lock_handler_->GetAuthType(user_email_)); |
346 } | 349 } |
347 | 350 |
348 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) { | 351 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) { |
349 std::vector<EasyUnlockScreenlockStateHandler::State> states; | 352 std::vector<EasyUnlockScreenlockStateHandler::State> states; |
350 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); | 353 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); |
351 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); | 354 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
352 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); | 355 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); |
353 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); | 356 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); |
354 states.push_back( | 357 states.push_back( |
355 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); | 358 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); |
356 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); | 359 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
357 | 360 |
358 for (size_t i = 0; i < states.size(); ++i) { | 361 for (size_t i = 0; i < states.size(); ++i) { |
359 state_handler_->ChangeState(states[i]); | 362 state_handler_->ChangeState(states[i]); |
360 EXPECT_TRUE(state_handler_->IsActive()); | 363 EXPECT_TRUE(state_handler_->IsActive()); |
361 | 364 |
362 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()) | 365 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()) |
363 << "State: " << states[i]; | 366 << "State: " << states[i]; |
364 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 367 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
365 lock_handler_->GetAuthType(user_email_)) | 368 lock_handler_->GetAuthType(user_email_)) |
366 << "State: " << states[i]; | 369 << "State: " << states[i]; |
367 | 370 |
368 ASSERT_TRUE(lock_handler_->HasCustomIcon()) | 371 ASSERT_TRUE(lock_handler_->HasCustomIcon()) |
369 << "State: " << states[i]; | 372 << "State: " << states[i]; |
370 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()) | 373 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()) |
371 << "State: " << states[i]; | 374 << "State: " << states[i]; |
372 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()) | 375 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()) |
373 << "State: " << states[i]; | 376 << "State: " << states[i]; |
374 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()) | 377 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()) |
375 << "State: " << states[i]; | 378 << "State: " << states[i]; |
376 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) | 379 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) |
377 << "State: " << states[i]; | 380 << "State: " << states[i]; |
378 | 381 |
379 state_handler_->ChangeState(states[i]); | 382 state_handler_->ChangeState(states[i]); |
380 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()) | 383 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()) |
381 << "State: " << states[i]; | 384 << "State: " << states[i]; |
382 } | 385 } |
383 } | 386 } |
384 | 387 |
385 TEST_F(EasyUnlockScreenlockStateHandlerTest, SettingTrialRunUpdatesUI) { | 388 TEST_F(EasyUnlockScreenlockStateHandlerTest, SettingTrialRunUpdatesUI) { |
386 state_handler_->ChangeState( | 389 state_handler_->ChangeState( |
387 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 390 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
388 | 391 |
389 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 392 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
390 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 393 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
391 lock_handler_->GetAuthType(user_email_)); | 394 lock_handler_->GetAuthType(user_email_)); |
392 | 395 |
393 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 396 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
394 ASSERT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); | 397 ASSERT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); |
395 | 398 |
396 state_handler_->SetTrialRun(); | 399 state_handler_->SetTrialRun(); |
397 | 400 |
398 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 401 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
399 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 402 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
400 lock_handler_->GetAuthType(user_email_)); | 403 lock_handler_->GetAuthType(user_email_)); |
401 | 404 |
402 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 405 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
403 ASSERT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); | 406 ASSERT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
404 } | 407 } |
405 | 408 |
406 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 409 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
407 LockScreenClearedOnStateHandlerDestruction) { | 410 LockScreenClearedOnStateHandlerDestruction) { |
408 state_handler_->ChangeState( | 411 state_handler_->ChangeState( |
409 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 412 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
410 | 413 |
411 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 414 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
412 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 415 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
413 lock_handler_->GetAuthType(user_email_)); | 416 lock_handler_->GetAuthType(user_email_)); |
414 | 417 |
415 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 418 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
416 | 419 |
417 state_handler_.reset(); | 420 state_handler_.reset(); |
418 | 421 |
419 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 422 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
420 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 423 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
421 lock_handler_->GetAuthType(user_email_)); | 424 lock_handler_->GetAuthType(user_email_)); |
422 | 425 |
423 ASSERT_FALSE(lock_handler_->HasCustomIcon()); | 426 ASSERT_FALSE(lock_handler_->HasCustomIcon()); |
424 } | 427 } |
425 | 428 |
426 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatePreservedWhenScreenUnlocks) { | 429 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatePreservedWhenScreenUnlocks) { |
427 state_handler_->ChangeState( | 430 state_handler_->ChangeState( |
428 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 431 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
429 | 432 |
430 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 433 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
431 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 434 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
432 lock_handler_->GetAuthType(user_email_)); | 435 lock_handler_->GetAuthType(user_email_)); |
433 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 436 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
434 | 437 |
435 ScreenlockBridge::Get()->SetLockHandler(NULL); | 438 GetScreenlockBridgeInstance()->SetLockHandler(NULL); |
436 lock_handler_.reset(new TestLockHandler(user_email_)); | 439 lock_handler_.reset(new TestLockHandler(user_email_)); |
437 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 440 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
438 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 441 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get()); |
439 | 442 |
440 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 443 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
441 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 444 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
442 lock_handler_->GetAuthType(user_email_)); | 445 lock_handler_->GetAuthType(user_email_)); |
443 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 446 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
444 } | 447 } |
445 | 448 |
446 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangeWhileScreenUnlocked) { | 449 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangeWhileScreenUnlocked) { |
447 state_handler_->ChangeState( | 450 state_handler_->ChangeState( |
448 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 451 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
449 | 452 |
450 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 453 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
451 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 454 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
452 lock_handler_->GetAuthType(user_email_)); | 455 lock_handler_->GetAuthType(user_email_)); |
453 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 456 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
454 | 457 |
455 ScreenlockBridge::Get()->SetLockHandler(NULL); | 458 GetScreenlockBridgeInstance()->SetLockHandler(NULL); |
456 lock_handler_.reset(new TestLockHandler(user_email_)); | 459 lock_handler_.reset(new TestLockHandler(user_email_)); |
457 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 460 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
458 | 461 |
459 state_handler_->ChangeState( | 462 state_handler_->ChangeState( |
460 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 463 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
461 | 464 |
462 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 465 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get()); |
463 | 466 |
464 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 467 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
465 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 468 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
466 lock_handler_->GetAuthType(user_email_)); | 469 lock_handler_->GetAuthType(user_email_)); |
467 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 470 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
468 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); | 471 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); |
469 } | 472 } |
470 | 473 |
471 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 474 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
472 HardlockEnabledAfterInitialUnlock) { | 475 HardlockEnabledAfterInitialUnlock) { |
473 state_handler_->SetTrialRun(); | 476 state_handler_->SetTrialRun(); |
474 | 477 |
475 std::vector<EasyUnlockScreenlockStateHandler::State> states; | 478 std::vector<EasyUnlockScreenlockStateHandler::State> states; |
476 states.push_back( | 479 states.push_back( |
477 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 480 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
478 states.push_back( | 481 states.push_back( |
479 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); | 482 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); |
480 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); | 483 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); |
481 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); | 484 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
482 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); | 485 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); |
483 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); | 486 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); |
484 // This one should go last as changing state to AUTHENTICATED enables hard | 487 // This one should go last as changing state to AUTHENTICATED enables hard |
485 // locking. | 488 // locking. |
486 states.push_back(EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 489 states.push_back(EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
487 | 490 |
488 for (size_t i = 0; i < states.size(); ++i) { | 491 for (size_t i = 0; i < states.size(); ++i) { |
489 state_handler_->ChangeState(states[i]); | 492 state_handler_->ChangeState(states[i]); |
490 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i]; | 493 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i]; |
491 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()) | 494 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()) |
492 << "State: " << states[i]; | 495 << "State: " << states[i]; |
493 } | 496 } |
494 | 497 |
495 ScreenlockBridge::Get()->SetLockHandler(NULL); | 498 GetScreenlockBridgeInstance()->SetLockHandler(NULL); |
496 lock_handler_.reset(new TestLockHandler(user_email_)); | 499 lock_handler_.reset(new TestLockHandler(user_email_)); |
497 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 500 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get()); |
498 | 501 |
499 for (size_t i = 0; i < states.size(); ++i) { | 502 for (size_t i = 0; i < states.size(); ++i) { |
500 state_handler_->ChangeState(states[i]); | 503 state_handler_->ChangeState(states[i]); |
501 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i]; | 504 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i]; |
502 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) | 505 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) |
503 << "State: " << states[i]; | 506 << "State: " << states[i]; |
504 } | 507 } |
505 } | 508 } |
506 | 509 |
507 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 510 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); | 614 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); |
612 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 615 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
613 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); | 616 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); |
614 } | 617 } |
615 | 618 |
616 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) { | 619 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) { |
617 state_handler_->ChangeState( | 620 state_handler_->ChangeState( |
618 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 621 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
619 | 622 |
620 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 623 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
621 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 624 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
622 lock_handler_->GetAuthType(user_email_)); | 625 lock_handler_->GetAuthType(user_email_)); |
623 | 626 |
624 state_handler_->SetHardlockState( | 627 state_handler_->SetHardlockState( |
625 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 628 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
626 | 629 |
627 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 630 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
628 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 631 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
629 lock_handler_->GetAuthType(user_email_)); | 632 lock_handler_->GetAuthType(user_email_)); |
630 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 633 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
631 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); | 634 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
632 | 635 |
633 state_handler_->ChangeState( | 636 state_handler_->ChangeState( |
634 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); | 637 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
635 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 638 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
636 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 639 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
637 | 640 |
638 state_handler_->ChangeState( | 641 state_handler_->ChangeState( |
639 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 642 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
640 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 643 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
641 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 644 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
642 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 645 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
643 lock_handler_->GetAuthType(user_email_)); | 646 lock_handler_->GetAuthType(user_email_)); |
644 } | 647 } |
645 | 648 |
646 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 649 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
647 LockScreenChangeableOnLockAfterHardlockReset) { | 650 LockScreenChangeableOnLockAfterHardlockReset) { |
648 state_handler_->ChangeState( | 651 state_handler_->ChangeState( |
649 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 652 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
650 | 653 |
651 state_handler_->SetHardlockState( | 654 state_handler_->SetHardlockState( |
652 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 655 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
653 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); | 656 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); |
654 | 657 |
655 state_handler_->SetHardlockState( | 658 state_handler_->SetHardlockState( |
656 EasyUnlockScreenlockStateHandler::NO_HARDLOCK); | 659 EasyUnlockScreenlockStateHandler::NO_HARDLOCK); |
657 | 660 |
658 ScreenlockBridge::Get()->SetLockHandler(NULL); | 661 GetScreenlockBridgeInstance()->SetLockHandler(NULL); |
659 lock_handler_.reset(new TestLockHandler(user_email_)); | 662 lock_handler_.reset(new TestLockHandler(user_email_)); |
660 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 663 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
661 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 664 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get()); |
662 | 665 |
663 state_handler_->ChangeState( | 666 state_handler_->ChangeState( |
664 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); | 667 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
665 | 668 |
666 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); | 669 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); |
667 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 670 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
668 | 671 |
669 ScreenlockBridge::Get()->SetLockHandler(NULL); | 672 GetScreenlockBridgeInstance()->SetLockHandler(NULL); |
670 lock_handler_.reset(new TestLockHandler(user_email_)); | 673 lock_handler_.reset(new TestLockHandler(user_email_)); |
671 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 674 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
672 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 675 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get()); |
673 | 676 |
674 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 677 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
675 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 678 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
676 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 679 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
677 lock_handler_->GetAuthType(user_email_)); | 680 lock_handler_->GetAuthType(user_email_)); |
678 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); | 681 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
679 | 682 |
680 state_handler_->ChangeState( | 683 state_handler_->ChangeState( |
681 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 684 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
682 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 685 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
683 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 686 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
684 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 687 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK, |
685 lock_handler_->GetAuthType(user_email_)); | 688 lock_handler_->GetAuthType(user_email_)); |
686 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 689 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
687 } | 690 } |
688 | 691 |
689 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) { | 692 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) { |
690 state_handler_->ChangeState( | 693 state_handler_->ChangeState( |
691 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 694 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
692 state_handler_->SetHardlockState( | 695 state_handler_->SetHardlockState( |
693 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 696 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
694 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); | 697 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); |
695 | 698 |
696 ScreenlockBridge::Get()->SetLockHandler(NULL); | 699 GetScreenlockBridgeInstance()->SetLockHandler(NULL); |
697 lock_handler_.reset(new TestLockHandler(user_email_)); | 700 lock_handler_.reset(new TestLockHandler(user_email_)); |
698 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 701 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
699 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 702 GetScreenlockBridgeInstance()->SetLockHandler(lock_handler_.get()); |
700 | 703 |
701 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 704 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
702 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 705 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
703 lock_handler_->GetAuthType(user_email_)); | 706 lock_handler_->GetAuthType(user_email_)); |
704 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 707 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
705 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); | 708 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
706 | 709 |
707 state_handler_->ChangeState( | 710 state_handler_->ChangeState( |
708 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 711 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
709 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 712 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
710 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 713 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
711 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 714 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
712 lock_handler_->GetAuthType(user_email_)); | 715 lock_handler_->GetAuthType(user_email_)); |
713 } | 716 } |
714 | 717 |
715 TEST_F(EasyUnlockScreenlockStateHandlerTest, NoOverrideOnlineSignin) { | 718 TEST_F(EasyUnlockScreenlockStateHandlerTest, NoOverrideOnlineSignin) { |
716 lock_handler_->SetAuthType(user_email_, | 719 lock_handler_->SetAuthType( |
717 ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, | 720 user_email_, |
718 base::string16()); | 721 proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, |
| 722 base::string16()); |
719 | 723 |
720 std::vector<EasyUnlockScreenlockStateHandler::State> states; | 724 std::vector<EasyUnlockScreenlockStateHandler::State> states; |
721 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); | 725 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); |
722 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); | 726 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
723 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); | 727 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); |
724 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); | 728 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); |
725 states.push_back( | 729 states.push_back( |
726 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); | 730 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); |
727 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); | 731 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
728 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); | 732 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); |
729 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); | 733 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); |
730 states.push_back(EasyUnlockScreenlockStateHandler::STATE_RSSI_TOO_LOW); | 734 states.push_back(EasyUnlockScreenlockStateHandler::STATE_RSSI_TOO_LOW); |
731 states.push_back(EasyUnlockScreenlockStateHandler::STATE_TX_POWER_TOO_HIGH); | 735 states.push_back(EasyUnlockScreenlockStateHandler::STATE_TX_POWER_TOO_HIGH); |
732 states.push_back(EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 736 states.push_back(EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
733 | 737 |
734 for (size_t i = 0; i < states.size(); ++i) { | 738 for (size_t i = 0; i < states.size(); ++i) { |
735 state_handler_->ChangeState(states[i]); | 739 state_handler_->ChangeState(states[i]); |
736 EXPECT_EQ(ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, | 740 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, |
737 lock_handler_->GetAuthType(user_email_)); | 741 lock_handler_->GetAuthType(user_email_)); |
738 EXPECT_FALSE(lock_handler_->HasCustomIcon()); | 742 EXPECT_FALSE(lock_handler_->HasCustomIcon()); |
739 } | 743 } |
740 | 744 |
741 std::vector<EasyUnlockScreenlockStateHandler::HardlockState> hardlock_states; | 745 std::vector<EasyUnlockScreenlockStateHandler::HardlockState> hardlock_states; |
742 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::NO_HARDLOCK); | 746 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::NO_HARDLOCK); |
743 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 747 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
744 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); | 748 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); |
745 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::PAIRING_ADDED); | 749 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::PAIRING_ADDED); |
746 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::NO_PAIRING); | 750 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::NO_PAIRING); |
747 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::LOGIN_FAILED); | 751 hardlock_states.push_back(EasyUnlockScreenlockStateHandler::LOGIN_FAILED); |
748 | 752 |
749 for (size_t i = 0; i < hardlock_states.size(); ++i) { | 753 for (size_t i = 0; i < hardlock_states.size(); ++i) { |
750 state_handler_->SetHardlockState(hardlock_states[i]); | 754 state_handler_->SetHardlockState(hardlock_states[i]); |
751 EXPECT_EQ(ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, | 755 EXPECT_EQ(proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN, |
752 lock_handler_->GetAuthType(user_email_)); | 756 lock_handler_->GetAuthType(user_email_)); |
753 EXPECT_FALSE(lock_handler_->HasCustomIcon()); | 757 EXPECT_FALSE(lock_handler_->HasCustomIcon()); |
754 } | 758 } |
755 } | 759 } |
756 | 760 |
757 TEST_F(EasyUnlockScreenlockStateHandlerTest, TrialRunMetrics) { | 761 TEST_F(EasyUnlockScreenlockStateHandlerTest, TrialRunMetrics) { |
758 base::HistogramTester histogram_tester; | 762 base::HistogramTester histogram_tester; |
759 | 763 |
760 // Simulate the user clicking on the lock icon twice outside of a trial run. | 764 // Simulate the user clicking on the lock icon twice outside of a trial run. |
761 // No trial run metrics should be recorded. | 765 // No trial run metrics should be recorded. |
762 state_handler_->RecordClickOnLockIcon(); | 766 state_handler_->RecordClickOnLockIcon(); |
763 state_handler_->RecordClickOnLockIcon(); | 767 state_handler_->RecordClickOnLockIcon(); |
764 histogram_tester.ExpectTotalCount("EasyUnlock.TrialRun.Events", 0); | 768 histogram_tester.ExpectTotalCount("EasyUnlock.TrialRun.Events", 0); |
765 | 769 |
766 // Simulate the user clicking on the lock icon three times during a trial run. | 770 // Simulate the user clicking on the lock icon three times during a trial run. |
767 state_handler_->SetTrialRun(); | 771 state_handler_->SetTrialRun(); |
768 state_handler_->RecordClickOnLockIcon(); | 772 state_handler_->RecordClickOnLockIcon(); |
769 state_handler_->RecordClickOnLockIcon(); | 773 state_handler_->RecordClickOnLockIcon(); |
770 state_handler_->RecordClickOnLockIcon(); | 774 state_handler_->RecordClickOnLockIcon(); |
771 histogram_tester.ExpectTotalCount("EasyUnlock.TrialRun.Events", 4); | 775 histogram_tester.ExpectTotalCount("EasyUnlock.TrialRun.Events", 4); |
772 histogram_tester.ExpectBucketCount("EasyUnlock.TrialRun.Events", | 776 histogram_tester.ExpectBucketCount("EasyUnlock.TrialRun.Events", |
773 EASY_UNLOCK_TRIAL_RUN_EVENT_LAUNCHED, 1); | 777 EASY_UNLOCK_TRIAL_RUN_EVENT_LAUNCHED, 1); |
774 histogram_tester.ExpectBucketCount( | 778 histogram_tester.ExpectBucketCount( |
775 "EasyUnlock.TrialRun.Events", | 779 "EasyUnlock.TrialRun.Events", |
776 EASY_UNLOCK_TRIAL_RUN_EVENT_CLICKED_LOCK_ICON, 3); | 780 EASY_UNLOCK_TRIAL_RUN_EVENT_CLICKED_LOCK_ICON, 3); |
777 } | 781 } |
778 | 782 |
779 } // namespace | 783 } // namespace |
OLD | NEW |