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.
5 #include "base/values.h"
6 #include "chrome/browser/ui/tabs/tab_strip_model.h"
7 #include "chrome/browser/ui/webui/options/options_ui_browsertest.h"
8 #include "components/policy/core/browser/browser_policy_connector.h"
9 #include "components/policy/core/common/external_data_fetcher.h"
10 #include "components/policy/core/common/mock_configuration_policy_provider.h"
11 #include "components/policy/core/common/policy_map.h"
12 #include "components/policy/core/common/policy_types.h"
13 #include "content/public/browser/render_frame_host.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/test/browser_test_utils.h"
16 #include "content/public/test/test_utils.h"
17 #include "policy/policy_constants.h"
18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h"
21 #if defined(OS_CHROMEOS)
22 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
23 #include "chromeos/network/onc/onc_test_utils.h"
26 using testing::Return
;
29 class CertificateManagerBrowserTest
: public options::OptionsUIBrowserTest
{
31 CertificateManagerBrowserTest() {}
32 ~CertificateManagerBrowserTest() override
{}
35 void SetUpInProcessBrowserTestFixture() override
{
36 #if defined(OS_CHROMEOS)
37 device_policy_test_helper_
.MarkAsEnterpriseOwned();
39 // Setup the policy provider for injecting certs through ONC policy.
40 EXPECT_CALL(provider_
, IsInitializationComplete(_
))
41 .WillRepeatedly(Return(true));
42 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_
);
45 #if defined(OS_CHROMEOS)
46 void LoadONCPolicy(const std::string
& filename
) {
47 const std::string
& user_policy_blob
=
48 chromeos::onc::test_utils::ReadTestData(filename
);
49 policy::PolicyMap policy
;
50 policy
.Set(policy::key::kOpenNetworkConfiguration
,
51 policy::POLICY_LEVEL_MANDATORY
,
52 policy::POLICY_SCOPE_USER
,
53 new base::StringValue(user_policy_blob
),
55 provider_
.UpdateChromePolicy(policy
);
56 content::RunAllPendingInMessageLoop();
60 void ClickElement(const std::string
& selector
) {
61 EXPECT_TRUE(content::ExecuteScript(
63 "document.querySelector(\"" + selector
+ "\").click()"));
66 bool HasElement(const std::string
& selector
) {
68 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
70 "window.domAutomationController.send("
71 " !!document.querySelector('" + selector
+ "'));",
76 policy::MockConfigurationPolicyProvider provider_
;
77 #if defined(OS_CHROMEOS)
78 policy::DevicePolicyCrosTestHelper device_policy_test_helper_
;
82 #if defined(OS_CHROMEOS)
83 // Ensure policy-installed certificates without web trust do not display
84 // the managed setting indicator (only on Chrome OS).
85 IN_PROC_BROWSER_TEST_F(CertificateManagerBrowserTest
,
86 PolicyCertificateWithoutWebTrustHasNoIndicator
) {
87 LoadONCPolicy("certificate-authority.onc");
89 ClickElement("#certificatesManageButton");
90 ClickElement("#ca-certs-nav-tab");
91 EXPECT_FALSE(HasElement(".cert-policy"));
95 #if defined(OS_CHROMEOS)
96 // Ensure policy-installed certificates with web trust display the
97 // managed setting indicator (only on Chrome OS).
98 IN_PROC_BROWSER_TEST_F(CertificateManagerBrowserTest
,
99 PolicyCertificateWithWebTrustHasIndicator
) {
100 LoadONCPolicy("certificate-web-authority.onc");
101 NavigateToSettings();
102 ClickElement("#certificatesManageButton");
103 ClickElement("#ca-certs-nav-tab");
104 EXPECT_TRUE(HasElement(".cert-policy"));