| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/signin/easy_unlock_service.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 | |
| 7 #include <map> | 8 #include <map> |
| 8 #include <string> | 9 #include <string> |
| 10 #include <utility> |
| 9 | 11 |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 13 #include "base/values.h" | 15 #include "base/values.h" |
| 14 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 16 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 17 #include "chrome/browser/signin/easy_unlock_app_manager.h" | 19 #include "chrome/browser/signin/easy_unlock_app_manager.h" |
| 18 #include "chrome/browser/signin/easy_unlock_service.h" | |
| 19 #include "chrome/browser/signin/easy_unlock_service_factory.h" | 20 #include "chrome/browser/signin/easy_unlock_service_factory.h" |
| 20 #include "chrome/browser/signin/easy_unlock_service_regular.h" | 21 #include "chrome/browser/signin/easy_unlock_service_regular.h" |
| 21 #include "chrome/browser/signin/signin_manager_factory.h" | 22 #include "chrome/browser/signin/signin_manager_factory.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
| 24 #include "chromeos/dbus/dbus_thread_manager.h" | 25 #include "chromeos/dbus/dbus_thread_manager.h" |
| 25 #include "chromeos/dbus/fake_power_manager_client.h" | 26 #include "chromeos/dbus/fake_power_manager_client.h" |
| 26 #include "components/signin/core/account_id/account_id.h" | 27 #include "components/signin/core/account_id/account_id.h" |
| 27 #include "components/signin/core/browser/signin_manager_base.h" | 28 #include "components/signin/core/browser/signin_manager_base.h" |
| 28 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 29 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 TestAppManagerFactory() {} | 139 TestAppManagerFactory() {} |
| 139 ~TestAppManagerFactory() {} | 140 ~TestAppManagerFactory() {} |
| 140 | 141 |
| 141 // Creates a TestAppManager for the provided browser context. If a | 142 // Creates a TestAppManager for the provided browser context. If a |
| 142 // TestAppManager was already created for the context, returns NULL. | 143 // TestAppManager was already created for the context, returns NULL. |
| 143 scoped_ptr<TestAppManager> Create(content::BrowserContext* context) { | 144 scoped_ptr<TestAppManager> Create(content::BrowserContext* context) { |
| 144 if (Find(context)) | 145 if (Find(context)) |
| 145 return scoped_ptr<TestAppManager>(); | 146 return scoped_ptr<TestAppManager>(); |
| 146 scoped_ptr<TestAppManager> app_manager(new TestAppManager()); | 147 scoped_ptr<TestAppManager> app_manager(new TestAppManager()); |
| 147 mapping_[context] = app_manager.get(); | 148 mapping_[context] = app_manager.get(); |
| 148 return app_manager.Pass(); | 149 return app_manager; |
| 149 } | 150 } |
| 150 | 151 |
| 151 // Finds a TestAppManager created for |context|. Returns NULL if no | 152 // Finds a TestAppManager created for |context|. Returns NULL if no |
| 152 // TestAppManagers have been created for the context. | 153 // TestAppManagers have been created for the context. |
| 153 TestAppManager* Find(content::BrowserContext* context) { | 154 TestAppManager* Find(content::BrowserContext* context) { |
| 154 std::map<content::BrowserContext*, TestAppManager*>::iterator it = | 155 std::map<content::BrowserContext*, TestAppManager*>::iterator it = |
| 155 mapping_.find(context); | 156 mapping_.find(context); |
| 156 if (it == mapping_.end()) | 157 if (it == mapping_.end()) |
| 157 return NULL; | 158 return NULL; |
| 158 return it->second; | 159 return it->second; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 180 return nullptr; | 181 return nullptr; |
| 181 | 182 |
| 182 scoped_ptr<EasyUnlockAppManager> app_manager = | 183 scoped_ptr<EasyUnlockAppManager> app_manager = |
| 183 app_manager_factory->Create(context); | 184 app_manager_factory->Create(context); |
| 184 EXPECT_TRUE(app_manager.get()); | 185 EXPECT_TRUE(app_manager.get()); |
| 185 if (!app_manager.get()) | 186 if (!app_manager.get()) |
| 186 return nullptr; | 187 return nullptr; |
| 187 | 188 |
| 188 scoped_ptr<EasyUnlockServiceRegular> service( | 189 scoped_ptr<EasyUnlockServiceRegular> service( |
| 189 new EasyUnlockServiceRegular(Profile::FromBrowserContext(context))); | 190 new EasyUnlockServiceRegular(Profile::FromBrowserContext(context))); |
| 190 service->Initialize(app_manager.Pass()); | 191 service->Initialize(std::move(app_manager)); |
| 191 return service.Pass(); | 192 return std::move(service); |
| 192 } | 193 } |
| 193 | 194 |
| 194 class EasyUnlockServiceTest : public testing::Test { | 195 class EasyUnlockServiceTest : public testing::Test { |
| 195 public: | 196 public: |
| 196 EasyUnlockServiceTest() | 197 EasyUnlockServiceTest() |
| 197 : mock_user_manager_(new testing::NiceMock<chromeos::MockUserManager>()), | 198 : mock_user_manager_(new testing::NiceMock<chromeos::MockUserManager>()), |
| 198 scoped_user_manager_(mock_user_manager_), | 199 scoped_user_manager_(mock_user_manager_), |
| 199 is_bluetooth_adapter_present_(true) {} | 200 is_bluetooth_adapter_present_(true) {} |
| 200 | 201 |
| 201 ~EasyUnlockServiceTest() override {} | 202 ~EasyUnlockServiceTest() override {} |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 ON_CALL(*mock_user_manager_, IsCurrentUserNonCryptohomeDataEphemeral()) | 369 ON_CALL(*mock_user_manager_, IsCurrentUserNonCryptohomeDataEphemeral()) |
| 369 .WillByDefault(Return(true)); | 370 .WillByDefault(Return(true)); |
| 370 | 371 |
| 371 SetAppManagerReady(profile_.get()); | 372 SetAppManagerReady(profile_.get()); |
| 372 EXPECT_FALSE(EasyUnlockService::Get(profile_.get())->IsAllowed()); | 373 EXPECT_FALSE(EasyUnlockService::Get(profile_.get())->IsAllowed()); |
| 373 EXPECT_TRUE( | 374 EXPECT_TRUE( |
| 374 EasyUnlockAppInState(profile_.get(), TestAppManager::STATE_NOT_LOADED)); | 375 EasyUnlockAppInState(profile_.get(), TestAppManager::STATE_NOT_LOADED)); |
| 375 } | 376 } |
| 376 | 377 |
| 377 } // namespace | 378 } // namespace |
| OLD | NEW |