Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: chrome/browser/policy/policy_browsertest.cc

Issue 1706503002: Add enterprise policy to turn off Bluetooth. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Switch to a unified browsertest Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0398af526c3a4688782693296006ef5797a1d68b 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"
@@ -3653,6 +3656,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 =
bartfab (slow) 2016/02/26 18:00:45 Nit: const pointer
Jeffrey Yasskin 2016/02/26 18:21:25 Nope, GetMainFrame() is non-const.
+ browser()->tab_strip_model()->GetActiveWebContents();
+ ASSERT_THAT(
bartfab (slow) 2016/02/26 18:00:45 Nit: Would an EXPECT not be sufficient here?
Jeffrey Yasskin 2016/02/26 18:21:25 We won't get useful errors from the rest of the te
+ web_contents->GetMainFrame()->GetLastCommittedOrigin().Serialize(),
bartfab (slow) 2016/02/26 18:00:45 Nit: #include "url/origin.h"
Jeffrey Yasskin 2016/02/26 18:21:25 Done.
+ 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'); },"
bartfab (slow) 2016/02/26 18:00:45 Nit: Indentation.
Jeffrey Yasskin 2016/02/26 18:21:25 Heh, I have no idea how to indent .then() calls. I
bartfab (slow) 2016/02/26 18:24:54 I have no idea either, but zero spaces seemed like
+ " 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) {

Powered by Google App Engine
This is Rietveld 408576698