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

Side by Side Diff: chrome/browser/policy/policy_prefs_browsertest.cc

Issue 2529083002: Make extensions developer mode adhere to policy (Closed)
Patch Set: Rebase Created 4 years 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) 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
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 { return indicator_test_url_; }
125
122 const std::string& indicator_test_setup_js() const { 126 const std::string& indicator_test_setup_js() const {
123 return indicator_test_setup_js_; 127 return indicator_test_setup_js_;
124 } 128 }
125 129
126 const std::string& indicator_selector() const { 130 const std::string& indicator_selector() const {
127 return indicator_selector_; 131 return indicator_selector_;
128 } 132 }
129 133
130 const ScopedVector<IndicatorTestCase>& indicator_test_cases() const { 134 const ScopedVector<IndicatorTestCase>& indicator_test_cases() const {
131 return indicator_test_cases_; 135 return indicator_test_cases_;
132 } 136 }
133 void AddIndicatorTestCase(IndicatorTestCase* test_case) { 137 void AddIndicatorTestCase(IndicatorTestCase* test_case) {
134 indicator_test_cases_.push_back(test_case); 138 indicator_test_cases_.push_back(test_case);
135 } 139 }
136 140
137 private: 141 private:
138 const std::string pref_; 142 const std::string pref_;
139 const bool is_local_state_; 143 const bool is_local_state_;
140 const bool check_for_mandatory_; 144 const bool check_for_mandatory_;
141 const bool check_for_recommended_; 145 const bool check_for_recommended_;
146 const std::string indicator_test_url_;
142 const std::string indicator_test_setup_js_; 147 const std::string indicator_test_setup_js_;
143 const std::string indicator_selector_; 148 const std::string indicator_selector_;
144 ScopedVector<IndicatorTestCase> indicator_test_cases_; 149 ScopedVector<IndicatorTestCase> indicator_test_cases_;
145 150
146 DISALLOW_COPY_AND_ASSIGN(PrefMapping); 151 DISALLOW_COPY_AND_ASSIGN(PrefMapping);
147 }; 152 };
148 153
149 // Contains the testing details for a single policy. This is part of the data 154 // 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. 155 // loaded from chrome/test/data/policy/policy_test_cases.json.
151 class PolicyTestCase { 156 class PolicyTestCase {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 bool is_official_only_; 216 bool is_official_only_;
212 bool can_be_recommended_; 217 bool can_be_recommended_;
213 std::vector<std::string> supported_os_; 218 std::vector<std::string> supported_os_;
214 base::DictionaryValue test_policy_; 219 base::DictionaryValue test_policy_;
215 ScopedVector<PrefMapping> pref_mappings_; 220 ScopedVector<PrefMapping> pref_mappings_;
216 std::string indicator_selector_; 221 std::string indicator_selector_;
217 222
218 DISALLOW_COPY_AND_ASSIGN(PolicyTestCase); 223 DISALLOW_COPY_AND_ASSIGN(PolicyTestCase);
219 }; 224 };
220 225
221 // Parses all policy test cases and makes then available in a map. 226 // Parses all policy test cases and makes them available in a map.
222 class PolicyTestCases { 227 class PolicyTestCases {
223 public: 228 public:
224 typedef std::vector<PolicyTestCase*> PolicyTestCaseVector; 229 typedef std::vector<PolicyTestCase*> PolicyTestCaseVector;
225 typedef std::map<std::string, PolicyTestCaseVector> PolicyTestCaseMap; 230 typedef std::map<std::string, PolicyTestCaseVector> PolicyTestCaseMap;
226 typedef PolicyTestCaseMap::const_iterator iterator; 231 typedef PolicyTestCaseMap::const_iterator iterator;
227 232
228 PolicyTestCases() { 233 PolicyTestCases() {
229 base::FilePath path = ui_test_utils::GetTestFilePath( 234 base::FilePath path = ui_test_utils::GetTestFilePath(
230 base::FilePath(FILE_PATH_LITERAL("policy")), 235 base::FilePath(FILE_PATH_LITERAL("policy")),
231 base::FilePath(FILE_PATH_LITERAL("policy_test_cases.json"))); 236 base::FilePath(FILE_PATH_LITERAL("policy_test_cases.json")));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 continue; 325 continue;
321 } 326 }
322 bool is_local_state = false; 327 bool is_local_state = false;
323 pref_mapping_dict->GetBoolean("local_state", &is_local_state); 328 pref_mapping_dict->GetBoolean("local_state", &is_local_state);
324 bool check_for_mandatory = true; 329 bool check_for_mandatory = true;
325 pref_mapping_dict->GetBoolean("check_for_mandatory", 330 pref_mapping_dict->GetBoolean("check_for_mandatory",
326 &check_for_mandatory); 331 &check_for_mandatory);
327 bool check_for_recommended = true; 332 bool check_for_recommended = true;
328 pref_mapping_dict->GetBoolean("check_for_recommended", 333 pref_mapping_dict->GetBoolean("check_for_recommended",
329 &check_for_recommended); 334 &check_for_recommended);
335 std::string indicator_test_url;
336 pref_mapping_dict->GetString("indicator_test_url", &indicator_test_url);
330 std::string indicator_test_setup_js; 337 std::string indicator_test_setup_js;
331 pref_mapping_dict->GetString("indicator_test_setup_js", 338 pref_mapping_dict->GetString("indicator_test_setup_js",
332 &indicator_test_setup_js); 339 &indicator_test_setup_js);
333 std::string indicator_selector; 340 std::string indicator_selector;
334 pref_mapping_dict->GetString("indicator_selector", &indicator_selector); 341 pref_mapping_dict->GetString("indicator_selector", &indicator_selector);
335 PrefMapping* pref_mapping = new PrefMapping(pref, 342 PrefMapping* pref_mapping = new PrefMapping(pref,
336 is_local_state, 343 is_local_state,
337 check_for_mandatory, 344 check_for_mandatory,
338 check_for_recommended, 345 check_for_recommended,
346 indicator_test_url,
339 indicator_test_setup_js, 347 indicator_test_setup_js,
340 indicator_selector); 348 indicator_selector);
341 const base::ListValue* indicator_tests = NULL; 349 const base::ListValue* indicator_tests = NULL;
342 if (pref_mapping_dict->GetList("indicator_tests", &indicator_tests)) { 350 if (pref_mapping_dict->GetList("indicator_tests", &indicator_tests)) {
343 for (size_t i = 0; i < indicator_tests->GetSize(); ++i) { 351 for (size_t i = 0; i < indicator_tests->GetSize(); ++i) {
344 const base::DictionaryValue* indicator_test_dict = NULL; 352 const base::DictionaryValue* indicator_test_dict = NULL;
345 const base::DictionaryValue* policy = NULL; 353 const base::DictionaryValue* policy = NULL;
346 if (!indicator_tests->GetDictionary(i, &indicator_test_dict) || 354 if (!indicator_tests->GetDictionary(i, &indicator_test_dict) ||
347 !indicator_test_dict->GetDictionary("policy", &policy)) { 355 !indicator_test_dict->GetDictionary("policy", &policy)) {
348 ADD_FAILURE() << "Malformed indicator_tests entry in " 356 ADD_FAILURE() << "Malformed indicator_tests entry in "
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 (*pref_mapping)->indicator_test_cases(); 694 (*pref_mapping)->indicator_test_cases();
687 if (indicator_test_cases.empty()) 695 if (indicator_test_cases.empty())
688 continue; 696 continue;
689 697
690 if (!(*pref_mapping)->indicator_test_setup_js().empty()) { 698 if (!(*pref_mapping)->indicator_test_setup_js().empty()) {
691 ASSERT_TRUE(content::ExecuteScript( 699 ASSERT_TRUE(content::ExecuteScript(
692 browser()->tab_strip_model()->GetActiveWebContents(), 700 browser()->tab_strip_model()->GetActiveWebContents(),
693 (*pref_mapping)->indicator_test_setup_js())); 701 (*pref_mapping)->indicator_test_setup_js()));
694 } 702 }
695 703
704 // A non-empty indicator_test_url is expected to be used in very
705 // few cases, so it's currently implemented by navigating to the URL
706 // right before the test and navigating back afterwards.
707 // If you introduce many test cases with the same non-empty
708 // indicator_test_url, this would be inefficient. We could consider
709 // navigting to a specific indicator_test_url once for many test cases
710 // instead.
711 if (!(*pref_mapping)->indicator_test_url().empty()) {
712 ui_test_utils::NavigateToURL(
713 browser(), GURL((*pref_mapping)->indicator_test_url()));
714 }
715
696 std::string indicator_selector = (*pref_mapping)->indicator_selector(); 716 std::string indicator_selector = (*pref_mapping)->indicator_selector();
697 if (indicator_selector.empty()) 717 if (indicator_selector.empty())
698 indicator_selector = "[pref=\"" + (*pref_mapping)->pref() + "\"]"; 718 indicator_selector = "[pref=\"" + (*pref_mapping)->pref() + "\"]";
699 for (ScopedVector<IndicatorTestCase>::const_iterator 719 for (ScopedVector<IndicatorTestCase>::const_iterator
700 indicator_test_case = indicator_test_cases.begin(); 720 indicator_test_case = indicator_test_cases.begin();
701 indicator_test_case != indicator_test_cases.end(); 721 indicator_test_case != indicator_test_cases.end();
702 ++indicator_test_case) { 722 ++indicator_test_case) {
703 // Check that no controlled setting indicator is visible when no value 723 // Check that no controlled setting indicator is visible when no value
704 // is set by policy. 724 // is set by policy.
705 ClearProviderPolicy(); 725 ClearProviderPolicy();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 // when a value is recommended by policy and the user has overridden 769 // when a value is recommended by policy and the user has overridden
750 // the recommendation. 770 // the recommendation.
751 prefs->Set((*pref_mapping)->pref().c_str(), *pref->GetValue()); 771 prefs->Set((*pref_mapping)->pref().c_str(), *pref->GetValue());
752 VerifyControlledSettingIndicators(browser(), 772 VerifyControlledSettingIndicators(browser(),
753 indicator_selector, 773 indicator_selector,
754 (*indicator_test_case)->value(), 774 (*indicator_test_case)->value(),
755 "hasRecommendation", 775 "hasRecommendation",
756 (*indicator_test_case)->readonly()); 776 (*indicator_test_case)->readonly());
757 prefs->ClearPref((*pref_mapping)->pref().c_str()); 777 prefs->ClearPref((*pref_mapping)->pref().c_str());
758 } 778 }
779
780 if (!(*pref_mapping)->indicator_test_url().empty())
781 ui_test_utils::NavigateToURL(browser(), GURL(kMainSettingsPage));
759 } 782 }
760 } 783 }
761 } 784 }
762 } 785 }
763 786
764 INSTANTIATE_TEST_CASE_P(PolicyPrefIndicatorTestInstance, 787 INSTANTIATE_TEST_CASE_P(PolicyPrefIndicatorTestInstance,
765 PolicyPrefIndicatorTest, 788 PolicyPrefIndicatorTest,
766 testing::ValuesIn(SplitPoliciesIntoChunks(10))); 789 testing::ValuesIn(SplitPoliciesIntoChunks(10)));
767 790
768 } // namespace policy 791 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_browsertest.cc ('k') | chrome/browser/resources/extensions/extensions.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698