| 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/dir_reader_posix.h" | 8 #include "base/files/dir_reader_posix.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 EXPECT_TRUE(connector->GetDeviceCloudPolicyInitializer()); | 79 EXPECT_TRUE(connector->GetDeviceCloudPolicyInitializer()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // This class is the base class for the tests of the behavior regarding | 82 // This class is the base class for the tests of the behavior regarding |
| 83 // extensions installed on the signin screen (which is generally possible only | 83 // extensions installed on the signin screen (which is generally possible only |
| 84 // through an admin policy, but the tests may install the extensions directly | 84 // through an admin policy, but the tests may install the extensions directly |
| 85 // for the test purposes). | 85 // for the test purposes). |
| 86 class SigninExtensionsDeviceCloudPolicyBrowserTestBase | 86 class SigninExtensionsDeviceCloudPolicyBrowserTestBase |
| 87 : public DevicePolicyCrosBrowserTest { | 87 : public DevicePolicyCrosBrowserTest { |
| 88 protected: | 88 protected: |
| 89 constexpr static const char* kTestExtensionId = | 89 static constexpr const char* kTestExtensionId = |
| 90 "baogpbmpccplckhhehfipokjaflkmbno"; | 90 "baogpbmpccplckhhehfipokjaflkmbno"; |
| 91 constexpr static const char* kTestExtensionSourceDir = | 91 static constexpr const char* kTestExtensionSourceDir = |
| 92 "extensions/signin_screen_managed_storage"; | 92 "extensions/signin_screen_managed_storage"; |
| 93 constexpr static const char* kTestExtensionVersion = "1.0"; | 93 static constexpr const char* kTestExtensionVersion = "1.0"; |
| 94 constexpr static const char* kTestExtensionTestPage = "test.html"; | 94 static constexpr const char* kTestExtensionTestPage = "test.html"; |
| 95 constexpr static const char* kFakePolicyUrl = | 95 static constexpr const char* kFakePolicyUrl = |
| 96 "http://example.org/test-policy.json"; | 96 "http://example.org/test-policy.json"; |
| 97 constexpr static const char* kFakePolicy = | 97 static constexpr const char* kFakePolicy = |
| 98 "{\"string-policy\": {\"Value\": \"value\"}}"; | 98 "{\"string-policy\": {\"Value\": \"value\"}}"; |
| 99 constexpr static const char* kPolicyProtoCacheKey = "signinextension-policy"; | 99 static constexpr int kFakePolicyPublicKeyVersion = 1; |
| 100 constexpr static const char* kPolicyDataCacheKey = | 100 static constexpr const char* kPolicyProtoCacheKey = "signinextension-policy"; |
| 101 static constexpr const char* kPolicyDataCacheKey = |
| 101 "signinextension-policy-data"; | 102 "signinextension-policy-data"; |
| 102 | 103 |
| 103 SigninExtensionsDeviceCloudPolicyBrowserTestBase() {} | 104 SigninExtensionsDeviceCloudPolicyBrowserTestBase() {} |
| 104 | 105 |
| 105 void SetUpCommandLine(base::CommandLine* command_line) override { | 106 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 106 DevicePolicyCrosBrowserTest::SetUpCommandLine(command_line); | 107 DevicePolicyCrosBrowserTest::SetUpCommandLine(command_line); |
| 107 command_line->AppendSwitch(chromeos::switches::kLoginManager); | 108 command_line->AppendSwitch(chromeos::switches::kLoginManager); |
| 108 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); | 109 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); |
| 109 // This flag is required for the successful installation of the test | 110 // This flag is required for the successful installation of the test |
| 110 // extension into the signin profile, due to some checks in | 111 // extension into the signin profile, due to some checks in |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 149 |
| 149 static const extensions::Extension* GetTestExtension() { | 150 static const extensions::Extension* GetTestExtension() { |
| 150 extensions::ExtensionRegistry* registry = | 151 extensions::ExtensionRegistry* registry = |
| 151 extensions::ExtensionRegistry::Get(GetSigninProfile()); | 152 extensions::ExtensionRegistry::Get(GetSigninProfile()); |
| 152 const extensions::Extension* extension = | 153 const extensions::Extension* extension = |
| 153 registry->enabled_extensions().GetByID(kTestExtensionId); | 154 registry->enabled_extensions().GetByID(kTestExtensionId); |
| 154 EXPECT_TRUE(extension); | 155 EXPECT_TRUE(extension); |
| 155 return extension; | 156 return extension; |
| 156 } | 157 } |
| 157 | 158 |
| 158 enterprise_management::PolicyFetchResponse BuildTestComponentPolicy() { | 159 static enterprise_management::PolicyFetchResponse BuildTestComponentPolicy() { |
| 159 ComponentPolicyBuilder builder; | 160 ComponentPolicyBuilder builder; |
| 160 MakeTestComponentPolicyBuilder(&builder); | 161 MakeTestComponentPolicyBuilder(&builder); |
| 161 return builder.policy(); | 162 return builder.policy(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 enterprise_management::ExternalPolicyData BuildTestComponentPolicyPayload() { | 165 static enterprise_management::ExternalPolicyData |
| 166 BuildTestComponentPolicyPayload() { |
| 165 ComponentPolicyBuilder builder; | 167 ComponentPolicyBuilder builder; |
| 166 MakeTestComponentPolicyBuilder(&builder); | 168 MakeTestComponentPolicyBuilder(&builder); |
| 167 return builder.payload(); | 169 return builder.payload(); |
| 168 } | 170 } |
| 169 | 171 |
| 170 private: | 172 private: |
| 171 void SetFakeDevicePolicy() { | 173 void SetFakeDevicePolicy() { |
| 172 device_policy()->policy_data().set_username(PolicyBuilder::kFakeUsername); | 174 device_policy()->policy_data().set_username(PolicyBuilder::kFakeUsername); |
| 173 device_policy()->SetDefaultSigningKey(); | 175 device_policy()->policy_data().set_public_key_version( |
| 176 kFakePolicyPublicKeyVersion); |
| 174 device_policy()->Build(); | 177 device_policy()->Build(); |
| 175 session_manager_client()->set_device_policy(device_policy()->GetBlob()); | 178 session_manager_client()->set_device_policy(device_policy()->GetBlob()); |
| 176 } | 179 } |
| 177 | 180 |
| 178 void MakeTestComponentPolicyBuilder(ComponentPolicyBuilder* builder) { | 181 static void MakeTestComponentPolicyBuilder(ComponentPolicyBuilder* builder) { |
| 179 builder->policy_data().set_policy_type( | 182 builder->policy_data().set_policy_type( |
| 180 dm_protocol::kChromeSigninExtensionPolicyType); | 183 dm_protocol::kChromeSigninExtensionPolicyType); |
| 181 builder->policy_data().set_username( | 184 builder->policy_data().set_username(PolicyBuilder::kFakeUsername); |
| 182 device_policy()->policy_data().username()); | |
| 183 builder->policy_data().set_settings_entity_id(kTestExtensionId); | 185 builder->policy_data().set_settings_entity_id(kTestExtensionId); |
| 184 builder->policy_data().set_public_key_version(1); | 186 builder->policy_data().set_public_key_version(kFakePolicyPublicKeyVersion); |
| 185 builder->payload().set_download_url(kFakePolicyUrl); | 187 builder->payload().set_download_url(kFakePolicyUrl); |
| 186 builder->payload().set_secure_hash(crypto::SHA256HashString(kFakePolicy)); | 188 builder->payload().set_secure_hash(crypto::SHA256HashString(kFakePolicy)); |
| 187 builder->SetDefaultSigningKey(); | |
| 188 builder->Build(); | 189 builder->Build(); |
| 189 } | 190 } |
| 190 | 191 |
| 191 DISALLOW_COPY_AND_ASSIGN(SigninExtensionsDeviceCloudPolicyBrowserTestBase); | 192 DISALLOW_COPY_AND_ASSIGN(SigninExtensionsDeviceCloudPolicyBrowserTestBase); |
| 192 }; | 193 }; |
| 193 | 194 |
| 194 // This class tests whether the component policy is successfully processed and | 195 // This class tests whether the component policy is successfully processed and |
| 195 // passed to the extension that is installed into the signin profile after the | 196 // passed to the extension that is installed into the signin profile after the |
| 196 // initialization finishes. | 197 // initialization finishes. |
| 197 // | 198 // |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 net::URLRequestStatus::SUCCESS); | 272 net::URLRequestStatus::SUCCESS); |
| 272 } | 273 } |
| 273 | 274 |
| 274 LocalPolicyTestServer policy_test_server_; | 275 LocalPolicyTestServer policy_test_server_; |
| 275 net::URLFetcherImplFactory fetcher_impl_factory_; | 276 net::URLFetcherImplFactory fetcher_impl_factory_; |
| 276 net::FakeURLFetcherFactory fetcher_factory_; | 277 net::FakeURLFetcherFactory fetcher_factory_; |
| 277 base::FilePath component_policy_cache_dir_; | 278 base::FilePath component_policy_cache_dir_; |
| 278 std::unique_ptr<base::AutoReset<bool>> signin_policy_provided_disabler_; | 279 std::unique_ptr<base::AutoReset<bool>> signin_policy_provided_disabler_; |
| 279 }; | 280 }; |
| 280 | 281 |
| 281 // DISABLED: see crbug.com/666720, crbug.com/644304. TODO(emaxx): Enable the | |
| 282 // test back. | |
| 283 IN_PROC_BROWSER_TEST_F(SigninExtensionsDeviceCloudPolicyBrowserTest, | 282 IN_PROC_BROWSER_TEST_F(SigninExtensionsDeviceCloudPolicyBrowserTest, |
| 284 DISABLED_InstallAndRunInWindow) { | 283 InstallAndRunInWindow) { |
| 285 const extensions::Extension* extension = InstallAndLoadTestExtension(); | 284 const extensions::Extension* extension = InstallAndLoadTestExtension(); |
| 286 ASSERT_TRUE(extension); | 285 ASSERT_TRUE(extension); |
| 287 Browser* browser = CreateBrowser(GetSigninProfile()); | 286 Browser* browser = CreateBrowser(GetSigninProfile()); |
| 288 extensions::ResultCatcher result_catcher; | 287 extensions::ResultCatcher result_catcher; |
| 289 ui_test_utils::NavigateToURL( | 288 ui_test_utils::NavigateToURL( |
| 290 browser, extension->GetResourceURL(kTestExtensionTestPage)); | 289 browser, extension->GetResourceURL(kTestExtensionTestPage)); |
| 291 EXPECT_TRUE(result_catcher.GetNextResult()); | 290 EXPECT_TRUE(result_catcher.GetNextResult()); |
| 292 CloseBrowserSynchronously(browser); | 291 CloseBrowserSynchronously(browser); |
| 293 } | 292 } |
| 294 | 293 |
| 295 // This class tests that the cached component policy is successfully loaded and | 294 // This class tests that the cached component policy is successfully loaded and |
| 296 // passed to the extension that is already installed into the signin profile. | 295 // passed to the extension that is already installed into the signin profile. |
| 297 // | 296 // |
| 298 // To accomplish this, the class prefills the signin profile with, first, the | 297 // To accomplish this, the class prefills the signin profile with, first, the |
| 299 // installed test extension, and, second, with the cached component policy. | 298 // installed test extension, and, second, with the cached component policy. |
| 300 class PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest | 299 class PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest |
| 301 : public SigninExtensionsDeviceCloudPolicyBrowserTestBase { | 300 : public SigninExtensionsDeviceCloudPolicyBrowserTestBase { |
| 302 protected: | 301 protected: |
| 303 constexpr static const char* kFakeProfileSourceDir = | 302 static constexpr const char* kFakeProfileSourceDir = |
| 304 "extensions/profiles/signin_screen_managed_storage"; | 303 "extensions/profiles/signin_screen_managed_storage"; |
| 305 | 304 |
| 306 std::unique_ptr<base::AutoReset<bool>> signin_policy_provided_disabler_; | |
| 307 | |
| 308 bool SetUpUserDataDirectory() override { | 305 bool SetUpUserDataDirectory() override { |
| 309 PrefillSigninProfile(); | 306 PrefillSigninProfile(); |
| 310 PrefillComponentPolicyCache(); | 307 PrefillComponentPolicyCache(); |
| 311 return DevicePolicyCrosBrowserTest::SetUpUserDataDirectory(); | 308 return DevicePolicyCrosBrowserTest::SetUpUserDataDirectory(); |
| 312 } | 309 } |
| 313 | 310 |
| 314 void SetUpInProcessBrowserTestFixture() override { | 311 void SetUpInProcessBrowserTestFixture() override { |
| 315 SigninExtensionsDeviceCloudPolicyBrowserTestBase:: | 312 SigninExtensionsDeviceCloudPolicyBrowserTestBase:: |
| 316 SetUpInProcessBrowserTestFixture(); | 313 SetUpInProcessBrowserTestFixture(); |
| 317 signin_policy_provided_disabler_ = | 314 signin_policy_provided_disabler_ = |
| 318 chromeos::GetScopedSigninScreenPolicyProviderDisablerForTesting(); | 315 chromeos::GetScopedSigninScreenPolicyProviderDisablerForTesting(); |
| 319 } | 316 } |
| 320 | 317 |
| 318 private: |
| 321 static void PrefillSigninProfile() { | 319 static void PrefillSigninProfile() { |
| 322 base::FilePath profile_source_path; | 320 base::FilePath profile_source_path; |
| 323 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &profile_source_path)); | 321 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &profile_source_path)); |
| 324 profile_source_path = profile_source_path.AppendASCII(kFakeProfileSourceDir) | 322 profile_source_path = profile_source_path.AppendASCII(kFakeProfileSourceDir) |
| 325 .AppendASCII(chrome::kInitialProfile); | 323 .AppendASCII(chrome::kInitialProfile); |
| 326 | 324 |
| 327 base::FilePath profile_target_path; | 325 base::FilePath profile_target_path; |
| 328 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_target_path)); | 326 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_target_path)); |
| 329 | 327 |
| 330 EXPECT_TRUE( | 328 EXPECT_TRUE( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 347 base::FilePath cache_dir; | 345 base::FilePath cache_dir; |
| 348 EXPECT_TRUE(PathService::Get(chromeos::DIR_SIGNIN_PROFILE_COMPONENT_POLICY, | 346 EXPECT_TRUE(PathService::Get(chromeos::DIR_SIGNIN_PROFILE_COMPONENT_POLICY, |
| 349 &cache_dir)); | 347 &cache_dir)); |
| 350 | 348 |
| 351 ResourceCache cache(cache_dir, new base::NullTaskRunner); | 349 ResourceCache cache(cache_dir, new base::NullTaskRunner); |
| 352 EXPECT_TRUE(cache.Store(kPolicyProtoCacheKey, kTestExtensionId, | 350 EXPECT_TRUE(cache.Store(kPolicyProtoCacheKey, kTestExtensionId, |
| 353 BuildTestComponentPolicy().SerializeAsString())); | 351 BuildTestComponentPolicy().SerializeAsString())); |
| 354 EXPECT_TRUE( | 352 EXPECT_TRUE( |
| 355 cache.Store(kPolicyDataCacheKey, kTestExtensionId, kFakePolicy)); | 353 cache.Store(kPolicyDataCacheKey, kTestExtensionId, kFakePolicy)); |
| 356 } | 354 } |
| 355 |
| 356 std::unique_ptr<base::AutoReset<bool>> signin_policy_provided_disabler_; |
| 357 }; | 357 }; |
| 358 | 358 |
| 359 // DISABLED: see crbug.com/666720, crbug.com/644304. TODO(emaxx): Enable the | |
| 360 // test back. | |
| 361 IN_PROC_BROWSER_TEST_F(PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest, | 359 IN_PROC_BROWSER_TEST_F(PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest, |
| 362 DISABLED_OfflineStart) { | 360 OfflineStart) { |
| 363 const extensions::Extension* extension = GetTestExtension(); | 361 const extensions::Extension* extension = GetTestExtension(); |
| 364 ASSERT_TRUE(extension); | 362 ASSERT_TRUE(extension); |
| 365 Browser* browser = CreateBrowser(GetSigninProfile()); | 363 Browser* browser = CreateBrowser(GetSigninProfile()); |
| 366 extensions::ResultCatcher result_catcher; | 364 extensions::ResultCatcher result_catcher; |
| 367 ui_test_utils::NavigateToURL( | 365 ui_test_utils::NavigateToURL( |
| 368 browser, extension->GetResourceURL(kTestExtensionTestPage)); | 366 browser, extension->GetResourceURL(kTestExtensionTestPage)); |
| 369 EXPECT_TRUE(result_catcher.GetNextResult()); | 367 EXPECT_TRUE(result_catcher.GetNextResult()); |
| 370 CloseBrowserSynchronously(browser); | 368 CloseBrowserSynchronously(browser); |
| 371 } | 369 } |
| 372 | 370 |
| 373 } // namespace policy | 371 } // namespace policy |
| OLD | NEW |