| Index: chrome/browser/policy/policy_browsertest.cc
|
| diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc
|
| index df2ca80827875c151b1d913cf5db938d7f4c4189..9a88dc6056ddf718f6759894015bfe04a70bddd7 100644
|
| --- a/chrome/browser/policy/policy_browsertest.cc
|
| +++ b/chrome/browser/policy/policy_browsertest.cc
|
| @@ -141,6 +141,7 @@
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/common/content_constants.h"
|
| #include "content/public/common/content_paths.h"
|
| +#include "content/public/common/content_switches.h"
|
| #include "content/public/common/process_type.h"
|
| #include "content/public/common/result_codes.h"
|
| #include "content/public/common/url_constants.h"
|
| @@ -150,6 +151,8 @@
|
| #include "content/public/test/mock_notification_observer.h"
|
| #include "content/public/test/test_navigation_observer.h"
|
| #include "content/public/test/test_utils.h"
|
| +#include "device/bluetooth/bluetooth_adapter_factory.h"
|
| +#include "device/bluetooth/test/mock_bluetooth_adapter.h"
|
| #include "extensions/browser/extension_dialog_auto_confirm.h"
|
| #include "extensions/browser/extension_host.h"
|
| #include "extensions/browser/extension_prefs.h"
|
| @@ -181,6 +184,7 @@
|
| #include "ui/base/page_transition_types.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "url/gurl.h"
|
| +#include "url/origin.h"
|
|
|
| #if defined(OS_CHROMEOS)
|
| #include "ash/accelerators/accelerator_controller.h"
|
| @@ -3653,6 +3657,53 @@ INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance,
|
| MediaStreamDevicesControllerBrowserTest,
|
| testing::Bool());
|
|
|
| +class WebBluetoothPolicyTest : public PolicyTest {
|
| + void SetUpCommandLine(base::CommandLine* command_line)override {
|
| + // This is needed while Web Bluetooth is an Origin Trial, but can go away
|
| + // once it ships globally.
|
| + command_line->AppendSwitch(switches::kEnableWebBluetooth);
|
| + PolicyTest::SetUpCommandLine(command_line);
|
| + }
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(WebBluetoothPolicyTest, Block) {
|
| + // Fake the BluetoothAdapter to say it's present.
|
| + scoped_refptr<device::MockBluetoothAdapter> adapter =
|
| + new testing::NiceMock<device::MockBluetoothAdapter>;
|
| + EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(testing::Return(true));
|
| + device::BluetoothAdapterFactory::SetAdapterForTesting(adapter);
|
| +
|
| + // Navigate to a secure context.
|
| + embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data");
|
| + ASSERT_TRUE(embedded_test_server()->Start());
|
| + ui_test_utils::NavigateToURL(
|
| + browser(),
|
| + embedded_test_server()->GetURL("localhost", "/simple_page.html"));
|
| + content::WebContents* const web_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + EXPECT_THAT(
|
| + web_contents->GetMainFrame()->GetLastCommittedOrigin().Serialize(),
|
| + testing::StartsWith("http://localhost:"));
|
| +
|
| + // Set the policy to block Web Bluetooth.
|
| + PolicyMap policies;
|
| + policies.Set(key::kDefaultWebBluetoothGuardSetting, POLICY_LEVEL_MANDATORY,
|
| + POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
|
| + new base::FundamentalValue(2), nullptr);
|
| + UpdateProviderPolicy(policies);
|
| +
|
| + std::string rejection;
|
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString(
|
| + web_contents,
|
| + "navigator.bluetooth.requestDevice({filters: [{name: 'Hello'}]})"
|
| + " .then(() => { domAutomationController.send('Success'); },"
|
| + " reason => {"
|
| + " domAutomationController.send(reason.name + ': ' + reason.message);"
|
| + " });",
|
| + &rejection));
|
| + EXPECT_THAT(rejection, testing::MatchesRegex("NotFoundError: .*policy.*"));
|
| +}
|
| +
|
| // Test that when extended reporting opt-in is disabled by policy, the
|
| // opt-in checkbox does not appear on SSL blocking pages.
|
| IN_PROC_BROWSER_TEST_F(PolicyTest, SafeBrowsingExtendedReportingOptInAllowed) {
|
|
|