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

Side by Side Diff: chrome/browser/ui/webui/policy_ui_browsertest.cc

Issue 1304843004: Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <vector> 5 #include <vector>
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 23 matching lines...) Expand all
34 #include "url/gurl.h" 34 #include "url/gurl.h"
35 35
36 using testing::Return; 36 using testing::Return;
37 using testing::_; 37 using testing::_;
38 38
39 namespace { 39 namespace {
40 40
41 std::vector<std::string> PopulateExpectedPolicy( 41 std::vector<std::string> PopulateExpectedPolicy(
42 const std::string& name, 42 const std::string& name,
43 const std::string& value, 43 const std::string& value,
44 const std::string& source,
44 const policy::PolicyMap::Entry* metadata, 45 const policy::PolicyMap::Entry* metadata,
45 bool unknown) { 46 bool unknown) {
46 std::vector<std::string> expected_policy; 47 std::vector<std::string> expected_policy;
47 48
48 // Populate expected scope. 49 // Populate expected scope.
49 if (metadata) { 50 if (metadata) {
50 expected_policy.push_back(l10n_util::GetStringUTF8( 51 expected_policy.push_back(l10n_util::GetStringUTF8(
51 metadata->scope == policy::POLICY_SCOPE_MACHINE ? 52 metadata->scope == policy::POLICY_SCOPE_MACHINE ?
52 IDS_POLICY_SCOPE_DEVICE : IDS_POLICY_SCOPE_USER)); 53 IDS_POLICY_SCOPE_DEVICE : IDS_POLICY_SCOPE_USER));
53 } else { 54 } else {
54 expected_policy.push_back(std::string()); 55 expected_policy.push_back(std::string());
55 } 56 }
56 57
57 // Populate expected level. 58 // Populate expected level.
58 if (metadata) { 59 if (metadata) {
59 expected_policy.push_back(l10n_util::GetStringUTF8( 60 expected_policy.push_back(l10n_util::GetStringUTF8(
60 metadata->level == policy::POLICY_LEVEL_RECOMMENDED ? 61 metadata->level == policy::POLICY_LEVEL_RECOMMENDED ?
61 IDS_POLICY_LEVEL_RECOMMENDED : IDS_POLICY_LEVEL_MANDATORY)); 62 IDS_POLICY_LEVEL_RECOMMENDED : IDS_POLICY_LEVEL_MANDATORY));
62 } else { 63 } else {
63 expected_policy.push_back(std::string()); 64 expected_policy.push_back(std::string());
64 } 65 }
66 // Populate expected source name.
67 expected_policy.push_back(source);
65 68
66 // Populate expected policy name. 69 // Populate expected policy name.
67 expected_policy.push_back(name); 70 expected_policy.push_back(name);
68 71
69 // Populate expected policy value. 72 // Populate expected policy value.
70 expected_policy.push_back(value); 73 expected_policy.push_back(value);
71 74
72 // Populate expected status. 75 // Populate expected status.
73 if (unknown) 76 if (unknown)
74 expected_policy.push_back(l10n_util::GetStringUTF8(IDS_POLICY_UNKNOWN)); 77 expected_policy.push_back(l10n_util::GetStringUTF8(IDS_POLICY_UNKNOWN));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 PolicyUITest::~PolicyUITest() { 114 PolicyUITest::~PolicyUITest() {
112 } 115 }
113 116
114 void PolicyUITest::SetUpInProcessBrowserTestFixture() { 117 void PolicyUITest::SetUpInProcessBrowserTestFixture() {
115 EXPECT_CALL(provider_, IsInitializationComplete(_)) 118 EXPECT_CALL(provider_, IsInitializationComplete(_))
116 .WillRepeatedly(Return(true)); 119 .WillRepeatedly(Return(true));
117 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); 120 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
118 } 121 }
119 122
120 void PolicyUITest::UpdateProviderPolicy(const policy::PolicyMap& policy) { 123 void PolicyUITest::UpdateProviderPolicy(const policy::PolicyMap& policy) {
121 provider_.UpdateChromePolicy(policy); 124 provider_.UpdateChromePolicy(policy);
122 base::RunLoop loop; 125 base::RunLoop loop;
123 loop.RunUntilIdle(); 126 loop.RunUntilIdle();
124 } 127 }
125 128
126 void PolicyUITest::VerifyPolicies( 129 void PolicyUITest::VerifyPolicies(
127 const std::vector<std::vector<std::string> >& expected_policies) { 130 const std::vector<std::vector<std::string> >& expected_policies) {
128 ui_test_utils::NavigateToURL(browser(), GURL("chrome://policy")); 131 ui_test_utils::NavigateToURL(browser(), GURL("chrome://policy"));
129 132
130 // Retrieve the text contents of the policy table cells for all policies. 133 // Retrieve the text contents of the policy table cells for all policies.
131 const std::string javascript = 134 const std::string javascript =
132 "var entries = document.querySelectorAll(" 135 "var entries = document.querySelectorAll("
133 " 'section.policy-table-section > * > tbody');" 136 " 'section.policy-table-section > * > tbody');"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 183
181 // Expect that the policy table contains all known policies in alphabetical 184 // Expect that the policy table contains all known policies in alphabetical
182 // order and none of the policies have a set value. 185 // order and none of the policies have a set value.
183 std::vector<std::vector<std::string> > expected_policies; 186 std::vector<std::vector<std::string> > expected_policies;
184 policy::Schema chrome_schema = 187 policy::Schema chrome_schema =
185 policy::Schema::Wrap(policy::GetChromeSchemaData()); 188 policy::Schema::Wrap(policy::GetChromeSchemaData());
186 ASSERT_TRUE(chrome_schema.valid()); 189 ASSERT_TRUE(chrome_schema.valid());
187 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator(); 190 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator();
188 !it.IsAtEnd(); it.Advance()) { 191 !it.IsAtEnd(); it.Advance()) {
189 expected_policies.push_back( 192 expected_policies.push_back(
190 PopulateExpectedPolicy(it.key(), std::string(), NULL, false)); 193 PopulateExpectedPolicy(
194 it.key(), std::string(), std::string(), NULL, false));
bartfab (slow) 2015/09/14 14:42:26 Nit: s/NULL/nullptr/
fhorschig 2015/09/16 13:52:04 Done.
191 } 195 }
192 196
193 // Retrieve the contents of the policy table from the UI and verify that it 197 // Retrieve the contents of the policy table from the UI and verify that it
194 // matches the expectation. 198 // matches the expectation.
195 VerifyPolicies(expected_policies); 199 VerifyPolicies(expected_policies);
196 } 200 }
197 201
198 IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) { 202 IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) {
199 // Verifies that policy values are sent to the UI and processed there 203 // Verifies that policy values are sent to the UI and processed there
200 // correctly by setting the values of four known and one unknown policy and 204 // correctly by setting the values of four known and one unknown policy and
(...skipping 26 matching lines...) Expand all
227 NULL); 231 NULL);
228 expected_values[policy::key::kRestoreOnStartup] = "4"; 232 expected_values[policy::key::kRestoreOnStartup] = "4";
229 values.Set(policy::key::kShowHomeButton, 233 values.Set(policy::key::kShowHomeButton,
230 policy::POLICY_LEVEL_RECOMMENDED, 234 policy::POLICY_LEVEL_RECOMMENDED,
231 policy::POLICY_SCOPE_MACHINE, 235 policy::POLICY_SCOPE_MACHINE,
232 new base::FundamentalValue(true), 236 new base::FundamentalValue(true),
233 NULL); 237 NULL);
234 expected_values[policy::key::kShowHomeButton] = "true"; 238 expected_values[policy::key::kShowHomeButton] = "true";
235 // Set the value of a policy that does not exist. 239 // Set the value of a policy that does not exist.
236 const std::string kUnknownPolicy = "NoSuchThing"; 240 const std::string kUnknownPolicy = "NoSuchThing";
237 values.Set(kUnknownPolicy, 241 values.SetWithSource(kUnknownPolicy,
238 policy::POLICY_LEVEL_MANDATORY, 242 policy::POLICY_LEVEL_MANDATORY,
239 policy::POLICY_SCOPE_USER, 243 policy::POLICY_SCOPE_USER,
240 new base::FundamentalValue(true), 244 new base::FundamentalValue(true),
241 NULL); 245 NULL,
bartfab (slow) 2015/09/14 14:42:26 Nit: s/NULL/nullptr/
fhorschig 2015/09/16 13:52:04 Done.
246 policy::POLICY_SOURCE_CLOUD);
242 expected_values[kUnknownPolicy] = "true"; 247 expected_values[kUnknownPolicy] = "true";
243 UpdateProviderPolicy(values); 248 UpdateProviderPolicy(values);
244 249
245 // Expect that the policy table contains, in order: 250 // Expect that the policy table contains, in order:
246 // * All known policies whose value has been set, in alphabetical order. 251 // * All known policies whose value has been set, in alphabetical order.
247 // * The unknown policy. 252 // * The unknown policy.
248 // * All known policies whose value has not been set, in alphabetical order. 253 // * All known policies whose value has not been set, in alphabetical order.
249 std::vector<std::vector<std::string> > expected_policies; 254 std::vector<std::vector<std::string> > expected_policies;
250 size_t first_unset_position = 0; 255 size_t first_unset_position = 0;
251 policy::Schema chrome_schema = 256 policy::Schema chrome_schema =
252 policy::Schema::Wrap(policy::GetChromeSchemaData()); 257 policy::Schema::Wrap(policy::GetChromeSchemaData());
253 ASSERT_TRUE(chrome_schema.valid()); 258 ASSERT_TRUE(chrome_schema.valid());
254 for (policy::Schema::Iterator props = chrome_schema.GetPropertiesIterator(); 259 for (policy::Schema::Iterator props = chrome_schema.GetPropertiesIterator();
255 !props.IsAtEnd(); props.Advance()) { 260 !props.IsAtEnd(); props.Advance()) {
256 std::map<std::string, std::string>::const_iterator it = 261 std::map<std::string, std::string>::const_iterator it =
257 expected_values.find(props.key()); 262 expected_values.find(props.key());
258 const std::string value = 263 const std::string value =
259 it == expected_values.end() ? std::string() : it->second; 264 it == expected_values.end() ? std::string() : it->second;
260 const policy::PolicyMap::Entry* metadata = values.Get(props.key()); 265 const policy::PolicyMap::Entry* metadata = values.Get(props.key());
261 expected_policies.insert( 266 expected_policies.insert(
262 metadata ? expected_policies.begin() + first_unset_position++ : 267 metadata ? expected_policies.begin() + first_unset_position++ :
263 expected_policies.end(), 268 expected_policies.end(),
264 PopulateExpectedPolicy(props.key(), value, metadata, false)); 269 PopulateExpectedPolicy(
270 props.key(), value, std::string(), metadata, false));
265 } 271 }
266 expected_policies.insert( 272 expected_policies.insert(
267 expected_policies.begin() + first_unset_position++, 273 expected_policies.begin() + first_unset_position++,
268 PopulateExpectedPolicy(kUnknownPolicy, 274 PopulateExpectedPolicy(kUnknownPolicy,
269 expected_values[kUnknownPolicy], 275 expected_values[kUnknownPolicy],
276 "Cloud",
270 values.Get(kUnknownPolicy), 277 values.Get(kUnknownPolicy),
271 true)); 278 true));
272 279
273 // Retrieve the contents of the policy table from the UI and verify that it 280 // Retrieve the contents of the policy table from the UI and verify that it
274 // matches the expectation. 281 // matches the expectation.
275 VerifyPolicies(expected_policies); 282 VerifyPolicies(expected_policies);
276 } 283 }
277 284
278 IN_PROC_BROWSER_TEST_F(PolicyUITest, ExtensionLoadAndSendPolicy) { 285 IN_PROC_BROWSER_TEST_F(PolicyUITest, ExtensionLoadAndSendPolicy) {
279 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIPolicyURL)); 286 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIPolicyURL));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 0); 318 0);
312 319
313 std::vector<std::vector<std::string>> expected_policies; 320 std::vector<std::vector<std::string>> expected_policies;
314 policy::Schema chrome_schema = 321 policy::Schema chrome_schema =
315 policy::Schema::Wrap(policy::GetChromeSchemaData()); 322 policy::Schema::Wrap(policy::GetChromeSchemaData());
316 ASSERT_TRUE(chrome_schema.valid()); 323 ASSERT_TRUE(chrome_schema.valid());
317 324
318 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator(); 325 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator();
319 !it.IsAtEnd(); it.Advance()) { 326 !it.IsAtEnd(); it.Advance()) {
320 expected_policies.push_back( 327 expected_policies.push_back(
321 PopulateExpectedPolicy(it.key(), std::string(), NULL, false)); 328 PopulateExpectedPolicy(
329 it.key(), std::string(), std::string(), NULL, false));
322 } 330 }
323 // Add newly added policy to expected policy list. 331 // Add newly added policy to expected policy list.
324 expected_policies.push_back(PopulateExpectedPolicy( 332 expected_policies.push_back(PopulateExpectedPolicy(
325 newly_added_policy_name, std::string(), NULL, false)); 333 newly_added_policy_name, std::string(), std::string(), NULL, false));
326 334
327 // Verify if policy UI includes policy that extension have. 335 // Verify if policy UI includes policy that extension have.
328 VerifyPolicies(expected_policies); 336 VerifyPolicies(expected_policies);
329 } 337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698