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

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: Fixed browsertest and removed unnecessary string for default values. 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,
Thiemo Nagel 2015/09/01 17:40:36 I don't see a point in adding the source here. It
fhorschig 2015/09/04 06:53:53 Equals compares for sources. This is a good thing
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 }
65 66
66 // Populate expected policy name. 67 // Populate expected policy name.
67 expected_policy.push_back(name); 68 expected_policy.push_back(name);
68 69
69 // Populate expected policy value. 70 // Populate expected policy value.
70 expected_policy.push_back(value); 71 expected_policy.push_back(value);
71 72
73 // Populate expected source name.
74 expected_policy.push_back(source);
75
72 // Populate expected status. 76 // Populate expected status.
73 if (unknown) 77 if (unknown)
74 expected_policy.push_back(l10n_util::GetStringUTF8(IDS_POLICY_UNKNOWN)); 78 expected_policy.push_back(l10n_util::GetStringUTF8(IDS_POLICY_UNKNOWN));
75 else if (metadata) 79 else if (metadata)
76 expected_policy.push_back(l10n_util::GetStringUTF8(IDS_POLICY_OK)); 80 expected_policy.push_back(l10n_util::GetStringUTF8(IDS_POLICY_OK));
77 else 81 else
78 expected_policy.push_back(l10n_util::GetStringUTF8(IDS_POLICY_UNSET)); 82 expected_policy.push_back(l10n_util::GetStringUTF8(IDS_POLICY_UNSET));
79 83
80 // Populate expected expanded policy value. 84 // Populate expected expanded policy value.
81 expected_policy.push_back(value); 85 expected_policy.push_back(value);
(...skipping 29 matching lines...) Expand all
111 PolicyUITest::~PolicyUITest() { 115 PolicyUITest::~PolicyUITest() {
112 } 116 }
113 117
114 void PolicyUITest::SetUpInProcessBrowserTestFixture() { 118 void PolicyUITest::SetUpInProcessBrowserTestFixture() {
115 EXPECT_CALL(provider_, IsInitializationComplete(_)) 119 EXPECT_CALL(provider_, IsInitializationComplete(_))
116 .WillRepeatedly(Return(true)); 120 .WillRepeatedly(Return(true));
117 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); 121 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
118 } 122 }
119 123
120 void PolicyUITest::UpdateProviderPolicy(const policy::PolicyMap& policy) { 124 void PolicyUITest::UpdateProviderPolicy(const policy::PolicyMap& policy) {
121 provider_.UpdateChromePolicy(policy); 125 provider_.UpdateChromePolicy(policy);
122 base::RunLoop loop; 126 base::RunLoop loop;
123 loop.RunUntilIdle(); 127 loop.RunUntilIdle();
124 } 128 }
125 129
126 void PolicyUITest::VerifyPolicies( 130 void PolicyUITest::VerifyPolicies(
127 const std::vector<std::vector<std::string> >& expected_policies) { 131 const std::vector<std::vector<std::string> >& expected_policies) {
128 ui_test_utils::NavigateToURL(browser(), GURL("chrome://policy")); 132 ui_test_utils::NavigateToURL(browser(), GURL("chrome://policy"));
129 133
130 // Retrieve the text contents of the policy table cells for all policies. 134 // Retrieve the text contents of the policy table cells for all policies.
131 const std::string javascript = 135 const std::string javascript =
132 "var entries = document.querySelectorAll(" 136 "var entries = document.querySelectorAll("
133 " 'section.policy-table-section > * > tbody');" 137 " 'section.policy-table-section > * > tbody');"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // the correct order. 183 // the correct order.
180 184
181 // Expect that the policy table contains all known policies in alphabetical 185 // Expect that the policy table contains all known policies in alphabetical
182 // order and none of the policies have a set value. 186 // order and none of the policies have a set value.
183 std::vector<std::vector<std::string> > expected_policies; 187 std::vector<std::vector<std::string> > expected_policies;
184 policy::Schema chrome_schema = 188 policy::Schema chrome_schema =
185 policy::Schema::Wrap(policy::GetChromeSchemaData()); 189 policy::Schema::Wrap(policy::GetChromeSchemaData());
186 ASSERT_TRUE(chrome_schema.valid()); 190 ASSERT_TRUE(chrome_schema.valid());
187 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator(); 191 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator();
188 !it.IsAtEnd(); it.Advance()) { 192 !it.IsAtEnd(); it.Advance()) {
189 expected_policies.push_back( 193 expected_policies.push_back(PopulateExpectedPolicy(
190 PopulateExpectedPolicy(it.key(), std::string(), NULL, false)); 194 it.key(), std::string(), std::string(), NULL, false));
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
201 // checking that the policy table contains the policy names, values and 205 // checking that the policy table contains the policy names, values and
202 // metadata in the correct order. 206 // metadata in the correct order.
203 policy::PolicyMap values; 207 policy::PolicyMap values;
204 std::map<std::string, std::string> expected_values; 208 std::map<std::string, std::string> expected_values;
205 209
206 // Set the values of four existing policies. 210 // Set the values of four existing policies.
207 base::ListValue* restore_on_startup_urls = new base::ListValue; 211 base::ListValue* restore_on_startup_urls = new base::ListValue;
208 restore_on_startup_urls->Append(new base::StringValue("aaa")); 212 restore_on_startup_urls->Append(new base::StringValue("aaa"));
209 restore_on_startup_urls->Append(new base::StringValue("bbb")); 213 restore_on_startup_urls->Append(new base::StringValue("bbb"));
210 restore_on_startup_urls->Append(new base::StringValue("ccc")); 214 restore_on_startup_urls->Append(new base::StringValue("ccc"));
211 values.Set(policy::key::kRestoreOnStartupURLs, 215 values.Set(policy::key::kRestoreOnStartupURLs, policy::POLICY_LEVEL_MANDATORY,
Thiemo Nagel 2015/09/01 17:40:36 Don't change existing formatting!
fhorschig 2015/09/04 06:53:53 Done.
212 policy::POLICY_LEVEL_MANDATORY, 216 policy::POLICY_SCOPE_USER, restore_on_startup_urls, NULL,
213 policy::POLICY_SCOPE_USER, 217 policy::POLICY_SOURCE_DEFAULT);
214 restore_on_startup_urls,
215 NULL);
216 expected_values[policy::key::kRestoreOnStartupURLs] = "aaa,bbb,ccc"; 218 expected_values[policy::key::kRestoreOnStartupURLs] = "aaa,bbb,ccc";
217 values.Set(policy::key::kHomepageLocation, 219 values.Set(policy::key::kHomepageLocation, policy::POLICY_LEVEL_MANDATORY,
218 policy::POLICY_LEVEL_MANDATORY,
219 policy::POLICY_SCOPE_MACHINE, 220 policy::POLICY_SCOPE_MACHINE,
220 new base::StringValue("http://google.com"), 221 new base::StringValue("http://google.com"), NULL,
221 NULL); 222 policy::POLICY_SOURCE_DEFAULT);
222 expected_values[policy::key::kHomepageLocation] = "http://google.com"; 223 expected_values[policy::key::kHomepageLocation] = "http://google.com";
223 values.Set(policy::key::kRestoreOnStartup, 224 values.Set(policy::key::kRestoreOnStartup, policy::POLICY_LEVEL_RECOMMENDED,
224 policy::POLICY_LEVEL_RECOMMENDED, 225 policy::POLICY_SCOPE_USER, new base::FundamentalValue(4), NULL,
225 policy::POLICY_SCOPE_USER, 226 policy::POLICY_SOURCE_DEFAULT);
226 new base::FundamentalValue(4),
227 NULL);
228 expected_values[policy::key::kRestoreOnStartup] = "4"; 227 expected_values[policy::key::kRestoreOnStartup] = "4";
229 values.Set(policy::key::kShowHomeButton, 228 values.Set(policy::key::kShowHomeButton, policy::POLICY_LEVEL_RECOMMENDED,
230 policy::POLICY_LEVEL_RECOMMENDED, 229 policy::POLICY_SCOPE_MACHINE, new base::FundamentalValue(true),
231 policy::POLICY_SCOPE_MACHINE, 230 NULL, policy::POLICY_SOURCE_DEFAULT);
232 new base::FundamentalValue(true),
233 NULL);
234 expected_values[policy::key::kShowHomeButton] = "true"; 231 expected_values[policy::key::kShowHomeButton] = "true";
235 // Set the value of a policy that does not exist. 232 // Set the value of a policy that does not exist.
236 const std::string kUnknownPolicy = "NoSuchThing"; 233 const std::string kUnknownPolicy = "NoSuchThing";
237 values.Set(kUnknownPolicy, 234 values.Set(kUnknownPolicy, policy::POLICY_LEVEL_MANDATORY,
238 policy::POLICY_LEVEL_MANDATORY, 235 policy::POLICY_SCOPE_USER, new base::FundamentalValue(true), NULL,
239 policy::POLICY_SCOPE_USER, 236 policy::POLICY_SOURCE_DEFAULT);
240 new base::FundamentalValue(true),
241 NULL);
242 expected_values[kUnknownPolicy] = "true"; 237 expected_values[kUnknownPolicy] = "true";
243 UpdateProviderPolicy(values); 238 UpdateProviderPolicy(values);
244 239
245 // Expect that the policy table contains, in order: 240 // Expect that the policy table contains, in order:
246 // * All known policies whose value has been set, in alphabetical order. 241 // * All known policies whose value has been set, in alphabetical order.
247 // * The unknown policy. 242 // * The unknown policy.
248 // * All known policies whose value has not been set, in alphabetical order. 243 // * All known policies whose value has not been set, in alphabetical order.
249 std::vector<std::vector<std::string> > expected_policies; 244 std::vector<std::vector<std::string> > expected_policies;
250 size_t first_unset_position = 0; 245 size_t first_unset_position = 0;
251 policy::Schema chrome_schema = 246 policy::Schema chrome_schema =
252 policy::Schema::Wrap(policy::GetChromeSchemaData()); 247 policy::Schema::Wrap(policy::GetChromeSchemaData());
253 ASSERT_TRUE(chrome_schema.valid()); 248 ASSERT_TRUE(chrome_schema.valid());
254 for (policy::Schema::Iterator props = chrome_schema.GetPropertiesIterator(); 249 for (policy::Schema::Iterator props = chrome_schema.GetPropertiesIterator();
255 !props.IsAtEnd(); props.Advance()) { 250 !props.IsAtEnd(); props.Advance()) {
256 std::map<std::string, std::string>::const_iterator it = 251 std::map<std::string, std::string>::const_iterator it =
257 expected_values.find(props.key()); 252 expected_values.find(props.key());
258 const std::string value = 253 const std::string value =
259 it == expected_values.end() ? std::string() : it->second; 254 it == expected_values.end() ? std::string() : it->second;
260 const policy::PolicyMap::Entry* metadata = values.Get(props.key()); 255 const policy::PolicyMap::Entry* metadata = values.Get(props.key());
261 expected_policies.insert( 256 expected_policies.insert(
262 metadata ? expected_policies.begin() + first_unset_position++ : 257 metadata ? expected_policies.begin() + first_unset_position++
263 expected_policies.end(), 258 : expected_policies.end(),
264 PopulateExpectedPolicy(props.key(), value, metadata, false)); 259 PopulateExpectedPolicy(props.key(), value, std::string(), metadata,
260 false));
265 } 261 }
266 expected_policies.insert( 262 expected_policies.insert(
267 expected_policies.begin() + first_unset_position++, 263 expected_policies.begin() + first_unset_position++,
268 PopulateExpectedPolicy(kUnknownPolicy, 264 PopulateExpectedPolicy(kUnknownPolicy, expected_values[kUnknownPolicy],
269 expected_values[kUnknownPolicy], 265 std::string(), values.Get(kUnknownPolicy), true));
270 values.Get(kUnknownPolicy),
271 true));
272 266
273 // Retrieve the contents of the policy table from the UI and verify that it 267 // Retrieve the contents of the policy table from the UI and verify that it
274 // matches the expectation. 268 // matches the expectation.
275 VerifyPolicies(expected_policies); 269 VerifyPolicies(expected_policies);
276 } 270 }
277 271
278 IN_PROC_BROWSER_TEST_F(PolicyUITest, ExtensionLoadAndSendPolicy) { 272 IN_PROC_BROWSER_TEST_F(PolicyUITest, ExtensionLoadAndSendPolicy) {
279 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIPolicyURL)); 273 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIPolicyURL));
280 base::ScopedTempDir temp_dir_; 274 base::ScopedTempDir temp_dir_;
281 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 275 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
(...skipping 28 matching lines...) Expand all
310 service->OnExtensionInstalled(builder.Build().get(), syncer::StringOrdinal(), 304 service->OnExtensionInstalled(builder.Build().get(), syncer::StringOrdinal(),
311 0); 305 0);
312 306
313 std::vector<std::vector<std::string>> expected_policies; 307 std::vector<std::vector<std::string>> expected_policies;
314 policy::Schema chrome_schema = 308 policy::Schema chrome_schema =
315 policy::Schema::Wrap(policy::GetChromeSchemaData()); 309 policy::Schema::Wrap(policy::GetChromeSchemaData());
316 ASSERT_TRUE(chrome_schema.valid()); 310 ASSERT_TRUE(chrome_schema.valid());
317 311
318 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator(); 312 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator();
319 !it.IsAtEnd(); it.Advance()) { 313 !it.IsAtEnd(); it.Advance()) {
320 expected_policies.push_back( 314 expected_policies.push_back(PopulateExpectedPolicy(
321 PopulateExpectedPolicy(it.key(), std::string(), NULL, false)); 315 it.key(), std::string(), std::string(), NULL, false));
322 } 316 }
323 // Add newly added policy to expected policy list. 317 // Add newly added policy to expected policy list.
324 expected_policies.push_back(PopulateExpectedPolicy( 318 expected_policies.push_back(PopulateExpectedPolicy(
325 newly_added_policy_name, std::string(), NULL, false)); 319 newly_added_policy_name, std::string(), std::string(), NULL, false));
326 320
327 // Verify if policy UI includes policy that extension have. 321 // Verify if policy UI includes policy that extension have.
328 VerifyPolicies(expected_policies); 322 VerifyPolicies(expected_policies);
329 } 323 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698