OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 #include <vector> |
| 7 |
| 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
| 12 #include "chrome/browser/signin/easy_unlock_service.h" |
| 13 #include "chrome/browser/signin/screenlock_bridge.h" |
| 14 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/grit/generated_resources.h" |
| 16 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 17 #include "components/pref_registry/pref_registry_syncable.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/base/l10n/l10n_util.h" |
| 20 |
| 21 namespace { |
| 22 |
| 23 // Resource URLs for icons used by EasyUnlockScreenlockStateHandler. |
| 24 const char kLockedIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_LOCKED"; |
| 25 const char kUnlockedIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_UNLOCKED"; |
| 26 const char kSpinnerIconURL[] = "chrome://theme/IDR_EASY_UNLOCK_SPINNER"; |
| 27 |
| 28 // The expected size of user pod custom icons set by |
| 29 // EasyUnlockScreenlockStateHandler. |
| 30 const int kExpectedIconSize = 27; |
| 31 |
| 32 // Checks if |input| string has any unreplaced placeholders. |
| 33 bool StringHasPlaceholders(const base::string16& input) { |
| 34 std::vector<size_t> offsets; |
| 35 std::vector<base::string16> subst; |
| 36 subst.push_back(base::string16()); |
| 37 |
| 38 base::string16 replaced = ReplaceStringPlaceholders(input, subst, &offsets); |
| 39 return !offsets.empty(); |
| 40 } |
| 41 |
| 42 // Fake lock handler to be used in these tests. |
| 43 class TestLockHandler : public ScreenlockBridge::LockHandler { |
| 44 public: |
| 45 explicit TestLockHandler(const std::string& user_email) |
| 46 : user_email_(user_email), |
| 47 show_icon_count_(0u), |
| 48 auth_type_(OFFLINE_PASSWORD) { |
| 49 } |
| 50 virtual ~TestLockHandler() {} |
| 51 |
| 52 // ScreenlockBridge::LockHandler implementation: |
| 53 virtual void ShowBannerMessage(const base::string16& message) OVERRIDE { |
| 54 ASSERT_FALSE(true) << "Should not be reached."; |
| 55 } |
| 56 |
| 57 virtual void ShowUserPodCustomIcon( |
| 58 const std::string& user_email, |
| 59 const ScreenlockBridge::UserPodCustomIconOptions& icon) OVERRIDE { |
| 60 ASSERT_EQ(user_email_, user_email); |
| 61 ++show_icon_count_; |
| 62 last_custom_icon_ = icon.ToDictionaryValue().Pass(); |
| 63 ValidateCustomIcon(); |
| 64 } |
| 65 |
| 66 virtual void HideUserPodCustomIcon(const std::string& user_email) OVERRIDE { |
| 67 ASSERT_EQ(user_email_, user_email); |
| 68 last_custom_icon_.reset(); |
| 69 } |
| 70 |
| 71 virtual void EnableInput() OVERRIDE { |
| 72 ASSERT_FALSE(true) << "Should not be reached."; |
| 73 } |
| 74 |
| 75 virtual void SetAuthType(const std::string& user_email, |
| 76 AuthType auth_type, |
| 77 const base::string16& auth_value) OVERRIDE { |
| 78 ASSERT_EQ(user_email_, user_email); |
| 79 // Generally, this is allowed, but EasyUnlockScreenlockStateHandler should |
| 80 // avoid resetting the same auth type. |
| 81 EXPECT_NE(auth_type_, auth_type); |
| 82 |
| 83 auth_type_ = auth_type; |
| 84 auth_value_ = auth_value; |
| 85 } |
| 86 |
| 87 virtual AuthType GetAuthType(const std::string& user_email) const OVERRIDE { |
| 88 EXPECT_EQ(user_email_, user_email); |
| 89 return auth_type_; |
| 90 } |
| 91 |
| 92 virtual void Unlock(const std::string& user_email) OVERRIDE { |
| 93 ASSERT_FALSE(true) << "Should not be reached."; |
| 94 } |
| 95 |
| 96 // Utility methods used by tests: |
| 97 |
| 98 // Gets last set auth value. |
| 99 base::string16 GetAuthValue() const { |
| 100 return auth_value_; |
| 101 } |
| 102 |
| 103 // Sets the auth value. |
| 104 void SetAuthValue(const base::string16& value) { |
| 105 auth_value_ = value; |
| 106 } |
| 107 |
| 108 // Returns the number of times an icon was shown since the last call to this |
| 109 // method. |
| 110 size_t GetAndResetShowIconCount() { |
| 111 size_t result = show_icon_count_; |
| 112 show_icon_count_ = 0u; |
| 113 return result; |
| 114 } |
| 115 |
| 116 // Whether the custom icon is set. |
| 117 bool HasCustomIcon() const { |
| 118 return last_custom_icon_; |
| 119 } |
| 120 |
| 121 // If custom icon is set, returns the icon's resource URL. |
| 122 // If there is no icon, or if it doesn't have a resource URL set, returns |
| 123 // an empty string. |
| 124 std::string GetCustomIconURL() const { |
| 125 std::string result; |
| 126 if (last_custom_icon_) |
| 127 last_custom_icon_->GetString("resourceUrl", &result); |
| 128 return result; |
| 129 } |
| 130 |
| 131 // Whether the custom icon is set and it has a tooltip. |
| 132 bool CustomIconHasTooltip() const { |
| 133 return last_custom_icon_ && last_custom_icon_->HasKey("tooltip"); |
| 134 } |
| 135 |
| 136 // Gets the custom icon's tooltip text, if one is set. |
| 137 base::string16 GetCustomIconTooltip() const { |
| 138 base::string16 result; |
| 139 if (last_custom_icon_) |
| 140 last_custom_icon_->GetString("tooltip.text", &result); |
| 141 return result; |
| 142 } |
| 143 |
| 144 // Whether the custom icon's tooltip should be autoshown. If the icon is not |
| 145 // set, or it doesn't have a tooltip, returns false. |
| 146 bool IsCustomIconTooltipAutoshown() const { |
| 147 bool result = false; |
| 148 if (last_custom_icon_) |
| 149 last_custom_icon_->GetBoolean("tooltip.autoshow", &result); |
| 150 return result; |
| 151 } |
| 152 |
| 153 // Returns the custom icon's opacity. If the icon is not set, a negative value |
| 154 // is returned. |
| 155 int GetCustomIconOpacity() const { |
| 156 int result = -1; |
| 157 if (last_custom_icon_) |
| 158 last_custom_icon_->GetInteger("opacity", &result); |
| 159 return result; |
| 160 } |
| 161 |
| 162 // Whether the custom icon is set and if has hardlock capability enabed. |
| 163 bool CustomIconHardlocksOnClick() const { |
| 164 bool result = false; |
| 165 if (last_custom_icon_) |
| 166 last_custom_icon_->GetBoolean("hardlockOnClick", &result); |
| 167 return result; |
| 168 } |
| 169 |
| 170 // Whether the custom icon is set and has an animation set. |
| 171 bool IsCustomIconAnimated() const { |
| 172 return last_custom_icon_ && last_custom_icon_->HasKey("animation"); |
| 173 } |
| 174 |
| 175 private: |
| 176 // Does some sanity checks on the last icon set by |ShowUserPodCustomIcon|. |
| 177 // It will cause a test failure if the icon is not valid. |
| 178 void ValidateCustomIcon() { |
| 179 ASSERT_TRUE(last_custom_icon_.get()); |
| 180 |
| 181 EXPECT_FALSE(last_custom_icon_->HasKey("data")); |
| 182 |
| 183 int height = 0; |
| 184 last_custom_icon_->GetInteger("size.height", &height); |
| 185 EXPECT_EQ(kExpectedIconSize, height); |
| 186 |
| 187 int width = 0; |
| 188 last_custom_icon_->GetInteger("size.width", &width); |
| 189 EXPECT_EQ(kExpectedIconSize, width); |
| 190 |
| 191 if (last_custom_icon_->HasKey("animation")) { |
| 192 int animation_resource_width = -1; |
| 193 EXPECT_TRUE(last_custom_icon_->GetInteger("animation.resourceWidth", |
| 194 &animation_resource_width)); |
| 195 EXPECT_GT(animation_resource_width, kExpectedIconSize); |
| 196 EXPECT_EQ(0, animation_resource_width % kExpectedIconSize); |
| 197 EXPECT_TRUE( |
| 198 last_custom_icon_->GetInteger("animation.frameLengthMs", NULL)); |
| 199 } |
| 200 |
| 201 if (last_custom_icon_->HasKey("tooltip")) { |
| 202 base::string16 tooltip; |
| 203 EXPECT_TRUE(last_custom_icon_->GetString("tooltip.text", &tooltip)); |
| 204 EXPECT_FALSE(tooltip.empty()); |
| 205 EXPECT_FALSE(StringHasPlaceholders(tooltip)); |
| 206 } |
| 207 } |
| 208 |
| 209 // The fake user email used in test. All methods called on |this| should be |
| 210 // associated with this user. |
| 211 const std::string user_email_; |
| 212 |
| 213 // The last icon set using |SetUserPodCustomIcon|. Call to |
| 214 // |HideUserPodcustomIcon| resets it. |
| 215 scoped_ptr<base::DictionaryValue> last_custom_icon_; |
| 216 size_t show_icon_count_; |
| 217 |
| 218 // Auth type and value set using |SetAuthType|. |
| 219 AuthType auth_type_; |
| 220 base::string16 auth_value_; |
| 221 |
| 222 DISALLOW_COPY_AND_ASSIGN(TestLockHandler); |
| 223 }; |
| 224 |
| 225 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { |
| 226 public: |
| 227 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {} |
| 228 virtual ~EasyUnlockScreenlockStateHandlerTest() {} |
| 229 |
| 230 virtual void SetUp() OVERRIDE { |
| 231 pref_service_.reset(new TestingPrefServiceSyncable()); |
| 232 |
| 233 // The preference used to determine if easy unlock was previously used by |
| 234 // the user on the device ought to be registered by the EasyUnlockService. |
| 235 EasyUnlockService::RegisterProfilePrefs(pref_service_->registry()); |
| 236 |
| 237 // Create and inject fake lock handler to the screenlock bridge. |
| 238 lock_handler_.reset(new TestLockHandler(user_email_)); |
| 239 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get(); |
| 240 screenlock_bridge->SetLockHandler(lock_handler_.get()); |
| 241 |
| 242 // Create the screenlock state handler object that will be tested. |
| 243 state_handler_.reset( |
| 244 new EasyUnlockScreenlockStateHandler(user_email_, |
| 245 pref_service_.get(), |
| 246 screenlock_bridge)); |
| 247 } |
| 248 |
| 249 virtual void TearDown() OVERRIDE { |
| 250 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 251 lock_handler_.reset(); |
| 252 state_handler_.reset(); |
| 253 } |
| 254 |
| 255 protected: |
| 256 // The state handler that is being tested. |
| 257 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; |
| 258 |
| 259 // The user associated with |state_handler_|. |
| 260 const std::string user_email_; |
| 261 |
| 262 // Faked lock handler given to ScreenlockBridge during the test. Abstracts |
| 263 // the screen lock UI. |
| 264 scoped_ptr<TestLockHandler> lock_handler_; |
| 265 |
| 266 // The user's preferences. |
| 267 scoped_ptr<TestingPrefServiceSyncable> pref_service_; |
| 268 }; |
| 269 |
| 270 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedInitialRun) { |
| 271 state_handler_->ChangeState( |
| 272 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 273 |
| 274 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 275 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 276 lock_handler_->GetAuthType(user_email_)); |
| 277 |
| 278 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 279 EXPECT_EQ(kUnlockedIconURL, lock_handler_->GetCustomIconURL()); |
| 280 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
| 281 EXPECT_TRUE(lock_handler_->IsCustomIconTooltipAutoshown()); |
| 282 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
| 283 EXPECT_FALSE(lock_handler_->IsCustomIconAnimated()); |
| 284 EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity()); |
| 285 |
| 286 state_handler_->ChangeState( |
| 287 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 288 // Duplicated state change should be ignored. |
| 289 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 290 } |
| 291 |
| 292 TEST_F(EasyUnlockScreenlockStateHandlerTest, AuthenticatedNotInitialRun) { |
| 293 // Update preference for showing tutorial. |
| 294 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); |
| 295 |
| 296 state_handler_->ChangeState( |
| 297 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 298 |
| 299 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 300 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 301 lock_handler_->GetAuthType(user_email_)); |
| 302 |
| 303 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 304 EXPECT_EQ(kUnlockedIconURL, lock_handler_->GetCustomIconURL()); |
| 305 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
| 306 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); |
| 307 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
| 308 EXPECT_FALSE(lock_handler_->IsCustomIconAnimated()); |
| 309 EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity()); |
| 310 } |
| 311 |
| 312 TEST_F(EasyUnlockScreenlockStateHandlerTest, BluetoothConnecting) { |
| 313 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); |
| 314 state_handler_->ChangeState( |
| 315 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 316 |
| 317 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 318 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 319 lock_handler_->GetAuthType(user_email_)); |
| 320 |
| 321 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 322 EXPECT_EQ(kSpinnerIconURL, lock_handler_->GetCustomIconURL()); |
| 323 EXPECT_FALSE(lock_handler_->CustomIconHasTooltip()); |
| 324 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
| 325 EXPECT_TRUE(lock_handler_->IsCustomIconAnimated()); |
| 326 EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity()); |
| 327 |
| 328 state_handler_->ChangeState( |
| 329 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 330 // Duplicated state change should be ignored. |
| 331 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 332 } |
| 333 |
| 334 TEST_F(EasyUnlockScreenlockStateHandlerTest, PhoneLocked) { |
| 335 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); |
| 336 state_handler_->ChangeState( |
| 337 EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 338 |
| 339 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 340 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 341 lock_handler_->GetAuthType(user_email_)); |
| 342 |
| 343 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 344 EXPECT_EQ(kLockedIconURL, lock_handler_->GetCustomIconURL()); |
| 345 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
| 346 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); |
| 347 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
| 348 EXPECT_FALSE(lock_handler_->IsCustomIconAnimated()); |
| 349 EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity()); |
| 350 |
| 351 state_handler_->ChangeState( |
| 352 EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED); |
| 353 // Duplicated state change should be ignored. |
| 354 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 355 } |
| 356 |
| 357 TEST_F(EasyUnlockScreenlockStateHandlerTest, PhoneNotAuthenticated) { |
| 358 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); |
| 359 state_handler_->ChangeState( |
| 360 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); |
| 361 |
| 362 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 363 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 364 lock_handler_->GetAuthType(user_email_)); |
| 365 |
| 366 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 367 EXPECT_EQ(kLockedIconURL, lock_handler_->GetCustomIconURL()); |
| 368 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()); |
| 369 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()); |
| 370 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
| 371 EXPECT_FALSE(lock_handler_->IsCustomIconAnimated()); |
| 372 EXPECT_EQ(100, lock_handler_->GetCustomIconOpacity()); |
| 373 |
| 374 state_handler_->ChangeState( |
| 375 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); |
| 376 // Duplicated state change should be ignored. |
| 377 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 378 } |
| 379 |
| 380 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatesWithOpaqueIcons) { |
| 381 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); |
| 382 |
| 383 std::vector<EasyUnlockScreenlockStateHandler::State> states; |
| 384 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH); |
| 385 states.push_back(EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
| 386 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED); |
| 387 states.push_back(EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE); |
| 388 |
| 389 for (size_t i = 0; i < states.size(); ++i) { |
| 390 state_handler_->ChangeState(states[i]); |
| 391 |
| 392 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()) |
| 393 << "State: " << states[i]; |
| 394 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 395 lock_handler_->GetAuthType(user_email_)) |
| 396 << "State: " << states[i]; |
| 397 |
| 398 ASSERT_TRUE(lock_handler_->HasCustomIcon()) |
| 399 << "State: " << states[i]; |
| 400 EXPECT_EQ(kLockedIconURL, lock_handler_->GetCustomIconURL()) |
| 401 << "State: " << states[i]; |
| 402 EXPECT_TRUE(lock_handler_->CustomIconHasTooltip()) |
| 403 << "State: " << states[i]; |
| 404 EXPECT_FALSE(lock_handler_->IsCustomIconTooltipAutoshown()) |
| 405 << "State: " << states[i]; |
| 406 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()) |
| 407 << "State: " << states[i]; |
| 408 EXPECT_FALSE(lock_handler_->IsCustomIconAnimated()) |
| 409 << "State: " << states[i]; |
| 410 EXPECT_EQ(50, lock_handler_->GetCustomIconOpacity()) |
| 411 << "State: " << states[i]; |
| 412 |
| 413 state_handler_->ChangeState(states[i]); |
| 414 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()) |
| 415 << "State: " << states[i]; |
| 416 } |
| 417 } |
| 418 |
| 419 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 420 LockScreenClearedOnStateHandlerDestruction) { |
| 421 state_handler_->ChangeState( |
| 422 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 423 |
| 424 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 425 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 426 lock_handler_->GetAuthType(user_email_)); |
| 427 |
| 428 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 429 |
| 430 state_handler_.reset(); |
| 431 |
| 432 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 433 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 434 lock_handler_->GetAuthType(user_email_)); |
| 435 |
| 436 ASSERT_FALSE(lock_handler_->HasCustomIcon()); |
| 437 } |
| 438 |
| 439 TEST_F(EasyUnlockScreenlockStateHandlerTest, StatePreservedWhenScreenUnlocks) { |
| 440 state_handler_->ChangeState( |
| 441 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 442 |
| 443 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 444 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 445 lock_handler_->GetAuthType(user_email_)); |
| 446 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 447 |
| 448 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 449 lock_handler_.reset(new TestLockHandler(user_email_)); |
| 450 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 451 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
| 452 |
| 453 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 454 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 455 lock_handler_->GetAuthType(user_email_)); |
| 456 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 457 } |
| 458 |
| 459 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangeWhileScreenUnlocked) { |
| 460 state_handler_->ChangeState( |
| 461 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 462 |
| 463 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 464 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 465 lock_handler_->GetAuthType(user_email_)); |
| 466 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 467 |
| 468 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 469 lock_handler_.reset(new TestLockHandler(user_email_)); |
| 470 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 471 |
| 472 state_handler_->ChangeState( |
| 473 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 474 |
| 475 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
| 476 |
| 477 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 478 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 479 lock_handler_->GetAuthType(user_email_)); |
| 480 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 481 EXPECT_TRUE(lock_handler_->IsCustomIconAnimated()); |
| 482 } |
| 483 |
| 484 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 485 HardlockEnabledAfterInitialUnlock) { |
| 486 state_handler_->ChangeState( |
| 487 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 488 |
| 489 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 490 EXPECT_FALSE(lock_handler_->CustomIconHardlocksOnClick()); |
| 491 |
| 492 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 493 lock_handler_.reset(new TestLockHandler(user_email_)); |
| 494 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
| 495 |
| 496 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 497 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
| 498 } |
| 499 |
| 500 TEST_F(EasyUnlockScreenlockStateHandlerTest, InactiveStateHidesIcon) { |
| 501 state_handler_->ChangeState( |
| 502 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 503 |
| 504 ASSERT_TRUE(lock_handler_->HasCustomIcon()); |
| 505 |
| 506 state_handler_->ChangeState( |
| 507 EasyUnlockScreenlockStateHandler::STATE_INACTIVE); |
| 508 |
| 509 ASSERT_FALSE(lock_handler_->HasCustomIcon()); |
| 510 } |
| 511 |
| 512 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 513 AuthenticatedStateClearsPreviousAuthValue) { |
| 514 state_handler_->ChangeState( |
| 515 EasyUnlockScreenlockStateHandler::STATE_INACTIVE); |
| 516 |
| 517 lock_handler_->SetAuthValue(base::ASCIIToUTF16("xxx")); |
| 518 |
| 519 state_handler_->ChangeState( |
| 520 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 521 |
| 522 EXPECT_EQ(l10n_util::GetStringUTF16( |
| 523 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE), |
| 524 lock_handler_->GetAuthValue()); |
| 525 |
| 526 state_handler_->ChangeState( |
| 527 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
| 528 |
| 529 EXPECT_EQ(base::string16(), lock_handler_->GetAuthValue()); |
| 530 } |
| 531 |
| 532 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 533 ChangingStateDoesNotAffectAuthValueIfAuthTypeDoesNotChange) { |
| 534 lock_handler_->SetAuthValue(base::ASCIIToUTF16("xxx")); |
| 535 |
| 536 state_handler_->ChangeState( |
| 537 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
| 538 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); |
| 539 |
| 540 state_handler_->ChangeState( |
| 541 EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED); |
| 542 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); |
| 543 |
| 544 state_handler_->ChangeState( |
| 545 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 546 EXPECT_EQ(base::ASCIIToUTF16("xxx"), lock_handler_->GetAuthValue()); |
| 547 EXPECT_TRUE(lock_handler_->IsCustomIconAnimated()); |
| 548 } |
| 549 |
| 550 TEST_F(EasyUnlockScreenlockStateHandlerTest, StateChangesIgnoredIfHardlocked) { |
| 551 state_handler_->ChangeState( |
| 552 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 553 |
| 554 lock_handler_->SetAuthType( |
| 555 user_email_, |
| 556 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, |
| 557 base::string16()); |
| 558 lock_handler_->HideUserPodCustomIcon(user_email_); |
| 559 |
| 560 state_handler_->ChangeState( |
| 561 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
| 562 EXPECT_FALSE(lock_handler_->HasCustomIcon()); |
| 563 |
| 564 state_handler_->ChangeState( |
| 565 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 566 EXPECT_FALSE(lock_handler_->HasCustomIcon()); |
| 567 EXPECT_EQ(ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, |
| 568 lock_handler_->GetAuthType(user_email_)); |
| 569 } |
| 570 |
| 571 TEST_F(EasyUnlockScreenlockStateHandlerTest, |
| 572 LockScreenChangeableAfterHardlockUnlocked) { |
| 573 state_handler_->ChangeState( |
| 574 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 575 |
| 576 lock_handler_->SetAuthType( |
| 577 user_email_, |
| 578 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, |
| 579 base::string16()); |
| 580 lock_handler_->HideUserPodCustomIcon(user_email_); |
| 581 |
| 582 state_handler_->ChangeState( |
| 583 EasyUnlockScreenlockStateHandler::STATE_NO_PHONE); |
| 584 EXPECT_FALSE(lock_handler_->HasCustomIcon()); |
| 585 |
| 586 ScreenlockBridge::Get()->SetLockHandler(NULL); |
| 587 lock_handler_.reset(new TestLockHandler(user_email_)); |
| 588 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
| 589 ScreenlockBridge::Get()->SetLockHandler(lock_handler_.get()); |
| 590 |
| 591 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 592 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
| 593 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 594 lock_handler_->GetAuthType(user_email_)); |
| 595 |
| 596 state_handler_->ChangeState( |
| 597 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
| 598 EXPECT_EQ(1u, lock_handler_->GetAndResetShowIconCount()); |
| 599 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
| 600 EXPECT_EQ(ScreenlockBridge::LockHandler::USER_CLICK, |
| 601 lock_handler_->GetAuthType(user_email_)); |
| 602 EXPECT_TRUE(lock_handler_->CustomIconHardlocksOnClick()); |
| 603 } |
| 604 |
| 605 } // namespace |
OLD | NEW |