| 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 <map> |    5 #include <map> | 
|    6 #include <string> |    6 #include <string> | 
|    7  |    7  | 
|    8 #include "base/macros.h" |    8 #include "base/macros.h" | 
|    9 #include "base/run_loop.h" |    9 #include "base/run_loop.h" | 
|   10 #include "base/values.h" |   10 #include "base/values.h" | 
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  182  |  182  | 
|  183   EasyUnlockService* service = |  183   EasyUnlockService* service = | 
|  184       new EasyUnlockServiceRegular(Profile::FromBrowserContext(context)); |  184       new EasyUnlockServiceRegular(Profile::FromBrowserContext(context)); | 
|  185   service->Initialize(app_manager.Pass()); |  185   service->Initialize(app_manager.Pass()); | 
|  186   return service; |  186   return service; | 
|  187 } |  187 } | 
|  188  |  188  | 
|  189 class EasyUnlockServiceTest : public testing::Test { |  189 class EasyUnlockServiceTest : public testing::Test { | 
|  190  public: |  190  public: | 
|  191   EasyUnlockServiceTest() |  191   EasyUnlockServiceTest() | 
|  192       : mock_user_manager_(new chromeos::MockUserManager()), |  192       : mock_user_manager_(new testing::NiceMock<chromeos::MockUserManager>()), | 
|  193         scoped_user_manager_(mock_user_manager_), |  193         scoped_user_manager_(mock_user_manager_), | 
|  194         is_bluetooth_adapter_present_(true) {} |  194         is_bluetooth_adapter_present_(true) {} | 
|  195  |  195  | 
|  196   ~EasyUnlockServiceTest() override {} |  196   ~EasyUnlockServiceTest() override {} | 
|  197  |  197  | 
|  198   void SetUp() override { |  198   void SetUp() override { | 
|  199     app_manager_factory = new TestAppManagerFactory(); |  199     app_manager_factory = new TestAppManagerFactory(); | 
|  200  |  200  | 
|  201     mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); |  201     mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); | 
|  202     device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter_); |  202     device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter_); | 
|  203     EXPECT_CALL(*mock_adapter_, IsPresent()) |  203     EXPECT_CALL(*mock_adapter_, IsPresent()) | 
|  204         .WillRepeatedly(testing::Invoke( |  204         .WillRepeatedly(testing::Invoke( | 
|  205             this, &EasyUnlockServiceTest::is_bluetooth_adapter_present)); |  205             this, &EasyUnlockServiceTest::is_bluetooth_adapter_present)); | 
|  206  |  206  | 
|  207     scoped_ptr<DBusThreadManagerSetter> dbus_setter = |  207     scoped_ptr<DBusThreadManagerSetter> dbus_setter = | 
|  208         chromeos::DBusThreadManager::GetSetterForTesting(); |  208         chromeos::DBusThreadManager::GetSetterForTesting(); | 
|  209     power_manager_client_ = new FakePowerManagerClient; |  209     power_manager_client_ = new FakePowerManagerClient; | 
|  210     dbus_setter->SetPowerManagerClient( |  210     dbus_setter->SetPowerManagerClient( | 
|  211         scoped_ptr<PowerManagerClient>(power_manager_client_)); |  211         scoped_ptr<PowerManagerClient>(power_manager_client_)); | 
|  212  |  212  | 
|  213     EXPECT_CALL(*mock_user_manager_, Shutdown()).Times(AnyNumber()); |  213     ON_CALL(*mock_user_manager_, Shutdown()).WillByDefault(Return()); | 
|  214     EXPECT_CALL(*mock_user_manager_, IsLoggedInAsUserWithGaiaAccount()) |  214     ON_CALL(*mock_user_manager_, IsLoggedInAsUserWithGaiaAccount()) | 
|  215         .WillRepeatedly(Return(true)); |  215         .WillByDefault(Return(true)); | 
 |  216     ON_CALL(*mock_user_manager_, IsCurrentUserNonCryptohomeDataEphemeral()) | 
 |  217         .WillByDefault(Return(false)); | 
