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 "components/policy/core/browser/browser_policy_connector.h" | 19 #include "components/policy/core/browser/browser_policy_connector.h" |
20 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 20 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
21 #include "components/policy/core/common/policy_map.h" | 21 #include "components/policy/core/common/policy_map.h" |
22 #include "components/policy/core/common/policy_types.h" | 22 #include "components/policy/core/common/policy_types.h" |
23 #include "components/user_manager/user_manager.h" | 23 #include "components/user_manager/user_manager.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 user_manager::UserManager; | 35 using user_manager::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 |
| 55 void SetUpBluetoothMock( |
| 56 scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter, |
| 57 bool is_present) { |
| 58 device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter); |
| 59 |
| 60 EXPECT_CALL(*mock_adapter, IsPresent()) |
| 61 .WillRepeatedly(testing::Return(is_present)); |
| 62 |
| 63 // These functions are called from ash system tray. They are speculations of |
| 64 // why flaky gmock errors are seen on bots. |
| 65 EXPECT_CALL(*mock_adapter, IsPowered()) |
| 66 .WillRepeatedly(testing::Return(true)); |
| 67 EXPECT_CALL(*mock_adapter, GetDevices()).WillRepeatedly( |
| 68 testing::Return(device::BluetoothAdapter::ConstDeviceList())); |
| 69 } |
| 70 |
52 } // namespace | 71 } // namespace |
53 | 72 |
54 class EasyUnlockServiceTest : public InProcessBrowserTest { | 73 class EasyUnlockServiceTest : public InProcessBrowserTest { |
55 public: | 74 public: |
56 EasyUnlockServiceTest() {} | 75 EasyUnlockServiceTest() : is_bluetooth_adapter_present_(true) {} |
57 virtual ~EasyUnlockServiceTest() {} | 76 virtual ~EasyUnlockServiceTest() {} |
58 | 77 |
59 void SetEasyUnlockAllowedPolicy(bool allowed) { | 78 void SetEasyUnlockAllowedPolicy(bool allowed) { |
60 policy::PolicyMap policy; | 79 policy::PolicyMap policy; |
61 policy.Set(policy::key::kEasyUnlockAllowed, | 80 policy.Set(policy::key::kEasyUnlockAllowed, |
62 policy::POLICY_LEVEL_MANDATORY, | 81 policy::POLICY_LEVEL_MANDATORY, |
63 policy::POLICY_SCOPE_USER, | 82 policy::POLICY_SCOPE_USER, |
64 new base::FundamentalValue(allowed), | 83 new base::FundamentalValue(allowed), |
65 NULL); | 84 NULL); |
66 provider_.UpdateChromePolicy(policy); | 85 provider_.UpdateChromePolicy(policy); |
67 base::RunLoop().RunUntilIdle(); | 86 base::RunLoop().RunUntilIdle(); |
68 } | 87 } |
69 | 88 |
70 #if defined(GOOGLE_CHROME_BUILD) | 89 #if defined(GOOGLE_CHROME_BUILD) |
71 bool HasEasyUnlockApp() const { | 90 bool HasEasyUnlockApp() const { |
72 return HasEasyUnlockAppForProfile(profile()); | 91 return HasEasyUnlockAppForProfile(profile()); |
73 } | 92 } |
74 #endif | 93 #endif |
75 | 94 |
76 // InProcessBrowserTest: | 95 // InProcessBrowserTest: |
77 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 96 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
78 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 97 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
79 .WillRepeatedly(Return(true)); | 98 .WillRepeatedly(Return(true)); |
80 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 99 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 100 |
| 101 mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); |
| 102 SetUpBluetoothMock(mock_adapter_, is_bluetooth_adapter_present_); |
81 } | 103 } |
82 | 104 |
83 Profile* profile() const { return browser()->profile(); } | 105 Profile* profile() const { return browser()->profile(); } |
84 | 106 |
85 EasyUnlockService* service() const { | 107 EasyUnlockService* service() const { |
86 return EasyUnlockService::Get(profile()); | 108 return EasyUnlockService::Get(profile()); |
87 } | 109 } |
88 | 110 |
| 111 void set_is_bluetooth_adapter_present(bool is_present) { |
| 112 is_bluetooth_adapter_present_ = is_present; |
| 113 } |
| 114 |
89 private: | 115 private: |
90 policy::MockConfigurationPolicyProvider provider_; | 116 policy::MockConfigurationPolicyProvider provider_; |
| 117 scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; |
| 118 bool is_bluetooth_adapter_present_; |
91 | 119 |
92 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); | 120 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); |
93 }; | 121 }; |
94 | 122 |
95 // Tests that EasyUnlock is on by default. | 123 // Tests that EasyUnlock is on by default. |
96 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, DefaultOn) { | 124 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, DefaultOn) { |
97 EXPECT_TRUE(service()->IsAllowed()); | 125 EXPECT_TRUE(service()->IsAllowed()); |
98 #if defined(GOOGLE_CHROME_BUILD) | 126 #if defined(GOOGLE_CHROME_BUILD) |
99 EXPECT_TRUE(HasEasyUnlockApp()); | 127 EXPECT_TRUE(HasEasyUnlockApp()); |
100 #endif | 128 #endif |
101 } | 129 } |
102 | 130 |
| 131 class EasyUnlockServiceNoBluetoothTest : public EasyUnlockServiceTest { |
| 132 public: |
| 133 EasyUnlockServiceNoBluetoothTest() {} |
| 134 virtual ~EasyUnlockServiceNoBluetoothTest() {} |
| 135 |
| 136 // InProcessBrowserTest: |
| 137 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 138 set_is_bluetooth_adapter_present(false); |
| 139 EasyUnlockServiceTest::SetUpInProcessBrowserTestFixture(); |
| 140 } |
| 141 |
| 142 private: |
| 143 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceNoBluetoothTest); |
| 144 }; |
| 145 |
| 146 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceNoBluetoothTest, NoService) { |
| 147 EXPECT_FALSE(service()->IsAllowed()); |
| 148 #if defined(GOOGLE_CHROME_BUILD) |
| 149 EXPECT_FALSE(HasEasyUnlockApp()); |
| 150 #endif |
| 151 } |
| 152 |
103 class EasyUnlockServiceFinchEnabledTest : public EasyUnlockServiceTest { | 153 class EasyUnlockServiceFinchEnabledTest : public EasyUnlockServiceTest { |
104 public: | 154 public: |
105 EasyUnlockServiceFinchEnabledTest() {} | 155 EasyUnlockServiceFinchEnabledTest() {} |
106 virtual ~EasyUnlockServiceFinchEnabledTest() {} | 156 virtual ~EasyUnlockServiceFinchEnabledTest() {} |
107 | 157 |
108 // InProcessBrowserTest: | 158 // InProcessBrowserTest: |
109 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 159 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
110 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | 160 command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
111 "EasyUnlock/Enable/"); | 161 "EasyUnlock/Enable/"); |
112 } | 162 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 #if defined(GOOGLE_CHROME_BUILD) | 215 #if defined(GOOGLE_CHROME_BUILD) |
166 EXPECT_FALSE(HasEasyUnlockApp()); | 216 EXPECT_FALSE(HasEasyUnlockApp()); |
167 #endif | 217 #endif |
168 } | 218 } |
169 | 219 |
170 class EasyUnlockServiceMultiProfileTest : public LoginManagerTest { | 220 class EasyUnlockServiceMultiProfileTest : public LoginManagerTest { |
171 public: | 221 public: |
172 EasyUnlockServiceMultiProfileTest() : LoginManagerTest(false) {} | 222 EasyUnlockServiceMultiProfileTest() : LoginManagerTest(false) {} |
173 virtual ~EasyUnlockServiceMultiProfileTest() {} | 223 virtual ~EasyUnlockServiceMultiProfileTest() {} |
174 | 224 |
| 225 // InProcessBrowserTest: |
| 226 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 227 LoginManagerTest::SetUpInProcessBrowserTestFixture(); |
| 228 |
| 229 mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); |
| 230 SetUpBluetoothMock(mock_adapter_, true); |
| 231 } |
| 232 |
175 private: | 233 private: |
| 234 scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; |
176 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceMultiProfileTest); | 235 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceMultiProfileTest); |
177 }; | 236 }; |
178 | 237 |
179 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceMultiProfileTest, | 238 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceMultiProfileTest, |
180 PRE_DisallowedOnSecondaryProfile) { | 239 PRE_DisallowedOnSecondaryProfile) { |
181 RegisterUser(kTestUser1); | 240 RegisterUser(kTestUser1); |
182 RegisterUser(kTestUser2); | 241 RegisterUser(kTestUser2); |
183 StartupUtils::MarkOobeCompleted(); | 242 StartupUtils::MarkOobeCompleted(); |
184 } | 243 } |
185 | 244 |
(...skipping 13 matching lines...) Expand all Loading... |
199 Profile* secondary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( | 258 Profile* secondary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( |
200 secondary_user->username_hash()); | 259 secondary_user->username_hash()); |
201 | 260 |
202 EXPECT_TRUE(EasyUnlockService::Get(primary_profile)->IsAllowed()); | 261 EXPECT_TRUE(EasyUnlockService::Get(primary_profile)->IsAllowed()); |
203 EXPECT_FALSE(EasyUnlockService::Get(secondary_profile)->IsAllowed()); | 262 EXPECT_FALSE(EasyUnlockService::Get(secondary_profile)->IsAllowed()); |
204 #if defined(GOOGLE_CHROME_BUILD) | 263 #if defined(GOOGLE_CHROME_BUILD) |
205 EXPECT_TRUE(HasEasyUnlockAppForProfile(primary_profile)); | 264 EXPECT_TRUE(HasEasyUnlockAppForProfile(primary_profile)); |
206 EXPECT_FALSE(HasEasyUnlockAppForProfile(secondary_profile)); | 265 EXPECT_FALSE(HasEasyUnlockAppForProfile(secondary_profile)); |
207 #endif | 266 #endif |
208 } | 267 } |
OLD | NEW |