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/profiles/profile_helper.h" | 12 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/signin/easy_unlock_service.h" | 15 #include "chrome/browser/signin/easy_unlock_service.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/common/extensions/extension_constants.h" | 17 #include "chrome/common/extensions/extension_constants.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
19 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
20 #include "chromeos/dbus/fake_power_manager_client.h" | 20 #include "chromeos/dbus/fake_power_manager_client.h" |
21 #include "components/policy/core/browser/browser_policy_connector.h" | 21 #include "components/policy/core/browser/browser_policy_connector.h" |
22 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 22 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
23 #include "components/policy/core/common/policy_map.h" | 23 #include "components/policy/core/common/policy_map.h" |
24 #include "components/policy/core/common/policy_types.h" | 24 #include "components/policy/core/common/policy_types.h" |
| 25 #include "components/proximity_auth/switches.h" |
25 #include "components/user_manager/user_manager.h" | 26 #include "components/user_manager/user_manager.h" |
26 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
27 #include "device/bluetooth/bluetooth_adapter_factory.h" | 28 #include "device/bluetooth/bluetooth_adapter_factory.h" |
28 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 29 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
29 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
30 #include "policy/policy_constants.h" | 31 #include "policy/policy_constants.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
32 | 33 |
33 using chromeos::DBusThreadManagerSetter; | 34 using chromeos::DBusThreadManagerSetter; |
34 using chromeos::FakePowerManagerClient; | 35 using chromeos::FakePowerManagerClient; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 130 |
130 private: | 131 private: |
131 policy::MockConfigurationPolicyProvider provider_; | 132 policy::MockConfigurationPolicyProvider provider_; |
132 scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; | 133 scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; |
133 bool is_bluetooth_adapter_present_; | 134 bool is_bluetooth_adapter_present_; |
134 FakePowerManagerClient* power_manager_client_; | 135 FakePowerManagerClient* power_manager_client_; |
135 | 136 |
136 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); | 137 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); |
137 }; | 138 }; |
138 | 139 |
139 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, NoFinchNoService) { | 140 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, DefaultOn) { |
140 EXPECT_FALSE(service()->IsAllowed()); | |
141 #if defined(GOOGLE_CHROME_BUILD) | |
142 EXPECT_FALSE(HasEasyUnlockApp()); | |
143 #endif | |
144 } | |
145 | |
146 class EasyUnlockServiceNoBluetoothTest : public EasyUnlockServiceTest { | |
147 public: | |
148 EasyUnlockServiceNoBluetoothTest() {} | |
149 virtual ~EasyUnlockServiceNoBluetoothTest() {} | |
150 | |
151 // InProcessBrowserTest: | |
152 virtual void SetUpInProcessBrowserTestFixture() override { | |
153 set_is_bluetooth_adapter_present(false); | |
154 EasyUnlockServiceTest::SetUpInProcessBrowserTestFixture(); | |
155 } | |
156 | |
157 private: | |
158 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceNoBluetoothTest); | |
159 }; | |
160 | |
161 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceNoBluetoothTest, NoService) { | |
162 EXPECT_FALSE(service()->IsAllowed()); | |
163 #if defined(GOOGLE_CHROME_BUILD) | |
164 EXPECT_FALSE(HasEasyUnlockApp()); | |
165 #endif | |
166 } | |
167 | |
168 class EasyUnlockServiceFinchEnabledTest : public EasyUnlockServiceTest { | |
169 public: | |
170 EasyUnlockServiceFinchEnabledTest() {} | |
171 virtual ~EasyUnlockServiceFinchEnabledTest() {} | |
172 | |
173 // InProcessBrowserTest: | |
174 virtual void SetUpCommandLine(CommandLine* command_line) override { | |
175 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | |
176 "EasyUnlock/Enable/"); | |
177 } | |
178 | |
179 private: | |
180 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceFinchEnabledTest); | |
181 }; | |
182 | |
183 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceFinchEnabledTest, Enabled) { | |
184 EXPECT_TRUE(service()->IsAllowed()); | 141 EXPECT_TRUE(service()->IsAllowed()); |
185 #if defined(GOOGLE_CHROME_BUILD) | 142 #if defined(GOOGLE_CHROME_BUILD) |
186 EXPECT_TRUE(HasEasyUnlockApp()); | 143 EXPECT_TRUE(HasEasyUnlockApp()); |
187 #endif | 144 #endif |
188 } | 145 } |
189 | 146 |
190 #if defined(GOOGLE_CHROME_BUILD) | 147 #if defined(GOOGLE_CHROME_BUILD) |
191 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceFinchEnabledTest, UnloadsOnSuspend) { | 148 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, UnloadsOnSuspend) { |
192 EXPECT_TRUE(HasEasyUnlockApp()); | 149 EXPECT_TRUE(HasEasyUnlockApp()); |
193 power_manager_client()->SendSuspendImminent(); | 150 power_manager_client()->SendSuspendImminent(); |
194 EXPECT_FALSE(HasEasyUnlockApp()); | 151 EXPECT_FALSE(HasEasyUnlockApp()); |
195 power_manager_client()->SendSuspendDone(); | 152 power_manager_client()->SendSuspendDone(); |
196 EXPECT_TRUE(HasEasyUnlockApp()); | 153 EXPECT_TRUE(HasEasyUnlockApp()); |
197 } | 154 } |
198 #endif | 155 #endif |
199 | 156 |
200 // Tests that policy can override finch to turn easy unlock off. | 157 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, PolicyOveride) { |
201 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceFinchEnabledTest, PolicyOveride) { | |
202 EXPECT_TRUE(service()->IsAllowed()); | 158 EXPECT_TRUE(service()->IsAllowed()); |
203 #if defined(GOOGLE_CHROME_BUILD) | 159 #if defined(GOOGLE_CHROME_BUILD) |
204 EXPECT_TRUE(HasEasyUnlockApp()); | 160 EXPECT_TRUE(HasEasyUnlockApp()); |
205 #endif | 161 #endif |
206 | 162 |
207 // Overridden by policy. | 163 // Overridden by policy. |
208 SetEasyUnlockAllowedPolicy(false); | 164 SetEasyUnlockAllowedPolicy(false); |
209 EXPECT_FALSE(service()->IsAllowed()); | 165 EXPECT_FALSE(service()->IsAllowed()); |
210 #if defined(GOOGLE_CHROME_BUILD) | 166 #if defined(GOOGLE_CHROME_BUILD) |
211 EXPECT_FALSE(HasEasyUnlockApp()); | 167 EXPECT_FALSE(HasEasyUnlockApp()); |
212 #endif | 168 #endif |
213 | 169 |
214 SetEasyUnlockAllowedPolicy(true); | 170 SetEasyUnlockAllowedPolicy(true); |
215 EXPECT_TRUE(service()->IsAllowed()); | 171 EXPECT_TRUE(service()->IsAllowed()); |
216 #if defined(GOOGLE_CHROME_BUILD) | 172 #if defined(GOOGLE_CHROME_BUILD) |
217 EXPECT_TRUE(HasEasyUnlockApp()); | 173 EXPECT_TRUE(HasEasyUnlockApp()); |
218 #endif | 174 #endif |
219 } | 175 } |
220 | 176 |
221 class EasyUnlockServiceFinchDisabledTest : public EasyUnlockServiceTest { | 177 class EasyUnlockServiceNoBluetoothTest : public EasyUnlockServiceTest { |
222 public: | 178 public: |
223 EasyUnlockServiceFinchDisabledTest() {} | 179 EasyUnlockServiceNoBluetoothTest() {} |
224 virtual ~EasyUnlockServiceFinchDisabledTest() {} | 180 virtual ~EasyUnlockServiceNoBluetoothTest() {} |
| 181 |
| 182 // InProcessBrowserTest: |
| 183 virtual void SetUpInProcessBrowserTestFixture() override { |
| 184 set_is_bluetooth_adapter_present(false); |
| 185 EasyUnlockServiceTest::SetUpInProcessBrowserTestFixture(); |
| 186 } |
| 187 |
| 188 private: |
| 189 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceNoBluetoothTest); |
| 190 }; |
| 191 |
| 192 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceNoBluetoothTest, NoService) { |
| 193 EXPECT_FALSE(service()->IsAllowed()); |
| 194 #if defined(GOOGLE_CHROME_BUILD) |
| 195 EXPECT_FALSE(HasEasyUnlockApp()); |
| 196 #endif |
| 197 } |
| 198 |
| 199 class EasyUnlockServiceDisabledTest : public EasyUnlockServiceTest { |
| 200 public: |
| 201 EasyUnlockServiceDisabledTest() {} |
| 202 virtual ~EasyUnlockServiceDisabledTest() {} |
225 | 203 |
226 // InProcessBrowserTest: | 204 // InProcessBrowserTest: |
227 virtual void SetUpCommandLine(CommandLine* command_line) override { | 205 virtual void SetUpCommandLine(CommandLine* command_line) override { |
228 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | 206 command_line->AppendSwitch(proximity_auth::switches::kDisableEasyUnlock); |
229 "EasyUnlock/Disable/"); | |
230 } | 207 } |
231 | 208 |
232 private: | 209 private: |
233 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceFinchDisabledTest); | 210 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceDisabledTest); |
234 }; | 211 }; |
235 | 212 |
236 // Tests that easy unlock is off when finch is disabled and policy overrides | 213 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceDisabledTest, Disabled) { |
237 // finch. | |
238 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceFinchDisabledTest, PolicyOverride) { | |
239 // Finch is disabled. | |
240 EXPECT_FALSE(service()->IsAllowed()); | 214 EXPECT_FALSE(service()->IsAllowed()); |
241 #if defined(GOOGLE_CHROME_BUILD) | 215 #if defined(GOOGLE_CHROME_BUILD) |
242 EXPECT_FALSE(HasEasyUnlockApp()); | 216 EXPECT_FALSE(HasEasyUnlockApp()); |
| 217 #endif |
| 218 } |
| 219 |
| 220 // Tests that policy does not override disabled switch. |
| 221 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceDisabledTest, NoPolicyOverride) { |
| 222 EXPECT_FALSE(service()->IsAllowed()); |
| 223 #if defined(GOOGLE_CHROME_BUILD) |
| 224 EXPECT_FALSE(HasEasyUnlockApp()); |
243 #endif | 225 #endif |
244 | 226 |
245 // Policy overrides finch and turns on Easy unlock. | 227 // Policy overrides finch and turns on Easy unlock. |
246 SetEasyUnlockAllowedPolicy(true); | 228 SetEasyUnlockAllowedPolicy(true); |
247 EXPECT_TRUE(service()->IsAllowed()); | 229 EXPECT_FALSE(service()->IsAllowed()); |
248 #if defined(GOOGLE_CHROME_BUILD) | 230 #if defined(GOOGLE_CHROME_BUILD) |
249 EXPECT_TRUE(HasEasyUnlockApp()); | 231 EXPECT_FALSE(HasEasyUnlockApp()); |
250 #endif | 232 #endif |
251 } | 233 } |
252 | 234 |
253 class EasyUnlockServiceMultiProfileTest : public LoginManagerTest { | 235 class EasyUnlockServiceMultiProfileTest : public LoginManagerTest { |
254 public: | 236 public: |
255 EasyUnlockServiceMultiProfileTest() : LoginManagerTest(false) {} | 237 EasyUnlockServiceMultiProfileTest() : LoginManagerTest(false) {} |
256 virtual ~EasyUnlockServiceMultiProfileTest() {} | 238 virtual ~EasyUnlockServiceMultiProfileTest() {} |
257 | 239 |
258 // InProcessBrowserTest: | 240 // InProcessBrowserTest: |
259 virtual void SetUpInProcessBrowserTestFixture() override { | 241 virtual void SetUpInProcessBrowserTestFixture() override { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 Profile* secondary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( | 274 Profile* secondary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( |
293 secondary_user->username_hash()); | 275 secondary_user->username_hash()); |
294 | 276 |
295 EXPECT_TRUE(EasyUnlockService::Get(primary_profile)->IsAllowed()); | 277 EXPECT_TRUE(EasyUnlockService::Get(primary_profile)->IsAllowed()); |
296 EXPECT_FALSE(EasyUnlockService::Get(secondary_profile)->IsAllowed()); | 278 EXPECT_FALSE(EasyUnlockService::Get(secondary_profile)->IsAllowed()); |
297 #if defined(GOOGLE_CHROME_BUILD) | 279 #if defined(GOOGLE_CHROME_BUILD) |
298 EXPECT_TRUE(HasEasyUnlockAppForProfile(primary_profile)); | 280 EXPECT_TRUE(HasEasyUnlockAppForProfile(primary_profile)); |
299 EXPECT_FALSE(HasEasyUnlockAppForProfile(secondary_profile)); | 281 EXPECT_FALSE(HasEasyUnlockAppForProfile(secondary_profile)); |
300 #endif | 282 #endif |
301 } | 283 } |
OLD | NEW |