| 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 14 matching lines...) Expand all Loading... |
| 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/threading/thread_restrictions.h" | 27 #include "base/threading/thread_restrictions.h" |
| 28 #include "base/values.h" | 28 #include "base/values.h" |
| 29 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 30 #include "chrome/browser/browser_process.h" | 30 #include "chrome/browser/browser_process.h" |
| 31 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/search_engines/template_url_service_factory.h" | 32 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 33 #include "chrome/browser/ui/browser.h" | 33 #include "chrome/browser/ui/browser.h" |
| 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 35 #include "chrome/common/url_constants.h" |
| 35 #include "chrome/test/base/in_process_browser_test.h" | 36 #include "chrome/test/base/in_process_browser_test.h" |
| 36 #include "chrome/test/base/search_test_utils.h" | 37 #include "chrome/test/base/search_test_utils.h" |
| 37 #include "chrome/test/base/ui_test_utils.h" | 38 #include "chrome/test/base/ui_test_utils.h" |
| 38 #include "components/policy/core/browser/browser_policy_connector.h" | 39 #include "components/policy/core/browser/browser_policy_connector.h" |
| 39 #include "components/policy/core/common/external_data_fetcher.h" | 40 #include "components/policy/core/common/external_data_fetcher.h" |
| 40 #include "components/policy/core/common/external_data_manager.h" | 41 #include "components/policy/core/common/external_data_manager.h" |
| 41 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 42 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 42 #include "components/policy/core/common/policy_details.h" | 43 #include "components/policy/core/common/policy_details.h" |
| 43 #include "components/policy/core/common/policy_map.h" | 44 #include "components/policy/core/common/policy_map.h" |
| 44 #include "components/policy/core/common/policy_types.h" | 45 #include "components/policy/core/common/policy_types.h" |
| 45 #include "components/policy/core/common/schema.h" | 46 #include "components/policy/core/common/schema.h" |
| 46 #include "components/policy/policy_constants.h" | 47 #include "components/policy/policy_constants.h" |
| 47 #include "components/prefs/pref_service.h" | 48 #include "components/prefs/pref_service.h" |
| 48 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
| 49 #include "content/public/test/browser_test_utils.h" | 50 #include "content/public/test/browser_test_utils.h" |
| 50 #include "testing/gmock/include/gmock/gmock.h" | 51 #include "testing/gmock/include/gmock/gmock.h" |
| 51 #include "testing/gtest/include/gtest/gtest.h" | 52 #include "testing/gtest/include/gtest/gtest.h" |
| 52 #include "url/gurl.h" | 53 #include "url/gurl.h" |
| 53 | 54 |
| 54 using testing::Return; | 55 using testing::Return; |
| 55 using testing::_; | 56 using testing::_; |
| 56 | 57 |
| 57 namespace policy { | 58 namespace policy { |
| 58 | 59 |
| 59 namespace { | 60 namespace { |
| 60 | 61 |
| 61 const char kMainSettingsPage[] = "chrome://settings-frame"; | |
| 62 | |
| 63 const char kCrosSettingsPrefix[] = "cros."; | 62 const char kCrosSettingsPrefix[] = "cros."; |
| 64 | 63 |
| 65 std::string GetPolicyName(const std::string& policy_name_decorated) { | 64 std::string GetPolicyName(const std::string& policy_name_decorated) { |
| 66 const size_t offset = policy_name_decorated.find('.'); | 65 const size_t offset = policy_name_decorated.find('.'); |
| 67 if (offset != std::string::npos) | 66 if (offset != std::string::npos) |
| 68 return policy_name_decorated.substr(0, offset); | 67 return policy_name_decorated.substr(0, offset); |
| 69 return policy_name_decorated; | 68 return policy_name_decorated; |
| 70 } | 69 } |
| 71 | 70 |
| 72 // Contains the details of a single test case verifying that the controlled | 71 // Contains the details of a single test case verifying that the controlled |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 } | 367 } |
| 369 } | 368 } |
| 370 return policy_test_case; | 369 return policy_test_case; |
| 371 } | 370 } |
| 372 | 371 |
| 373 PolicyTestCaseMap policy_test_cases_; | 372 PolicyTestCaseMap policy_test_cases_; |
| 374 | 373 |
| 375 DISALLOW_COPY_AND_ASSIGN(PolicyTestCases); | 374 DISALLOW_COPY_AND_ASSIGN(PolicyTestCases); |
| 376 }; | 375 }; |
| 377 | 376 |
| 377 #if defined(OS_CHROMEOS) |
| 378 |
| 378 // Returns a pseudo-random integer distributed in [0, range). | 379 // Returns a pseudo-random integer distributed in [0, range). |
| 379 int GetRandomNumber(int range) { | 380 int GetRandomNumber(int range) { |
| 380 return rand() % range; | 381 return rand() % range; |
| 381 } | 382 } |
| 382 | 383 |
| 383 // Splits all known policies into subsets of the given |chunk_size|. The | 384 // Splits all known policies into subsets of the given |chunk_size|. The |
| 384 // policies are shuffled so that there is no correlation between their initial | 385 // policies are shuffled so that there is no correlation between their initial |
| 385 // alphabetic ordering and the assignment to chunks. This ensures that the | 386 // alphabetic ordering and the assignment to chunks. This ensures that the |
| 386 // expected number of policies with long-running test cases is equal for each | 387 // expected number of policies with long-running test cases is equal for each |
| 387 // subset. The shuffle algorithm uses a fixed seed, ensuring that no randomness | 388 // subset. The shuffle algorithm uses a fixed seed, ensuring that no randomness |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 EXPECT_FALSE(indicator_visible); | 474 EXPECT_FALSE(indicator_visible); |
| 474 } | 475 } |
| 475 } | 476 } |
| 476 if (!controlled_by.empty()) { | 477 if (!controlled_by.empty()) { |
| 477 EXPECT_TRUE(have_visible_indicators) | 478 EXPECT_TRUE(have_visible_indicators) |
| 478 << "Expected to find at least one visible controlled setting " | 479 << "Expected to find at least one visible controlled setting " |
| 479 << "indicator."; | 480 << "indicator."; |
| 480 } | 481 } |
| 481 } | 482 } |
| 482 | 483 |
| 484 #endif // defined(OS_CHROMEOS) |
| 485 |
| 483 } // namespace | 486 } // namespace |
| 484 | 487 |
| 485 typedef InProcessBrowserTest PolicyPrefsTestCoverageTest; | 488 typedef InProcessBrowserTest PolicyPrefsTestCoverageTest; |
| 486 | 489 |
| 487 IN_PROC_BROWSER_TEST_F(PolicyPrefsTestCoverageTest, AllPoliciesHaveATestCase) { | 490 IN_PROC_BROWSER_TEST_F(PolicyPrefsTestCoverageTest, AllPoliciesHaveATestCase) { |
| 488 // Verifies that all known policies have a test case in the JSON file. | 491 // Verifies that all known policies have a test case in the JSON file. |
| 489 // This test fails when a policy is added to | 492 // This test fails when a policy is added to |
| 490 // components/policy/resources/policy_templates.json but a test case is not | 493 // components/policy/resources/policy_templates.json but a test case is not |
| 491 // added to chrome/test/data/policy/policy_test_cases.json. | 494 // added to chrome/test/data/policy/policy_test_cases.json. |
| 492 Schema chrome_schema = Schema::Wrap(GetChromeSchemaData()); | 495 Schema chrome_schema = Schema::Wrap(GetChromeSchemaData()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 } | 600 } |
| 598 } | 601 } |
| 599 } | 602 } |
| 600 } | 603 } |
| 601 | 604 |
| 602 class PolicyPrefIndicatorTest | 605 class PolicyPrefIndicatorTest |
| 603 : public PolicyPrefsTest, | 606 : public PolicyPrefsTest, |
| 604 public testing::WithParamInterface<std::vector<std::string> > { | 607 public testing::WithParamInterface<std::vector<std::string> > { |
| 605 }; | 608 }; |
| 606 | 609 |
| 610 #if defined(OS_CHROMEOS) |
| 611 |
| 607 // Verifies that controlled setting indicators correctly show whether a pref's | 612 // Verifies that controlled setting indicators correctly show whether a pref's |
| 608 // value is recommended or enforced by a corresponding policy. | 613 // value is recommended or enforced by a corresponding policy. |
| 609 IN_PROC_BROWSER_TEST_P(PolicyPrefIndicatorTest, CheckPolicyIndicators) { | 614 IN_PROC_BROWSER_TEST_P(PolicyPrefIndicatorTest, CheckPolicyIndicators) { |
| 610 const PolicyTestCases test_cases; | 615 const PolicyTestCases test_cases; |
| 611 PrefService* local_state = g_browser_process->local_state(); | 616 PrefService* local_state = g_browser_process->local_state(); |
| 612 PrefService* user_prefs = browser()->profile()->GetPrefs(); | 617 PrefService* user_prefs = browser()->profile()->GetPrefs(); |
| 613 | 618 |
| 614 ui_test_utils::NavigateToURL(browser(), GURL(kMainSettingsPage)); | 619 ui_test_utils::NavigateToURL(browser(), |
| 620 GURL(chrome::kChromeUISettingsFrameURL)); |
| 615 | 621 |
| 616 for (std::vector<std::string>::const_iterator policy = GetParam().begin(); | 622 for (std::vector<std::string>::const_iterator policy = GetParam().begin(); |
| 617 policy != GetParam().end(); | 623 policy != GetParam().end(); |
| 618 ++policy) { | 624 ++policy) { |
| 619 const std::vector<PolicyTestCase*>* policy_test_cases = | 625 const std::vector<PolicyTestCase*>* policy_test_cases = |
| 620 test_cases.Get(*policy); | 626 test_cases.Get(*policy); |
| 621 ASSERT_TRUE(policy_test_cases) << "PolicyTestCase not found for " | 627 ASSERT_TRUE(policy_test_cases) << "PolicyTestCase not found for " |
| 622 << *policy; | 628 << *policy; |
| 623 for (std::vector<PolicyTestCase*>::const_iterator test_case = | 629 for (std::vector<PolicyTestCase*>::const_iterator test_case = |
| 624 policy_test_cases->begin(); | 630 policy_test_cases->begin(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 // the recommendation. | 762 // the recommendation. |
| 757 prefs->Set(pref_mapping->pref().c_str(), *pref->GetValue()); | 763 prefs->Set(pref_mapping->pref().c_str(), *pref->GetValue()); |
| 758 VerifyControlledSettingIndicators(browser(), | 764 VerifyControlledSettingIndicators(browser(), |
| 759 indicator_selector, | 765 indicator_selector, |
| 760 (*indicator_test_case)->value(), | 766 (*indicator_test_case)->value(), |
| 761 "hasRecommendation", | 767 "hasRecommendation", |
| 762 (*indicator_test_case)->readonly()); | 768 (*indicator_test_case)->readonly()); |
| 763 prefs->ClearPref(pref_mapping->pref().c_str()); | 769 prefs->ClearPref(pref_mapping->pref().c_str()); |
| 764 } | 770 } |
| 765 | 771 |
| 766 if (!pref_mapping->indicator_test_url().empty()) | 772 if (!pref_mapping->indicator_test_url().empty()) { |
| 767 ui_test_utils::NavigateToURL(browser(), GURL(kMainSettingsPage)); | 773 ui_test_utils::NavigateToURL(browser(), |
| 774 GURL(chrome::kChromeUISettingsFrameURL)); |
| 775 } |
| 768 } | 776 } |
| 769 } | 777 } |
| 770 } | 778 } |
| 771 } | 779 } |
| 772 | 780 |
| 773 INSTANTIATE_TEST_CASE_P(PolicyPrefIndicatorTestInstance, | 781 INSTANTIATE_TEST_CASE_P(PolicyPrefIndicatorTestInstance, |
| 774 PolicyPrefIndicatorTest, | 782 PolicyPrefIndicatorTest, |
| 775 testing::ValuesIn(SplitPoliciesIntoChunks(10))); | 783 testing::ValuesIn(SplitPoliciesIntoChunks(10))); |
| 776 | 784 |
| 785 #endif // defined(OS_CHROMEOS) |
| 786 |
| 777 } // namespace policy | 787 } // namespace policy |
| OLD | NEW |