| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> |
| 8 #include <utility> |
| 7 #include <vector> | 9 #include <vector> |
| 8 | 10 |
| 9 #include "base/callback.h" | 11 #include "base/callback.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 12 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
| 13 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 14 #include "base/values.h" | 17 #include "base/values.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/test_extension_system.h" | 19 #include "chrome/browser/extensions/test_extension_system.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 207 |
| 205 IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) { | 208 IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) { |
| 206 // Verifies that policy values are sent to the UI and processed there | 209 // Verifies that policy values are sent to the UI and processed there |
| 207 // correctly by setting the values of four known and one unknown policy and | 210 // correctly by setting the values of four known and one unknown policy and |
| 208 // checking that the policy table contains the policy names, values and | 211 // checking that the policy table contains the policy names, values and |
| 209 // metadata in the correct order. | 212 // metadata in the correct order. |
| 210 policy::PolicyMap values; | 213 policy::PolicyMap values; |
| 211 std::map<std::string, std::string> expected_values; | 214 std::map<std::string, std::string> expected_values; |
| 212 | 215 |
| 213 // Set the values of four existing policies. | 216 // Set the values of four existing policies. |
| 214 base::ListValue* restore_on_startup_urls = new base::ListValue; | 217 std::unique_ptr<base::ListValue> restore_on_startup_urls(new base::ListValue); |
| 215 restore_on_startup_urls->Append(new base::StringValue("aaa")); | 218 restore_on_startup_urls->Append(new base::StringValue("aaa")); |
| 216 restore_on_startup_urls->Append(new base::StringValue("bbb")); | 219 restore_on_startup_urls->Append(new base::StringValue("bbb")); |
| 217 restore_on_startup_urls->Append(new base::StringValue("ccc")); | 220 restore_on_startup_urls->Append(new base::StringValue("ccc")); |
| 218 values.Set(policy::key::kRestoreOnStartupURLs, | 221 values.Set(policy::key::kRestoreOnStartupURLs, policy::POLICY_LEVEL_MANDATORY, |
| 219 policy::POLICY_LEVEL_MANDATORY, | 222 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
| 220 policy::POLICY_SCOPE_USER, | 223 std::move(restore_on_startup_urls), nullptr); |
| 221 policy::POLICY_SOURCE_CLOUD, | |
| 222 restore_on_startup_urls, | |
| 223 NULL); | |
| 224 expected_values[policy::key::kRestoreOnStartupURLs] = "aaa,bbb,ccc"; | 224 expected_values[policy::key::kRestoreOnStartupURLs] = "aaa,bbb,ccc"; |
| 225 values.Set(policy::key::kHomepageLocation, | 225 values.Set(policy::key::kHomepageLocation, policy::POLICY_LEVEL_MANDATORY, |
| 226 policy::POLICY_LEVEL_MANDATORY, | 226 policy::POLICY_SCOPE_MACHINE, policy::POLICY_SOURCE_CLOUD, |
| 227 policy::POLICY_SCOPE_MACHINE, | 227 base::WrapUnique(new base::StringValue("http://google.com")), |
| 228 policy::POLICY_SOURCE_CLOUD, | 228 nullptr); |
| 229 new base::StringValue("http://google.com"), | |
| 230 NULL); | |
| 231 expected_values[policy::key::kHomepageLocation] = "http://google.com"; | 229 expected_values[policy::key::kHomepageLocation] = "http://google.com"; |
| 232 values.Set(policy::key::kRestoreOnStartup, | 230 values.Set(policy::key::kRestoreOnStartup, policy::POLICY_LEVEL_RECOMMENDED, |
| 233 policy::POLICY_LEVEL_RECOMMENDED, | 231 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
| 234 policy::POLICY_SCOPE_USER, | 232 base::WrapUnique(new base::FundamentalValue(4)), nullptr); |
| 235 policy::POLICY_SOURCE_CLOUD, | |
| 236 new base::FundamentalValue(4), | |
| 237 NULL); | |
| 238 expected_values[policy::key::kRestoreOnStartup] = "4"; | 233 expected_values[policy::key::kRestoreOnStartup] = "4"; |
| 239 values.Set(policy::key::kShowHomeButton, | 234 values.Set(policy::key::kShowHomeButton, policy::POLICY_LEVEL_RECOMMENDED, |
| 240 policy::POLICY_LEVEL_RECOMMENDED, | 235 policy::POLICY_SCOPE_MACHINE, policy::POLICY_SOURCE_CLOUD, |
| 241 policy::POLICY_SCOPE_MACHINE, | 236 base::WrapUnique(new base::FundamentalValue(true)), nullptr); |
| 242 policy::POLICY_SOURCE_CLOUD, | |
| 243 new base::FundamentalValue(true), | |
| 244 NULL); | |
| 245 expected_values[policy::key::kShowHomeButton] = "true"; | 237 expected_values[policy::key::kShowHomeButton] = "true"; |
| 246 // Set the value of a policy that does not exist. | 238 // Set the value of a policy that does not exist. |
| 247 const std::string kUnknownPolicy = "NoSuchThing"; | 239 const std::string kUnknownPolicy = "NoSuchThing"; |
| 248 values.Set(kUnknownPolicy, | 240 values.Set(kUnknownPolicy, policy::POLICY_LEVEL_MANDATORY, |
| 249 policy::POLICY_LEVEL_MANDATORY, | 241 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_PLATFORM, |
| 250 policy::POLICY_SCOPE_USER, | 242 base::WrapUnique(new base::FundamentalValue(true)), nullptr); |
| 251 policy::POLICY_SOURCE_PLATFORM, | |
| 252 new base::FundamentalValue(true), | |
| 253 NULL); | |
| 254 expected_values[kUnknownPolicy] = "true"; | 243 expected_values[kUnknownPolicy] = "true"; |
| 255 UpdateProviderPolicy(values); | 244 UpdateProviderPolicy(values); |
| 256 | 245 |
| 257 // Expect that the policy table contains, in order: | 246 // Expect that the policy table contains, in order: |
| 258 // * All known policies whose value has been set, in alphabetical order. | 247 // * All known policies whose value has been set, in alphabetical order. |
| 259 // * The unknown policy. | 248 // * The unknown policy. |
| 260 // * All known policies whose value has not been set, in alphabetical order. | 249 // * All known policies whose value has not been set, in alphabetical order. |
| 261 std::vector<std::vector<std::string> > expected_policies; | 250 std::vector<std::vector<std::string> > expected_policies; |
| 262 size_t first_unset_position = 0; | 251 size_t first_unset_position = 0; |
| 263 policy::Schema chrome_schema = | 252 policy::Schema chrome_schema = |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 PopulateExpectedPolicy( | 325 PopulateExpectedPolicy( |
| 337 it.key(), std::string(), std::string(), nullptr, false)); | 326 it.key(), std::string(), std::string(), nullptr, false)); |
| 338 } | 327 } |
| 339 // Add newly added policy to expected policy list. | 328 // Add newly added policy to expected policy list. |
| 340 expected_policies.push_back(PopulateExpectedPolicy( | 329 expected_policies.push_back(PopulateExpectedPolicy( |
| 341 newly_added_policy_name, std::string(), std::string(), nullptr, false)); | 330 newly_added_policy_name, std::string(), std::string(), nullptr, false)); |
| 342 | 331 |
| 343 // Verify if policy UI includes policy that extension have. | 332 // Verify if policy UI includes policy that extension have. |
| 344 VerifyPolicies(expected_policies); | 333 VerifyPolicies(expected_policies); |
| 345 } | 334 } |
| OLD | NEW |