| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/chromeos/login/login_manager_test.h" | 9 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 10 #include "chrome/browser/chromeos/login/startup_utils.h" | 10 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 11 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 11 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 12 #include "chrome/browser/chromeos/login/users/user_manager.h" | 12 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 13 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 13 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/signin/easy_unlock_service.h" | 16 #include "chrome/browser/signin/easy_unlock_service.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "components/policy/core/browser/browser_policy_connector.h" | 20 #include "components/policy/core/browser/browser_policy_connector.h" |
| 21 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 21 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 22 #include "components/policy/core/common/policy_map.h" | 22 #include "components/policy/core/common/policy_map.h" |
| 23 #include "components/policy/core/common/policy_types.h" | 23 #include "components/policy/core/common/policy_types.h" |
| 24 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 25 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 26 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 25 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
| 26 #include "policy/policy_constants.h" | 28 #include "policy/policy_constants.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 28 | 30 |
| 29 using chromeos::ProfileHelper; | 31 using chromeos::ProfileHelper; |
| 30 using chromeos::LoginManagerTest; | 32 using chromeos::LoginManagerTest; |
| 31 using chromeos::StartupUtils; | 33 using chromeos::StartupUtils; |
| 32 using chromeos::UserAddingScreen; | 34 using chromeos::UserAddingScreen; |
| 33 using chromeos::UserManager; | 35 using chromeos::UserManager; |
| 36 using device::MockBluetoothAdapter; |
| 34 using testing::_; | 37 using testing::_; |
| 35 using testing::Return; | 38 using testing::Return; |
| 36 | 39 |
| 37 namespace { | 40 namespace { |
| 38 | 41 |
| 39 const char kTestUser1[] = "primary.user@example.com"; | 42 const char kTestUser1[] = "primary.user@example.com"; |
| 40 const char kTestUser2[] = "secondary.user@example.com"; | 43 const char kTestUser2[] = "secondary.user@example.com"; |
| 41 | 44 |
| 42 #if defined(GOOGLE_CHROME_BUILD) | 45 #if defined(GOOGLE_CHROME_BUILD) |
| 43 bool HasEasyUnlockAppForProfile(Profile* profile) { | 46 bool HasEasyUnlockAppForProfile(Profile* profile) { |
| 44 extensions::ExtensionSystem* extension_system = | 47 extensions::ExtensionSystem* extension_system = |
| 45 extensions::ExtensionSystem::Get(profile); | 48 extensions::ExtensionSystem::Get(profile); |
| 46 ExtensionService* extension_service = extension_system->extension_service(); | 49 ExtensionService* extension_service = extension_system->extension_service(); |
| 47 return !!extension_service->GetExtensionById( | 50 return !!extension_service->GetExtensionById( |
| 48 extension_misc::kEasyUnlockAppId, false); | 51 extension_misc::kEasyUnlockAppId, false); |
| 49 } | 52 } |
| 50 #endif | 53 #endif |
| 51 | 54 |
| 52 } //namespace | 55 } // namespace |
| 53 | 56 |
| 54 class EasyUnlockServiceTest : public InProcessBrowserTest { | 57 class EasyUnlockServiceTest : public InProcessBrowserTest { |
| 55 public: | 58 public: |
| 56 EasyUnlockServiceTest() {} | 59 EasyUnlockServiceTest() : is_bluetooth_adapter_present_(true) {} |
| 57 virtual ~EasyUnlockServiceTest() {} | 60 virtual ~EasyUnlockServiceTest() {} |
| 58 | 61 |
| 59 void SetEasyUnlockAllowedPolicy(bool allowed) { | 62 void SetEasyUnlockAllowedPolicy(bool allowed) { |
| 60 policy::PolicyMap policy; | 63 policy::PolicyMap policy; |
| 61 policy.Set(policy::key::kEasyUnlockAllowed, | 64 policy.Set(policy::key::kEasyUnlockAllowed, |
| 62 policy::POLICY_LEVEL_MANDATORY, | 65 policy::POLICY_LEVEL_MANDATORY, |
| 63 policy::POLICY_SCOPE_USER, | 66 policy::POLICY_SCOPE_USER, |
| 64 new base::FundamentalValue(allowed), | 67 new base::FundamentalValue(allowed), |
| 65 NULL); | 68 NULL); |
| 66 provider_.UpdateChromePolicy(policy); | 69 provider_.UpdateChromePolicy(policy); |
| 67 base::RunLoop().RunUntilIdle(); | 70 base::RunLoop().RunUntilIdle(); |
| 68 } | 71 } |
| 69 | 72 |
| 73 void SetupBluetoothMock(bool is_present) { |
| 74 mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); |
| 75 device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter_); |
| 76 |
| 77 EXPECT_CALL(*mock_adapter_, IsPresent()) |
| 78 .WillRepeatedly(testing::Return(is_present)); |
| 79 } |
| 80 |
| 70 #if defined(GOOGLE_CHROME_BUILD) | 81 #if defined(GOOGLE_CHROME_BUILD) |
| 71 bool HasEasyUnlockApp() const { | 82 bool HasEasyUnlockApp() const { |
| 72 return HasEasyUnlockAppForProfile(profile()); | 83 return HasEasyUnlockAppForProfile(profile()); |
| 73 } | 84 } |
| 74 #endif | 85 #endif |
| 75 | 86 |
| 76 // InProcessBrowserTest: | 87 // InProcessBrowserTest: |
| 77 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 88 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 78 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 89 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 79 .WillRepeatedly(Return(true)); | 90 .WillRepeatedly(Return(true)); |
| 80 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 91 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 92 SetupBluetoothMock(is_bluetooth_adapter_present_); |
| 81 } | 93 } |
| 82 | 94 |
| 83 Profile* profile() const { return browser()->profile(); } | 95 Profile* profile() const { return browser()->profile(); } |
| 84 | 96 |
| 85 EasyUnlockService* service() const { | 97 EasyUnlockService* service() const { |
| 86 return EasyUnlockService::Get(profile()); | 98 return EasyUnlockService::Get(profile()); |
| 87 } | 99 } |
| 88 | 100 |
| 101 void set_is_bluetooth_adapter_present(bool is_present) { |
| 102 is_bluetooth_adapter_present_ = is_present; |
| 103 } |
| 104 |
| 89 private: | 105 private: |
| 90 policy::MockConfigurationPolicyProvider provider_; | 106 policy::MockConfigurationPolicyProvider provider_; |
| 107 scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; |
| 108 bool is_bluetooth_adapter_present_; |
| 91 | 109 |
| 92 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); | 110 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); |
| 93 }; | 111 }; |
| 94 | 112 |
| 95 // Tests that EasyUnlock is on by default. | 113 // Tests that EasyUnlock is on by default. |
| 96 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, DefaultOn) { | 114 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, DefaultOn) { |
| 97 EXPECT_TRUE(service()->IsAllowed()); | 115 EXPECT_TRUE(service()->IsAllowed()); |
| 98 #if defined(GOOGLE_CHROME_BUILD) | 116 #if defined(GOOGLE_CHROME_BUILD) |
| 99 EXPECT_TRUE(HasEasyUnlockApp()); | 117 EXPECT_TRUE(HasEasyUnlockApp()); |
| 100 #endif | 118 #endif |
| 101 } | 119 } |
| 102 | 120 |
| 121 class EasyUnlockServiceNoBluetoothTest : public EasyUnlockServiceTest { |
| 122 public: |
| 123 EasyUnlockServiceNoBluetoothTest() {} |
| 124 virtual ~EasyUnlockServiceNoBluetoothTest() {} |
| 125 |
| 126 // InProcessBrowserTest: |
| 127 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 128 set_is_bluetooth_adapter_present(false); |
| 129 EasyUnlockServiceTest::SetUpInProcessBrowserTestFixture(); |
| 130 } |
| 131 |
| 132 private: |
| 133 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceNoBluetoothTest); |
| 134 }; |
| 135 |
| 136 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceNoBluetoothTest, NoService) { |
| 137 EXPECT_FALSE(service()->IsAllowed()); |
| 138 #if defined(GOOGLE_CHROME_BUILD) |
| 139 EXPECT_FALSE(HasEasyUnlockApp()); |
| 140 #endif |
| 141 } |
| 142 |
| 103 class EasyUnlockServiceFinchEnabledTest : public EasyUnlockServiceTest { | 143 class EasyUnlockServiceFinchEnabledTest : public EasyUnlockServiceTest { |
| 104 public: | 144 public: |
| 105 EasyUnlockServiceFinchEnabledTest() {} | 145 EasyUnlockServiceFinchEnabledTest() {} |
| 106 virtual ~EasyUnlockServiceFinchEnabledTest() {} | 146 virtual ~EasyUnlockServiceFinchEnabledTest() {} |
| 107 | 147 |
| 108 // InProcessBrowserTest: | 148 // InProcessBrowserTest: |
| 109 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 149 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 110 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | 150 command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
| 111 "EasyUnlock/Enable/"); | 151 "EasyUnlock/Enable/"); |
| 112 } | 152 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 #if defined(GOOGLE_CHROME_BUILD) | 205 #if defined(GOOGLE_CHROME_BUILD) |
| 166 EXPECT_FALSE(HasEasyUnlockApp()); | 206 EXPECT_FALSE(HasEasyUnlockApp()); |
| 167 #endif | 207 #endif |
| 168 } | 208 } |
| 169 | 209 |
| 170 class EasyUnlockServiceMultiProfileTest : public LoginManagerTest { | 210 class EasyUnlockServiceMultiProfileTest : public LoginManagerTest { |
| 171 public: | 211 public: |
| 172 EasyUnlockServiceMultiProfileTest() : LoginManagerTest(false) {} | 212 EasyUnlockServiceMultiProfileTest() : LoginManagerTest(false) {} |
| 173 virtual ~EasyUnlockServiceMultiProfileTest() {} | 213 virtual ~EasyUnlockServiceMultiProfileTest() {} |
| 174 | 214 |
| 215 // InProcessBrowserTest: |
| 216 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 217 LoginManagerTest::SetUpInProcessBrowserTestFixture(); |
| 218 |
| 219 mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); |
| 220 device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter_); |
| 221 EXPECT_CALL(*mock_adapter_, IsPresent()) |
| 222 .WillRepeatedly(testing::Return(true)); |
| 223 } |
| 224 |
| 175 private: | 225 private: |
| 226 scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; |
| 176 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceMultiProfileTest); | 227 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceMultiProfileTest); |
| 177 }; | 228 }; |
| 178 | 229 |
| 179 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceMultiProfileTest, | 230 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceMultiProfileTest, |
| 180 PRE_DisallowedOnSecondaryProfile) { | 231 PRE_DisallowedOnSecondaryProfile) { |
| 181 RegisterUser(kTestUser1); | 232 RegisterUser(kTestUser1); |
| 182 RegisterUser(kTestUser2); | 233 RegisterUser(kTestUser2); |
| 183 StartupUtils::MarkOobeCompleted(); | 234 StartupUtils::MarkOobeCompleted(); |
| 184 } | 235 } |
| 185 | 236 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 199 Profile* secondary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( | 250 Profile* secondary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( |
| 200 secondary_user->username_hash()); | 251 secondary_user->username_hash()); |
| 201 | 252 |
| 202 EXPECT_TRUE(EasyUnlockService::Get(primary_profile)->IsAllowed()); | 253 EXPECT_TRUE(EasyUnlockService::Get(primary_profile)->IsAllowed()); |
| 203 EXPECT_FALSE(EasyUnlockService::Get(secondary_profile)->IsAllowed()); | 254 EXPECT_FALSE(EasyUnlockService::Get(secondary_profile)->IsAllowed()); |
| 204 #if defined(GOOGLE_CHROME_BUILD) | 255 #if defined(GOOGLE_CHROME_BUILD) |
| 205 EXPECT_TRUE(HasEasyUnlockAppForProfile(primary_profile)); | 256 EXPECT_TRUE(HasEasyUnlockAppForProfile(primary_profile)); |
| 206 EXPECT_FALSE(HasEasyUnlockAppForProfile(secondary_profile)); | 257 EXPECT_FALSE(HasEasyUnlockAppForProfile(secondary_profile)); |
| 207 #endif | 258 #endif |
| 208 } | 259 } |
| OLD | NEW |