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

Side by Side Diff: chrome/browser/web_bluetooth_browsertest.cc

Issue 1922923002: bluetooth: Move requestDevice to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-request-device
Patch Set: Change ref to pointer Created 4 years, 6 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 | « no previous file | content/browser/bluetooth/bluetooth_adapter_factory_wrapper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file contains browsertests for Web Bluetooth that depend on behavior 5 // This file contains browsertests for Web Bluetooth that depend on behavior
6 // defined in chrome/, not just in content/. 6 // defined in chrome/, not just in content/.
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "chrome/browser/permissions/permission_context_base.h" 10 #include "chrome/browser/permissions/permission_context_base.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
15 #include "components/variations/variations_associated_data.h" 16 #include "components/variations/variations_associated_data.h"
16 #include "content/public/browser/render_frame_host.h" 17 #include "content/public/browser/render_frame_host.h"
18 #include "content/public/browser/render_process_host.h"
17 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
18 #include "content/public/test/browser_test_utils.h" 20 #include "content/public/test/browser_test_utils.h"
19 #include "device/bluetooth/bluetooth_adapter_factory.h" 21 #include "device/bluetooth/bluetooth_adapter_factory.h"
20 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 22 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
21 23
24 using device::MockBluetoothAdapter;
25 using testing::Return;
26
27 typedef testing::NiceMock<MockBluetoothAdapter> NiceMockBluetoothAdapter;
28
22 namespace { 29 namespace {
23 30
24 class WebBluetoothTest : public InProcessBrowserTest { 31 class WebBluetoothTest : public InProcessBrowserTest {
25 protected: 32 protected:
26 void SetUpCommandLine(base::CommandLine* command_line) override { 33 void SetUpCommandLine(base::CommandLine* command_line) override {
27 // This is needed while Web Bluetooth is an Origin Trial, but can go away 34 // This is needed while Web Bluetooth is an Origin Trial, but can go away
28 // once it ships globally. 35 // once it ships globally.
29 command_line->AppendSwitch(switches::kEnableWebBluetooth); 36 command_line->AppendSwitch(switches::kEnableWebBluetooth);
30 InProcessBrowserTest::SetUpCommandLine(command_line); 37 InProcessBrowserTest::SetUpCommandLine(command_line);
31 } 38 }
32 39
33 void SetUpOnMainThread() override { 40 void SetUpOnMainThread() override {
34 // Navigate to a secure context. 41 // Navigate to a secure context.
35 embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data"); 42 embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data");
36 ASSERT_TRUE(embedded_test_server()->Start()); 43 ASSERT_TRUE(embedded_test_server()->Start());
37 ui_test_utils::NavigateToURL( 44 ui_test_utils::NavigateToURL(
38 browser(), 45 browser(),
39 embedded_test_server()->GetURL("localhost", "/simple_page.html")); 46 embedded_test_server()->GetURL("localhost", "/simple_page.html"));
40 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents(); 47 web_contents_ = browser()->tab_strip_model()->GetActiveWebContents();
41 EXPECT_THAT( 48 EXPECT_THAT(
42 web_contents_->GetMainFrame()->GetLastCommittedOrigin().Serialize(), 49 web_contents_->GetMainFrame()->GetLastCommittedOrigin().Serialize(),
43 testing::StartsWith("http://localhost:")); 50 testing::StartsWith("http://localhost:"));
44 } 51 }
45 52
46 content::WebContents* web_contents_ = nullptr; 53 content::WebContents* web_contents_ = nullptr;
47 }; 54 };
48 55
56 IN_PROC_BROWSER_TEST_F(WebBluetoothTest, WebBluetoothAfterCrash) {
57 // Make sure we can use Web Bluetooth after the tab crashes.
58 // Set up adapter with one device.
59 scoped_refptr<NiceMockBluetoothAdapter> adapter(
60 new NiceMockBluetoothAdapter());
61 ON_CALL(*adapter, IsPresent()).WillByDefault(Return(false));
62
63 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter);
64
65 std::string result;
66 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
67 web_contents_,
68 "navigator.bluetooth.requestDevice({filters: [{services: [0x180d]}]})"
69 " .catch(e => domAutomationController.send(e.toString()));",
70 &result));
71 EXPECT_EQ("NotFoundError: Bluetooth adapter not available.", result);
72
73 // Crash the renderer process.
74 content::RenderProcessHost* process = web_contents_->GetRenderProcessHost();
75 content::RenderProcessHostWatcher crash_observer(
76 process, content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
77 process->Shutdown(0, false);
78 crash_observer.Wait();
79
80 // Reload tab.
81 chrome::Reload(browser(), CURRENT_TAB);
82 content::WaitForLoadStop(
83 browser()->tab_strip_model()->GetActiveWebContents());
84
85 // Use Web Bluetooth again.
86 std::string result_after_crash;
87 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
88 web_contents_,
89 "navigator.bluetooth.requestDevice({filters: [{services: [0x180d]}]})"
90 " .catch(e => domAutomationController.send(e.toString()));",
91 &result_after_crash));
92 EXPECT_EQ("NotFoundError: Bluetooth adapter not available.",
93 result_after_crash);
94 }
95
49 IN_PROC_BROWSER_TEST_F(WebBluetoothTest, KillSwitchShouldBlock) { 96 IN_PROC_BROWSER_TEST_F(WebBluetoothTest, KillSwitchShouldBlock) {
50 // Fake the BluetoothAdapter to say it's present. 97 // Fake the BluetoothAdapter to say it's present.
51 scoped_refptr<device::MockBluetoothAdapter> adapter = 98 scoped_refptr<device::MockBluetoothAdapter> adapter =
52 new testing::NiceMock<device::MockBluetoothAdapter>; 99 new testing::NiceMock<device::MockBluetoothAdapter>;
53 EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(testing::Return(true)); 100 EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(Return(true));
54 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter); 101 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter);
55 102
56 // Turn on the global kill switch. 103 // Turn on the global kill switch.
57 std::map<std::string, std::string> params; 104 std::map<std::string, std::string> params;
58 params["Bluetooth"] = 105 params["Bluetooth"] =
59 PermissionContextBase::kPermissionsKillSwitchBlockedValue; 106 PermissionContextBase::kPermissionsKillSwitchBlockedValue;
60 variations::AssociateVariationParams( 107 variations::AssociateVariationParams(
61 PermissionContextBase::kPermissionsKillSwitchFieldStudy, "TestGroup", 108 PermissionContextBase::kPermissionsKillSwitchFieldStudy, "TestGroup",
62 params); 109 params);
63 base::FieldTrialList::CreateFieldTrial( 110 base::FieldTrialList::CreateFieldTrial(
(...skipping 11 matching lines...) Expand all
75 EXPECT_THAT(rejection, 122 EXPECT_THAT(rejection,
76 testing::MatchesRegex("NotFoundError: .*globally disabled.*")); 123 testing::MatchesRegex("NotFoundError: .*globally disabled.*"));
77 } 124 }
78 125
79 // Tests that using Finch field trial parameters for blacklist additions has 126 // Tests that using Finch field trial parameters for blacklist additions has
80 // the effect of rejecting requestDevice calls. 127 // the effect of rejecting requestDevice calls.
81 IN_PROC_BROWSER_TEST_F(WebBluetoothTest, BlacklistShouldBlock) { 128 IN_PROC_BROWSER_TEST_F(WebBluetoothTest, BlacklistShouldBlock) {
82 // Fake the BluetoothAdapter to say it's present. 129 // Fake the BluetoothAdapter to say it's present.
83 scoped_refptr<device::MockBluetoothAdapter> adapter = 130 scoped_refptr<device::MockBluetoothAdapter> adapter =
84 new testing::NiceMock<device::MockBluetoothAdapter>; 131 new testing::NiceMock<device::MockBluetoothAdapter>;
85 EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(testing::Return(true)); 132 EXPECT_CALL(*adapter, IsPresent()).WillRepeatedly(Return(true));
86 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter); 133 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter);
87 134
88 std::map<std::string, std::string> params; 135 std::map<std::string, std::string> params;
89 params["blacklist_additions"] = "ee01:e"; 136 params["blacklist_additions"] = "ee01:e";
90 variations::AssociateVariationParams("WebBluetoothBlacklist", "TestGroup", 137 variations::AssociateVariationParams("WebBluetoothBlacklist", "TestGroup",
91 params); 138 params);
92 base::FieldTrialList::CreateFieldTrial("WebBluetoothBlacklist", "TestGroup"); 139 base::FieldTrialList::CreateFieldTrial("WebBluetoothBlacklist", "TestGroup");
93 140
94 std::string rejection; 141 std::string rejection;
95 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 142 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
96 web_contents_, 143 web_contents_,
97 "navigator.bluetooth.requestDevice({filters: [{services: [0xee01]}]})" 144 "navigator.bluetooth.requestDevice({filters: [{services: [0xee01]}]})"
98 " .then(() => { domAutomationController.send('Success'); }," 145 " .then(() => { domAutomationController.send('Success'); },"
99 " reason => {" 146 " reason => {"
100 " domAutomationController.send(reason.name + ': ' + reason.message);" 147 " domAutomationController.send(reason.name + ': ' + reason.message);"
101 " });", 148 " });",
102 &rejection)); 149 &rejection));
103 EXPECT_THAT(rejection, 150 EXPECT_THAT(rejection,
104 testing::MatchesRegex("SecurityError: .*blacklisted UUID.*")); 151 testing::MatchesRegex("SecurityError: .*blacklisted UUID.*"));
105 } 152 }
106 153
107 } // namespace 154 } // namespace
OLDNEW
« no previous file with comments | « no previous file | content/browser/bluetooth/bluetooth_adapter_factory_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698