|  216  |  218  | 
|  217     SetUpProfile(&profile_, kTestUserPrimary); |  219     SetUpProfile(&profile_, kTestUserPrimary); | 
|  218   } |  220   } | 
|  219  |  221  | 
|  220   void TearDown() override { |  222   void TearDown() override { | 
|  221     delete app_manager_factory; |  223     delete app_manager_factory; | 
|  222     app_manager_factory = NULL; |  224     app_manager_factory = NULL; | 
|  223   } |  225   } | 
|  224  |  226  | 
|  225   void SetEasyUnlockAllowedPolicy(bool allowed) { |  227   void SetEasyUnlockAllowedPolicy(bool allowed) { | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  277     profile->get()->set_profile_name(user_id); |  279     profile->get()->set_profile_name(user_id); | 
|  278  |  280  | 
|  279     SigninManagerBase* signin_manager = |  281     SigninManagerBase* signin_manager = | 
|  280         SigninManagerFactory::GetForProfile(profile->get()); |  282         SigninManagerFactory::GetForProfile(profile->get()); | 
|  281     signin_manager->SetAuthenticatedUsername(user_id); |  283     signin_manager->SetAuthenticatedUsername(user_id); | 
|  282   } |  284   } | 
|  283  |  285  | 
|  284  protected: |  286  protected: | 
|  285   scoped_ptr<TestingProfile> profile_; |  287   scoped_ptr<TestingProfile> profile_; | 
|  286   scoped_ptr<TestingProfile> secondary_profile_; |  288   scoped_ptr<TestingProfile> secondary_profile_; | 
 |  289   chromeos::MockUserManager* mock_user_manager_; | 
|  287  |  290  | 
|  288  private: |  291  private: | 
|  289   content::TestBrowserThreadBundle thread_bundle_; |  292   content::TestBrowserThreadBundle thread_bundle_; | 
|  290  |  293  | 
|  291   chromeos::MockUserManager* mock_user_manager_; |  | 
|  292   chromeos::ScopedUserManagerEnabler scoped_user_manager_; |  294   chromeos::ScopedUserManagerEnabler scoped_user_manager_; | 
|  293  |  295  | 
|  294   FakePowerManagerClient* power_manager_client_; |  296   FakePowerManagerClient* power_manager_client_; | 
|  295  |  297  | 
|  296   bool is_bluetooth_adapter_present_; |  298   bool is_bluetooth_adapter_present_; | 
|  297   scoped_refptr<testing::NiceMock<MockBluetoothAdapter>> mock_adapter_; |  299   scoped_refptr<testing::NiceMock<MockBluetoothAdapter>> mock_adapter_; | 
|  298  |  300  | 
|  299   DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); |  301   DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); | 
|  300 }; |  302 }; | 
|  301  |  303  | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  348  |  350  | 
|  349   EasyUnlockService* secondary_service = |  351   EasyUnlockService* secondary_service = | 
|  350       EasyUnlockService::Get(secondary_profile_.get()); |  352       EasyUnlockService::Get(secondary_profile_.get()); | 
|  351   ASSERT_TRUE(secondary_service); |  353   ASSERT_TRUE(secondary_service); | 
|  352  |  354  | 
|  353   EXPECT_FALSE(secondary_service->IsAllowed()); |  355   EXPECT_FALSE(secondary_service->IsAllowed()); | 
|  354   EXPECT_TRUE(EasyUnlockAppInState(secondary_profile_.get(), |  356   EXPECT_TRUE(EasyUnlockAppInState(secondary_profile_.get(), | 
|  355                                    TestAppManager::STATE_NOT_LOADED)); |  357                                    TestAppManager::STATE_NOT_LOADED)); | 
|  356 } |  358 } | 
|  357  |  359  | 
 |  360 TEST_F(EasyUnlockServiceTest, NotAllowedForEphemeralAccounts) { | 
 |  361   ON_CALL(*mock_user_manager_, IsCurrentUserNonCryptohomeDataEphemeral()) | 
 |  362       .WillByDefault(Return(true)); | 
 |  363  | 
 |  364   SetAppManagerReady(profile_.get()); | 
 |  365   EXPECT_FALSE(EasyUnlockService::Get(profile_.get())->IsAllowed()); | 
 |  366   EXPECT_TRUE( | 
 |  367       EasyUnlockAppInState(profile_.get(), TestAppManager::STATE_NOT_LOADED)); | 
 |  368 } | 
 |  369  | 
|  358 }  // namespace |  370 }  // namespace | 
| OLD | NEW |