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/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/policy/browser_policy_connector.h" | 11 #include "chrome/browser/policy/browser_policy_connector.h" |
12 #include "chrome/browser/policy/external_data_fetcher.h" | 12 #include "chrome/browser/policy/external_data_fetcher.h" |
13 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 13 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
14 #include "chrome/browser/policy/policy_map.h" | 14 #include "chrome/browser/policy/policy_map.h" |
15 #include "chrome/browser/policy/policy_types.h" | 15 #include "chrome/browser/policy/policy_types.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "components/policy/core/common/schema.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
21 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
23 #include "policy/policy_constants.h" | 24 #include "policy/policy_constants.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
28 | 29 |
29 using testing::AnyNumber; | 30 using testing::AnyNumber; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 168 } |
168 | 169 |
169 IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyNames) { | 170 IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyNames) { |
170 // Verifies that the names of known policies are sent to the UI and processed | 171 // Verifies that the names of known policies are sent to the UI and processed |
171 // there correctly by checking that the policy table contains all policies in | 172 // there correctly by checking that the policy table contains all policies in |
172 // the correct order. | 173 // the correct order. |
173 | 174 |
174 // Expect that the policy table contains all known policies in alphabetical | 175 // Expect that the policy table contains all known policies in alphabetical |
175 // order and none of the policies have a set value. | 176 // order and none of the policies have a set value. |
176 std::vector<std::vector<std::string> > expected_policies; | 177 std::vector<std::vector<std::string> > expected_policies; |
177 const policy::PolicyDefinitionList* policies = | 178 policy::Schema chrome_schema = |
178 policy::GetChromePolicyDefinitionList(); | 179 policy::Schema::Wrap(policy::GetChromeSchemaData()); |
179 for (const policy::PolicyDefinitionList::Entry* policy = policies->begin; | 180 ASSERT_TRUE(chrome_schema.valid()); |
180 policy != policies->end; ++policy) { | 181 for (policy::Schema::Iterator it = chrome_schema.GetPropertiesIterator(); |
| 182 !it.IsAtEnd(); it.Advance()) { |
181 expected_policies.push_back( | 183 expected_policies.push_back( |
182 PopulateExpectedPolicy(policy->name, std::string(), NULL, false)); | 184 PopulateExpectedPolicy(it.key(), std::string(), NULL, false)); |
183 } | 185 } |
184 | 186 |
185 // Retrieve the contents of the policy table from the UI and verify that it | 187 // Retrieve the contents of the policy table from the UI and verify that it |
186 // matches the expectation. | 188 // matches the expectation. |
187 VerifyPolicies(expected_policies); | 189 VerifyPolicies(expected_policies); |
188 } | 190 } |
189 | 191 |
190 IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) { | 192 IN_PROC_BROWSER_TEST_F(PolicyUITest, SendPolicyValues) { |
191 // Verifies that policy values are sent to the UI and processed there | 193 // Verifies that policy values are sent to the UI and processed there |
192 // correctly by setting the values of four known and one unknown policy and | 194 // correctly by setting the values of four known and one unknown policy and |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 NULL); | 235 NULL); |
234 expected_values[kUnknownPolicy] = "true"; | 236 expected_values[kUnknownPolicy] = "true"; |
235 UpdateProviderPolicy(values); | 237 UpdateProviderPolicy(values); |
236 | 238 |
237 // Expect that the policy table contains, in order: | 239 // Expect that the policy table contains, in order: |
238 // * All known policies whose value has been set, in alphabetical order. | 240 // * All known policies whose value has been set, in alphabetical order. |
239 // * The unknown policy. | 241 // * The unknown policy. |
240 // * All known policies whose value has not been set, in alphabetical order. | 242 // * All known policies whose value has not been set, in alphabetical order. |
241 std::vector<std::vector<std::string> > expected_policies; | 243 std::vector<std::vector<std::string> > expected_policies; |
242 size_t first_unset_position = 0; | 244 size_t first_unset_position = 0; |
243 const policy::PolicyDefinitionList* policies = | 245 policy::Schema chrome_schema = |
244 policy::GetChromePolicyDefinitionList(); | 246 policy::Schema::Wrap(policy::GetChromeSchemaData()); |
245 for (const policy::PolicyDefinitionList::Entry* policy = policies->begin; | 247 ASSERT_TRUE(chrome_schema.valid()); |
246 policy != policies->end; ++policy) { | 248 for (policy::Schema::Iterator props = chrome_schema.GetPropertiesIterator(); |
| 249 !props.IsAtEnd(); props.Advance()) { |
247 std::map<std::string, std::string>::const_iterator it = | 250 std::map<std::string, std::string>::const_iterator it = |
248 expected_values.find(policy->name); | 251 expected_values.find(props.key()); |
249 const std::string value = | 252 const std::string value = |
250 it == expected_values.end() ? std::string() : it->second; | 253 it == expected_values.end() ? std::string() : it->second; |
251 const policy::PolicyMap::Entry* metadata = values.Get(policy->name); | 254 const policy::PolicyMap::Entry* metadata = values.Get(props.key()); |
252 expected_policies.insert( | 255 expected_policies.insert( |
253 metadata ? expected_policies.begin() + first_unset_position++ : | 256 metadata ? expected_policies.begin() + first_unset_position++ : |
254 expected_policies.end(), | 257 expected_policies.end(), |
255 PopulateExpectedPolicy(policy->name, value, metadata, false)); | 258 PopulateExpectedPolicy(props.key(), value, metadata, false)); |
256 } | 259 } |
257 expected_policies.insert( | 260 expected_policies.insert( |
258 expected_policies.begin() + first_unset_position++, | 261 expected_policies.begin() + first_unset_position++, |
259 PopulateExpectedPolicy(kUnknownPolicy, | 262 PopulateExpectedPolicy(kUnknownPolicy, |
260 expected_values[kUnknownPolicy], | 263 expected_values[kUnknownPolicy], |
261 values.Get(kUnknownPolicy), | 264 values.Get(kUnknownPolicy), |
262 true)); | 265 true)); |
263 | 266 |
264 // 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 |
265 // matches the expectation. | 268 // matches the expectation. |
266 VerifyPolicies(expected_policies); | 269 VerifyPolicies(expected_policies); |
267 } | 270 } |
OLD | NEW |