Chromium Code Reviews| 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) { | |
|
Ilya Sherman
2014/08/14 21:38:28
nit: "Setup" -> "SetUp"
xiyuan
2014/08/14 22:56:46
Done.
| |
| 74 mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); | |
| 75 device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter_); | |
| 76 | |
| 77 EXPECT_CALL(*mock_adapter_, AddObserver(_)) | |
| 78 .WillRepeatedly(testing::Return()); | |
| 79 EXPECT_CALL(*mock_adapter_, RemoveObserver(_)) | |
| 80 .WillRepeatedly(testing::Return()); | |
|
Ilya Sherman
2014/08/14 21:38:28
Hmm, why are these four lines needed?
xiyuan
2014/08/14 22:56:46
It was because I was desperately trying to figure
| |
| 81 EXPECT_CALL(*mock_adapter_, IsPresent()) | |
| 82 .WillRepeatedly(testing::Return(is_present)); | |
| 83 } | |
| 84 | |
| 70 #if defined(GOOGLE_CHROME_BUILD) | 85 #if defined(GOOGLE_CHROME_BUILD) |
| 71 bool HasEasyUnlockApp() const { | 86 bool HasEasyUnlockApp() const { |
| 72 return HasEasyUnlockAppForProfile(profile()); | 87 return HasEasyUnlockAppForProfile(profile()); |
| 73 } | 88 } |
| 74 #endif | 89 #endif |
| 75 | 90 |
| 76 // InProcessBrowserTest: | 91 // InProcessBrowserTest: |
| 77 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 92 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 78 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 93 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 79 .WillRepeatedly(Return(true)); | 94 .WillRepeatedly(Return(true)); |
| 80 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 95 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 96 SetupBluetoothMock(is_bluetooth_adapter_present_); | |
| 81 } | 97 } |
| 82 | 98 |
| 83 Profile* profile() const { return browser()->profile(); } | 99 Profile* profile() const { return browser()->profile(); } |
| 84 | 100 |
| 85 EasyUnlockService* service() const { | 101 EasyUnlockService* service() const { |
| 86 return EasyUnlockService::Get(profile()); | 102 return EasyUnlockService::Get(profile()); |
| 87 } | 103 } |
| 88 | 104 |
| 105 void set_is_bluetooth_adapter_present(bool is_present) { | |
| 106 is_bluetooth_adapter_present_ = is_present; | |
| 107 } | |
| 108 | |
| 89 private: | 109 private: |
| 90 policy::MockConfigurationPolicyProvider provider_; | 110 policy::MockConfigurationPolicyProvider provider_; |
| 111 scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; | |
|
Ilya Sherman
2014/08/14 21:38:28
nit: Does this really need to be a class member, o
xiyuan
2014/08/14 22:56:46
It turns out that we have to do this. Otherwise, i
| |
| 112 bool is_bluetooth_adapter_present_; | |
| 91 | 113 |
| 92 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); | 114 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); |
| 93 }; | 115 }; |
| 94 | 116 |
| 95 // Tests that EasyUnlock is on by default. | 117 // Tests that EasyUnlock is on by default. |
| 96 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, DefaultOn) { | 118 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, DefaultOn) { |
| 97 EXPECT_TRUE(service()->IsAllowed()); | 119 EXPECT_TRUE(service()->IsAllowed()); |
| 98 #if defined(GOOGLE_CHROME_BUILD) | 120 #if defined(GOOGLE_CHROME_BUILD) |
| 99 EXPECT_TRUE(HasEasyUnlockApp()); | 121 EXPECT_TRUE(HasEasyUnlockApp()); |
| 100 #endif | 122 #endif |
| 101 } | 123 } |
| 102 | 124 |
| 125 class EasyUnlockServiceNoBluetoothTest : public EasyUnlockServiceTest { | |
| 126 public: | |
| 127 EasyUnlockServiceNoBluetoothTest() {} | |
| 128 virtual ~EasyUnlockServiceNoBluetoothTest() {} | |
| 129 | |
| 130 // InProcessBrowserTest: | |
| 131 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | |
| 132 set_is_bluetooth_adapter_present(false); | |
| 133 EasyUnlockServiceTest::SetUpInProcessBrowserTestFixture(); | |
| 134 } | |
| 135 | |
| 136 private: | |
| 137 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceNoBluetoothTest); | |
| 138 }; | |
| 139 | |
| 140 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceNoBluetoothTest, NoService) { | |
| 141 EXPECT_FALSE(service()->IsAllowed()); | |
| 142 #if defined(GOOGLE_CHROME_BUILD) | |
| 143 EXPECT_FALSE(HasEasyUnlockApp()); | |
| 144 #endif | |
| 145 } | |
| 146 | |
| 103 class EasyUnlockServiceFinchEnabledTest : public EasyUnlockServiceTest { | 147 class EasyUnlockServiceFinchEnabledTest : public EasyUnlockServiceTest { |
| 104 public: | 148 public: |
| 105 EasyUnlockServiceFinchEnabledTest() {} | 149 EasyUnlockServiceFinchEnabledTest() {} |
| 106 virtual ~EasyUnlockServiceFinchEnabledTest() {} | 150 virtual ~EasyUnlockServiceFinchEnabledTest() {} |
| 107 | 151 |
| 108 // InProcessBrowserTest: | 152 // InProcessBrowserTest: |
| 109 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 153 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 110 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | 154 command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
| 111 "EasyUnlock/Enable/"); | 155 "EasyUnlock/Enable/"); |
| 112 } | 156 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 #if defined(GOOGLE_CHROME_BUILD) | 209 #if defined(GOOGLE_CHROME_BUILD) |
| 166 EXPECT_FALSE(HasEasyUnlockApp()); | 210 EXPECT_FALSE(HasEasyUnlockApp()); |
| 167 #endif | 211 #endif |
| 168 } | 212 } |
| 169 | 213 |
| 170 class EasyUnlockServiceMultiProfileTest : public LoginManagerTest { | 214 class EasyUnlockServiceMultiProfileTest : public LoginManagerTest { |
| 171 public: | 215 public: |
| 172 EasyUnlockServiceMultiProfileTest() : LoginManagerTest(false) {} | 216 EasyUnlockServiceMultiProfileTest() : LoginManagerTest(false) {} |
| 173 virtual ~EasyUnlockServiceMultiProfileTest() {} | 217 virtual ~EasyUnlockServiceMultiProfileTest() {} |
| 174 | 218 |
| 219 // InProcessBrowserTest: | |
| 220 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | |
| 221 LoginManagerTest::SetUpInProcessBrowserTestFixture(); | |
| 222 | |
| 223 mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); | |
| 224 device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter_); | |
| 225 EXPECT_CALL(*mock_adapter_, IsPresent()) | |
| 226 .WillRepeatedly(testing::Return(true)); | |
| 227 } | |
| 228 | |
| 175 private: | 229 private: |
| 230 scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; | |
|
Ilya Sherman
2014/08/14 21:38:28
nit: Does this really need to be a class member, o
xiyuan
2014/08/14 22:56:46
ditto.
| |
| 176 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceMultiProfileTest); | 231 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceMultiProfileTest); |
| 177 }; | 232 }; |
| 178 | 233 |
| 179 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceMultiProfileTest, | 234 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceMultiProfileTest, |
| 180 PRE_DisallowedOnSecondaryProfile) { | 235 PRE_DisallowedOnSecondaryProfile) { |
| 181 RegisterUser(kTestUser1); | 236 RegisterUser(kTestUser1); |
| 182 RegisterUser(kTestUser2); | 237 RegisterUser(kTestUser2); |
| 183 StartupUtils::MarkOobeCompleted(); | 238 StartupUtils::MarkOobeCompleted(); |
| 184 } | 239 } |
| 185 | 240 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 199 Profile* secondary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( | 254 Profile* secondary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( |
| 200 secondary_user->username_hash()); | 255 secondary_user->username_hash()); |
| 201 | 256 |
| 202 EXPECT_TRUE(EasyUnlockService::Get(primary_profile)->IsAllowed()); | 257 EXPECT_TRUE(EasyUnlockService::Get(primary_profile)->IsAllowed()); |
| 203 EXPECT_FALSE(EasyUnlockService::Get(secondary_profile)->IsAllowed()); | 258 EXPECT_FALSE(EasyUnlockService::Get(secondary_profile)->IsAllowed()); |
| 204 #if defined(GOOGLE_CHROME_BUILD) | 259 #if defined(GOOGLE_CHROME_BUILD) |
| 205 EXPECT_TRUE(HasEasyUnlockAppForProfile(primary_profile)); | 260 EXPECT_TRUE(HasEasyUnlockAppForProfile(primary_profile)); |
| 206 EXPECT_FALSE(HasEasyUnlockAppForProfile(secondary_profile)); | 261 EXPECT_FALSE(HasEasyUnlockAppForProfile(secondary_profile)); |
| 207 #endif | 262 #endif |
| 208 } | 263 } |
| OLD | NEW |