| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/memory/ptr_util.h" | |
| 6 #include "base/values.h" | |
| 7 #include "build/build_config.h" | |
| 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 9 #include "chrome/browser/ui/webui/options/options_ui_browsertest.h" | |
| 10 #include "components/policy/core/browser/browser_policy_connector.h" | |
| 11 #include "components/policy/core/common/external_data_fetcher.h" | |
| 12 #include "components/policy/core/common/mock_configuration_policy_provider.h" | |
| 13 #include "components/policy/core/common/policy_map.h" | |
| 14 #include "components/policy/core/common/policy_types.h" | |
| 15 #include "components/policy/policy_constants.h" | |
| 16 #include "content/public/browser/render_frame_host.h" | |
| 17 #include "content/public/browser/web_contents.h" | |
| 18 #include "content/public/test/browser_test_utils.h" | |
| 19 #include "content/public/test/test_utils.h" | |
| 20 #include "testing/gmock/include/gmock/gmock.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | |
| 22 | |
| 23 #if defined(OS_CHROMEOS) | |
| 24 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | |
| 25 #include "chromeos/network/onc/onc_test_utils.h" | |
| 26 #endif | |
| 27 | |
| 28 using testing::Return; | |
| 29 using testing::_; | |
| 30 | |
| 31 class CertificateManagerBrowserTest : public options::OptionsUIBrowserTest { | |
| 32 public: | |
| 33 CertificateManagerBrowserTest() {} | |
| 34 ~CertificateManagerBrowserTest() override {} | |
| 35 | |
| 36 protected: | |
| 37 void SetUpInProcessBrowserTestFixture() override { | |
| 38 options::OptionsUIBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 39 #if defined(OS_CHROMEOS) | |
| 40 device_policy_test_helper_.MarkAsEnterpriseOwned(); | |
| 41 #endif | |
| 42 // Setup the policy provider for injecting certs through ONC policy. | |
| 43 EXPECT_CALL(provider_, IsInitializationComplete(_)) | |
| 44 .WillRepeatedly(Return(true)); | |
| 45 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | |
| 46 } | |
| 47 | |
| 48 #if defined(OS_CHROMEOS) | |
| 49 void LoadONCPolicy(const std::string& filename) { | |
| 50 const std::string& user_policy_blob = | |
| 51 chromeos::onc::test_utils::ReadTestData(filename); | |
| 52 policy::PolicyMap policy; | |
| 53 policy.Set(policy::key::kOpenNetworkConfiguration, | |
| 54 policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | |
| 55 policy::POLICY_SOURCE_CLOUD, | |
| 56 base::MakeUnique<base::Value>(user_policy_blob), nullptr); | |
| 57 provider_.UpdateChromePolicy(policy); | |
| 58 content::RunAllPendingInMessageLoop(); | |
| 59 } | |
| 60 #endif | |
| 61 | |
| 62 void ClickElement(const std::string& selector) { | |
| 63 EXPECT_TRUE(content::ExecuteScript( | |
| 64 GetSettingsFrame(), | |
| 65 "document.querySelector(\"" + selector + "\").click()")); | |
| 66 } | |
| 67 | |
| 68 bool HasElement(const std::string& selector) { | |
| 69 bool result; | |
| 70 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 71 GetSettingsFrame(), | |
| 72 "window.domAutomationController.send(" | |
| 73 " !!document.querySelector('" + selector + "'));", | |
| 74 &result)); | |
| 75 return result; | |
| 76 } | |
| 77 | |
| 78 policy::MockConfigurationPolicyProvider provider_; | |
| 79 #if defined(OS_CHROMEOS) | |
| 80 policy::DevicePolicyCrosTestHelper device_policy_test_helper_; | |
| 81 #endif | |
| 82 }; | |
| 83 | |
| 84 #if defined(OS_CHROMEOS) | |
| 85 // Ensure policy-installed certificates without web trust do not display | |
| 86 // the managed setting indicator (only on Chrome OS). | |
| 87 IN_PROC_BROWSER_TEST_F(CertificateManagerBrowserTest, | |
| 88 PolicyCertificateWithoutWebTrustHasNoIndicator) { | |
| 89 LoadONCPolicy("certificate-authority.onc"); | |
| 90 NavigateToSettings(); | |
| 91 ClickElement("#certificatesManageButton"); | |
| 92 ClickElement("#ca-certs-nav-tab"); | |
| 93 EXPECT_FALSE(HasElement(".cert-policy")); | |
| 94 } | |
| 95 #endif | |
| 96 | |
| 97 #if defined(OS_CHROMEOS) | |
| 98 // Ensure policy-installed certificates with web trust display the | |
| 99 // managed setting indicator (only on Chrome OS). | |
| 100 IN_PROC_BROWSER_TEST_F(CertificateManagerBrowserTest, | |
| 101 PolicyCertificateWithWebTrustHasIndicator) { | |
| 102 LoadONCPolicy("certificate-web-authority.onc"); | |
| 103 NavigateToSettings(); | |
| 104 ClickElement("#certificatesManageButton"); | |
| 105 ClickElement("#ca-certs-nav-tab"); | |
| 106 EXPECT_TRUE(HasElement(".cert-policy")); | |
| 107 } | |
| 108 #endif | |
| OLD | NEW |