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

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: Increased ID range for Messages. 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 56
57 // Populate expected level. 57 // Populate expected level.
58 if (metadata) { 58 if (metadata) {
59 expected_policy.push_back(l10n_util::GetStringUTF8( 59 expected_policy.push_back(l10n_util::GetStringUTF8(
60 metadata->level == policy::POLICY_LEVEL_RECOMMENDED ? 60 metadata->level == policy::POLICY_LEVEL_RECOMMENDED ?
61 IDS_POLICY_LEVEL_RECOMMENDED : IDS_POLICY_LEVEL_MANDATORY)); 61 IDS_POLICY_LEVEL_RECOMMENDED : IDS_POLICY_LEVEL_MANDATORY));
62 } else { 62 } else {
63 expected_policy.push_back(std::string()); 63 expected_policy.push_back(std::string());
64 } 64 }
65 // Populate expected source name.
66 // TODO(fhorschig): Make MockProvider use another source.
67 expected_policy.push_back(std::string()); // MockProvider sets to unknown.
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
75
Thiemo Nagel 2015/09/04 20:15:53 Remove blank line.
fhorschig 2015/09/07 14:09:33 Done.
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(
Thiemo Nagel 2015/09/04 20:15:53 Don't reformat!
fhorschig 2015/09/07 14:09:34 Done.
190 PopulateExpectedPolicy(it.key(), std::string(), NULL, false)); 194 it.key(), 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
(...skipping 11 matching lines...) Expand all
212 policy::POLICY_LEVEL_MANDATORY, 216 policy::POLICY_LEVEL_MANDATORY,
213 policy::POLICY_SCOPE_USER, 217 policy::POLICY_SCOPE_USER,
214 restore_on_startup_urls, 218 restore_on_startup_urls,
215 NULL); 219 NULL);
216 expected_values[policy::key::kRestoreOnStartupURLs] = "aaa,bbb,ccc"; 220 expected_values[policy::key::kRestoreOnStartupURLs] = "aaa,bbb,ccc";
217 values.Set(policy::key::kHomepageLocation, 221 values.Set(policy::key::kHomepageLocation,
218 policy::POLICY_LEVEL_MANDATORY, 222 policy::POLICY_LEVEL_MANDATORY,
219 policy::POLICY_SCOPE_MACHINE, 223 policy::POLICY_SCOPE_MACHINE,
220 new base::StringValue("http://google.com"), 224 new base::StringValue("http://google.com"),
221 NULL); 225 NULL);
226
Thiemo Nagel 2015/09/04 20:15:53 Remove blank line.
fhorschig 2015/09/07 14:09:34 Done.
222 expected_values[policy::key::kHomepageLocation] = "http://google.com"; 227 expected_values[policy::key::kHomepageLocation] = "http://google.com";
223 values.Set(policy::key::kRestoreOnStartup, 228 values.Set(policy::key::kRestoreOnStartup,
224 policy::POLICY_LEVEL_RECOMMENDED, 229 policy::POLICY_LEVEL_RECOMMENDED,
225 policy::POLICY_SCOPE_USER, 230 policy::POLICY_SCOPE_USER,
226 new base::FundamentalValue(4), 231 new base::FundamentalValue(4),
227 NULL); 232 NULL);
228 expected_values[policy::key::kRestoreOnStartup] = "4"; 233 expected_values[policy::key::kRestoreOnStartup] = "4";
229 values.Set(policy::key::kShowHomeButton, 234 values.Set(policy::key::kShowHomeButton,
230 policy::POLICY_LEVEL_RECOMMENDED, 235 policy::POLICY_LEVEL_RECOMMENDED,
231 policy::POLICY_SCOPE_MACHINE, 236 policy::POLICY_SCOPE_MACHINE,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 service->OnExtensionInstalled(builder.Build().get(), syncer::StringOrdinal(), 315 service->OnExtensionInstalled(builder.Build().get(), syncer::StringOrdinal(),
311 0); 316 0);
312 317
313 std::vector<std::vector<std::string>> expected_policies; 318 std::vector<std::vector<std::string>> expected_policies;
314 policy::Schema chrome_schema = 319 policy::Schema chrome_schema =
315 policy::Schema::Wrap(policy::GetChromeSchemaData()); 320 policy::Schema::Wrap(policy::GetChromeSchemaData());
316 ASSERT_TRUE(chrome_schema.valid()); 321 ASSERT_TRUE(chrome_schema.valid());
317 322
318 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator(); 323 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator();
319 !it.IsAtEnd(); it.Advance()) { 324 !it.IsAtEnd(); it.Advance()) {
320 expected_policies.push_back( 325 expected_policies.push_back(PopulateExpectedPolicy(
Thiemo Nagel 2015/09/04 20:15:53 Don't reformat.
fhorschig 2015/09/07 14:09:33 Done.
321 PopulateExpectedPolicy(it.key(), std::string(), NULL, false)); 326 it.key(), std::string(), NULL, false));
322 } 327 }
323 // Add newly added policy to expected policy list. 328 // Add newly added policy to expected policy list.
324 expected_policies.push_back(PopulateExpectedPolicy( 329 expected_policies.push_back(PopulateExpectedPolicy(
325 newly_added_policy_name, std::string(), NULL, false)); 330 newly_added_policy_name, std::string(), NULL, false));
326 331
327 // Verify if policy UI includes policy that extension have. 332 // Verify if policy UI includes policy that extension have.
328 VerifyPolicies(expected_policies); 333 VerifyPolicies(expected_policies);
329 } 334 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698