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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 class TestLockHandler : public ScreenlockBridge::LockHandler { | 41 class TestLockHandler : public ScreenlockBridge::LockHandler { |
42 public: | 42 public: |
43 explicit TestLockHandler(const std::string& user_email) | 43 explicit TestLockHandler(const std::string& user_email) |
44 : user_email_(user_email), | 44 : user_email_(user_email), |
45 show_icon_count_(0u), | 45 show_icon_count_(0u), |
46 auth_type_(OFFLINE_PASSWORD) { | 46 auth_type_(OFFLINE_PASSWORD) { |
47 } | 47 } |
48 virtual ~TestLockHandler() {} | 48 virtual ~TestLockHandler() {} |
49 | 49 |
50 // ScreenlockBridge::LockHandler implementation: | 50 // ScreenlockBridge::LockHandler implementation: |
51 virtual void ShowBannerMessage(const base::string16& message) OVERRIDE { | 51 virtual void ShowBannerMessage(const base::string16& message) override { |
52 ASSERT_FALSE(true) << "Should not be reached."; | 52 ASSERT_FALSE(true) << "Should not be reached."; |
53 } | 53 } |
54 | 54 |
55 virtual void ShowUserPodCustomIcon( | 55 virtual void ShowUserPodCustomIcon( |
56 const std::string& user_email, | 56 const std::string& user_email, |
57 const ScreenlockBridge::UserPodCustomIconOptions& icon) OVERRIDE { | 57 const ScreenlockBridge::UserPodCustomIconOptions& icon) override { |
58 ASSERT_EQ(user_email_, user_email); | 58 ASSERT_EQ(user_email_, user_email); |
59 ++show_icon_count_; | 59 ++show_icon_count_; |
60 last_custom_icon_ = icon.ToDictionaryValue().Pass(); | 60 last_custom_icon_ = icon.ToDictionaryValue().Pass(); |
61 ValidateCustomIcon(); | 61 ValidateCustomIcon(); |
62 } | 62 } |
63 | 63 |
64 virtual void HideUserPodCustomIcon(const std::string& user_email) OVERRIDE { | 64 virtual void HideUserPodCustomIcon(const std::string& user_email) override { |
65 ASSERT_EQ(user_email_, user_email); | 65 ASSERT_EQ(user_email_, user_email); |
66 last_custom_icon_.reset(); | 66 last_custom_icon_.reset(); |
67 } | 67 } |
68 | 68 |
69 virtual void EnableInput() OVERRIDE { | 69 virtual void EnableInput() override { |
70 ASSERT_FALSE(true) << "Should not be reached."; | 70 ASSERT_FALSE(true) << "Should not be reached."; |
71 } | 71 } |
72 | 72 |
73 virtual void SetAuthType(const std::string& user_email, | 73 virtual void SetAuthType(const std::string& user_email, |
74 AuthType auth_type, | 74 AuthType auth_type, |
75 const base::string16& auth_value) OVERRIDE { | 75 const base::string16& auth_value) override { |
76 ASSERT_EQ(user_email_, user_email); | 76 ASSERT_EQ(user_email_, user_email); |
77 // Generally, this is allowed, but EasyUnlockScreenlockStateHandler should | 77 // Generally, this is allowed, but EasyUnlockScreenlockStateHandler should |
78 // avoid resetting the same auth type. | 78 // avoid resetting the same auth type. |
79 EXPECT_NE(auth_type_, auth_type); | 79 EXPECT_NE(auth_type_, auth_type); |
80 | 80 |
81 auth_type_ = auth_type; | 81 auth_type_ = auth_type; |
82 auth_value_ = auth_value; | 82 auth_value_ = auth_value; |
83 } | 83 } |
84 | 84 |
85 virtual AuthType GetAuthType(const std::string& user_email) const OVERRIDE { | 85 virtual AuthType GetAuthType(const std::string& user_email) const override { |
86 EXPECT_EQ(user_email_, user_email); | 86 EXPECT_EQ(user_email_, user_email); |
87 return auth_type_; | 87 return auth_type_; |
88 } | 88 } |
89 | 89 |
90 virtual void Unlock(const std::string& user_email) OVERRIDE { | 90 virtual void Unlock(const std::string& user_email) override { |
91 ASSERT_FALSE(true) << "Should not be reached."; | 91 ASSERT_FALSE(true) << "Should not be reached."; |
92 } | 92 } |
93 | 93 |
94 virtual void AttemptEasySignin(const std::string& user_email, | 94 virtual void AttemptEasySignin(const std::string& user_email, |
95 const std::string& secret, | 95 const std::string& secret, |
96 const std::string& key_label) OVERRIDE { | 96 const std::string& key_label) override { |
97 ASSERT_FALSE(true) << "Should not be reached."; | 97 ASSERT_FALSE(true) << "Should not be reached."; |
98 } | 98 } |
99 | 99 |
100 // Utility methods used by tests: | 100 // Utility methods used by tests: |
101 | 101 |
102 // Gets last set auth value. | 102 // Gets last set auth value. |
103 base::string16 GetAuthValue() const { | 103 base::string16 GetAuthValue() const { |
104 return auth_value_; | 104 return auth_value_; |
105 } | 105 } |
106 | 106 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 base::string16 auth_value_; | 192 base::string16 auth_value_; |
193 | 193 |
194 DISALLOW_COPY_AND_ASSIGN(TestLockHandler); | 194 DISALLOW_COPY_AND_ASSIGN(TestLockHandler); |
195 }; | 195 }; |
196 | 196 |
197 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { | 197 class EasyUnlockScreenlockStateHandlerTest : public testing::Test { |
198 public: | 198 public: |
199 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {} | 199 EasyUnlockScreenlockStateHandlerTest() : user_email_("test_user@gmail.com") {} |
200 virtual ~EasyUnlockScreenlockStateHandlerTest() {} | 200 virtual ~EasyUnlockScreenlockStateHandlerTest() {} |
201 | 201 |
202 virtual void SetUp() OVERRIDE { | 202 virtual void SetUp() override { |
203 pref_service_.reset(new TestingPrefServiceSyncable()); | 203 pref_service_.reset(new TestingPrefServiceSyncable()); |
204 | 204 |
205 // The preference used to determine if easy unlock was previously used by | 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. | 206 // the user on the device ought to be registered by the EasyUnlockService. |
207 EasyUnlockService::RegisterProfilePrefs(pref_service_->registry()); | 207 EasyUnlockService::RegisterProfilePrefs(pref_service_->registry()); |
208 | 208 |
209 // Create and inject fake lock handler to the screenlock bridge. | 209 // Create and inject fake lock handler to the screenlock bridge. |
210 lock_handler_.reset(new TestLockHandler(user_email_)); | 210 lock_handler_.reset(new TestLockHandler(user_email_)); |
211 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get(); | 211 ScreenlockBridge* screenlock_bridge = ScreenlockBridge::Get(); |
212 screenlock_bridge->SetLockHandler(lock_handler_.get()); | 212 screenlock_bridge->SetLockHandler(lock_handler_.get()); |
213 | 213 |
214 // Create the screenlock state handler object that will be tested. | 214 // Create the screenlock state handler object that will be tested. |
215 state_handler_.reset(new EasyUnlockScreenlockStateHandler( | 215 state_handler_.reset(new EasyUnlockScreenlockStateHandler( |
216 user_email_, | 216 user_email_, |
217 EasyUnlockScreenlockStateHandler::NO_HARDLOCK, | 217 EasyUnlockScreenlockStateHandler::NO_HARDLOCK, |
218 pref_service_.get(), | 218 pref_service_.get(), |
219 screenlock_bridge)); | 219 screenlock_bridge)); |
220 } | 220 } |
221 | 221 |
222 virtual void TearDown() OVERRIDE { | 222 virtual void TearDown() override { |
223 ScreenlockBridge::Get()->SetLockHandler(NULL); | 223 ScreenlockBridge::Get()->SetLockHandler(NULL); |
224 lock_handler_.reset(); | 224 lock_handler_.reset(); |
225 state_handler_.reset(); | 225 state_handler_.reset(); |
226 } | 226 } |
227 | 227 |
228 protected: | 228 protected: |
229 // The state handler that is being tested. | 229 // The state handler that is being tested. |
230 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; | 230 scoped_ptr<EasyUnlockScreenlockStateHandler> state_handler_; |
231 | 231 |
232 // The user associated with |state_handler_|. | 232 // The user associated with |state_handler_|. |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 627 |
628 state_handler_->ChangeState( | 628 state_handler_->ChangeState( |
629 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); | 629 EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED); |
630 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); | 630 EXPECT_EQ(0u, lock_handler_->GetAndResetShowIconCount()); |
631 EXPECT_TRUE(lock_handler_->HasCustomIcon()); | 631 EXPECT_TRUE(lock_handler_->HasCustomIcon()); |
632 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 632 EXPECT_EQ(ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
633 lock_handler_->GetAuthType(user_email_)); | 633 lock_handler_->GetAuthType(user_email_)); |
634 } | 634 } |
635 | 635 |
636 } // namespace | 636 } // namespace |
OLD | NEW |