OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 7 #include <algorithm> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 }; | 94 }; |
95 | 95 |
96 // Contains the testing details for a single pref affected by a policy. This is | 96 // Contains the testing details for a single pref affected by a policy. This is |
97 // part of the data loaded from chrome/test/data/policy/policy_test_cases.json. | 97 // part of the data loaded from chrome/test/data/policy/policy_test_cases.json. |
98 class PrefMapping { | 98 class PrefMapping { |
99 public: | 99 public: |
100 PrefMapping(const std::string& pref, | 100 PrefMapping(const std::string& pref, |
101 bool is_local_state, | 101 bool is_local_state, |
102 bool check_for_mandatory, | 102 bool check_for_mandatory, |
103 bool check_for_recommended, | 103 bool check_for_recommended, |
104 const std::string& indicator_test_url, | |
104 const std::string& indicator_test_setup_js, | 105 const std::string& indicator_test_setup_js, |
105 const std::string& indicator_selector) | 106 const std::string& indicator_selector) |
106 : pref_(pref), | 107 : pref_(pref), |
107 is_local_state_(is_local_state), | 108 is_local_state_(is_local_state), |
108 check_for_mandatory_(check_for_mandatory), | 109 check_for_mandatory_(check_for_mandatory), |
109 check_for_recommended_(check_for_recommended), | 110 check_for_recommended_(check_for_recommended), |
111 indicator_test_url_(indicator_test_url), | |
110 indicator_test_setup_js_(indicator_test_setup_js), | 112 indicator_test_setup_js_(indicator_test_setup_js), |
111 indicator_selector_(indicator_selector) {} | 113 indicator_selector_(indicator_selector) {} |
112 ~PrefMapping() {} | 114 ~PrefMapping() {} |
113 | 115 |
114 const std::string& pref() const { return pref_; } | 116 const std::string& pref() const { return pref_; } |
115 | 117 |
116 bool is_local_state() const { return is_local_state_; } | 118 bool is_local_state() const { return is_local_state_; } |
117 | 119 |
118 bool check_for_mandatory() const { return check_for_mandatory_; } | 120 bool check_for_mandatory() const { return check_for_mandatory_; } |
119 | 121 |
120 bool check_for_recommended() const { return check_for_recommended_; } | 122 bool check_for_recommended() const { return check_for_recommended_; } |
121 | 123 |
124 const std::string& indicator_test_url() const { | |
125 return indicator_test_url_; | |
126 } | |
127 | |
122 const std::string& indicator_test_setup_js() const { | 128 const std::string& indicator_test_setup_js() const { |
123 return indicator_test_setup_js_; | 129 return indicator_test_setup_js_; |
124 } | 130 } |
125 | 131 |
126 const std::string& indicator_selector() const { | 132 const std::string& indicator_selector() const { |
127 return indicator_selector_; | 133 return indicator_selector_; |
128 } | 134 } |
129 | 135 |
130 const ScopedVector<IndicatorTestCase>& indicator_test_cases() const { | 136 const ScopedVector<IndicatorTestCase>& indicator_test_cases() const { |
131 return indicator_test_cases_; | 137 return indicator_test_cases_; |
132 } | 138 } |
133 void AddIndicatorTestCase(IndicatorTestCase* test_case) { | 139 void AddIndicatorTestCase(IndicatorTestCase* test_case) { |
134 indicator_test_cases_.push_back(test_case); | 140 indicator_test_cases_.push_back(test_case); |
135 } | 141 } |
136 | 142 |
137 private: | 143 private: |
138 const std::string pref_; | 144 const std::string pref_; |
139 const bool is_local_state_; | 145 const bool is_local_state_; |
140 const bool check_for_mandatory_; | 146 const bool check_for_mandatory_; |
141 const bool check_for_recommended_; | 147 const bool check_for_recommended_; |
148 const std::string indicator_test_url_; | |
142 const std::string indicator_test_setup_js_; | 149 const std::string indicator_test_setup_js_; |
143 const std::string indicator_selector_; | 150 const std::string indicator_selector_; |
144 ScopedVector<IndicatorTestCase> indicator_test_cases_; | 151 ScopedVector<IndicatorTestCase> indicator_test_cases_; |
145 | 152 |
146 DISALLOW_COPY_AND_ASSIGN(PrefMapping); | 153 DISALLOW_COPY_AND_ASSIGN(PrefMapping); |
147 }; | 154 }; |
148 | 155 |
149 // Contains the testing details for a single policy. This is part of the data | 156 // Contains the testing details for a single policy. This is part of the data |
150 // loaded from chrome/test/data/policy/policy_test_cases.json. | 157 // loaded from chrome/test/data/policy/policy_test_cases.json. |
151 class PolicyTestCase { | 158 class PolicyTestCase { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 bool is_official_only_; | 218 bool is_official_only_; |
212 bool can_be_recommended_; | 219 bool can_be_recommended_; |
213 std::vector<std::string> supported_os_; | 220 std::vector<std::string> supported_os_; |
214 base::DictionaryValue test_policy_; | 221 base::DictionaryValue test_policy_; |
215 ScopedVector<PrefMapping> pref_mappings_; | 222 ScopedVector<PrefMapping> pref_mappings_; |
216 std::string indicator_selector_; | 223 std::string indicator_selector_; |
217 | 224 |
218 DISALLOW_COPY_AND_ASSIGN(PolicyTestCase); | 225 DISALLOW_COPY_AND_ASSIGN(PolicyTestCase); |
219 }; | 226 }; |
220 | 227 |
221 // Parses all policy test cases and makes then available in a map. | 228 // Parses all policy test cases and makes them available in a map. |
222 class PolicyTestCases { | 229 class PolicyTestCases { |
223 public: | 230 public: |
224 typedef std::vector<PolicyTestCase*> PolicyTestCaseVector; | 231 typedef std::vector<PolicyTestCase*> PolicyTestCaseVector; |
225 typedef std::map<std::string, PolicyTestCaseVector> PolicyTestCaseMap; | 232 typedef std::map<std::string, PolicyTestCaseVector> PolicyTestCaseMap; |
226 typedef PolicyTestCaseMap::const_iterator iterator; | 233 typedef PolicyTestCaseMap::const_iterator iterator; |
227 | 234 |
228 PolicyTestCases() { | 235 PolicyTestCases() { |
229 base::FilePath path = ui_test_utils::GetTestFilePath( | 236 base::FilePath path = ui_test_utils::GetTestFilePath( |
230 base::FilePath(FILE_PATH_LITERAL("policy")), | 237 base::FilePath(FILE_PATH_LITERAL("policy")), |
231 base::FilePath(FILE_PATH_LITERAL("policy_test_cases.json"))); | 238 base::FilePath(FILE_PATH_LITERAL("policy_test_cases.json"))); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 continue; | 327 continue; |
321 } | 328 } |
322 bool is_local_state = false; | 329 bool is_local_state = false; |
323 pref_mapping_dict->GetBoolean("local_state", &is_local_state); | 330 pref_mapping_dict->GetBoolean("local_state", &is_local_state); |
324 bool check_for_mandatory = true; | 331 bool check_for_mandatory = true; |
325 pref_mapping_dict->GetBoolean("check_for_mandatory", | 332 pref_mapping_dict->GetBoolean("check_for_mandatory", |
326 &check_for_mandatory); | 333 &check_for_mandatory); |
327 bool check_for_recommended = true; | 334 bool check_for_recommended = true; |
328 pref_mapping_dict->GetBoolean("check_for_recommended", | 335 pref_mapping_dict->GetBoolean("check_for_recommended", |
329 &check_for_recommended); | 336 &check_for_recommended); |
337 std::string indicator_test_url; | |
338 pref_mapping_dict->GetString("indicator_test_url", | |
339 &indicator_test_url); | |
330 std::string indicator_test_setup_js; | 340 std::string indicator_test_setup_js; |
331 pref_mapping_dict->GetString("indicator_test_setup_js", | 341 pref_mapping_dict->GetString("indicator_test_setup_js", |
332 &indicator_test_setup_js); | 342 &indicator_test_setup_js); |
333 std::string indicator_selector; | 343 std::string indicator_selector; |
334 pref_mapping_dict->GetString("indicator_selector", &indicator_selector); | 344 pref_mapping_dict->GetString("indicator_selector", &indicator_selector); |
335 PrefMapping* pref_mapping = new PrefMapping(pref, | 345 PrefMapping* pref_mapping = new PrefMapping(pref, |
336 is_local_state, | 346 is_local_state, |
337 check_for_mandatory, | 347 check_for_mandatory, |
338 check_for_recommended, | 348 check_for_recommended, |
349 indicator_test_url, | |
339 indicator_test_setup_js, | 350 indicator_test_setup_js, |
340 indicator_selector); | 351 indicator_selector); |
341 const base::ListValue* indicator_tests = NULL; | 352 const base::ListValue* indicator_tests = NULL; |
342 if (pref_mapping_dict->GetList("indicator_tests", &indicator_tests)) { | 353 if (pref_mapping_dict->GetList("indicator_tests", &indicator_tests)) { |
343 for (size_t i = 0; i < indicator_tests->GetSize(); ++i) { | 354 for (size_t i = 0; i < indicator_tests->GetSize(); ++i) { |
344 const base::DictionaryValue* indicator_test_dict = NULL; | 355 const base::DictionaryValue* indicator_test_dict = NULL; |
345 const base::DictionaryValue* policy = NULL; | 356 const base::DictionaryValue* policy = NULL; |
346 if (!indicator_tests->GetDictionary(i, &indicator_test_dict) || | 357 if (!indicator_tests->GetDictionary(i, &indicator_test_dict) || |
347 !indicator_test_dict->GetDictionary("policy", &policy)) { | 358 !indicator_test_dict->GetDictionary("policy", &policy)) { |
348 ADD_FAILURE() << "Malformed indicator_tests entry in " | 359 ADD_FAILURE() << "Malformed indicator_tests entry in " |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 (*pref_mapping)->indicator_test_cases(); | 697 (*pref_mapping)->indicator_test_cases(); |
687 if (indicator_test_cases.empty()) | 698 if (indicator_test_cases.empty()) |
688 continue; | 699 continue; |
689 | 700 |
690 if (!(*pref_mapping)->indicator_test_setup_js().empty()) { | 701 if (!(*pref_mapping)->indicator_test_setup_js().empty()) { |
691 ASSERT_TRUE(content::ExecuteScript( | 702 ASSERT_TRUE(content::ExecuteScript( |
692 browser()->tab_strip_model()->GetActiveWebContents(), | 703 browser()->tab_strip_model()->GetActiveWebContents(), |
693 (*pref_mapping)->indicator_test_setup_js())); | 704 (*pref_mapping)->indicator_test_setup_js())); |
694 } | 705 } |
695 | 706 |
707 // Note: a non-empty indicator_test_url is expected to be used in very | |
708 // few cases, so it's currently implemented by navigating to the URL | |
709 // right before the test and navigating back afterwards. | |
710 // If there should ever be many of these, we could consider grouping | |
Andrew T Wilson (Slow)
2016/12/04 14:54:54
For whatever reason, I don't actually understand w
pmarko
2016/12/07 16:12:11
I've tried to make it understandable, PTAL.
| |
711 // tests by indicator_test_url and only navigate to the URL once for | |
712 // many tests. | |
713 if (!(*pref_mapping)->indicator_test_url().empty()) { | |
714 ui_test_utils::NavigateToURL( | |
715 browser(), | |
716 GURL((*pref_mapping)->indicator_test_url())); | |
717 } | |
718 | |
696 std::string indicator_selector = (*pref_mapping)->indicator_selector(); | 719 std::string indicator_selector = (*pref_mapping)->indicator_selector(); |
697 if (indicator_selector.empty()) | 720 if (indicator_selector.empty()) |
698 indicator_selector = "[pref=\"" + (*pref_mapping)->pref() + "\"]"; | 721 indicator_selector = "[pref=\"" + (*pref_mapping)->pref() + "\"]"; |
699 for (ScopedVector<IndicatorTestCase>::const_iterator | 722 for (ScopedVector<IndicatorTestCase>::const_iterator |
700 indicator_test_case = indicator_test_cases.begin(); | 723 indicator_test_case = indicator_test_cases.begin(); |
701 indicator_test_case != indicator_test_cases.end(); | 724 indicator_test_case != indicator_test_cases.end(); |
702 ++indicator_test_case) { | 725 ++indicator_test_case) { |
703 // Check that no controlled setting indicator is visible when no value | 726 // Check that no controlled setting indicator is visible when no value |
704 // is set by policy. | 727 // is set by policy. |
705 ClearProviderPolicy(); | 728 ClearProviderPolicy(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 // when a value is recommended by policy and the user has overridden | 772 // when a value is recommended by policy and the user has overridden |
750 // the recommendation. | 773 // the recommendation. |
751 prefs->Set((*pref_mapping)->pref().c_str(), *pref->GetValue()); | 774 prefs->Set((*pref_mapping)->pref().c_str(), *pref->GetValue()); |
752 VerifyControlledSettingIndicators(browser(), | 775 VerifyControlledSettingIndicators(browser(), |
753 indicator_selector, | 776 indicator_selector, |
754 (*indicator_test_case)->value(), | 777 (*indicator_test_case)->value(), |
755 "hasRecommendation", | 778 "hasRecommendation", |
756 (*indicator_test_case)->readonly()); | 779 (*indicator_test_case)->readonly()); |
757 prefs->ClearPref((*pref_mapping)->pref().c_str()); | 780 prefs->ClearPref((*pref_mapping)->pref().c_str()); |
758 } | 781 } |
782 | |
783 if (!(*pref_mapping)->indicator_test_url().empty()) | |
784 ui_test_utils::NavigateToURL(browser(), GURL(kMainSettingsPage)); | |
759 } | 785 } |
760 } | 786 } |
761 } | 787 } |
762 } | 788 } |
763 | 789 |
764 INSTANTIATE_TEST_CASE_P(PolicyPrefIndicatorTestInstance, | 790 INSTANTIATE_TEST_CASE_P(PolicyPrefIndicatorTestInstance, |
765 PolicyPrefIndicatorTest, | 791 PolicyPrefIndicatorTest, |
766 testing::ValuesIn(SplitPoliciesIntoChunks(10))); | 792 testing::ValuesIn(SplitPoliciesIntoChunks(10))); |
767 | 793 |
768 } // namespace policy | 794 } // namespace policy |
OLD | NEW |