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

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

Issue 1350913006: Revert of 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,
45 const policy::PolicyMap::Entry* metadata, 44 const policy::PolicyMap::Entry* metadata,
46 bool unknown) { 45 bool unknown) {
47 std::vector<std::string> expected_policy; 46 std::vector<std::string> expected_policy;
48 47
49 // Populate expected scope. 48 // Populate expected scope.
50 if (metadata) { 49 if (metadata) {
51 expected_policy.push_back(l10n_util::GetStringUTF8( 50 expected_policy.push_back(l10n_util::GetStringUTF8(
52 metadata->scope == policy::POLICY_SCOPE_MACHINE ? 51 metadata->scope == policy::POLICY_SCOPE_MACHINE ?
53 IDS_POLICY_SCOPE_DEVICE : IDS_POLICY_SCOPE_USER)); 52 IDS_POLICY_SCOPE_DEVICE : IDS_POLICY_SCOPE_USER));
54 } else { 53 } else {
55 expected_policy.push_back(std::string()); 54 expected_policy.push_back(std::string());
56 } 55 }
57 56
58 // Populate expected level. 57 // Populate expected level.
59 if (metadata) { 58 if (metadata) {
60 expected_policy.push_back(l10n_util::GetStringUTF8( 59 expected_policy.push_back(l10n_util::GetStringUTF8(
61 metadata->level == policy::POLICY_LEVEL_RECOMMENDED ? 60 metadata->level == policy::POLICY_LEVEL_RECOMMENDED ?
62 IDS_POLICY_LEVEL_RECOMMENDED : IDS_POLICY_LEVEL_MANDATORY)); 61 IDS_POLICY_LEVEL_RECOMMENDED : IDS_POLICY_LEVEL_MANDATORY));
63 } else { 62 } else {
64 expected_policy.push_back(std::string()); 63 expected_policy.push_back(std::string());
65 } 64 }
66 // Populate expected source name.
67 expected_policy.push_back(source);
68 65
69 // Populate expected policy name. 66 // Populate expected policy name.
70 expected_policy.push_back(name); 67 expected_policy.push_back(name);
71 68
72 // Populate expected policy value. 69 // Populate expected policy value.
73 expected_policy.push_back(value); 70 expected_policy.push_back(value);
74 71
75 // Populate expected status. 72 // Populate expected status.
76 if (unknown) 73 if (unknown)
77 expected_policy.push_back(l10n_util::GetStringUTF8(IDS_POLICY_UNKNOWN)); 74 expected_policy.push_back(l10n_util::GetStringUTF8(IDS_POLICY_UNKNOWN));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 PolicyUITest::~PolicyUITest() { 111 PolicyUITest::~PolicyUITest() {
115 } 112 }
116 113
117 void PolicyUITest::SetUpInProcessBrowserTestFixture() { 114 void PolicyUITest::SetUpInProcessBrowserTestFixture() {
118 EXPECT_CALL(provider_, IsInitializationComplete(_)) 115 EXPECT_CALL(provider_, IsInitializationComplete(_))
119 .WillRepeatedly(Return(true)); 116 .WillRepeatedly(Return(true));
120 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); 117 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
121 } 118 }
122 119
123 void PolicyUITest::UpdateProviderPolicy(const policy::PolicyMap& policy) { 120 void PolicyUITest::UpdateProviderPolicy(const policy::PolicyMap& policy) {
124 provider_.UpdateChromePolicy(policy); 121 provider_.UpdateChromePolicy(policy);
125 base::RunLoop loop; 122 base::RunLoop loop;
126 loop.RunUntilIdle(); 123 loop.RunUntilIdle();
127 } 124 }
128 125
129 void PolicyUITest::VerifyPolicies( 126 void PolicyUITest::VerifyPolicies(
130 const std::vector<std::vector<std::string> >& expected_policies) { 127 const std::vector<std::vector<std::string> >& expected_policies) {
131 ui_test_utils::NavigateToURL(browser(), GURL("chrome://policy")); 128 ui_test_utils::NavigateToURL(browser(), GURL("chrome://policy"));
132 129
133 // Retrieve the text contents of the policy table cells for all policies. 130 // Retrieve the text contents of the policy table cells for all policies.
134 const std::string javascript = 131 const std::string javascript =
135 "var entries = document.querySelectorAll(" 132 "var entries = document.querySelectorAll("
136 " 'section.policy-table-section > * > tbody');" 133 " 'section.policy-table-section > * > tbody');"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 180
184 // Expect that the policy table contains all known policies in alphabetical 181 // Expect that the policy table contains all known policies in alphabetical
185 // order and none of the policies have a set value. 182 // order and none of the policies have a set value.
186 std::vector<std::vector<std::string> > expected_policies; 183 std::vector<std::vector<std::string> > expected_policies;
187 policy::Schema chrome_schema = 184 policy::Schema chrome_schema =
188 policy::Schema::Wrap(policy::GetChromeSchemaData()); 185 policy::Schema::Wrap(policy::GetChromeSchemaData());
189 ASSERT_TRUE(chrome_schema.valid()); 186 ASSERT_TRUE(chrome_schema.valid());
190 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator(); 187 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator();
191 !it.IsAtEnd(); it.Advance()) { 188 !it.IsAtEnd(); it.Advance()) {
192 expected_policies.push_back( 189 expected_policies.push_back(
193 PopulateExpectedPolicy( 190 PopulateExpectedPolicy(it.key(), std::string(), NULL, false));
194 it.key(), std::string(), std::string(), nullptr, false));
195 } 191 }
196 192
197 // Retrieve the contents of the policy table from the UI and verify that it 193 // Retrieve the contents of the policy table from the UI and verify that it
198 // matches the expectation. 194 // matches the expectation.
199 VerifyPolicies(expected_policies); 195 VerifyPolicies(expected_policies);
200 } 196 }
201 197
202 IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) { 198 IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) {
203 // Verifies that policy values are sent to the UI and processed there 199 // Verifies that policy values are sent to the UI and processed there
204 // correctly by setting the values of four known and one unknown policy and 200 // correctly by setting the values of four known and one unknown policy and
205 // checking that the policy table contains the policy names, values and 201 // checking that the policy table contains the policy names, values and
206 // metadata in the correct order. 202 // metadata in the correct order.
207 policy::PolicyMap values; 203 policy::PolicyMap values;
208 std::map<std::string, std::string> expected_values; 204 std::map<std::string, std::string> expected_values;
209 205
210 // Set the values of four existing policies. 206 // Set the values of four existing policies.
211 base::ListValue* restore_on_startup_urls = new base::ListValue; 207 base::ListValue* restore_on_startup_urls = new base::ListValue;
212 restore_on_startup_urls->Append(new base::StringValue("aaa")); 208 restore_on_startup_urls->Append(new base::StringValue("aaa"));
213 restore_on_startup_urls->Append(new base::StringValue("bbb")); 209 restore_on_startup_urls->Append(new base::StringValue("bbb"));
214 restore_on_startup_urls->Append(new base::StringValue("ccc")); 210 restore_on_startup_urls->Append(new base::StringValue("ccc"));
215 values.Set(policy::key::kRestoreOnStartupURLs, 211 values.Set(policy::key::kRestoreOnStartupURLs,
216 policy::POLICY_LEVEL_MANDATORY, 212 policy::POLICY_LEVEL_MANDATORY,
217 policy::POLICY_SCOPE_USER, 213 policy::POLICY_SCOPE_USER,
218 policy::POLICY_SOURCE_CLOUD,
219 restore_on_startup_urls, 214 restore_on_startup_urls,
220 NULL); 215 NULL);
221 expected_values[policy::key::kRestoreOnStartupURLs] = "aaa,bbb,ccc"; 216 expected_values[policy::key::kRestoreOnStartupURLs] = "aaa,bbb,ccc";
222 values.Set(policy::key::kHomepageLocation, 217 values.Set(policy::key::kHomepageLocation,
223 policy::POLICY_LEVEL_MANDATORY, 218 policy::POLICY_LEVEL_MANDATORY,
224 policy::POLICY_SCOPE_MACHINE, 219 policy::POLICY_SCOPE_MACHINE,
225 policy::POLICY_SOURCE_CLOUD,
226 new base::StringValue("http://google.com"), 220 new base::StringValue("http://google.com"),
227 NULL); 221 NULL);
228 expected_values[policy::key::kHomepageLocation] = "http://google.com"; 222 expected_values[policy::key::kHomepageLocation] = "http://google.com";
229 values.Set(policy::key::kRestoreOnStartup, 223 values.Set(policy::key::kRestoreOnStartup,
230 policy::POLICY_LEVEL_RECOMMENDED, 224 policy::POLICY_LEVEL_RECOMMENDED,
231 policy::POLICY_SCOPE_USER, 225 policy::POLICY_SCOPE_USER,
232 policy::POLICY_SOURCE_CLOUD,
233 new base::FundamentalValue(4), 226 new base::FundamentalValue(4),
234 NULL); 227 NULL);
235 expected_values[policy::key::kRestoreOnStartup] = "4"; 228 expected_values[policy::key::kRestoreOnStartup] = "4";
236 values.Set(policy::key::kShowHomeButton, 229 values.Set(policy::key::kShowHomeButton,
237 policy::POLICY_LEVEL_RECOMMENDED, 230 policy::POLICY_LEVEL_RECOMMENDED,
238 policy::POLICY_SCOPE_MACHINE, 231 policy::POLICY_SCOPE_MACHINE,
239 policy::POLICY_SOURCE_CLOUD,
240 new base::FundamentalValue(true), 232 new base::FundamentalValue(true),
241 NULL); 233 NULL);
242 expected_values[policy::key::kShowHomeButton] = "true"; 234 expected_values[policy::key::kShowHomeButton] = "true";
243 // Set the value of a policy that does not exist. 235 // Set the value of a policy that does not exist.
244 const std::string kUnknownPolicy = "NoSuchThing"; 236 const std::string kUnknownPolicy = "NoSuchThing";
245 values.Set(kUnknownPolicy, 237 values.Set(kUnknownPolicy,
246 policy::POLICY_LEVEL_MANDATORY, 238 policy::POLICY_LEVEL_MANDATORY,
247 policy::POLICY_SCOPE_USER, 239 policy::POLICY_SCOPE_USER,
248 policy::POLICY_SOURCE_PLATFORM,
249 new base::FundamentalValue(true), 240 new base::FundamentalValue(true),
250 NULL); 241 NULL);
251 expected_values[kUnknownPolicy] = "true"; 242 expected_values[kUnknownPolicy] = "true";
252 UpdateProviderPolicy(values); 243 UpdateProviderPolicy(values);
253 244
254 // Expect that the policy table contains, in order: 245 // Expect that the policy table contains, in order:
255 // * All known policies whose value has been set, in alphabetical order. 246 // * All known policies whose value has been set, in alphabetical order.
256 // * The unknown policy. 247 // * The unknown policy.
257 // * All known policies whose value has not been set, in alphabetical order. 248 // * All known policies whose value has not been set, in alphabetical order.
258 std::vector<std::vector<std::string> > expected_policies; 249 std::vector<std::vector<std::string> > expected_policies;
259 size_t first_unset_position = 0; 250 size_t first_unset_position = 0;
260 policy::Schema chrome_schema = 251 policy::Schema chrome_schema =
261 policy::Schema::Wrap(policy::GetChromeSchemaData()); 252 policy::Schema::Wrap(policy::GetChromeSchemaData());
262 ASSERT_TRUE(chrome_schema.valid()); 253 ASSERT_TRUE(chrome_schema.valid());
263 for (policy::Schema::Iterator props = chrome_schema.GetPropertiesIterator(); 254 for (policy::Schema::Iterator props = chrome_schema.GetPropertiesIterator();
264 !props.IsAtEnd(); props.Advance()) { 255 !props.IsAtEnd(); props.Advance()) {
265 std::map<std::string, std::string>::const_iterator it = 256 std::map<std::string, std::string>::const_iterator it =
266 expected_values.find(props.key()); 257 expected_values.find(props.key());
267 const std::string value = 258 const std::string value =
268 it == expected_values.end() ? std::string() : it->second; 259 it == expected_values.end() ? std::string() : it->second;
269 const std::string source =
270 it == expected_values.end() ? std::string() : "Cloud";
271 const policy::PolicyMap::Entry* metadata = values.Get(props.key()); 260 const policy::PolicyMap::Entry* metadata = values.Get(props.key());
272 expected_policies.insert( 261 expected_policies.insert(
273 metadata ? expected_policies.begin() + first_unset_position++ : 262 metadata ? expected_policies.begin() + first_unset_position++ :
274 expected_policies.end(), 263 expected_policies.end(),
275 PopulateExpectedPolicy(props.key(), value, source, metadata, false)); 264 PopulateExpectedPolicy(props.key(), value, metadata, false));
276 } 265 }
277 expected_policies.insert( 266 expected_policies.insert(
278 expected_policies.begin() + first_unset_position++, 267 expected_policies.begin() + first_unset_position++,
279 PopulateExpectedPolicy(kUnknownPolicy, 268 PopulateExpectedPolicy(kUnknownPolicy,
280 expected_values[kUnknownPolicy], 269 expected_values[kUnknownPolicy],
281 "Platform",
282 values.Get(kUnknownPolicy), 270 values.Get(kUnknownPolicy),
283 true)); 271 true));
284 272
285 // Retrieve the contents of the policy table from the UI and verify that it 273 // Retrieve the contents of the policy table from the UI and verify that it
286 // matches the expectation. 274 // matches the expectation.
287 VerifyPolicies(expected_policies); 275 VerifyPolicies(expected_policies);
288 } 276 }
289 277
290 IN_PROC_BROWSER_TEST_F(PolicyUITest, ExtensionLoadAndSendPolicy) { 278 IN_PROC_BROWSER_TEST_F(PolicyUITest, ExtensionLoadAndSendPolicy) {
291 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIPolicyURL)); 279 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIPolicyURL));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 0); 311 0);
324 312
325 std::vector<std::vector<std::string>> expected_policies; 313 std::vector<std::vector<std::string>> expected_policies;
326 policy::Schema chrome_schema = 314 policy::Schema chrome_schema =
327 policy::Schema::Wrap(policy::GetChromeSchemaData()); 315 policy::Schema::Wrap(policy::GetChromeSchemaData());
328 ASSERT_TRUE(chrome_schema.valid()); 316 ASSERT_TRUE(chrome_schema.valid());
329 317
330 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator(); 318 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator();
331 !it.IsAtEnd(); it.Advance()) { 319 !it.IsAtEnd(); it.Advance()) {
332 expected_policies.push_back( 320 expected_policies.push_back(
333 PopulateExpectedPolicy( 321 PopulateExpectedPolicy(it.key(), std::string(), NULL, false));
334 it.key(), std::string(), std::string(), nullptr, false));
335 } 322 }
336 // Add newly added policy to expected policy list. 323 // Add newly added policy to expected policy list.
337 expected_policies.push_back(PopulateExpectedPolicy( 324 expected_policies.push_back(PopulateExpectedPolicy(
338 newly_added_policy_name, std::string(), std::string(), nullptr, false)); 325 newly_added_policy_name, std::string(), NULL, false));
339 326
340 // Verify if policy UI includes policy that extension have. 327 // Verify if policy UI includes policy that extension have.
341 VerifyPolicies(expected_policies); 328 VerifyPolicies(expected_policies);
342 } 329 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/policy_ui.cc ('k') | components/policy/core/browser/android/policy_converter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698