| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/prefs/scoped_user_pref_update.h" |
| 9 #include "base/prefs/testing_pref_service.h" |
| 8 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 13 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
| 12 #include "chrome/browser/signin/easy_unlock_service.h" | 14 #include "chrome/browser/signin/easy_unlock_service.h" |
| 13 #include "chrome/browser/signin/screenlock_bridge.h" | 15 #include "chrome/browser/signin/screenlock_bridge.h" |
| 14 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 16 #include "chrome/test/base/testing_pref_service_syncable.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
| 17 #include "components/pref_registry/pref_registry_syncable.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 ScreenlockBridge. |
| 25 const char kLockedIconId[] = "locked"; | 26 const char kLockedIconId[] = "locked"; |
| 26 const char kUnlockedIconId[] = "unlocked"; | 27 const char kUnlockedIconId[] = "unlocked"; |
| 27 const char kSpinnerIconId[] = "spinner"; | 28 const char kSpinnerIconId[] = "spinner"; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 194 |
| 194 DISALLOW_COPY_AND_ASSIGN(TestLockHandler); | 195 DISALLOW_COPY_AND_ASSIGN(TestLockHandler); |
| 195 }; | 196 }; |
| 196 | 197 |
| 197 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { | 198 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { |
| 198 public: | 199 public: |
| 199 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {} | 200 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {} |
| 200 virtual ~EasyUnlockScreenlockStateHandlerTest() {} | 201 virtual ~EasyUnlockScreenlockStateHandlerTest() {} |
| 201 | 202 |
| 202 virtual void SetUp() override { | 203 virtual void SetUp() override { |
| 203 pref_service_.reset(new TestingPrefServiceSyncable()); | 204 pref_service_.reset(new TestingPrefServiceSimple()); |
| 205 |
| 206 TestingBrowserProcess::GetGlobal()->SetApplicationLocale("en-US"); |
| 204 | 207 |
| 205 // The preference used to determine if easy unlock was previously used by | 208 // The preference used to determine if easy unlock was previously used by |
| 206 // the user on the device ought to be registered by the EasyUnlockService. | 209 // the user on the device ought to be registered by the EasyUnlockService. |
| 207 EasyUnlockService::RegisterProfilePrefs(pref_service_->registry()); | 210 EasyUnlockService::RegisterPrefs(pref_service_->registry()); |
| 208 | 211 |
| 209 // Create and inject fake lock handler to the screenlock bridge. | 212 // Create and inject fake lock handler to the screenlock bridge. |
| 210 lock_handler_.reset(new TestLockHandler(user_email_)); | 213 lock_handler_.reset(new TestLockHandler(user_email_)); |
| 211 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get(); | 214 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get(); |
| 212 screenlock_bridge->SetLockHandler(lock_handler_.get()); | 215 screenlock_bridge->SetLockHandler(lock_handler_.get()); |
| 213 | 216 |
| 214 // Create the screenlock state handler object that will be tested. | 217 // Create the screenlock state handler object that will be tested. |
| 215 state_handler_.reset(new EasyUnlockScreenlockStateHandler( | 218 state_handler_.reset(new EasyUnlockScreenlockStateHandler( |
| 216 user_email_, | 219 user_email_, |
| 217 EasyUnlockScreenlockStateHandler::NO_HARDLOCK, | 220 EasyUnlockScreenlockStateHandler::NO_HARDLOCK, |
| 218 pref_service_.get(), | 221 pref_service_.get(), |
| 219 screenlock_bridge)); | 222 screenlock_bridge)); |
| 220 } | 223 } |
| 221 | 224 |
| 222 virtual void TearDown() override { | 225 virtual void TearDown() override { |
| 223 ScreenlockBridge::Get()->SetLockHandler(NULL); | 226 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 224 lock_handler_.reset(); | 227 lock_handler_.reset(); |
| 225 state_handler_.reset(); | 228 state_handler_.reset(); |
| 226 } | 229 } |
| 227 | 230 |
| 231 void SetFirstRunCompleteValue(bool value) { |
| 232 DictionaryPrefUpdate update(pref_service_.get(), |
| 233 prefs::kEasyUnlockFirstRunComplete); |
| 234 update->SetBooleanWithoutPathExpansion(user_email_, value); |
| 235 } |
| 236 |
| 228 protected: | 237 protected: |
| 229 // The state handler that is being tested. | 238 // The state handler that is being tested. |
| 230 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; | 239 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; |
| 231 | 240 |
| 232 // The user associated with |state_handler_|. | 241 // The user associated with |state_handler_|. |
| 233 const std::string user_email_; | 242 const std::string user_email_; |
| 234 | 243 |
| 235 // Faked lock handler given to ScreenlockBridge during the test. Abstracts | 244 // Faked lock handler given to ScreenlockBridge during the test. Abstracts |
| 236 // the screen lock UI. | 245 // the screen lock UI. |
| 237 scoped_ptr<TestLockHandler> lock_handler_; | 246 scoped_ptr<TestLockHandler> lock_handler_; |
| 238 | 247 |
| 239 // The user's preferences. | 248 // The user's preferences. |
| 240 scoped_ptr<TestingPrefServiceSyncable> pref_service_; | 249 scoped_ptr<TestingPrefServiceSimple> pref_service_; |
| 241 }; | 250 }; |
| 242 | 251 |
| 243 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedInitialRun) { | 252 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedInitialRun) { |
| 244 state_handler_->ChangeState( | 253 state_handler_->ChangeState( |
| 245 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 254 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 246 | 255 |
| 247 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 256 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 248 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 257 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 249 lock_handler_->GetAuthType(user_email_)); | 258 lock_handler_->GetAuthType(user_email_)); |
| 250 | 259 |
| 251 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 260 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 252 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); | 261 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); |
| 253 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 262 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
| 254 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); | 263 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
| 255 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); | 264 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
| 256 | 265 |
| 257 state_handler_->ChangeState( | 266 state_handler_->ChangeState( |
| 258 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 267 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 259 // Duplicated state change should be ignored. | 268 // Duplicated state change should be ignored. |
| 260 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 269 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 261 } | 270 } |
| 262 | 271 |
| 263 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) { | 272 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) { |
| 264 // Update preference for showing tutorial. | 273 SetFirstRunCompleteValue(true); |
| 265 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | |
| 266 | 274 |
| 267 state_handler_->ChangeState( | 275 state_handler_->ChangeState( |
| 268 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 276 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 269 | 277 |
| 270 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 278 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 271 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 279 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 272 lock_handler_->GetAuthType(user_email_)); | 280 lock_handler_->GetAuthType(user_email_)); |
| 273 | 281 |
| 274 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 282 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 275 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); | 283 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); |
| 276 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 284 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
| 277 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); | 285 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); |
| 278 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 286 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
| 279 } | 287 } |
| 280 | 288 |
| 281 TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) { | 289 TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) { |
| 282 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | 290 SetFirstRunCompleteValue(true); |
| 291 |
| 283 state_handler_->ChangeState( | 292 state_handler_->ChangeState( |
| 284 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 293 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 285 | 294 |
| 286 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 295 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 287 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 296 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 288 lock_handler_->GetAuthType(user_email_)); | 297 lock_handler_->GetAuthType(user_email_)); |
| 289 | 298 |
| 290 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 299 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 291 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); | 300 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); |
| 292 EXPECT_FALSE(lock_handler_->CustomIconHasTooltip()); | 301 EXPECT_FALSE(lock_handler_->CustomIconHasTooltip()); |
| 293 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 302 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
| 294 | 303 |
| 295 state_handler_->ChangeState( | 304 state_handler_->ChangeState( |
| 296 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 305 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 297 // Duplicated state change should be ignored. | 306 // Duplicated state change should be ignored. |
| 298 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 307 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 299 } | 308 } |
| 300 | 309 |
| 301 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedState) { | 310 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedState) { |
| 302 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | 311 SetFirstRunCompleteValue(true); |
| 312 |
| 303 state_handler_->ChangeState( | 313 state_handler_->ChangeState( |
| 304 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 314 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 305 | 315 |
| 306 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 316 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 307 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 317 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 308 lock_handler_->GetAuthType(user_email_)); | 318 lock_handler_->GetAuthType(user_email_)); |
| 309 | 319 |
| 310 state_handler_->SetHardlockState( | 320 state_handler_->SetHardlockState( |
| 311 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 321 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
| 312 | 322 |
| 313 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 323 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 314 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 324 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 315 lock_handler_->GetAuthType(user_email_)); | 325 lock_handler_->GetAuthType(user_email_)); |
| 316 | 326 |
| 317 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 327 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 318 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); | 328 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
| 319 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 329 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
| 320 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); | 330 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
| 321 | 331 |
| 322 state_handler_->SetHardlockState( | 332 state_handler_->SetHardlockState( |
| 323 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 333 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
| 324 | 334 |
| 325 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 335 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 326 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 336 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 327 } | 337 } |
| 328 | 338 |
| 329 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedStateNoPairing) { | 339 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedStateNoPairing) { |
| 330 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | 340 SetFirstRunCompleteValue(true); |
| 341 |
| 331 state_handler_->ChangeState( | 342 state_handler_->ChangeState( |
| 332 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 343 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 333 | 344 |
| 334 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 345 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 335 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 346 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 336 lock_handler_->GetAuthType(user_email_)); | 347 lock_handler_->GetAuthType(user_email_)); |
| 337 | 348 |
| 338 state_handler_->SetHardlockState( | 349 state_handler_->SetHardlockState( |
| 339 EasyUnlockScreenlockStateHandler::NO_PAIRING); | 350 EasyUnlockScreenlockStateHandler::NO_PAIRING); |
| 340 | 351 |
| 341 EXPECT_FALSE(lock_handler_->HasCustomIcon()); | 352 EXPECT_FALSE(lock_handler_->HasCustomIcon()); |
| 342 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 353 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 343 lock_handler_->GetAuthType(user_email_)); | 354 lock_handler_->GetAuthType(user_email_)); |
| 344 } | 355 } |
| 345 | 356 |
| 346 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) { | 357 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) { |
| 347 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | 358 SetFirstRunCompleteValue(true); |
| 348 | 359 |
| 349 std::vector<EasyUnlockScreenlockStateHandler::State> states; | 360 std::vector<EasyUnlockScreenlockStateHandler::State> states; |
| 350 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); | 361 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); |
| 351 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); | 362 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
| 352 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); | 363 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); |
| 353 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); | 364 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); |
| 354 states.push_back( | 365 states.push_back( |
| 355 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); | 366 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); |
| 356 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); | 367 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 357 | 368 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 374 << "State: " << states[i]; | 385 << "State: " << states[i]; |
| 375 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) | 386 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) |
| 376 << "State: " << states[i]; | 387 << "State: " << states[i]; |
| 377 | 388 |
| 378 state_handler_->ChangeState(states[i]); | 389 state_handler_->ChangeState(states[i]); |
| 379 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()) | 390 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()) |
| 380 << "State: " << states[i]; | 391 << "State: " << states[i]; |
| 381 } | 392 } |
| 382 } | 393 } |
| 383 | 394 |
| 395 // Verifies tooltips are autoshown on initial run. |
| 396 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon_InitialRun) { |
| 397 std::vector<EasyUnlockScreenlockStateHandler::State> states; |
| 398 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); |
| 399 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
| 400 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); |
| 401 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); |
| 402 states.push_back( |
| 403 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); |
| 404 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 405 |
| 406 for (size_t i = 0; i < states.size(); ++i) { |
| 407 state_handler_->ChangeState(states[i]); |
| 408 ASSERT_TRUE(lock_handler_->HasCustomIcon()) |
| 409 << "State: " << states[i]; |
| 410 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()) |
| 411 << "State: " << states[i]; |
| 412 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()) |
| 413 << "State: " << states[i]; |
| 414 } |
| 415 |
| 416 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 417 lock_handler_.reset(new TestLockHandler(user_email_)); |
| 418 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 419 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
| 420 |
| 421 // After the screen unlocks the tooltips should not be shown anymore. |
| 422 for (size_t i = 0; i < states.size(); ++i) { |
| 423 state_handler_->ChangeState(states[i]); |
| 424 ASSERT_TRUE(lock_handler_->HasCustomIcon()) |
| 425 << "State: " << states[i]; |
| 426 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()) |
| 427 << "State: " << states[i]; |
| 428 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()) |
| 429 << "State: " << states[i]; |
| 430 } |
| 431 } |
| 432 |
| 384 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 433 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 385 LockScreenClearedOnStateHandlerDestruction) { | 434 LockScreenClearedOnStateHandlerDestruction) { |
| 386 state_handler_->ChangeState( | 435 state_handler_->ChangeState( |
| 387 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 436 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 388 | 437 |
| 389 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 438 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 390 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 439 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 391 lock_handler_->GetAuthType(user_email_)); | 440 lock_handler_->GetAuthType(user_email_)); |
| 392 | 441 |
| 393 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 442 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 522 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
| 474 | 523 |
| 475 for (size_t i = 0; i < states.size(); ++i) { | 524 for (size_t i = 0; i < states.size(); ++i) { |
| 476 state_handler_->ChangeState(states[i]); | 525 state_handler_->ChangeState(states[i]); |
| 477 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i]; | 526 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i]; |
| 478 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) | 527 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) |
| 479 << "State: " << states[i]; | 528 << "State: " << states[i]; |
| 480 } | 529 } |
| 481 } | 530 } |
| 482 | 531 |
| 532 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 533 NoPairingHardlockClearsIcon) { |
| 534 SetFirstRunCompleteValue(true); |
| 535 |
| 536 state_handler_->ChangeState( |
| 537 EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 538 |
| 539 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 540 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 541 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
| 542 |
| 543 state_handler_->SetHardlockState( |
| 544 EasyUnlockScreenlockStateHandler::NO_PAIRING); |
| 545 |
| 546 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 547 ASSERT_FALSE(lock_handler_->HasCustomIcon()); |
| 548 } |
| 549 |
| 550 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 551 NoPairingHardlockIgnoredOnInitialRun) { |
| 552 state_handler_->ChangeState( |
| 553 EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 554 |
| 555 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 556 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 557 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
| 558 |
| 559 state_handler_->SetHardlockState( |
| 560 EasyUnlockScreenlockStateHandler::NO_PAIRING); |
| 561 |
| 562 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 563 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 564 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
| 565 } |
| 566 |
| 567 TEST_F(EasyUnlockScreenlockStateHandlerTest, PairingChangedHardlock) { |
| 568 SetFirstRunCompleteValue(true); |
| 569 state_handler_->ChangeState( |
| 570 EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 571 |
| 572 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 573 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 574 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
| 575 |
| 576 state_handler_->SetHardlockState( |
| 577 EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); |
| 578 |
| 579 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 580 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 581 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
| 582 |
| 583 state_handler_->ChangeState( |
| 584 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 585 |
| 586 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 587 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 588 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
| 589 } |
| 590 |
| 591 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 592 PairingChangedHardlockEffectiveOnInitialRun) { |
| 593 state_handler_->ChangeState( |
| 594 EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 595 |
| 596 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 597 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 598 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
| 599 |
| 600 state_handler_->SetHardlockState( |
| 601 EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); |
| 602 |
| 603 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 604 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 605 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
| 606 } |
| 607 |
| 483 TEST_F(EasyUnlockScreenlockStateHandlerTest, InactiveStateHidesIcon) { | 608 TEST_F(EasyUnlockScreenlockStateHandlerTest, InactiveStateHidesIcon) { |
| 484 state_handler_->ChangeState( | 609 state_handler_->ChangeState( |
| 485 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 610 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 486 | 611 |
| 487 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 612 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 488 | 613 |
| 489 state_handler_->ChangeState( | 614 state_handler_->ChangeState( |
| 490 EasyUnlockScreenlockStateHandler::STATE_INACTIVE); | 615 EasyUnlockScreenlockStateHandler::STATE_INACTIVE); |
| 491 | 616 |
| 492 ASSERT_FALSE(lock_handler_->HasCustomIcon()); | 617 ASSERT_FALSE(lock_handler_->HasCustomIcon()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); | 650 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); |
| 526 | 651 |
| 527 state_handler_->ChangeState( | 652 state_handler_->ChangeState( |
| 528 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 653 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 529 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); | 654 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); |
| 530 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 655 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 531 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); | 656 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); |
| 532 } | 657 } |
| 533 | 658 |
| 534 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) { | 659 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) { |
| 535 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | 660 SetFirstRunCompleteValue(true); |
| 536 state_handler_->ChangeState( | 661 state_handler_->ChangeState( |
| 537 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 662 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 538 | 663 |
| 539 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 664 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 540 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 665 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 541 lock_handler_->GetAuthType(user_email_)); | 666 lock_handler_->GetAuthType(user_email_)); |
| 542 | 667 |
| 543 state_handler_->SetHardlockState( | 668 state_handler_->SetHardlockState( |
| 544 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 669 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
| 545 | 670 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 557 state_handler_->ChangeState( | 682 state_handler_->ChangeState( |
| 558 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 683 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 559 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 684 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 560 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 685 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 561 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 686 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 562 lock_handler_->GetAuthType(user_email_)); | 687 lock_handler_->GetAuthType(user_email_)); |
| 563 } | 688 } |
| 564 | 689 |
| 565 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 690 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 566 LockScreenChangeableOnLockAfterHardlockReset) { | 691 LockScreenChangeableOnLockAfterHardlockReset) { |
| 567 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | 692 SetFirstRunCompleteValue(true); |
| 568 state_handler_->ChangeState( | 693 state_handler_->ChangeState( |
| 569 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 694 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 570 | 695 |
| 571 state_handler_->SetHardlockState( | 696 state_handler_->SetHardlockState( |
| 572 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 697 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
| 573 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); | 698 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); |
| 574 | 699 |
| 575 state_handler_->SetHardlockState( | 700 state_handler_->SetHardlockState( |
| 576 EasyUnlockScreenlockStateHandler::NO_HARDLOCK); | 701 EasyUnlockScreenlockStateHandler::NO_HARDLOCK); |
| 577 | 702 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 600 state_handler_->ChangeState( | 725 state_handler_->ChangeState( |
| 601 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 726 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 602 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 727 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 603 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 728 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
| 604 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 729 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 605 lock_handler_->GetAuthType(user_email_)); | 730 lock_handler_->GetAuthType(user_email_)); |
| 606 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 731 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
| 607 } | 732 } |
| 608 | 733 |
| 609 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) { | 734 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) { |
| 610 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | 735 SetFirstRunCompleteValue(true); |
| 611 state_handler_->ChangeState( | 736 state_handler_->ChangeState( |
| 612 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 737 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 613 state_handler_->SetHardlockState( | 738 state_handler_->SetHardlockState( |
| 614 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 739 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
| 615 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); | 740 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); |
| 616 | 741 |
| 617 ScreenlockBridge::Get()->SetLockHandler(NULL); | 742 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 618 lock_handler_.reset(new TestLockHandler(user_email_)); | 743 lock_handler_.reset(new TestLockHandler(user_email_)); |
| 619 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 744 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 620 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 745 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
| 621 | 746 |
| 622 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 747 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 623 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 748 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 624 lock_handler_->GetAuthType(user_email_)); | 749 lock_handler_->GetAuthType(user_email_)); |
| 625 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 750 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 626 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); | 751 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
| 627 | 752 |
| 628 state_handler_->ChangeState( | 753 state_handler_->ChangeState( |
| 629 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 754 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 630 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 755 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 631 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 756 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
| 632 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 757 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 633 lock_handler_->GetAuthType(user_email_)); | 758 lock_handler_->GetAuthType(user_email_)); |
| 634 } | 759 } |
| 635 | 760 |
| 636 } // namespace | 761 } // namespace |
| OLD | NEW |