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> |
11 #include <sstream> | 11 #include <sstream> |
12 #include <string> | 12 #include <string> |
| 13 #include <utility> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
16 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
17 #include "base/json/json_reader.h" | 18 #include "base/json/json_reader.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/macros.h" | 20 #include "base/macros.h" |
20 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
21 #include "base/memory/scoped_vector.h" | |
22 #include "base/memory/weak_ptr.h" | 22 #include "base/memory/weak_ptr.h" |
23 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
24 #include "base/stl_util.h" | 24 #include "base/stl_util.h" |
25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
27 #include "base/values.h" | 27 #include "base/values.h" |
28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
29 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/search_engines/template_url_service_factory.h" | 31 #include "chrome/browser/search_engines/template_url_service_factory.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 const std::string& indicator_test_url() const { return indicator_test_url_; } | 124 const std::string& indicator_test_url() const { return indicator_test_url_; } |
125 | 125 |
126 const std::string& indicator_test_setup_js() const { | 126 const std::string& indicator_test_setup_js() const { |
127 return indicator_test_setup_js_; | 127 return indicator_test_setup_js_; |
128 } | 128 } |
129 | 129 |
130 const std::string& indicator_selector() const { | 130 const std::string& indicator_selector() const { |
131 return indicator_selector_; | 131 return indicator_selector_; |
132 } | 132 } |
133 | 133 |
134 const ScopedVector<IndicatorTestCase>& indicator_test_cases() const { | 134 const std::vector<std::unique_ptr<IndicatorTestCase>>& indicator_test_cases() |
| 135 const { |
135 return indicator_test_cases_; | 136 return indicator_test_cases_; |
136 } | 137 } |
137 void AddIndicatorTestCase(IndicatorTestCase* test_case) { | 138 void AddIndicatorTestCase(std::unique_ptr<IndicatorTestCase> test_case) { |
138 indicator_test_cases_.push_back(test_case); | 139 indicator_test_cases_.push_back(std::move(test_case)); |
139 } | 140 } |
140 | 141 |
141 private: | 142 private: |
142 const std::string pref_; | 143 const std::string pref_; |
143 const bool is_local_state_; | 144 const bool is_local_state_; |
144 const bool check_for_mandatory_; | 145 const bool check_for_mandatory_; |
145 const bool check_for_recommended_; | 146 const bool check_for_recommended_; |
146 const std::string indicator_test_url_; | 147 const std::string indicator_test_url_; |
147 const std::string indicator_test_setup_js_; | 148 const std::string indicator_test_setup_js_; |
148 const std::string indicator_selector_; | 149 const std::string indicator_selector_; |
149 ScopedVector<IndicatorTestCase> indicator_test_cases_; | 150 std::vector<std::unique_ptr<IndicatorTestCase>> indicator_test_cases_; |
150 | 151 |
151 DISALLOW_COPY_AND_ASSIGN(PrefMapping); | 152 DISALLOW_COPY_AND_ASSIGN(PrefMapping); |
152 }; | 153 }; |
153 | 154 |
154 // Contains the testing details for a single policy. This is part of the data | 155 // Contains the testing details for a single policy. This is part of the data |
155 // loaded from chrome/test/data/policy/policy_test_cases.json. | 156 // loaded from chrome/test/data/policy/policy_test_cases.json. |
156 class PolicyTestCase { | 157 class PolicyTestCase { |
157 public: | 158 public: |
158 PolicyTestCase(const std::string& name, | 159 PolicyTestCase(const std::string& name, |
159 bool is_official_only, | 160 bool is_official_only, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 #endif | 196 #endif |
196 return IsOsSupported(); | 197 return IsOsSupported(); |
197 } | 198 } |
198 | 199 |
199 const base::DictionaryValue& test_policy() const { return test_policy_; } | 200 const base::DictionaryValue& test_policy() const { return test_policy_; } |
200 void SetTestPolicy(const base::DictionaryValue& policy) { | 201 void SetTestPolicy(const base::DictionaryValue& policy) { |
201 test_policy_.Clear(); | 202 test_policy_.Clear(); |
202 test_policy_.MergeDictionary(&policy); | 203 test_policy_.MergeDictionary(&policy); |
203 } | 204 } |
204 | 205 |
205 const ScopedVector<PrefMapping>& pref_mappings() const { | 206 const std::vector<std::unique_ptr<PrefMapping>>& pref_mappings() const { |
206 return pref_mappings_; | 207 return pref_mappings_; |
207 } | 208 } |
208 void AddPrefMapping(PrefMapping* pref_mapping) { | 209 void AddPrefMapping(std::unique_ptr<PrefMapping> pref_mapping) { |
209 pref_mappings_.push_back(pref_mapping); | 210 pref_mappings_.push_back(std::move(pref_mapping)); |
210 } | 211 } |
211 | 212 |
212 const std::string& indicator_selector() const { return indicator_selector_; } | 213 const std::string& indicator_selector() const { return indicator_selector_; } |
213 | 214 |
214 private: | 215 private: |
215 std::string name_; | 216 std::string name_; |
216 bool is_official_only_; | 217 bool is_official_only_; |
217 bool can_be_recommended_; | 218 bool can_be_recommended_; |
218 std::vector<std::string> supported_os_; | 219 std::vector<std::string> supported_os_; |
219 base::DictionaryValue test_policy_; | 220 base::DictionaryValue test_policy_; |
220 ScopedVector<PrefMapping> pref_mappings_; | 221 std::vector<std::unique_ptr<PrefMapping>> pref_mappings_; |
221 std::string indicator_selector_; | 222 std::string indicator_selector_; |
222 | 223 |
223 DISALLOW_COPY_AND_ASSIGN(PolicyTestCase); | 224 DISALLOW_COPY_AND_ASSIGN(PolicyTestCase); |
224 }; | 225 }; |
225 | 226 |
226 // Parses all policy test cases and makes them available in a map. | 227 // Parses all policy test cases and makes them available in a map. |
227 class PolicyTestCases { | 228 class PolicyTestCases { |
228 public: | 229 public: |
229 typedef std::vector<PolicyTestCase*> PolicyTestCaseVector; | 230 typedef std::vector<PolicyTestCase*> PolicyTestCaseVector; |
230 typedef std::map<std::string, PolicyTestCaseVector> PolicyTestCaseMap; | 231 typedef std::map<std::string, PolicyTestCaseVector> PolicyTestCaseMap; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 bool check_for_recommended = true; | 333 bool check_for_recommended = true; |
333 pref_mapping_dict->GetBoolean("check_for_recommended", | 334 pref_mapping_dict->GetBoolean("check_for_recommended", |
334 &check_for_recommended); | 335 &check_for_recommended); |
335 std::string indicator_test_url; | 336 std::string indicator_test_url; |
336 pref_mapping_dict->GetString("indicator_test_url", &indicator_test_url); | 337 pref_mapping_dict->GetString("indicator_test_url", &indicator_test_url); |
337 std::string indicator_test_setup_js; | 338 std::string indicator_test_setup_js; |
338 pref_mapping_dict->GetString("indicator_test_setup_js", | 339 pref_mapping_dict->GetString("indicator_test_setup_js", |
339 &indicator_test_setup_js); | 340 &indicator_test_setup_js); |
340 std::string indicator_selector; | 341 std::string indicator_selector; |
341 pref_mapping_dict->GetString("indicator_selector", &indicator_selector); | 342 pref_mapping_dict->GetString("indicator_selector", &indicator_selector); |
342 PrefMapping* pref_mapping = new PrefMapping(pref, | 343 auto pref_mapping = base::MakeUnique<PrefMapping>( |
343 is_local_state, | 344 pref, is_local_state, check_for_mandatory, check_for_recommended, |
344 check_for_mandatory, | 345 indicator_test_url, indicator_test_setup_js, indicator_selector); |
345 check_for_recommended, | |
346 indicator_test_url, | |
347 indicator_test_setup_js, | |
348 indicator_selector); | |
349 const base::ListValue* indicator_tests = NULL; | 346 const base::ListValue* indicator_tests = NULL; |
350 if (pref_mapping_dict->GetList("indicator_tests", &indicator_tests)) { | 347 if (pref_mapping_dict->GetList("indicator_tests", &indicator_tests)) { |
351 for (size_t i = 0; i < indicator_tests->GetSize(); ++i) { | 348 for (size_t i = 0; i < indicator_tests->GetSize(); ++i) { |
352 const base::DictionaryValue* indicator_test_dict = NULL; | 349 const base::DictionaryValue* indicator_test_dict = NULL; |
353 const base::DictionaryValue* policy = NULL; | 350 const base::DictionaryValue* policy = NULL; |
354 if (!indicator_tests->GetDictionary(i, &indicator_test_dict) || | 351 if (!indicator_tests->GetDictionary(i, &indicator_test_dict) || |
355 !indicator_test_dict->GetDictionary("policy", &policy)) { | 352 !indicator_test_dict->GetDictionary("policy", &policy)) { |
356 ADD_FAILURE() << "Malformed indicator_tests entry in " | 353 ADD_FAILURE() << "Malformed indicator_tests entry in " |
357 << "policy_test_cases.json."; | 354 << "policy_test_cases.json."; |
358 continue; | 355 continue; |
359 } | 356 } |
360 std::string value; | 357 std::string value; |
361 indicator_test_dict->GetString("value", &value); | 358 indicator_test_dict->GetString("value", &value); |
362 bool readonly = false; | 359 bool readonly = false; |
363 indicator_test_dict->GetBoolean("readonly", &readonly); | 360 indicator_test_dict->GetBoolean("readonly", &readonly); |
364 pref_mapping->AddIndicatorTestCase( | 361 pref_mapping->AddIndicatorTestCase( |
365 new IndicatorTestCase(*policy, value, readonly)); | 362 base::MakeUnique<IndicatorTestCase>(*policy, value, readonly)); |
366 } | 363 } |
367 } | 364 } |
368 policy_test_case->AddPrefMapping(pref_mapping); | 365 policy_test_case->AddPrefMapping(std::move(pref_mapping)); |
369 } | 366 } |
370 } | 367 } |
371 return policy_test_case; | 368 return policy_test_case; |
372 } | 369 } |
373 | 370 |
374 PolicyTestCaseMap policy_test_cases_; | 371 PolicyTestCaseMap policy_test_cases_; |
375 | 372 |
376 DISALLOW_COPY_AND_ASSIGN(PolicyTestCases); | 373 DISALLOW_COPY_AND_ASSIGN(PolicyTestCases); |
377 }; | 374 }; |
378 | 375 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 PrefService* user_prefs = browser()->profile()->GetPrefs(); | 547 PrefService* user_prefs = browser()->profile()->GetPrefs(); |
551 | 548 |
552 const PolicyTestCases test_cases; | 549 const PolicyTestCases test_cases; |
553 for (PolicyTestCases::iterator policy = test_cases.begin(); | 550 for (PolicyTestCases::iterator policy = test_cases.begin(); |
554 policy != test_cases.end(); | 551 policy != test_cases.end(); |
555 ++policy) { | 552 ++policy) { |
556 for (PolicyTestCases::PolicyTestCaseVector::const_iterator test_case = | 553 for (PolicyTestCases::PolicyTestCaseVector::const_iterator test_case = |
557 policy->second.begin(); | 554 policy->second.begin(); |
558 test_case != policy->second.end(); | 555 test_case != policy->second.end(); |
559 ++test_case) { | 556 ++test_case) { |
560 const ScopedVector<PrefMapping>& pref_mappings = | 557 const auto& pref_mappings = (*test_case)->pref_mappings(); |
561 (*test_case)->pref_mappings(); | |
562 if (!(*test_case)->IsSupported() || pref_mappings.empty()) | 558 if (!(*test_case)->IsSupported() || pref_mappings.empty()) |
563 continue; | 559 continue; |
564 | 560 |
565 LOG(INFO) << "Testing policy: " << policy->first; | 561 LOG(INFO) << "Testing policy: " << policy->first; |
566 | 562 |
567 for (ScopedVector<PrefMapping>::const_iterator pref_mapping = | 563 for (const auto& pref_mapping : pref_mappings) { |
568 pref_mappings.begin(); | |
569 pref_mapping != pref_mappings.end(); | |
570 ++pref_mapping) { | |
571 // Skip Chrome OS preferences that use a different backend and cannot be | 564 // Skip Chrome OS preferences that use a different backend and cannot be |
572 // retrieved through the prefs mechanism. | 565 // retrieved through the prefs mechanism. |
573 if (base::StartsWith((*pref_mapping)->pref(), kCrosSettingsPrefix, | 566 if (base::StartsWith(pref_mapping->pref(), kCrosSettingsPrefix, |
574 base::CompareCase::SENSITIVE)) | 567 base::CompareCase::SENSITIVE)) |
575 continue; | 568 continue; |
576 | 569 |
577 // Skip preferences that should not be checked when the policy is set to | 570 // Skip preferences that should not be checked when the policy is set to |
578 // a mandatory value. | 571 // a mandatory value. |
579 if (!(*pref_mapping)->check_for_mandatory()) | 572 if (!pref_mapping->check_for_mandatory()) |
580 continue; | 573 continue; |
581 | 574 |
582 PrefService* prefs = | 575 PrefService* prefs = |
583 (*pref_mapping)->is_local_state() ? local_state : user_prefs; | 576 pref_mapping->is_local_state() ? local_state : user_prefs; |
584 // The preference must have been registered. | 577 // The preference must have been registered. |
585 const PrefService::Preference* pref = | 578 const PrefService::Preference* pref = |
586 prefs->FindPreference((*pref_mapping)->pref().c_str()); | 579 prefs->FindPreference(pref_mapping->pref().c_str()); |
587 ASSERT_TRUE(pref); | 580 ASSERT_TRUE(pref); |
588 | 581 |
589 // Verify that setting the policy overrides the pref. | 582 // Verify that setting the policy overrides the pref. |
590 ClearProviderPolicy(); | 583 ClearProviderPolicy(); |
591 prefs->ClearPref((*pref_mapping)->pref().c_str()); | 584 prefs->ClearPref(pref_mapping->pref().c_str()); |
592 EXPECT_TRUE(pref->IsDefaultValue()); | 585 EXPECT_TRUE(pref->IsDefaultValue()); |
593 EXPECT_TRUE(pref->IsUserModifiable()); | 586 EXPECT_TRUE(pref->IsUserModifiable()); |
594 EXPECT_FALSE(pref->IsUserControlled()); | 587 EXPECT_FALSE(pref->IsUserControlled()); |
595 EXPECT_FALSE(pref->IsManaged()); | 588 EXPECT_FALSE(pref->IsManaged()); |
596 | 589 |
597 SetProviderPolicy((*test_case)->test_policy(), POLICY_LEVEL_MANDATORY); | 590 SetProviderPolicy((*test_case)->test_policy(), POLICY_LEVEL_MANDATORY); |
598 EXPECT_FALSE(pref->IsDefaultValue()); | 591 EXPECT_FALSE(pref->IsDefaultValue()); |
599 EXPECT_FALSE(pref->IsUserModifiable()); | 592 EXPECT_FALSE(pref->IsUserModifiable()); |
600 EXPECT_FALSE(pref->IsUserControlled()); | 593 EXPECT_FALSE(pref->IsUserControlled()); |
601 EXPECT_TRUE(pref->IsManaged()); | 594 EXPECT_TRUE(pref->IsManaged()); |
(...skipping 23 matching lines...) Expand all Loading... |
625 test_cases.Get(*policy); | 618 test_cases.Get(*policy); |
626 ASSERT_TRUE(policy_test_cases) << "PolicyTestCase not found for " | 619 ASSERT_TRUE(policy_test_cases) << "PolicyTestCase not found for " |
627 << *policy; | 620 << *policy; |
628 for (std::vector<PolicyTestCase*>::const_iterator test_case = | 621 for (std::vector<PolicyTestCase*>::const_iterator test_case = |
629 policy_test_cases->begin(); | 622 policy_test_cases->begin(); |
630 test_case != policy_test_cases->end(); | 623 test_case != policy_test_cases->end(); |
631 ++test_case) { | 624 ++test_case) { |
632 PolicyTestCase* policy_test_case = *test_case; | 625 PolicyTestCase* policy_test_case = *test_case; |
633 if (!policy_test_case->IsSupported()) | 626 if (!policy_test_case->IsSupported()) |
634 continue; | 627 continue; |
635 const ScopedVector<PrefMapping>& pref_mappings = | 628 const auto& pref_mappings = policy_test_case->pref_mappings(); |
636 policy_test_case->pref_mappings(); | |
637 if (policy_test_case->indicator_selector().empty()) { | 629 if (policy_test_case->indicator_selector().empty()) { |
638 bool has_pref_indicator_tests = false; | 630 bool has_pref_indicator_tests = false; |
639 for (ScopedVector<PrefMapping>::const_iterator pref_mapping = | 631 for (const auto& pref_mapping : pref_mappings) { |
640 pref_mappings.begin(); | |
641 pref_mapping != pref_mappings.end(); | |
642 ++pref_mapping) { | |
643 PrefService* prefs = | 632 PrefService* prefs = |
644 (*pref_mapping)->is_local_state() ? local_state : user_prefs; | 633 pref_mapping->is_local_state() ? local_state : user_prefs; |
645 if (prefs->FindPreference((*pref_mapping)->pref())) | 634 if (prefs->FindPreference(pref_mapping->pref())) |
646 prefs->ClearPref((*pref_mapping)->pref()); | 635 prefs->ClearPref(pref_mapping->pref()); |
647 if (!(*pref_mapping)->indicator_test_cases().empty()) { | 636 if (!pref_mapping->indicator_test_cases().empty()) { |
648 has_pref_indicator_tests = true; | 637 has_pref_indicator_tests = true; |
649 break; | 638 break; |
650 } | 639 } |
651 } | 640 } |
652 if (!has_pref_indicator_tests) | 641 if (!has_pref_indicator_tests) |
653 continue; | 642 continue; |
654 } | 643 } |
655 | 644 |
656 LOG(INFO) << "Testing policy: " << *policy; | 645 LOG(INFO) << "Testing policy: " << *policy; |
657 | 646 |
(...skipping 21 matching lines...) Expand all Loading... |
679 // enforced value is removed. | 668 // enforced value is removed. |
680 ClearProviderPolicy(); | 669 ClearProviderPolicy(); |
681 VerifyControlledSettingIndicators( | 670 VerifyControlledSettingIndicators( |
682 browser(), | 671 browser(), |
683 policy_test_case->indicator_selector(), | 672 policy_test_case->indicator_selector(), |
684 std::string(), | 673 std::string(), |
685 std::string(), | 674 std::string(), |
686 false); | 675 false); |
687 } | 676 } |
688 | 677 |
689 for (ScopedVector<PrefMapping>::const_iterator | 678 for (const auto& pref_mapping : pref_mappings) { |
690 pref_mapping = pref_mappings.begin(); | 679 const auto& indicator_test_cases = pref_mapping->indicator_test_cases(); |
691 pref_mapping != pref_mappings.end(); | |
692 ++pref_mapping) { | |
693 const ScopedVector<IndicatorTestCase>& indicator_test_cases = | |
694 (*pref_mapping)->indicator_test_cases(); | |
695 if (indicator_test_cases.empty()) | 680 if (indicator_test_cases.empty()) |
696 continue; | 681 continue; |
697 | 682 |
698 if (!(*pref_mapping)->indicator_test_setup_js().empty()) { | 683 if (!pref_mapping->indicator_test_setup_js().empty()) { |
699 ASSERT_TRUE(content::ExecuteScript( | 684 ASSERT_TRUE(content::ExecuteScript( |
700 browser()->tab_strip_model()->GetActiveWebContents(), | 685 browser()->tab_strip_model()->GetActiveWebContents(), |
701 (*pref_mapping)->indicator_test_setup_js())); | 686 pref_mapping->indicator_test_setup_js())); |
702 } | 687 } |
703 | 688 |
704 // A non-empty indicator_test_url is expected to be used in very | 689 // 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 | 690 // few cases, so it's currently implemented by navigating to the URL |
706 // right before the test and navigating back afterwards. | 691 // right before the test and navigating back afterwards. |
707 // If you introduce many test cases with the same non-empty | 692 // If you introduce many test cases with the same non-empty |
708 // indicator_test_url, this would be inefficient. We could consider | 693 // indicator_test_url, this would be inefficient. We could consider |
709 // navigting to a specific indicator_test_url once for many test cases | 694 // navigting to a specific indicator_test_url once for many test cases |
710 // instead. | 695 // instead. |
711 if (!(*pref_mapping)->indicator_test_url().empty()) { | 696 if (!pref_mapping->indicator_test_url().empty()) { |
712 ui_test_utils::NavigateToURL( | 697 ui_test_utils::NavigateToURL( |
713 browser(), GURL((*pref_mapping)->indicator_test_url())); | 698 browser(), GURL(pref_mapping->indicator_test_url())); |
714 } | 699 } |
715 | 700 |
716 std::string indicator_selector = (*pref_mapping)->indicator_selector(); | 701 std::string indicator_selector = pref_mapping->indicator_selector(); |
717 if (indicator_selector.empty()) | 702 if (indicator_selector.empty()) |
718 indicator_selector = "[pref=\"" + (*pref_mapping)->pref() + "\"]"; | 703 indicator_selector = "[pref=\"" + pref_mapping->pref() + "\"]"; |
719 for (ScopedVector<IndicatorTestCase>::const_iterator | 704 for (auto indicator_test_case = indicator_test_cases.begin(); |
720 indicator_test_case = indicator_test_cases.begin(); | |
721 indicator_test_case != indicator_test_cases.end(); | 705 indicator_test_case != indicator_test_cases.end(); |
722 ++indicator_test_case) { | 706 ++indicator_test_case) { |
723 // Check that no controlled setting indicator is visible when no value | 707 // Check that no controlled setting indicator is visible when no value |
724 // is set by policy. | 708 // is set by policy. |
725 ClearProviderPolicy(); | 709 ClearProviderPolicy(); |
726 VerifyControlledSettingIndicators(browser(), | 710 VerifyControlledSettingIndicators(browser(), |
727 indicator_selector, | 711 indicator_selector, |
728 std::string(), | 712 std::string(), |
729 std::string(), | 713 std::string(), |
730 false); | 714 false); |
731 | 715 |
732 if ((*pref_mapping)->check_for_mandatory()) { | 716 if (pref_mapping->check_for_mandatory()) { |
733 // Check that the appropriate controlled setting indicator is shown | 717 // Check that the appropriate controlled setting indicator is shown |
734 // when a value is enforced by policy. | 718 // when a value is enforced by policy. |
735 SetProviderPolicy((*indicator_test_case)->policy(), | 719 SetProviderPolicy((*indicator_test_case)->policy(), |
736 POLICY_LEVEL_MANDATORY); | 720 POLICY_LEVEL_MANDATORY); |
737 | 721 |
738 VerifyControlledSettingIndicators( | 722 VerifyControlledSettingIndicators( |
739 browser(), | 723 browser(), |
740 indicator_selector, | 724 indicator_selector, |
741 (*indicator_test_case)->value(), | 725 (*indicator_test_case)->value(), |
742 "policy", | 726 "policy", |
743 (*indicator_test_case)->readonly()); | 727 (*indicator_test_case)->readonly()); |
744 } | 728 } |
745 | 729 |
746 if (!policy_test_case->can_be_recommended() || | 730 if (!policy_test_case->can_be_recommended() || |
747 !(*pref_mapping)->check_for_recommended()) { | 731 !pref_mapping->check_for_recommended()) { |
748 continue; | 732 continue; |
749 } | 733 } |
750 | 734 |
751 PrefService* prefs = | 735 PrefService* prefs = |
752 (*pref_mapping)->is_local_state() ? local_state : user_prefs; | 736 pref_mapping->is_local_state() ? local_state : user_prefs; |
753 // The preference must have been registered. | 737 // The preference must have been registered. |
754 const PrefService::Preference* pref = | 738 const PrefService::Preference* pref = |
755 prefs->FindPreference((*pref_mapping)->pref().c_str()); | 739 prefs->FindPreference(pref_mapping->pref().c_str()); |
756 ASSERT_TRUE(pref); | 740 ASSERT_TRUE(pref); |
757 | 741 |
758 // Check that the appropriate controlled setting indicator is shown | 742 // Check that the appropriate controlled setting indicator is shown |
759 // when a value is recommended by policy and the user has not | 743 // when a value is recommended by policy and the user has not |
760 // overridden the recommendation. | 744 // overridden the recommendation. |
761 SetProviderPolicy((*indicator_test_case)->policy(), | 745 SetProviderPolicy((*indicator_test_case)->policy(), |
762 POLICY_LEVEL_RECOMMENDED); | 746 POLICY_LEVEL_RECOMMENDED); |
763 VerifyControlledSettingIndicators(browser(), | 747 VerifyControlledSettingIndicators(browser(), |
764 indicator_selector, | 748 indicator_selector, |
765 (*indicator_test_case)->value(), | 749 (*indicator_test_case)->value(), |
766 "recommended", | 750 "recommended", |
767 (*indicator_test_case)->readonly()); | 751 (*indicator_test_case)->readonly()); |
768 // Check that the appropriate controlled setting indicator is shown | 752 // Check that the appropriate controlled setting indicator is shown |
769 // when a value is recommended by policy and the user has overridden | 753 // when a value is recommended by policy and the user has overridden |
770 // the recommendation. | 754 // the recommendation. |
771 prefs->Set((*pref_mapping)->pref().c_str(), *pref->GetValue()); | 755 prefs->Set(pref_mapping->pref().c_str(), *pref->GetValue()); |
772 VerifyControlledSettingIndicators(browser(), | 756 VerifyControlledSettingIndicators(browser(), |
773 indicator_selector, | 757 indicator_selector, |
774 (*indicator_test_case)->value(), | 758 (*indicator_test_case)->value(), |
775 "hasRecommendation", | 759 "hasRecommendation", |
776 (*indicator_test_case)->readonly()); | 760 (*indicator_test_case)->readonly()); |
777 prefs->ClearPref((*pref_mapping)->pref().c_str()); | 761 prefs->ClearPref(pref_mapping->pref().c_str()); |
778 } | 762 } |
779 | 763 |
780 if (!(*pref_mapping)->indicator_test_url().empty()) | 764 if (!pref_mapping->indicator_test_url().empty()) |
781 ui_test_utils::NavigateToURL(browser(), GURL(kMainSettingsPage)); | 765 ui_test_utils::NavigateToURL(browser(), GURL(kMainSettingsPage)); |
782 } | 766 } |
783 } | 767 } |
784 } | 768 } |
785 } | 769 } |
786 | 770 |
787 INSTANTIATE_TEST_CASE_P(PolicyPrefIndicatorTestInstance, | 771 INSTANTIATE_TEST_CASE_P(PolicyPrefIndicatorTestInstance, |
788 PolicyPrefIndicatorTest, | 772 PolicyPrefIndicatorTest, |
789 testing::ValuesIn(SplitPoliciesIntoChunks(10))); | 773 testing::ValuesIn(SplitPoliciesIntoChunks(10))); |
790 | 774 |
791 } // namespace policy | 775 } // namespace policy |
OLD | NEW |