| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <map> | 6 #include <map> |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/string_util.h" |
| 18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/policy/browser_policy_connector.h" | 22 #include "chrome/browser/policy/browser_policy_connector.h" |
| 22 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 23 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 23 #include "chrome/browser/policy/policy_map.h" | 24 #include "chrome/browser/policy/policy_map.h" |
| 24 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 27 #include "chrome/browser/ui/browser_tabstrip.h" | 28 #include "chrome/browser/ui/browser_tabstrip.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 46 "chrome://settings-frame/passwords", | 47 "chrome://settings-frame/passwords", |
| 47 "chrome://settings-frame/autofill", | 48 "chrome://settings-frame/autofill", |
| 48 "chrome://settings-frame/content", | 49 "chrome://settings-frame/content", |
| 49 "chrome://settings-frame/homePageOverlay", | 50 "chrome://settings-frame/homePageOverlay", |
| 50 "chrome://settings-frame/languages", | 51 "chrome://settings-frame/languages", |
| 51 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
| 52 "chrome://settings-frame/accounts", | 53 "chrome://settings-frame/accounts", |
| 53 #endif | 54 #endif |
| 54 }; | 55 }; |
| 55 | 56 |
| 57 const char kCrosSettingsPrefix[] = "cros."; |
| 58 |
| 56 // Contains the details of a single test case verifying that the controlled | 59 // Contains the details of a single test case verifying that the controlled |
| 57 // setting indicators for a pref affected by a policy work correctly. This is | 60 // setting indicators for a pref affected by a policy work correctly. This is |
| 58 // part of the data loaded from chrome/test/data/policy/policy_test_cases.json. | 61 // part of the data loaded from chrome/test/data/policy/policy_test_cases.json. |
| 59 class IndicatorTestCase { | 62 class IndicatorTestCase { |
| 60 public: | 63 public: |
| 61 IndicatorTestCase(const base::DictionaryValue& policy, | 64 IndicatorTestCase(const base::DictionaryValue& policy, |
| 62 const std::string& value, | 65 const std::string& value, |
| 63 bool readonly) | 66 bool readonly) |
| 64 : policy_(policy.DeepCopy()), value_(value), readonly_(readonly) {} | 67 : policy_(policy.DeepCopy()), value_(value), readonly_(readonly) {} |
| 65 ~IndicatorTestCase() {} | 68 ~IndicatorTestCase() {} |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 ASSERT_TRUE(test_case); | 500 ASSERT_TRUE(test_case); |
| 498 const ScopedVector<PrefMapping>& pref_mappings = test_case->pref_mappings(); | 501 const ScopedVector<PrefMapping>& pref_mappings = test_case->pref_mappings(); |
| 499 if (!test_case->IsSupported() || pref_mappings.empty()) | 502 if (!test_case->IsSupported() || pref_mappings.empty()) |
| 500 return; | 503 return; |
| 501 LOG(INFO) << "Testing policy: " << test_case->name(); | 504 LOG(INFO) << "Testing policy: " << test_case->name(); |
| 502 | 505 |
| 503 for (ScopedVector<PrefMapping>::const_iterator | 506 for (ScopedVector<PrefMapping>::const_iterator |
| 504 pref_mapping = pref_mappings.begin(); | 507 pref_mapping = pref_mappings.begin(); |
| 505 pref_mapping != pref_mappings.end(); | 508 pref_mapping != pref_mappings.end(); |
| 506 ++pref_mapping) { | 509 ++pref_mapping) { |
| 510 // Skip Chrome OS preferences that use a different backend and cannot be |
| 511 // retrieved through the prefs mechanism. |
| 512 if (StartsWithASCII((*pref_mapping)->pref(), kCrosSettingsPrefix, true)) |
| 513 continue; |
| 514 |
| 507 PrefService* prefs = (*pref_mapping)->is_local_state() ? | 515 PrefService* prefs = (*pref_mapping)->is_local_state() ? |
| 508 g_browser_process->local_state() : browser()->profile()->GetPrefs(); | 516 g_browser_process->local_state() : browser()->profile()->GetPrefs(); |
| 509 // The preference must have been registered. | 517 // The preference must have been registered. |
| 510 const PrefService::Preference* pref = | 518 const PrefService::Preference* pref = |
| 511 prefs->FindPreference((*pref_mapping)->pref().c_str()); | 519 prefs->FindPreference((*pref_mapping)->pref().c_str()); |
| 512 ASSERT_TRUE(pref); | 520 ASSERT_TRUE(pref); |
| 513 prefs->ClearPref((*pref_mapping)->pref().c_str()); | 521 prefs->ClearPref((*pref_mapping)->pref().c_str()); |
| 514 | 522 |
| 515 // Verify that setting the policy overrides the pref. | 523 // Verify that setting the policy overrides the pref. |
| 516 const PolicyMap kNoPolicies; | 524 const PolicyMap kNoPolicies; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 LOG(INFO) << "Testing policy: " << policy_test_case->name(); | 582 LOG(INFO) << "Testing policy: " << policy_test_case->name(); |
| 575 | 583 |
| 576 for (ScopedVector<PrefMapping>::const_iterator | 584 for (ScopedVector<PrefMapping>::const_iterator |
| 577 pref_mapping = pref_mappings.begin(); | 585 pref_mapping = pref_mappings.begin(); |
| 578 pref_mapping != pref_mappings.end(); | 586 pref_mapping != pref_mappings.end(); |
| 579 ++pref_mapping) { | 587 ++pref_mapping) { |
| 580 const ScopedVector<IndicatorTestCase>& | 588 const ScopedVector<IndicatorTestCase>& |
| 581 indicator_test_cases = (*pref_mapping)->indicator_test_cases(); | 589 indicator_test_cases = (*pref_mapping)->indicator_test_cases(); |
| 582 if (indicator_test_cases.empty()) | 590 if (indicator_test_cases.empty()) |
| 583 continue; | 591 continue; |
| 584 PrefService* prefs = (*pref_mapping)->is_local_state() ? | |
| 585 g_browser_process->local_state() : browser()->profile()->GetPrefs(); | |
| 586 // The preference must have been registered. | |
| 587 const PrefService::Preference* pref = | |
| 588 prefs->FindPreference((*pref_mapping)->pref().c_str()); | |
| 589 ASSERT_TRUE(pref); | |
| 590 | 592 |
| 591 ui_test_utils::NavigateToURL(browser(), GURL(kSettingsPages[0])); | 593 ui_test_utils::NavigateToURL(browser(), GURL(kSettingsPages[0])); |
| 592 if (!(*pref_mapping)->indicator_test_setup_js().empty()) { | 594 if (!(*pref_mapping)->indicator_test_setup_js().empty()) { |
| 593 ASSERT_TRUE(content::ExecuteJavaScript( | 595 ASSERT_TRUE(content::ExecuteJavaScript( |
| 594 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", | 596 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
| 595 (*pref_mapping)->indicator_test_setup_js())); | 597 (*pref_mapping)->indicator_test_setup_js())); |
| 596 } | 598 } |
| 597 | 599 |
| 598 std::string indicator_selector = (*pref_mapping)->indicator_selector(); | 600 std::string indicator_selector = (*pref_mapping)->indicator_selector(); |
| 599 if (indicator_selector.empty()) | 601 if (indicator_selector.empty()) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 610 "", "", false); | 612 "", "", false); |
| 611 // Check that the appropriate controlled setting indicator is shown when a | 613 // Check that the appropriate controlled setting indicator is shown when a |
| 612 // value is enforced by policy. | 614 // value is enforced by policy. |
| 613 policies.LoadFrom(&(*indicator_test_case)->policy(), | 615 policies.LoadFrom(&(*indicator_test_case)->policy(), |
| 614 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); | 616 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); |
| 615 provider_.UpdateChromePolicy(policies); | 617 provider_.UpdateChromePolicy(policies); |
| 616 VerifyControlledSettingIndicators(browser(), indicator_selector, | 618 VerifyControlledSettingIndicators(browser(), indicator_selector, |
| 617 (*indicator_test_case)->value(), | 619 (*indicator_test_case)->value(), |
| 618 "policy", | 620 "policy", |
| 619 (*indicator_test_case)->readonly()); | 621 (*indicator_test_case)->readonly()); |
| 622 |
| 620 if (!policy_test_case->can_be_recommended()) | 623 if (!policy_test_case->can_be_recommended()) |
| 621 continue; | 624 continue; |
| 625 |
| 626 PrefService* prefs = (*pref_mapping)->is_local_state() ? |
| 627 g_browser_process->local_state() : browser()->profile()->GetPrefs(); |
| 628 // The preference must have been registered. |
| 629 const PrefService::Preference* pref = |
| 630 prefs->FindPreference((*pref_mapping)->pref().c_str()); |
| 631 ASSERT_TRUE(pref); |
| 632 |
| 622 // Check that the appropriate controlled setting indicator is shown when a | 633 // Check that the appropriate controlled setting indicator is shown when a |
| 623 // value is recommended by policy and the user has not overridden the | 634 // value is recommended by policy and the user has not overridden the |
| 624 // recommendation. | 635 // recommendation. |
| 625 policies.LoadFrom(&(*indicator_test_case)->policy(), | 636 policies.LoadFrom(&(*indicator_test_case)->policy(), |
| 626 POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER); | 637 POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER); |
| 627 provider_.UpdateChromePolicy(policies); | 638 provider_.UpdateChromePolicy(policies); |
| 628 VerifyControlledSettingIndicators(browser(), indicator_selector, | 639 VerifyControlledSettingIndicators(browser(), indicator_selector, |
| 629 (*indicator_test_case)->value(), | 640 (*indicator_test_case)->value(), |
| 630 "recommended", | 641 "recommended", |
| 631 (*indicator_test_case)->readonly()); | 642 (*indicator_test_case)->readonly()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 642 } | 653 } |
| 643 } | 654 } |
| 644 | 655 |
| 645 INSTANTIATE_TEST_CASE_P( | 656 INSTANTIATE_TEST_CASE_P( |
| 646 PolicyPrefsTestInstance, | 657 PolicyPrefsTestInstance, |
| 647 PolicyPrefsTest, | 658 PolicyPrefsTest, |
| 648 testing::ValuesIn(GetChromePolicyDefinitionList()->begin, | 659 testing::ValuesIn(GetChromePolicyDefinitionList()->begin, |
| 649 GetChromePolicyDefinitionList()->end)); | 660 GetChromePolicyDefinitionList()->end)); |
| 650 | 661 |
| 651 } // namespace policy | 662 } // namespace policy |
| OLD | NEW |