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" | |
| 10 #include "chrome/browser/chromeos/login/startup_utils.h" | |
| 11 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | |
| 12 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
| 13 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 9 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/signin/easy_unlock_service.h" | 16 #include "chrome/browser/signin/easy_unlock_service.h" |
| 12 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "components/policy/core/browser/browser_policy_connector.h" | 20 #include "components/policy/core/browser/browser_policy_connector.h" |
| 16 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 21 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 17 #include "components/policy/core/common/policy_map.h" | 22 #include "components/policy/core/common/policy_map.h" |
| 18 #include "components/policy/core/common/policy_types.h" | 23 #include "components/policy/core/common/policy_types.h" |
| 19 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 20 #include "extensions/browser/extension_system.h" | 25 #include "extensions/browser/extension_system.h" |
| 21 #include "policy/policy_constants.h" | 26 #include "policy/policy_constants.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 23 | 28 |
| 29 using chromeos::ProfileHelper; | |
| 30 using chromeos::LoginManagerTest; | |
| 31 using chromeos::StartupUtils; | |
| 32 using chromeos::UserAddingScreen; | |
| 33 using chromeos::UserManager; | |
| 24 using testing::_; | 34 using testing::_; |
| 25 using testing::Return; | 35 using testing::Return; |
| 26 | 36 |
| 37 namespace { | |
| 38 | |
| 39 static const char kTestUser1[] = "primary.user@example.com"; | |
| 40 static const char kTestUser2[] = "secondary.user@example.com"; | |
|
xiyuan
2014/08/06 21:50:33
nit: "static" not needed
Tim Song
2014/08/06 21:55:55
Done.
| |
| 41 | |
| 42 #if defined(GOOGLE_CHROME_BUILD) | |
| 43 bool HasEasyUnlockAppForProfile(Profile* profile) { | |
| 44 extensions::ExtensionSystem* extension_system = | |
| 45 extensions::ExtensionSystem::Get(profile); | |
| 46 ExtensionService* extension_service = extension_system->extension_service(); | |
| 47 return !!extension_service->GetExtensionById( | |
| 48 extension_misc::kEasyUnlockAppId, false); | |
| 49 } | |
| 50 #endif | |
| 51 | |
| 52 } //namespace | |
| 53 | |
| 27 class EasyUnlockServiceTest : public InProcessBrowserTest { | 54 class EasyUnlockServiceTest : public InProcessBrowserTest { |
| 28 public: | 55 public: |
| 29 EasyUnlockServiceTest() {} | 56 EasyUnlockServiceTest() {} |
| 30 virtual ~EasyUnlockServiceTest() {} | 57 virtual ~EasyUnlockServiceTest() {} |
| 31 | 58 |
| 32 void SetEasyUnlockAllowedPolicy(bool allowed) { | 59 void SetEasyUnlockAllowedPolicy(bool allowed) { |
| 33 policy::PolicyMap policy; | 60 policy::PolicyMap policy; |
| 34 policy.Set(policy::key::kEasyUnlockAllowed, | 61 policy.Set(policy::key::kEasyUnlockAllowed, |
| 35 policy::POLICY_LEVEL_MANDATORY, | 62 policy::POLICY_LEVEL_MANDATORY, |
| 36 policy::POLICY_SCOPE_USER, | 63 policy::POLICY_SCOPE_USER, |
| 37 new base::FundamentalValue(allowed), | 64 new base::FundamentalValue(allowed), |
| 38 NULL); | 65 NULL); |
| 39 provider_.UpdateChromePolicy(policy); | 66 provider_.UpdateChromePolicy(policy); |
| 40 base::RunLoop().RunUntilIdle(); | 67 base::RunLoop().RunUntilIdle(); |
| 41 } | 68 } |
| 42 | 69 |
| 43 #if defined(GOOGLE_CHROME_BUILD) | 70 #if defined(GOOGLE_CHROME_BUILD) |
| 44 bool HasEasyUnlockApp() const { | 71 bool HasEasyUnlockApp() const { |
| 45 extensions::ExtensionSystem* extension_system = | 72 return HasEasyUnlockAppForProfile(profile()); |
| 46 extensions::ExtensionSystem::Get(profile()); | |
| 47 ExtensionService* extension_service = extension_system->extension_service(); | |
| 48 return !!extension_service->GetExtensionById( | |
| 49 extension_misc::kEasyUnlockAppId, false); | |
| 50 } | 73 } |
| 51 #endif | 74 #endif |
| 52 | 75 |
| 53 // InProcessBrowserTest: | 76 // InProcessBrowserTest: |
| 54 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 77 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 55 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 78 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 56 .WillRepeatedly(Return(true)); | 79 .WillRepeatedly(Return(true)); |
| 57 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 80 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 58 } | 81 } |
| 59 | 82 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 EXPECT_FALSE(HasEasyUnlockApp()); | 159 EXPECT_FALSE(HasEasyUnlockApp()); |
| 137 #endif | 160 #endif |
| 138 | 161 |
| 139 // Easy unlock stays off even when it is allowed by policy. | 162 // Easy unlock stays off even when it is allowed by policy. |
| 140 SetEasyUnlockAllowedPolicy(true); | 163 SetEasyUnlockAllowedPolicy(true); |
| 141 EXPECT_FALSE(service()->IsAllowed()); | 164 EXPECT_FALSE(service()->IsAllowed()); |
| 142 #if defined(GOOGLE_CHROME_BUILD) | 165 #if defined(GOOGLE_CHROME_BUILD) |
| 143 EXPECT_FALSE(HasEasyUnlockApp()); | 166 EXPECT_FALSE(HasEasyUnlockApp()); |
| 144 #endif | 167 #endif |
| 145 } | 168 } |
| 169 | |
| 170 class EasyUnlockServiceMultiProfileTest : public LoginManagerTest { | |
| 171 public: | |
| 172 EasyUnlockServiceMultiProfileTest() : LoginManagerTest(false) {} | |
| 173 virtual ~EasyUnlockServiceMultiProfileTest() {} | |
| 174 | |
| 175 private: | |
| 176 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceMultiProfileTest); | |
| 177 }; | |
| 178 | |
| 179 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceMultiProfileTest, | |
| 180 PRE_DisallowedOnSecondaryProfile) { | |
| 181 RegisterUser(kTestUser1); | |
| 182 RegisterUser(kTestUser2); | |
| 183 StartupUtils::MarkOobeCompleted(); | |
| 184 } | |
| 185 | |
| 186 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceMultiProfileTest, | |
| 187 DisallowedOnSecondaryProfile) { | |
| 188 LoginUser(kTestUser1); | |
| 189 chromeos::UserAddingScreen::Get()->Start(); | |
| 190 base::RunLoop().RunUntilIdle(); | |
| 191 AddUser(kTestUser2); | |
| 192 const user_manager::User* primary_user = | |
| 193 UserManager::Get()->FindUser(kTestUser1); | |
| 194 const user_manager::User* secondary_user = | |
| 195 UserManager::Get()->FindUser(kTestUser2); | |
| 196 | |
| 197 Profile* primary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( | |
| 198 primary_user->username_hash()); | |
| 199 Profile* secondary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( | |
| 200 secondary_user->username_hash()); | |
| 201 | |
| 202 EXPECT_TRUE(EasyUnlockService::Get(primary_profile)->IsAllowed()); | |
| 203 EXPECT_FALSE(EasyUnlockService::Get(secondary_profile)->IsAllowed()); | |
| 204 #if defined(GOOGLE_CHROME_BUILD) | |
| 205 EXPECT_TRUE(HasEasyUnlockAppForProfile(primary_profile)); | |
| 206 EXPECT_FALSE(HasEasyUnlockAppForProfile(secondary_profile)); | |
| 207 #endif | |
| 208 } | |
| OLD | NEW |