Vectorize sad tab image.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / certificate_manager_browsertest.cc
blob881eec7913d758d5202d3e083faea3e31b81348e
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"
24 #endif
26 using testing::Return;
27 using testing::_;
29 class CertificateManagerBrowserTest : public options::OptionsUIBrowserTest {
30 public:
31 CertificateManagerBrowserTest() {}
32 ~CertificateManagerBrowserTest() override {}
34 protected:
35 void SetUpInProcessBrowserTestFixture() override {
36 #if defined(OS_CHROMEOS)
37 device_policy_test_helper_.MarkAsEnterpriseOwned();
38 #endif
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 policy::POLICY_SOURCE_CLOUD,
54 new base::StringValue(user_policy_blob),
55 NULL);
56 provider_.UpdateChromePolicy(policy);
57 content::RunAllPendingInMessageLoop();
59 #endif
61 void ClickElement(const std::string& selector) {
62 EXPECT_TRUE(content::ExecuteScript(
63 GetSettingsFrame(),
64 "document.querySelector(\"" + selector + "\").click()"));
67 bool HasElement(const std::string& selector) {
68 bool result;
69 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
70 GetSettingsFrame(),
71 "window.domAutomationController.send("
72 " !!document.querySelector('" + selector + "'));",
73 &result));
74 return result;
77 policy::MockConfigurationPolicyProvider provider_;
78 #if defined(OS_CHROMEOS)
79 policy::DevicePolicyCrosTestHelper device_policy_test_helper_;
80 #endif
83 #if defined(OS_CHROMEOS)
84 // Ensure policy-installed certificates without web trust do not display
85 // the managed setting indicator (only on Chrome OS).
86 IN_PROC_BROWSER_TEST_F(CertificateManagerBrowserTest,
87 PolicyCertificateWithoutWebTrustHasNoIndicator) {
88 LoadONCPolicy("certificate-authority.onc");
89 NavigateToSettings();
90 ClickElement("#certificatesManageButton");
91 ClickElement("#ca-certs-nav-tab");
92 EXPECT_FALSE(HasElement(".cert-policy"));
94 #endif
96 #if defined(OS_CHROMEOS)
97 // Ensure policy-installed certificates with web trust display the
98 // managed setting indicator (only on Chrome OS).
99 IN_PROC_BROWSER_TEST_F(CertificateManagerBrowserTest,
100 PolicyCertificateWithWebTrustHasIndicator) {
101 LoadONCPolicy("certificate-web-authority.onc");
102 NavigateToSettings();
103 ClickElement("#certificatesManageButton");
104 ClickElement("#ca-certs-nav-tab");
105 EXPECT_TRUE(HasElement(".cert-policy"));
107 #endif