Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: chrome/browser/chromeos/policy/device_cloud_policy_browsertest.cc

Issue 2159103006: Add policy provider that would filter extensions/apps allowed on the (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 void SetUpCommandLine(base::CommandLine* command_line) override { 226 void SetUpCommandLine(base::CommandLine* command_line) override {
226 SigninExtensionsDeviceCloudPolicyBrowserTestBase::SetUpCommandLine( 227 SigninExtensionsDeviceCloudPolicyBrowserTestBase::SetUpCommandLine(
227 command_line); 228 command_line);
228 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, 229 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
229 policy_test_server_.GetServiceURL().spec()); 230 policy_test_server_.GetServiceURL().spec());
230 } 231 }
231 232
232 void SetUpInProcessBrowserTestFixture() override { 233 void SetUpInProcessBrowserTestFixture() override {
233 SigninExtensionsDeviceCloudPolicyBrowserTestBase:: 234 SigninExtensionsDeviceCloudPolicyBrowserTestBase::
234 SetUpInProcessBrowserTestFixture(); 235 SetUpInProcessBrowserTestFixture();
236 signin_policy_provided_disabler_ =
237 chromeos::GetScopedSigninScreenPolicyProviderDisablerForTesting();
235 EXPECT_TRUE(PathService::Get(chromeos::DIR_SIGNIN_PROFILE_COMPONENT_POLICY, 238 EXPECT_TRUE(PathService::Get(chromeos::DIR_SIGNIN_PROFILE_COMPONENT_POLICY,
236 &component_policy_cache_dir_)); 239 &component_policy_cache_dir_));
237 PrepareFakeComponentPolicyResponse(); 240 PrepareFakeComponentPolicyResponse();
238 } 241 }
239 242
240 void TearDownInProcessBrowserTestFixture() override { 243 void TearDownInProcessBrowserTestFixture() override {
241 // Check that the component policy cache was not cleared during browser 244 // Check that the component policy cache was not cleared during browser
242 // teardown. 245 // teardown.
243 ResourceCache cache(component_policy_cache_dir_, new base::NullTaskRunner); 246 ResourceCache cache(component_policy_cache_dir_, new base::NullTaskRunner);
244 std::string stub; 247 std::string stub;
(...skipping 20 matching lines...) Expand all
265 BuildTestComponentPolicyPayload().SerializeAsString())); 268 BuildTestComponentPolicyPayload().SerializeAsString()));
266 fetcher_factory_.SetFakeResponse(GURL(kFakePolicyUrl), kFakePolicy, 269 fetcher_factory_.SetFakeResponse(GURL(kFakePolicyUrl), kFakePolicy,
267 net::HTTP_OK, 270 net::HTTP_OK,
268 net::URLRequestStatus::SUCCESS); 271 net::URLRequestStatus::SUCCESS);
269 } 272 }
270 273
271 LocalPolicyTestServer policy_test_server_; 274 LocalPolicyTestServer policy_test_server_;
272 net::URLFetcherImplFactory fetcher_impl_factory_; 275 net::URLFetcherImplFactory fetcher_impl_factory_;
273 net::FakeURLFetcherFactory fetcher_factory_; 276 net::FakeURLFetcherFactory fetcher_factory_;
274 base::FilePath component_policy_cache_dir_; 277 base::FilePath component_policy_cache_dir_;
278 std::unique_ptr<base::AutoReset<bool>> signin_policy_provided_disabler_;
275 }; 279 };
276 280
277 IN_PROC_BROWSER_TEST_F(SigninExtensionsDeviceCloudPolicyBrowserTest, 281 IN_PROC_BROWSER_TEST_F(SigninExtensionsDeviceCloudPolicyBrowserTest,
278 InstallAndRunInWindow) { 282 InstallAndRunInWindow) {
279 const extensions::Extension* extension = InstallAndLoadTestExtension(); 283 const extensions::Extension* extension = InstallAndLoadTestExtension();
280 ASSERT_TRUE(extension); 284 ASSERT_TRUE(extension);
281 Browser* browser = CreateBrowser(GetSigninProfile()); 285 Browser* browser = CreateBrowser(GetSigninProfile());
282 extensions::ResultCatcher result_catcher; 286 extensions::ResultCatcher result_catcher;
283 ui_test_utils::NavigateToURL( 287 ui_test_utils::NavigateToURL(
284 browser, extension->GetResourceURL(kTestExtensionTestPage)); 288 browser, extension->GetResourceURL(kTestExtensionTestPage));
285 EXPECT_TRUE(result_catcher.GetNextResult()); 289 EXPECT_TRUE(result_catcher.GetNextResult());
286 CloseBrowserSynchronously(browser); 290 CloseBrowserSynchronously(browser);
287 } 291 }
288 292
289 // This class tests that the cached component policy is successfully loaded and 293 // 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. 294 // passed to the extension that is already installed into the signin profile.
291 // 295 //
292 // To accomplish this, the class prefills the signin profile with, first, the 296 // To accomplish this, the class prefills the signin profile with, first, the
293 // installed test extension, and, second, with the cached component policy. 297 // installed test extension, and, second, with the cached component policy.
294 class PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest 298 class PreinstalledSigninExtensionsDeviceCloudPolicyBrowserTest
295 : public SigninExtensionsDeviceCloudPolicyBrowserTestBase { 299 : public SigninExtensionsDeviceCloudPolicyBrowserTestBase {
296 protected: 300 protected:
297 constexpr static const char* kFakeProfileSourceDir = 301 constexpr static const char* kFakeProfileSourceDir =
298 "extensions/profiles/signin_screen_managed_storage"; 302 "extensions/profiles/signin_screen_managed_storage";
299 303
300 private: 304 std::unique_ptr<base::AutoReset<bool>> signin_policy_provided_disabler_;
305
301 bool SetUpUserDataDirectory() override { 306 bool SetUpUserDataDirectory() override {
302 PrefillSigninProfile(); 307 PrefillSigninProfile();
303 PrefillComponentPolicyCache(); 308 PrefillComponentPolicyCache();
304 return DevicePolicyCrosBrowserTest::SetUpUserDataDirectory(); 309 return DevicePolicyCrosBrowserTest::SetUpUserDataDirectory();
305 } 310 }
306 311
312 void SetUpInProcessBrowserTestFixture() override {
313 SigninExtensionsDeviceCloudPolicyBrowserTestBase::
314 SetUpInProcessBrowserTestFixture();
315 signin_policy_provided_disabler_ =
316 chromeos::GetScopedSigninScreenPolicyProviderDisablerForTesting();
317 }
318
307 static void PrefillSigninProfile() { 319 static void PrefillSigninProfile() {
308 base::FilePath profile_source_path; 320 base::FilePath profile_source_path;
309 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &profile_source_path)); 321 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &profile_source_path));
310 profile_source_path = profile_source_path.AppendASCII(kFakeProfileSourceDir) 322 profile_source_path = profile_source_path.AppendASCII(kFakeProfileSourceDir)
311 .AppendASCII(chrome::kInitialProfile); 323 .AppendASCII(chrome::kInitialProfile);
312 324
313 base::FilePath profile_target_path; 325 base::FilePath profile_target_path;
314 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_target_path)); 326 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_target_path));
315 327
316 EXPECT_TRUE( 328 EXPECT_TRUE(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 ASSERT_TRUE(extension); 360 ASSERT_TRUE(extension);
349 Browser* browser = CreateBrowser(GetSigninProfile()); 361 Browser* browser = CreateBrowser(GetSigninProfile());
350 extensions::ResultCatcher result_catcher; 362 extensions::ResultCatcher result_catcher;
351 ui_test_utils::NavigateToURL( 363 ui_test_utils::NavigateToURL(
352 browser, extension->GetResourceURL(kTestExtensionTestPage)); 364 browser, extension->GetResourceURL(kTestExtensionTestPage));
353 EXPECT_TRUE(result_catcher.GetNextResult()); 365 EXPECT_TRUE(result_catcher.GetNextResult());
354 CloseBrowserSynchronously(browser); 366 CloseBrowserSynchronously(browser);
355 } 367 }
356 368
357 } // namespace policy 369 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698