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