OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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(), nullptr, 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, |
212 policy::POLICY_LEVEL_MANDATORY, | 216 policy::POLICY_LEVEL_MANDATORY, |
213 policy::POLICY_SCOPE_USER, | 217 policy::POLICY_SCOPE_USER, |
| 218 policy::POLICY_SOURCE_CLOUD, |
214 restore_on_startup_urls, | 219 restore_on_startup_urls, |
215 NULL); | 220 NULL); |
216 expected_values[policy::key::kRestoreOnStartupURLs] = "aaa,bbb,ccc"; | 221 expected_values[policy::key::kRestoreOnStartupURLs] = "aaa,bbb,ccc"; |
217 values.Set(policy::key::kHomepageLocation, | 222 values.Set(policy::key::kHomepageLocation, |
218 policy::POLICY_LEVEL_MANDATORY, | 223 policy::POLICY_LEVEL_MANDATORY, |
219 policy::POLICY_SCOPE_MACHINE, | 224 policy::POLICY_SCOPE_MACHINE, |
| 225 policy::POLICY_SOURCE_CLOUD, |
220 new base::StringValue("http://google.com"), | 226 new base::StringValue("http://google.com"), |
221 NULL); | 227 NULL); |
222 expected_values[policy::key::kHomepageLocation] = "http://google.com"; | 228 expected_values[policy::key::kHomepageLocation] = "http://google.com"; |
223 values.Set(policy::key::kRestoreOnStartup, | 229 values.Set(policy::key::kRestoreOnStartup, |
224 policy::POLICY_LEVEL_RECOMMENDED, | 230 policy::POLICY_LEVEL_RECOMMENDED, |
225 policy::POLICY_SCOPE_USER, | 231 policy::POLICY_SCOPE_USER, |
| 232 policy::POLICY_SOURCE_CLOUD, |
226 new base::FundamentalValue(4), | 233 new base::FundamentalValue(4), |
227 NULL); | 234 NULL); |
228 expected_values[policy::key::kRestoreOnStartup] = "4"; | 235 expected_values[policy::key::kRestoreOnStartup] = "4"; |
229 values.Set(policy::key::kShowHomeButton, | 236 values.Set(policy::key::kShowHomeButton, |
230 policy::POLICY_LEVEL_RECOMMENDED, | 237 policy::POLICY_LEVEL_RECOMMENDED, |
231 policy::POLICY_SCOPE_MACHINE, | 238 policy::POLICY_SCOPE_MACHINE, |
| 239 policy::POLICY_SOURCE_CLOUD, |
232 new base::FundamentalValue(true), | 240 new base::FundamentalValue(true), |
233 NULL); | 241 NULL); |
234 expected_values[policy::key::kShowHomeButton] = "true"; | 242 expected_values[policy::key::kShowHomeButton] = "true"; |
235 // Set the value of a policy that does not exist. | 243 // Set the value of a policy that does not exist. |
236 const std::string kUnknownPolicy = "NoSuchThing"; | 244 const std::string kUnknownPolicy = "NoSuchThing"; |
237 values.Set(kUnknownPolicy, | 245 values.Set(kUnknownPolicy, |
238 policy::POLICY_LEVEL_MANDATORY, | 246 policy::POLICY_LEVEL_MANDATORY, |
239 policy::POLICY_SCOPE_USER, | 247 policy::POLICY_SCOPE_USER, |
| 248 policy::POLICY_SOURCE_PLATFORM, |
240 new base::FundamentalValue(true), | 249 new base::FundamentalValue(true), |
241 NULL); | 250 NULL); |
242 expected_values[kUnknownPolicy] = "true"; | 251 expected_values[kUnknownPolicy] = "true"; |
243 UpdateProviderPolicy(values); | 252 UpdateProviderPolicy(values); |
244 | 253 |
245 // Expect that the policy table contains, in order: | 254 // Expect that the policy table contains, in order: |
246 // * All known policies whose value has been set, in alphabetical order. | 255 // * All known policies whose value has been set, in alphabetical order. |
247 // * The unknown policy. | 256 // * The unknown policy. |
248 // * All known policies whose value has not been set, in alphabetical order. | 257 // * All known policies whose value has not been set, in alphabetical order. |
249 std::vector<std::vector<std::string> > expected_policies; | 258 std::vector<std::vector<std::string> > expected_policies; |
250 size_t first_unset_position = 0; | 259 size_t first_unset_position = 0; |
251 policy::Schema chrome_schema = | 260 policy::Schema chrome_schema = |
252 policy::Schema::Wrap(policy::GetChromeSchemaData()); | 261 policy::Schema::Wrap(policy::GetChromeSchemaData()); |
253 ASSERT_TRUE(chrome_schema.valid()); | 262 ASSERT_TRUE(chrome_schema.valid()); |
254 for (policy::Schema::Iterator props = chrome_schema.GetPropertiesIterator(); | 263 for (policy::Schema::Iterator props = chrome_schema.GetPropertiesIterator(); |
255 !props.IsAtEnd(); props.Advance()) { | 264 !props.IsAtEnd(); props.Advance()) { |
256 std::map<std::string, std::string>::const_iterator it = | 265 std::map<std::string, std::string>::const_iterator it = |
257 expected_values.find(props.key()); | 266 expected_values.find(props.key()); |
258 const std::string value = | 267 const std::string value = |
259 it == expected_values.end() ? std::string() : it->second; | 268 it == expected_values.end() ? std::string() : it->second; |
| 269 const std::string source = |
| 270 it == expected_values.end() ? std::string() : "Cloud"; |
260 const policy::PolicyMap::Entry* metadata = values.Get(props.key()); | 271 const policy::PolicyMap::Entry* metadata = values.Get(props.key()); |
261 expected_policies.insert( | 272 expected_policies.insert( |
262 metadata ? expected_policies.begin() + first_unset_position++ : | 273 metadata ? expected_policies.begin() + first_unset_position++ : |
263 expected_policies.end(), | 274 expected_policies.end(), |
264 PopulateExpectedPolicy(props.key(), value, metadata, false)); | 275 PopulateExpectedPolicy(props.key(), value, source, metadata, false)); |
265 } | 276 } |
266 expected_policies.insert( | 277 expected_policies.insert( |
267 expected_policies.begin() + first_unset_position++, | 278 expected_policies.begin() + first_unset_position++, |
268 PopulateExpectedPolicy(kUnknownPolicy, | 279 PopulateExpectedPolicy(kUnknownPolicy, |
269 expected_values[kUnknownPolicy], | 280 expected_values[kUnknownPolicy], |
| 281 "Platform", |
270 values.Get(kUnknownPolicy), | 282 values.Get(kUnknownPolicy), |
271 true)); | 283 true)); |
272 | 284 |
273 // Retrieve the contents of the policy table from the UI and verify that it | 285 // Retrieve the contents of the policy table from the UI and verify that it |
274 // matches the expectation. | 286 // matches the expectation. |
275 VerifyPolicies(expected_policies); | 287 VerifyPolicies(expected_policies); |
276 } | 288 } |
277 | 289 |
278 IN_PROC_BROWSER_TEST_F(PolicyUITest, ExtensionLoadAndSendPolicy) { | 290 IN_PROC_BROWSER_TEST_F(PolicyUITest, ExtensionLoadAndSendPolicy) { |
279 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIPolicyURL)); | 291 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIPolicyURL)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 0); | 323 0); |
312 | 324 |
313 std::vector<std::vector<std::string>> expected_policies; | 325 std::vector<std::vector<std::string>> expected_policies; |
314 policy::Schema chrome_schema = | 326 policy::Schema chrome_schema = |
315 policy::Schema::Wrap(policy::GetChromeSchemaData()); | 327 policy::Schema::Wrap(policy::GetChromeSchemaData()); |
316 ASSERT_TRUE(chrome_schema.valid()); | 328 ASSERT_TRUE(chrome_schema.valid()); |
317 | 329 |
318 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator(); | 330 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator(); |
319 !it.IsAtEnd(); it.Advance()) { | 331 !it.IsAtEnd(); it.Advance()) { |
320 expected_policies.push_back( | 332 expected_policies.push_back( |
321 PopulateExpectedPolicy(it.key(), std::string(), NULL, false)); | 333 PopulateExpectedPolicy( |
| 334 it.key(), std::string(), std::string(), nullptr, false)); |
322 } | 335 } |
323 // Add newly added policy to expected policy list. | 336 // Add newly added policy to expected policy list. |
324 expected_policies.push_back(PopulateExpectedPolicy( | 337 expected_policies.push_back(PopulateExpectedPolicy( |
325 newly_added_policy_name, std::string(), NULL, false)); | 338 newly_added_policy_name, std::string(), std::string(), nullptr, false)); |
326 | 339 |
327 // Verify if policy UI includes policy that extension have. | 340 // Verify if policy UI includes policy that extension have. |
328 VerifyPolicies(expected_policies); | 341 VerifyPolicies(expected_policies); |
329 } | 342 } |
OLD | NEW |