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

Side by Side Diff: chrome/browser/policy/cloud/cloud_policy_browsertest.cc

Issue 2534983002: Re-enabled UserCloudPolicyManagerChromeOS unit tests (Closed)
Patch Set: review feedback Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" 20 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h"
21 #include "chrome/browser/policy/cloud/cloud_policy_test_utils.h"
21 #include "chrome/browser/policy/profile_policy_connector.h" 22 #include "chrome/browser/policy/profile_policy_connector.h"
22 #include "chrome/browser/policy/profile_policy_connector_factory.h" 23 #include "chrome/browser/policy/profile_policy_connector_factory.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/test/base/in_process_browser_test.h" 27 #include "chrome/test/base/in_process_browser_test.h"
27 #include "components/invalidation/impl/fake_invalidation_service.h" 28 #include "components/invalidation/impl/fake_invalidation_service.h"
28 #include "components/invalidation/impl/profile_invalidation_provider.h" 29 #include "components/invalidation/impl/profile_invalidation_provider.h"
29 #include "components/invalidation/public/invalidation.h" 30 #include "components/invalidation/public/invalidation.h"
30 #include "components/invalidation/public/invalidation_service.h" 31 #include "components/invalidation/public/invalidation_service.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 " \"invalidation_name\": \"test_policy\"" 142 " \"invalidation_name\": \"test_policy\""
142 "}"; 143 "}";
143 144
144 return base::StringPrintf(kTestPolicy, 145 return base::StringPrintf(kTestPolicy,
145 dm_protocol::kChromeUserPolicyType, 146 dm_protocol::kChromeUserPolicyType,
146 homepage, 147 homepage,
147 GetTestUser(), 148 GetTestUser(),
148 key_version); 149 key_version);
149 } 150 }
150 151
151 void GetExpectedDefaultPolicy(PolicyMap* policy_map) {
152 policy_map->Set(key::kNTPContentSuggestionsEnabled, POLICY_LEVEL_MANDATORY,
153 POLICY_SCOPE_USER, POLICY_SOURCE_ENTERPRISE_DEFAULT,
154 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
155 #if defined(OS_CHROMEOS)
156 policy_map->Set(key::kChromeOsMultiProfileUserBehavior,
157 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
158 POLICY_SOURCE_ENTERPRISE_DEFAULT,
159 base::MakeUnique<base::StringValue>("primary-only"), nullptr);
160 policy_map->Set(key::kEasyUnlockAllowed, POLICY_LEVEL_MANDATORY,
161 POLICY_SCOPE_USER, POLICY_SOURCE_ENTERPRISE_DEFAULT,
162 base::MakeUnique<base::FundamentalValue>(false), nullptr);
163 policy_map->Set(key::kCaptivePortalAuthenticationIgnoresProxy,
164 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
165 POLICY_SOURCE_ENTERPRISE_DEFAULT,
166 base::MakeUnique<base::FundamentalValue>(false), nullptr);
167 policy_map->Set(key::kAllowDinosaurEasterEgg, POLICY_LEVEL_MANDATORY,
168 POLICY_SCOPE_USER, POLICY_SOURCE_ENTERPRISE_DEFAULT,
169 base::MakeUnique<base::FundamentalValue>(false), nullptr);
170 policy_map->Set(key::kArcEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
171 POLICY_SOURCE_ENTERPRISE_DEFAULT,
172 base::MakeUnique<base::FundamentalValue>(false), nullptr);
173 policy_map->Set(key::kPacHttpsUrlStrippingEnabled, POLICY_LEVEL_MANDATORY,
174 POLICY_SCOPE_USER, POLICY_SOURCE_ENTERPRISE_DEFAULT,
175 base::MakeUnique<base::FundamentalValue>(false), nullptr);
176 #endif
177 }
178
179 void GetExpectedTestPolicy(PolicyMap* expected, const char* homepage) { 152 void GetExpectedTestPolicy(PolicyMap* expected, const char* homepage) {
180 GetExpectedDefaultPolicy(expected); 153 GetExpectedDefaultPolicy(expected);
181 154
182 expected->Set(key::kShowHomeButton, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 155 expected->Set(key::kShowHomeButton, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
183 POLICY_SOURCE_CLOUD, 156 POLICY_SOURCE_CLOUD,
184 base::MakeUnique<base::FundamentalValue>(true), nullptr); 157 base::MakeUnique<base::FundamentalValue>(true), nullptr);
185 expected->Set(key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY, 158 expected->Set(key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY,
186 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 159 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
187 base::MakeUnique<base::FundamentalValue>(4), nullptr); 160 base::MakeUnique<base::FundamentalValue>(4), nullptr);
188 base::ListValue list; 161 base::ListValue list;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 { 327 {
355 base::RunLoop run_loop; 328 base::RunLoop run_loop;
356 // This fetches the new policies, using the same key. 329 // This fetches the new policies, using the same key.
357 policy_service->RefreshPolicies(run_loop.QuitClosure()); 330 policy_service->RefreshPolicies(run_loop.QuitClosure());
358 run_loop.Run(); 331 run_loop.Run();
359 } 332 }
360 EXPECT_TRUE(expected.Equals(policy_service->GetPolicies( 333 EXPECT_TRUE(expected.Equals(policy_service->GetPolicies(
361 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); 334 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))));
362 } 335 }
363 336
337 #if defined(OS_CHROMEOS)
338 // ENTERPRISE_DEFAULT policies only are supported on Chrome OS currently.
339 IN_PROC_BROWSER_TEST_F(CloudPolicyTest, EnsureDefaultPoliciesSet) {
340 PolicyService* policy_service = GetPolicyService();
341 {
342 base::RunLoop run_loop;
343 // This does the initial fetch and stores the initial key.
344 policy_service->RefreshPolicies(run_loop.QuitClosure());
345 run_loop.Run();
346 }
347
348 PolicyMap default_policy;
349 GetExpectedDefaultPolicy(&default_policy);
350 // Make sure the expected policy has at least one of the policies we're
351 // expecting.
352 EXPECT_TRUE(default_policy.GetValue(key::kEasyUnlockAllowed));
353
354 // Now make sure that these default policies are actually getting injected.
355 EXPECT_TRUE(default_policy.Equals(policy_service->GetPolicies(
356 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))));
357 }
358 #endif
359
364 IN_PROC_BROWSER_TEST_F(CloudPolicyTest, InvalidatePolicy) { 360 IN_PROC_BROWSER_TEST_F(CloudPolicyTest, InvalidatePolicy) {
365 PolicyService* policy_service = GetPolicyService(); 361 PolicyService* policy_service = GetPolicyService();
366 policy_service->AddObserver(POLICY_DOMAIN_CHROME, this); 362 policy_service->AddObserver(POLICY_DOMAIN_CHROME, this);
367 363
368 // Perform the initial fetch. 364 // Perform the initial fetch.
369 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy("google.com", 0))); 365 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy("google.com", 0)));
370 { 366 {
371 base::RunLoop run_loop; 367 base::RunLoop run_loop;
372 policy_service->RefreshPolicies(run_loop.QuitClosure()); 368 policy_service->RefreshPolicies(run_loop.QuitClosure());
373 run_loop.Run(); 369 run_loop.Run();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 490
495 // They should now serialize to the same bytes. 491 // They should now serialize to the same bytes.
496 std::string chrome_settings_serialized; 492 std::string chrome_settings_serialized;
497 std::string cloud_policy_serialized; 493 std::string cloud_policy_serialized;
498 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); 494 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized));
499 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); 495 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized));
500 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); 496 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized);
501 } 497 }
502 498
503 } // namespace policy 499 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698