1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/values.h" 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/webui/options/options_ui_browsertest.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/policy/core/browser/browser_policy_connector.h" 9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/external_data_fetcher.h" 10a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/mock_configuration_policy_provider.h" 11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/policy_map.h" 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/policy_types.h" 13effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "content/public/browser/render_frame_host.h" 14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/public/browser/web_contents.h" 15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/public/test/browser_test_utils.h" 16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/public/test/test_utils.h" 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "policy/policy_constants.h" 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h" 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#if defined(OS_CHROMEOS) 2268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" 23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chromeos/network/onc/onc_test_utils.h" 24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)using testing::Return; 27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)using testing::_; 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 29558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochclass CertificateManagerBrowserTest : public options::OptionsUIBrowserTest { 30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public: 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CertificateManagerBrowserTest() {} 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual ~CertificateManagerBrowserTest() {} 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) protected: 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 36424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#if defined(OS_CHROMEOS) 3768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) device_policy_test_helper_.MarkAsEnterpriseOwned(); 38424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#endif 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Setup the policy provider for injecting certs through ONC policy. 40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_CALL(provider_, IsInitializationComplete(_)) 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) .WillRepeatedly(Return(true)); 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); 43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_CHROMEOS) 46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void LoadONCPolicy(const std::string& filename) { 47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const std::string& user_policy_blob = 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) chromeos::onc::test_utils::ReadTestData(filename); 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) policy::PolicyMap policy; 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) policy.Set(policy::key::kOpenNetworkConfiguration, 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) policy::POLICY_LEVEL_MANDATORY, 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) policy::POLICY_SCOPE_USER, 535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) new base::StringValue(user_policy_blob), 547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch NULL); 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) provider_.UpdateChromePolicy(policy); 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) content::RunAllPendingInMessageLoop(); 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 60effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch void ClickElement(const std::string& selector) { 61effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_TRUE(content::ExecuteScript( 620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch GetSettingsFrame(), 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "document.querySelector(\"" + selector + "\").click()")); 64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool HasElement(const std::string& selector) { 67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool result; 68effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch GetSettingsFrame(), 70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) "window.domAutomationController.send(" 71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) " !!document.querySelector('" + selector + "'));", 72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) &result)); 73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return result; 74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) policy::MockConfigurationPolicyProvider provider_; 773240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#if defined(OS_CHROMEOS) 7868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) policy::DevicePolicyCrosTestHelper device_policy_test_helper_; 793240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#endif 80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}; 81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#if defined(OS_CHROMEOS) 83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Ensure policy-installed certificates without web trust do not display 84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// the managed setting indicator (only on Chrome OS). 85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(CertificateManagerBrowserTest, 86a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) PolicyCertificateWithoutWebTrustHasNoIndicator) { 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) LoadONCPolicy("certificate-authority.onc"); 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NavigateToSettings(); 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ClickElement("#certificatesManageButton"); 90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ClickElement("#ca-certs-nav-tab"); 91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_FALSE(HasElement(".cert-policy")); 92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif 94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 95868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#if defined(OS_CHROMEOS) 96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Ensure policy-installed certificates with web trust display the 97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// managed setting indicator (only on Chrome OS). 98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(CertificateManagerBrowserTest, 99a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) PolicyCertificateWithWebTrustHasIndicator) { 100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) LoadONCPolicy("certificate-web-authority.onc"); 101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NavigateToSettings(); 102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ClickElement("#certificatesManageButton"); 103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ClickElement("#ca-certs-nav-tab"); 104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) EXPECT_TRUE(HasElement(".cert-policy")); 105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 106868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif 107