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

Unified Diff: chrome/browser/web_bluetooth_browsertest.cc

Issue 1841763002: Add a kill switch for all of Web Bluetooth. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Sync and rename an enum value. Created 4 years, 9 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
« no previous file with comments | « chrome/browser/permissions/permission_context_base.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/web_bluetooth_browsertest.cc
diff --git a/chrome/browser/web_bluetooth_browsertest.cc b/chrome/browser/web_bluetooth_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a94ea45e64b0bea1cb48c004943d62d35cf5405
--- /dev/null
+++ b/chrome/browser/web_bluetooth_browsertest.cc
@@ -0,0 +1,79 @@
+// Copyright 2016 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.
+
+// This file contains browsertests for Web Bluetooth that depend on behavior
+// defined in chrome/, not just in content/.
+
+#include "base/command_line.h"
+#include "base/metrics/field_trial.h"
+#include "chrome/browser/permissions/permission_context_base.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "components/variations/variations_associated_data.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/test/browser_test_utils.h"
+#include "device/bluetooth/bluetooth_adapter_factory.h"
+#include "device/bluetooth/test/mock_bluetooth_adapter.h"
+
+namespace {
+
+class WebBluetoothTest : public InProcessBrowserTest {
+ protected:
+ 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);
+ InProcessBrowserTest::SetUpCommandLine(command_line);
+ }
+
+ void SetUpOnMainThread() override {
+ // 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"));
+ web_contents_ = browser()->tab_strip_model()->GetActiveWebContents();
+ EXPECT_THAT(
+ web_contents_->GetMainFrame()->GetLastCommittedOrigin().Serialize(),
+ testing::StartsWith("http://localhost:"));
+ }
+
+ content::WebContents* web_contents_ = nullptr;
+};
+
+IN_PROC_BROWSER_TEST_F(WebBluetoothTest, KillSwitchShouldBlock) {
+ // 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);
+
+ // Turn on the global kill switch.
+ std::map<std::string, std::string> params;
+ params["Bluetooth"] =
+ PermissionContextBase::kPermissionsKillSwitchBlockedValue;
+ variations::AssociateVariationParams(
+ PermissionContextBase::kPermissionsKillSwitchFieldStudy, "TestGroup",
+ params);
+ base::FieldTrialList::CreateFieldTrial(
+ PermissionContextBase::kPermissionsKillSwitchFieldStudy, "TestGroup");
+
+ 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: .*globally disabled.*"));
+}
+
+} // namespace
« no previous file with comments | « chrome/browser/permissions/permission_context_base.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698