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 <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" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/test/null_task_runner.h" | 14 #include "base/test/null_task_runner.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/browser_process_platform_part.h" | 16 #include "chrome/browser/browser_process_platform_part.h" |
| 17 #include "chrome/browser/chromeos/extensions/signin_screen_policy_provider.h" | |
| 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 18 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 19 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 19 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 20 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 21 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
| 22 #include "chrome/browser/extensions/unpacked_installer.h" | 23 #include "chrome/browser/extensions/unpacked_installer.h" |
| 23 #include "chrome/browser/policy/test/local_policy_test_server.h" | 24 #include "chrome/browser/policy/test/local_policy_test_server.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/common/chrome_constants.cc" | 27 #include "chrome/common/chrome_constants.cc" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 BrowserPolicyConnectorChromeOS* connector = | 126 BrowserPolicyConnectorChromeOS* connector = |
| 126 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 127 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 127 connector->device_management_service()->ScheduleInitialization(0); | 128 connector->device_management_service()->ScheduleInitialization(0); |
| 128 | 129 |
| 129 ExtensionService* service = | 130 ExtensionService* service = |
| 130 extensions::ExtensionSystem::Get(GetSigninProfile()) | 131 extensions::ExtensionSystem::Get(GetSigninProfile()) |
| 131 ->extension_service(); | 132 ->extension_service(); |
| 132 service->set_extensions_enabled(true); | 133 service->set_extensions_enabled(true); |
| 133 } | 134 } |
| 134 | 135 |
| 136 void TearDownOnMainThread() override { | |
|
emaxx
2016/11/11 16:11:37
Is this actually needed?
Denis Kuznetsov (DE-MUC)
2016/11/11 21:26:34
Done.
| |
| 137 DevicePolicyCrosBrowserTest::TearDownOnMainThread(); | |
| 138 } | |
| 139 | |
| 135 static base::FilePath GetTestExtensionSourcePath() { | 140 static base::FilePath GetTestExtensionSourcePath() { |
| 136 base::FilePath test_data_dir; | 141 base::FilePath test_data_dir; |
| 137 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); | 142 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); |
| 138 return test_data_dir.AppendASCII(kTestExtensionSourceDir); | 143 return test_data_dir.AppendASCII(kTestExtensionSourceDir); |
| 139 } | 144 } |
| 140 | 145 |
| 141 static Profile* GetSigninProfile() { | 146 static Profile* GetSigninProfile() { |
| 142 Profile* signin_profile = | 147 Profile* signin_profile = |
| 143 chromeos::ProfileHelper::GetSigninProfile()->GetOriginalProfile(); | 148 chromeos::ProfileHelper::GetSigninProfile()->GetOriginalProfile(); |
| 144 EXPECT_TRUE(signin_profile); | 149 EXPECT_TRUE(signin_profile); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 void SetUpCommandLine(base::CommandLine* command_line) override { | 230 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 226 SigninExtensionsDeviceCloudPolicyBrowserTestBase::SetUpCommandLine( | 231 SigninExtensionsDeviceCloudPolicyBrowserTestBase::SetUpCommandLine( |
| 227 command_line); | 232 command_line); |
| 228 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, | 233 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, |
| 229 policy_test_server_.GetServiceURL().spec()); | 234 policy_test_server_.GetServiceURL().spec()); |
| 230 } | 235 } |
| 231 | 236 |
| 232 void SetUpInProcessBrowserTestFixture() override { | 237 void SetUpInProcessBrowserTestFixture() override { |
| 233 SigninExtensionsDeviceCloudPolicyBrowserTestBase:: | 238 SigninExtensionsDeviceCloudPolicyBrowserTestBase:: |
| 234 SetUpInProcessBrowserTestFixture(); | 239 SetUpInProcessBrowserTestFixture(); |
| 240 disabler_ = | |
| 241 base::MakeUnique<chromeos::ScopedSigninScreenPolicyProviderDisabler>(); | |
| 235 EXPECT_TRUE(PathService::Get(chromeos::DIR_SIGNIN_PROFILE_COMPONENT_POLICY, | 242 EXPECT_TRUE(PathService::Get(chromeos::DIR_SIGNIN_PROFILE_COMPONENT_POLICY, |
| 236 &component_policy_cache_dir_)); | 243 &component_policy_cache_dir_)); |
| 237 PrepareFakeComponentPolicyResponse(); | 244 PrepareFakeComponentPolicyResponse(); |
| 238 } | 245 } |
| 239 | 246 |
| 240 void TearDownInProcessBrowserTestFixture() override { | 247 void TearDownInProcessBrowserTestFixture() override { |
| 241 // Check that the component policy cache was not cleared during browser | 248 // Check that the component policy cache was not cleared during browser |
| 242 // teardown. | 249 // teardown. |
| 243 ResourceCache cache(component_policy_cache_dir_, new base::NullTaskRunner); | 250 ResourceCache cache(component_policy_cache_dir_, new base::NullTaskRunner); |
| 244 std::string stub; | 251 std::string stub; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 265 BuildTestComponentPolicyPayload().SerializeAsString())); | 272 BuildTestComponentPolicyPayload().SerializeAsString())); |
| 266 fetcher_factory_.SetFakeResponse(GURL(kFakePolicyUrl), kFakePolicy, | 273 fetcher_factory_.SetFakeResponse(GURL(kFakePolicyUrl), kFakePolicy, |
| 267 net::HTTP_OK, | 274 net::HTTP_OK, |
| 268 net::URLRequestStatus::SUCCESS); | 275 net::URLRequestStatus::SUCCESS); |
| 269 } | 276 } |
| 270 | 277 |
| 271 LocalPolicyTestServer policy_test_server_; | 278 LocalPolicyTestServer policy_test_server_; |
| 272 net::URLFetcherImplFactory fetcher_impl_factory_; | 279 net::URLFetcherImplFactory fetcher_impl_factory_; |
| 273 net::FakeURLFetcherFactory fetcher_factory_; | 280 net::FakeURLFetcherFactory fetcher_factory_; |
| 274 base::FilePath component_policy_cache_dir_; | 281 base::FilePath component_policy_cache_dir_; |
| 282 std::unique_ptr<chromeos::ScopedSigninScreenPolicyProviderDisabler> disabler_; | |
|
emaxx
2016/11/11 16:11:37
Maybe change this member to have a more descriptiv
Denis Kuznetsov (DE-MUC)
2016/11/11 21:26:34
Done.
| |
| 275 }; | 283 }; |
| 276 | 284 |
| 277 IN_PROC_BROWSER_TEST_F(SigninExtensionsDeviceCloudPolicyBrowserTest, | 285 IN_PROC_BROWSER_TEST_F(SigninExtensionsDeviceCloudPolicyBrowserTest, |
| 278 InstallAndRunInWindow) { | 286 InstallAndRunInWindow) { |
| 279 const extensions::Extension* extension = InstallAndLoadTestExtension(); | 287 const extensions::Extension* extension = InstallAndLoadTestExtension(); |
| 280 ASSERT_TRUE(extension); | 288 ASSERT_TRUE(extension); |
| 281 Browser* browser = CreateBrowser(GetSigninProfile()); | 289 Browser* browser = CreateBrowser(GetSigninProfile()); |
| 282 extensions::ResultCatcher result_catcher; | 290 extensions::ResultCatcher result_catcher; |
| 283 ui_test_utils::NavigateToURL( | 291 ui_test_utils::NavigateToURL( |
| 284 browser, extension->GetResourceURL(kTestExtensionTestPage)); | 292 browser, extension->GetResourceURL(kTestExtensionTestPage)); |
| 285 EXPECT_TRUE(result_catcher.GetNextResult()); | 293 EXPECT_TRUE(result_catcher.GetNextResult()); |
| 286 CloseBrowserSynchronously(browser); | 294 CloseBrowserSynchronously(browser); |
| 287 } | 295 } |
| 288 | 296 |
| 289 // This class tests that the cached component policy is successfully loaded and | 297 // This class tests that the cached component policy is successfully loaded and |
| 290 // passed to the extension that is already installed into the signin profile. | 298 // passed to the extension that is already installed into the signin profile. |
| 291 // | 299 // |
| 292 // To accomplish this, the class prefills the signin profile with, first, the | 300 // To accomplish this, the class prefills the signin profile with, first, the |
| 293 // installed test extension, and, second, with the cached component policy. | 301 // installed test extension, and, second, with the cached component policy. |
| 294 class PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest | 302 class PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest |
| 295 : public SigninExtensionsDeviceCloudPolicyBrowserTestBase { | 303 : public SigninExtensionsDeviceCloudPolicyBrowserTestBase { |
| 296 protected: | 304 protected: |
| 297 constexpr static const char* kFakeProfileSourceDir = | 305 constexpr static const char* kFakeProfileSourceDir = |
| 298 "extensions/profiles/signin_screen_managed_storage"; | 306 "extensions/profiles/signin_screen_managed_storage"; |
| 299 | 307 |
| 300 private: | 308 std::unique_ptr<chromeos::ScopedSigninScreenPolicyProviderDisabler> disabler_; |
| 309 | |
| 301 bool SetUpUserDataDirectory() override { | 310 bool SetUpUserDataDirectory() override { |
| 302 PrefillSigninProfile(); | 311 PrefillSigninProfile(); |
| 303 PrefillComponentPolicyCache(); | 312 PrefillComponentPolicyCache(); |
| 304 return DevicePolicyCrosBrowserTest::SetUpUserDataDirectory(); | 313 return DevicePolicyCrosBrowserTest::SetUpUserDataDirectory(); |
| 305 } | 314 } |
| 306 | 315 |
| 316 void SetUpInProcessBrowserTestFixture() override { | |
| 317 SigninExtensionsDeviceCloudPolicyBrowserTestBase:: | |
| 318 SetUpInProcessBrowserTestFixture(); | |
| 319 disabler_ = | |
|
emaxx
2016/11/11 16:11:37
If both test subclasses need this disabler, then w
Denis Kuznetsov (DE-MUC)
2016/11/11 21:26:34
Acknowledged.
| |
| 320 base::MakeUnique<chromeos::ScopedSigninScreenPolicyProviderDisabler>(); | |
| 321 } | |
| 322 | |
| 307 static void PrefillSigninProfile() { | 323 static void PrefillSigninProfile() { |
| 308 base::FilePath profile_source_path; | 324 base::FilePath profile_source_path; |
| 309 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &profile_source_path)); | 325 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &profile_source_path)); |
| 310 profile_source_path = profile_source_path.AppendASCII(kFakeProfileSourceDir) | 326 profile_source_path = profile_source_path.AppendASCII(kFakeProfileSourceDir) |
| 311 .AppendASCII(chrome::kInitialProfile); | 327 .AppendASCII(chrome::kInitialProfile); |
| 312 | 328 |
| 313 base::FilePath profile_target_path; | 329 base::FilePath profile_target_path; |
| 314 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_target_path)); | 330 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_target_path)); |
| 315 | 331 |
| 316 EXPECT_TRUE( | 332 EXPECT_TRUE( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 ASSERT_TRUE(extension); | 364 ASSERT_TRUE(extension); |
| 349 Browser* browser = CreateBrowser(GetSigninProfile()); | 365 Browser* browser = CreateBrowser(GetSigninProfile()); |
| 350 extensions::ResultCatcher result_catcher; | 366 extensions::ResultCatcher result_catcher; |
| 351 ui_test_utils::NavigateToURL( | 367 ui_test_utils::NavigateToURL( |
| 352 browser, extension->GetResourceURL(kTestExtensionTestPage)); | 368 browser, extension->GetResourceURL(kTestExtensionTestPage)); |
| 353 EXPECT_TRUE(result_catcher.GetNextResult()); | 369 EXPECT_TRUE(result_catcher.GetNextResult()); |
| 354 CloseBrowserSynchronously(browser); | 370 CloseBrowserSynchronously(browser); |
| 355 } | 371 } |
| 356 | 372 |
| 357 } // namespace policy | 373 } // namespace policy |
| OLD | NEW |