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

Side by Side 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: Move navigating to a secure context into SetUpOnMainThread Created 4 years, 8 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This file contains browsertests for Web Bluetooth that depend on behavior
6 // defined in chrome/, not just in content/.
7
8 #include "base/command_line.h"
9 #include "base/metrics/field_trial.h"
10 #include "chrome/browser/permissions/permission_context_base.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "components/variations/variations_associated_data.h"
16 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/common/content_switches.h"
18 #include "content/public/test/browser_test_utils.h"
19 #include "device/bluetooth/bluetooth_adapter_factory.h"
20 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
21
22 namespace {
23
24 class WebBluetoothTest : public InProcessBrowserTest {
25 protected:
26 void SetUpCommandLine(base::CommandLine* command_line) override {
27 // This is needed while Web Bluetooth is an Origin Trial, but can go away
28 // once it ships globally.
29 command_line->AppendSwitch(switches::kEnableWebBluetooth);
30 InProcessBrowserTest::SetUpCommandLine(command_line);
31 }
32
33 void SetUpOnMainThread() override {
34 // Navigate to a secure context.
35 embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data");
36 ASSERT_TRUE(embedded_test_server()->Start());
37 ui_test_utils::NavigateToURL(
38 browser(),
39 embedded_test_server()->GetURL("localhost", "/simple_page.html"));
40 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents();
41 EXPECT_THAT(
42 web_contents_->GetMainFrame()->GetLastCommittedOrigin().Serialize(),
43 testing::StartsWith("http://localhost:"));
44 }
45
46 content::WebContents* web_contents_ = nullptr;
47 };
48
49 IN_PROC_BROWSER_TEST_F(WebBluetoothTest, KillSwitchShouldBlock) {
50 // Fake the BluetoothAdapter to say it's present.
51 scoped_refptr<device::MockBluetoothAdapter> adapter =
52 new testing::NiceMock<device::MockBluetoothAdapter>;
53 EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(testing::Return(true));
54 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter);
55
56 // Turn on the global kill switch.
57 std::map<std::string, std::string> params;
58 params["Bluetooth"] =
59 PermissionContextBase::kPermissionsKillSwitchBlockedValue;
60 variations::AssociateVariationParams(
61 PermissionContextBase::kPermissionsKillSwitchFieldStudy, "TestGroup",
62 params);
63 base::FieldTrialList::CreateFieldTrial(
64 PermissionContextBase::kPermissionsKillSwitchFieldStudy, "TestGroup");
65
66 std::string rejection;
67 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
68 web_contents_,
69 "navigator.bluetooth.requestDevice({filters: [{name: 'Hello'}]})"
70 " .then(() => { domAutomationController.send('Success'); },"
71 " reason => {"
72 " domAutomationController.send(reason.name + ': ' + reason.message);"
73 " });",
74 &rejection));
75 EXPECT_THAT(rejection,
76 testing::MatchesRegex("NotFoundError: .*globally disabled.*"));
77 }
78
79 } // namespace
OLDNEW
« 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