| 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/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 11 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
| 12 #include "chrome/browser/signin/easy_unlock_service.h" | 12 #include "chrome/browser/signin/easy_unlock_service.h" |
| 13 #include "chrome/browser/signin/screenlock_bridge.h" | 13 #include "chrome/browser/signin/screenlock_bridge.h" |
| 14 #include "chrome/common/pref_names.h" | |
| 15 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 16 #include "chrome/test/base/testing_pref_service_syncable.h" | 15 #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" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 | 20 |
| 23 // Icons used by EasyUnlockScreenlockStateHandler. The icon id values are the | 21 // Icons used by EasyUnlockScreenlockStateHandler. The icon id values are the |
| 24 // same as the ones set by ScreenlockBridge. | 22 // same as the ones set by ScreenlockBridge. |
| 25 const char kLockedIconId[] = "locked"; | 23 const char kLockedIconId[] = "locked"; |
| 26 const char kUnlockedIconId[] = "unlocked"; | 24 const char kUnlockedIconId[] = "unlocked"; |
| 27 const char kSpinnerIconId[] = "spinner"; | 25 const char kSpinnerIconId[] = "spinner"; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 191 |
| 194 DISALLOW_COPY_AND_ASSIGN(TestLockHandler); | 192 DISALLOW_COPY_AND_ASSIGN(TestLockHandler); |
| 195 }; | 193 }; |
| 196 | 194 |
| 197 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { | 195 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { |
| 198 public: | 196 public: |
| 199 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {} | 197 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {} |
| 200 virtual ~EasyUnlockScreenlockStateHandlerTest() {} | 198 virtual ~EasyUnlockScreenlockStateHandlerTest() {} |
| 201 | 199 |
| 202 virtual void SetUp() override { | 200 virtual void SetUp() override { |
| 203 pref_service_.reset(new TestingPrefServiceSyncable()); | 201 TestingBrowserProcess::GetGlobal()->SetApplicationLocale("en-US"); |
| 204 | |
| 205 // 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. | |
| 207 EasyUnlockService::RegisterProfilePrefs(pref_service_->registry()); | |
| 208 | 202 |
| 209 // Create and inject fake lock handler to the screenlock bridge. | 203 // Create and inject fake lock handler to the screenlock bridge. |
| 210 lock_handler_.reset(new TestLockHandler(user_email_)); | 204 lock_handler_.reset(new TestLockHandler(user_email_)); |
| 211 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get(); | 205 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get(); |
| 212 screenlock_bridge->SetLockHandler(lock_handler_.get()); | 206 screenlock_bridge->SetLockHandler(lock_handler_.get()); |
| 213 | 207 |
| 214 // Create the screenlock state handler object that will be tested. | 208 // Create the screenlock state handler object that will be tested. |
| 215 state_handler_.reset(new EasyUnlockScreenlockStateHandler( | 209 state_handler_.reset(new EasyUnlockScreenlockStateHandler( |
| 216 user_email_, | 210 user_email_, |
| 217 EasyUnlockScreenlockStateHandler::NO_HARDLOCK, | 211 EasyUnlockScreenlockStateHandler::NO_HARDLOCK, |
| 218 pref_service_.get(), | |
| 219 screenlock_bridge)); | 212 screenlock_bridge)); |
| 220 } | 213 } |
| 221 | 214 |
| 222 virtual void TearDown() override { | 215 virtual void TearDown() override { |
| 223 ScreenlockBridge::Get()->SetLockHandler(NULL); | 216 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 224 lock_handler_.reset(); | 217 lock_handler_.reset(); |
| 225 state_handler_.reset(); | 218 state_handler_.reset(); |
| 226 } | 219 } |
| 227 | 220 |
| 228 protected: | 221 protected: |
| 229 // The state handler that is being tested. | 222 // The state handler that is being tested. |
| 230 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; | 223 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; |
| 231 | 224 |
| 232 // The user associated with |state_handler_|. | 225 // The user associated with |state_handler_|. |
| 233 const std::string user_email_; | 226 const std::string user_email_; |
| 234 | 227 |
| 235 // Faked lock handler given to ScreenlockBridge during the test. Abstracts | 228 // Faked lock handler given to ScreenlockBridge during the test. Abstracts |
| 236 // the screen lock UI. | 229 // the screen lock UI. |
| 237 scoped_ptr<TestLockHandler> lock_handler_; | 230 scoped_ptr<TestLockHandler> lock_handler_; |
| 238 | |
| 239 // The user's preferences. | |
| 240 scoped_ptr<TestingPrefServiceSyncable> pref_service_; | |
| 241 }; | 231 }; |
| 242 | 232 |
| 243 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedInitialRun) { | 233 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedTrialRun) { |
| 234 state_handler_->SetTrialRun(); |
| 244 state_handler_->ChangeState( | 235 state_handler_->ChangeState( |
| 245 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 236 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 246 | 237 |
| 247 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 238 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 248 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 239 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 249 lock_handler_->GetAuthType(user_email_)); | 240 lock_handler_->GetAuthType(user_email_)); |
| 250 | 241 |
| 251 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 242 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 252 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); | 243 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); |
| 253 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 244 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
| 254 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); | 245 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
| 255 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); | 246 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
| 256 | 247 |
| 257 state_handler_->ChangeState( | 248 state_handler_->ChangeState( |
| 258 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 249 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 259 // Duplicated state change should be ignored. | 250 // Duplicated state change should be ignored. |
| 260 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 251 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 261 } | 252 } |
| 262 | 253 |
| 263 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) { | 254 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) { |
| 264 // Update preference for showing tutorial. | |
| 265 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | |
| 266 | |
| 267 state_handler_->ChangeState( | 255 state_handler_->ChangeState( |
| 268 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 256 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 269 | 257 |
| 270 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 258 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 271 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 259 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 272 lock_handler_->GetAuthType(user_email_)); | 260 lock_handler_->GetAuthType(user_email_)); |
| 273 | 261 |
| 274 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 262 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 275 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); | 263 EXPECT_EQ(kUnlockedIconId, lock_handler_->GetCustomIconId()); |
| 276 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 264 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
| 277 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); | 265 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); |
| 278 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 266 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
| 279 } | 267 } |
| 280 | 268 |
| 281 TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) { | 269 TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) { |
| 282 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | |
| 283 state_handler_->ChangeState( | 270 state_handler_->ChangeState( |
| 284 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 271 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 285 | 272 |
| 286 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 273 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 287 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 274 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 288 lock_handler_->GetAuthType(user_email_)); | 275 lock_handler_->GetAuthType(user_email_)); |
| 289 | 276 |
| 290 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 277 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 291 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); | 278 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); |
| 292 EXPECT_FALSE(lock_handler_->CustomIconHasTooltip()); | 279 EXPECT_FALSE(lock_handler_->CustomIconHasTooltip()); |
| 293 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 280 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
| 294 | 281 |
| 295 state_handler_->ChangeState( | 282 state_handler_->ChangeState( |
| 296 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 283 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 297 // Duplicated state change should be ignored. | 284 // Duplicated state change should be ignored. |
| 298 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 285 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 299 } | 286 } |
| 300 | 287 |
| 301 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedState) { | 288 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedState) { |
| 302 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | |
| 303 state_handler_->ChangeState( | 289 state_handler_->ChangeState( |
| 304 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 290 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 305 | 291 |
| 306 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 292 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 307 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 293 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 308 lock_handler_->GetAuthType(user_email_)); | 294 lock_handler_->GetAuthType(user_email_)); |
| 309 | 295 |
| 310 state_handler_->SetHardlockState( | 296 state_handler_->SetHardlockState( |
| 311 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 297 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
| 312 | 298 |
| 313 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 299 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 314 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 300 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 315 lock_handler_->GetAuthType(user_email_)); | 301 lock_handler_->GetAuthType(user_email_)); |
| 316 | 302 |
| 317 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 303 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 318 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); | 304 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
| 319 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); | 305 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
| 306 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
| 320 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); | 307 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
| 321 | 308 |
| 322 state_handler_->SetHardlockState( | 309 state_handler_->SetHardlockState( |
| 323 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 310 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
| 324 | 311 |
| 325 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 312 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 326 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 313 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 327 } | 314 } |
| 328 | 315 |
| 329 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedStateNoPairing) { | 316 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockedStateNoPairing) { |
| 330 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | |
| 331 state_handler_->ChangeState( | 317 state_handler_->ChangeState( |
| 332 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 318 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 333 | 319 |
| 334 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 320 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 335 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 321 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 336 lock_handler_->GetAuthType(user_email_)); | 322 lock_handler_->GetAuthType(user_email_)); |
| 337 | 323 |
| 338 state_handler_->SetHardlockState( | 324 state_handler_->SetHardlockState( |
| 339 EasyUnlockScreenlockStateHandler::NO_PAIRING); | 325 EasyUnlockScreenlockStateHandler::NO_PAIRING); |
| 340 | 326 |
| 341 EXPECT_FALSE(lock_handler_->HasCustomIcon()); | 327 EXPECT_FALSE(lock_handler_->HasCustomIcon()); |
| 342 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 328 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 343 lock_handler_->GetAuthType(user_email_)); | 329 lock_handler_->GetAuthType(user_email_)); |
| 344 } | 330 } |
| 345 | 331 |
| 346 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) { | 332 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon) { |
| 347 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | |
| 348 | |
| 349 std::vector<EasyUnlockScreenlockStateHandler::State> states; | 333 std::vector<EasyUnlockScreenlockStateHandler::State> states; |
| 350 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); | 334 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); |
| 351 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); | 335 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
| 352 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); | 336 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); |
| 353 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); | 337 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); |
| 354 states.push_back( | 338 states.push_back( |
| 355 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); | 339 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); |
| 356 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); | 340 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 357 | 341 |
| 358 for (size_t i = 0; i < states.size(); ++i) { | 342 for (size_t i = 0; i < states.size(); ++i) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 374 << "State: " << states[i]; | 358 << "State: " << states[i]; |
| 375 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) | 359 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) |
| 376 << "State: " << states[i]; | 360 << "State: " << states[i]; |
| 377 | 361 |
| 378 state_handler_->ChangeState(states[i]); | 362 state_handler_->ChangeState(states[i]); |
| 379 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()) | 363 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()) |
| 380 << "State: " << states[i]; | 364 << "State: " << states[i]; |
| 381 } | 365 } |
| 382 } | 366 } |
| 383 | 367 |
| 368 // Verifies tooltips are autoshown on initial run. |
| 369 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithLockedIcon_TrialRun) { |
| 370 state_handler_->SetTrialRun(); |
| 371 |
| 372 std::vector<EasyUnlockScreenlockStateHandler::State> states; |
| 373 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); |
| 374 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
| 375 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); |
| 376 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); |
| 377 states.push_back( |
| 378 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); |
| 379 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 380 |
| 381 for (size_t i = 0; i < states.size(); ++i) { |
| 382 state_handler_->ChangeState(states[i]); |
| 383 ASSERT_TRUE(lock_handler_->HasCustomIcon()) |
| 384 << "State: " << states[i]; |
| 385 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()) |
| 386 << "State: " << states[i]; |
| 387 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()) |
| 388 << "State: " << states[i]; |
| 389 } |
| 390 |
| 391 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 392 lock_handler_.reset(new TestLockHandler(user_email_)); |
| 393 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 394 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
| 395 |
| 396 // After the screen unlocks the tooltips should not be shown anymore. |
| 397 for (size_t i = 0; i < states.size(); ++i) { |
| 398 state_handler_->ChangeState(states[i]); |
| 399 ASSERT_TRUE(lock_handler_->HasCustomIcon()) |
| 400 << "State: " << states[i]; |
| 401 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()) |
| 402 << "State: " << states[i]; |
| 403 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()) |
| 404 << "State: " << states[i]; |
| 405 } |
| 406 } |
| 407 |
| 408 TEST_F(EasyUnlockScreenlockStateHandlerTest, SettingTrialRunUpdatesUI) { |
| 409 state_handler_->ChangeState( |
| 410 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 411 |
| 412 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 413 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 414 lock_handler_->GetAuthType(user_email_)); |
| 415 |
| 416 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 417 ASSERT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); |
| 418 |
| 419 state_handler_->SetTrialRun(); |
| 420 |
| 421 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 422 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 423 lock_handler_->GetAuthType(user_email_)); |
| 424 |
| 425 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 426 ASSERT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
| 427 } |
| 428 |
| 384 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 429 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 385 LockScreenClearedOnStateHandlerDestruction) { | 430 LockScreenClearedOnStateHandlerDestruction) { |
| 386 state_handler_->ChangeState( | 431 state_handler_->ChangeState( |
| 387 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 432 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 388 | 433 |
| 389 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 434 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 390 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 435 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 391 lock_handler_->GetAuthType(user_email_)); | 436 lock_handler_->GetAuthType(user_email_)); |
| 392 | 437 |
| 393 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 438 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 486 |
| 442 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 487 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 443 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 488 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 444 lock_handler_->GetAuthType(user_email_)); | 489 lock_handler_->GetAuthType(user_email_)); |
| 445 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 490 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 446 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); | 491 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); |
| 447 } | 492 } |
| 448 | 493 |
| 449 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 494 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 450 HardlockEnabledAfterInitialUnlock) { | 495 HardlockEnabledAfterInitialUnlock) { |
| 496 state_handler_->SetTrialRun(); |
| 497 |
| 451 std::vector<EasyUnlockScreenlockStateHandler::State> states; | 498 std::vector<EasyUnlockScreenlockStateHandler::State> states; |
| 452 states.push_back( | 499 states.push_back( |
| 453 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 500 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 454 states.push_back( | 501 states.push_back( |
| 455 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); | 502 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); |
| 456 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); | 503 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); |
| 457 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); | 504 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
| 458 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); | 505 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); |
| 459 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); | 506 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); |
| 460 // This one should go last as changing state to AUTHENTICATED enables hard | 507 // This one should go last as changing state to AUTHENTICATED enables hard |
| (...skipping 12 matching lines...) Expand all Loading... |
| 473 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 520 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
| 474 | 521 |
| 475 for (size_t i = 0; i < states.size(); ++i) { | 522 for (size_t i = 0; i < states.size(); ++i) { |
| 476 state_handler_->ChangeState(states[i]); | 523 state_handler_->ChangeState(states[i]); |
| 477 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i]; | 524 ASSERT_TRUE(lock_handler_->HasCustomIcon()) << "State: " << states[i]; |
| 478 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) | 525 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()) |
| 479 << "State: " << states[i]; | 526 << "State: " << states[i]; |
| 480 } | 527 } |
| 481 } | 528 } |
| 482 | 529 |
| 530 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 531 NoPairingHardlockClearsIcon) { |
| 532 state_handler_->ChangeState( |
| 533 EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 534 |
| 535 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 536 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 537 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
| 538 |
| 539 state_handler_->SetHardlockState( |
| 540 EasyUnlockScreenlockStateHandler::NO_PAIRING); |
| 541 |
| 542 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 543 ASSERT_FALSE(lock_handler_->HasCustomIcon()); |
| 544 } |
| 545 |
| 546 TEST_F(EasyUnlockScreenlockStateHandlerTest, PairingChangedHardlock) { |
| 547 state_handler_->ChangeState( |
| 548 EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 549 |
| 550 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 551 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 552 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
| 553 |
| 554 state_handler_->SetHardlockState( |
| 555 EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); |
| 556 |
| 557 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 558 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 559 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
| 560 |
| 561 state_handler_->ChangeState( |
| 562 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 563 |
| 564 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 565 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 566 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
| 567 } |
| 568 |
| 569 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 570 PairingChangedHardlockIneffectiveOnInitialRun) { |
| 571 state_handler_->SetTrialRun(); |
| 572 |
| 573 state_handler_->ChangeState( |
| 574 EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 575 |
| 576 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 577 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 578 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
| 579 |
| 580 state_handler_->SetHardlockState( |
| 581 EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); |
| 582 |
| 583 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 584 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 585 EXPECT_EQ(kLockedIconId, lock_handler_->GetCustomIconId()); |
| 586 } |
| 587 |
| 483 TEST_F(EasyUnlockScreenlockStateHandlerTest, InactiveStateHidesIcon) { | 588 TEST_F(EasyUnlockScreenlockStateHandlerTest, InactiveStateHidesIcon) { |
| 484 state_handler_->ChangeState( | 589 state_handler_->ChangeState( |
| 485 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 590 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 486 | 591 |
| 487 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 592 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 488 | 593 |
| 489 state_handler_->ChangeState( | 594 state_handler_->ChangeState( |
| 490 EasyUnlockScreenlockStateHandler::STATE_INACTIVE); | 595 EasyUnlockScreenlockStateHandler::STATE_INACTIVE); |
| 491 | 596 |
| 492 ASSERT_FALSE(lock_handler_->HasCustomIcon()); | 597 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()); | 630 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); |
| 526 | 631 |
| 527 state_handler_->ChangeState( | 632 state_handler_->ChangeState( |
| 528 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 633 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 529 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); | 634 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); |
| 530 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 635 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 531 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); | 636 EXPECT_EQ(kSpinnerIconId, lock_handler_->GetCustomIconId()); |
| 532 } | 637 } |
| 533 | 638 |
| 534 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) { | 639 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) { |
| 535 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | |
| 536 state_handler_->ChangeState( | 640 state_handler_->ChangeState( |
| 537 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 641 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 538 | 642 |
| 539 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 643 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 540 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 644 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 541 lock_handler_->GetAuthType(user_email_)); | 645 lock_handler_->GetAuthType(user_email_)); |
| 542 | 646 |
| 543 state_handler_->SetHardlockState( | 647 state_handler_->SetHardlockState( |
| 544 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 648 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
| 545 | 649 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 557 state_handler_->ChangeState( | 661 state_handler_->ChangeState( |
| 558 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 662 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 559 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 663 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 560 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 664 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 561 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 665 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 562 lock_handler_->GetAuthType(user_email_)); | 666 lock_handler_->GetAuthType(user_email_)); |
| 563 } | 667 } |
| 564 | 668 |
| 565 TEST_F(EasyUnlockScreenlockStateHandlerTest, | 669 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 566 LockScreenChangeableOnLockAfterHardlockReset) { | 670 LockScreenChangeableOnLockAfterHardlockReset) { |
| 567 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | |
| 568 state_handler_->ChangeState( | 671 state_handler_->ChangeState( |
| 569 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 672 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 570 | 673 |
| 571 state_handler_->SetHardlockState( | 674 state_handler_->SetHardlockState( |
| 572 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 675 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
| 573 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); | 676 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); |
| 574 | 677 |
| 575 state_handler_->SetHardlockState( | 678 state_handler_->SetHardlockState( |
| 576 EasyUnlockScreenlockStateHandler::NO_HARDLOCK); | 679 EasyUnlockScreenlockStateHandler::NO_HARDLOCK); |
| 577 | 680 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 600 state_handler_->ChangeState( | 703 state_handler_->ChangeState( |
| 601 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 704 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 602 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 705 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 603 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 706 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
| 604 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, | 707 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 605 lock_handler_->GetAuthType(user_email_)); | 708 lock_handler_->GetAuthType(user_email_)); |
| 606 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); | 709 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
| 607 } | 710 } |
| 608 | 711 |
| 609 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) { | 712 TEST_F(EasyUnlockScreenlockStateHandlerTest, HardlockStatePersistsOverUnlocks) { |
| 610 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | |
| 611 state_handler_->ChangeState( | 713 state_handler_->ChangeState( |
| 612 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 714 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 613 state_handler_->SetHardlockState( | 715 state_handler_->SetHardlockState( |
| 614 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); | 716 EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
| 615 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); | 717 EXPECT_EQ(2u, lock_handler_->GetAndResetShowIconCount()); |
| 616 | 718 |
| 617 ScreenlockBridge::Get()->SetLockHandler(NULL); | 719 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 618 lock_handler_.reset(new TestLockHandler(user_email_)); | 720 lock_handler_.reset(new TestLockHandler(user_email_)); |
| 619 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 721 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 620 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); | 722 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
| 621 | 723 |
| 622 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); | 724 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 623 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 725 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 624 lock_handler_->GetAuthType(user_email_)); | 726 lock_handler_->GetAuthType(user_email_)); |
| 625 ASSERT_TRUE(lock_handler_->HasCustomIcon()); | 727 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 626 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); | 728 EXPECT_EQ(kHardlockedIconId, lock_handler_->GetCustomIconId()); |
| 627 | 729 |
| 628 state_handler_->ChangeState( | 730 state_handler_->ChangeState( |
| 629 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 731 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 630 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 732 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 631 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 733 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
| 632 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 734 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 633 lock_handler_->GetAuthType(user_email_)); | 735 lock_handler_->GetAuthType(user_email_)); |
| 634 } | 736 } |
| 635 | 737 |
| 636 } // namespace | 738 } // namespace |
| OLD | NEW |