Commit 16a567f1 authored by Mike Wasserman's avatar Mike Wasserman Committed by Commit Bot

Web Bluetooth: Fix and renable flaky browser tests

Remove the fake scanning prompt; reply with kAllow automatically.
This seems to resolve flaky crashes around prompt show/accept timing.

Bug: 1147582
Test: No automated test flakes
Change-Id: I889f9c97400901f235d6beebfa6a40e43bc8dc93
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2547842Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Michael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829051}
parent f64375c0
...@@ -220,30 +220,6 @@ class FakeBluetoothChooser : public content::BluetoothChooser { ...@@ -220,30 +220,6 @@ class FakeBluetoothChooser : public content::BluetoothChooser {
base::Optional<std::string> device_to_select_; base::Optional<std::string> device_to_select_;
}; };
class FakeBluetoothScanningPrompt : public content::BluetoothScanningPrompt {
public:
explicit FakeBluetoothScanningPrompt(
const content::BluetoothScanningPrompt::EventHandler& event_handler)
: event_handler_(event_handler) {}
~FakeBluetoothScanningPrompt() override = default;
// Move-only class
FakeBluetoothScanningPrompt(const FakeBluetoothScanningPrompt&) = delete;
FakeBluetoothScanningPrompt& operator=(const FakeBluetoothScanningPrompt&) =
delete;
void RunPromptEventHandler(content::BluetoothScanningPrompt::Event event) {
if (event_handler_.is_null()) {
FAIL() << "event_handler_ is not set";
return;
}
event_handler_.Run(event);
}
protected:
content::BluetoothScanningPrompt::EventHandler event_handler_;
};
class TestBluetoothDelegate : public ChromeBluetoothDelegate { class TestBluetoothDelegate : public ChromeBluetoothDelegate {
public: public:
TestBluetoothDelegate() = default; TestBluetoothDelegate() = default;
...@@ -255,18 +231,6 @@ class TestBluetoothDelegate : public ChromeBluetoothDelegate { ...@@ -255,18 +231,6 @@ class TestBluetoothDelegate : public ChromeBluetoothDelegate {
device_to_select_ = device_address; device_to_select_ = device_address;
} }
// This method waits until ShowBluetoothScanningPrompt() has been called and
// |scanning_prompt_| contains a pointer to the created prompt, so the test
// will timeout if |navigator.bluetooth.requestLEScan()| has not been called
// in JavaScript.
void RunPromptEventHandler(content::BluetoothScanningPrompt::Event event) {
if (!scanning_prompt_) {
scanning_prompt_creation_loop_.emplace();
scanning_prompt_creation_loop_->Run();
}
scanning_prompt_->RunPromptEventHandler(event);
}
protected: protected:
// content::BluetoothDelegate implementation: // content::BluetoothDelegate implementation:
std::unique_ptr<content::BluetoothChooser> RunBluetoothChooser( std::unique_ptr<content::BluetoothChooser> RunBluetoothChooser(
...@@ -280,20 +244,12 @@ class TestBluetoothDelegate : public ChromeBluetoothDelegate { ...@@ -280,20 +244,12 @@ class TestBluetoothDelegate : public ChromeBluetoothDelegate {
content::RenderFrameHost* frame, content::RenderFrameHost* frame,
const content::BluetoothScanningPrompt::EventHandler& event_handler) const content::BluetoothScanningPrompt::EventHandler& event_handler)
override { override {
auto scanning_prompt = // Simulate that a prompt was accepted; no actual prompt is needed here.
std::make_unique<FakeBluetoothScanningPrompt>(event_handler); event_handler.Run(content::BluetoothScanningPrompt::Event::kAllow);
scanning_prompt_ = scanning_prompt.get(); return nullptr;
if (scanning_prompt_creation_loop_)
scanning_prompt_creation_loop_->Quit();
return scanning_prompt;
} }
base::Optional<std::string> device_to_select_; base::Optional<std::string> device_to_select_;
FakeBluetoothScanningPrompt* scanning_prompt_;
// This RunLoop is used to ensure that |scanning_prompt_| is not nullptr when
// RunPromptEventHandler() is called.
base::Optional<base::RunLoop> scanning_prompt_creation_loop_;
}; };
class TestContentBrowserClient : public ChromeContentBrowserClient { class TestContentBrowserClient : public ChromeContentBrowserClient {
...@@ -393,10 +349,6 @@ class WebBluetoothTest : public InProcessBrowserTest { ...@@ -393,10 +349,6 @@ class WebBluetoothTest : public InProcessBrowserTest {
browser_client_.bluetooth_delegate()->SetDeviceToSelect(device_address); browser_client_.bluetooth_delegate()->SetDeviceToSelect(device_address);
} }
void RunPromptEventHandler(content::BluetoothScanningPrompt::Event event) {
browser_client_.bluetooth_delegate()->RunPromptEventHandler(event);
}
std::unique_ptr<device::BluetoothAdapterFactory::GlobalValuesForTesting> std::unique_ptr<device::BluetoothAdapterFactory::GlobalValuesForTesting>
global_values_; global_values_;
scoped_refptr<FakeBluetoothAdapter> adapter_; scoped_refptr<FakeBluetoothAdapter> adapter_;
...@@ -596,14 +548,13 @@ IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled, ...@@ -596,14 +548,13 @@ IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled,
IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled, IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled,
PRE_WebBluetoothScanningIdsNotPersistent) { PRE_WebBluetoothScanningIdsNotPersistent) {
// Grant permission to scan for Bluetooth devices and store the detected // The request to scan should be automatically accepted. Store the detected
// device's WebBluetoothDeviceId in localStorage to retrieve it after the // device's WebBluetoothDeviceId in localStorage to retrieve it after the
// browser restarts. // browser restarts.
ASSERT_TRUE(content::ExecJs(web_contents_, R"( ASSERT_TRUE(content::ExecJs(web_contents_, R"(
var requestLEScanPromise = navigator.bluetooth.requestLEScan({ var requestLEScanPromise = navigator.bluetooth.requestLEScan({
acceptAllAdvertisements: true}); acceptAllAdvertisements: true});
)")); )"));
RunPromptEventHandler(content::BluetoothScanningPrompt::Event::kAllow);
ASSERT_TRUE(content::ExecJs(web_contents_, "requestLEScanPromise")); ASSERT_TRUE(content::ExecJs(web_contents_, "requestLEScanPromise"));
ASSERT_TRUE(content::ExecJs(web_contents_, R"( ASSERT_TRUE(content::ExecJs(web_contents_, R"(
...@@ -625,16 +576,14 @@ IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled, ...@@ -625,16 +576,14 @@ IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled,
EXPECT_TRUE(blink::WebBluetoothDeviceId::IsValid(scan_id)); EXPECT_TRUE(blink::WebBluetoothDeviceId::IsValid(scan_id));
} }
// TODO(crbug.com/1147575) Test failure on Mac10.15
IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled, IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled,
DISABLED_WebBluetoothScanningIdsNotPersistent) { WebBluetoothScanningIdsNotPersistent) {
// Grant permission to scan for Bluetooth devices again, and compare the ID // The request to scan should be automatically accepted. Store the detected
// assigned to the scanned device against the one that was stored previously. // assigned to the scanned device against the one that was stored previously.
ASSERT_TRUE(content::ExecJs(web_contents_, R"( ASSERT_TRUE(content::ExecJs(web_contents_, R"(
var requestLEScanPromise = navigator.bluetooth.requestLEScan({ var requestLEScanPromise = navigator.bluetooth.requestLEScan({
acceptAllAdvertisements: true}); acceptAllAdvertisements: true});
)")); )"));
RunPromptEventHandler(content::BluetoothScanningPrompt::Event::kAllow);
ASSERT_TRUE(content::ExecJs(web_contents_, "requestLEScanPromise")); ASSERT_TRUE(content::ExecJs(web_contents_, "requestLEScanPromise"));
ASSERT_TRUE(content::ExecJs(web_contents_, R"( ASSERT_TRUE(content::ExecJs(web_contents_, R"(
...@@ -683,16 +632,14 @@ IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled, ...@@ -683,16 +632,14 @@ IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled,
EXPECT_TRUE(blink::WebBluetoothDeviceId::IsValid(granted_id)); EXPECT_TRUE(blink::WebBluetoothDeviceId::IsValid(granted_id));
} }
// TODO(crbug.com/1147582): Flaky
IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled, IN_PROC_BROWSER_TEST_F(WebBluetoothTestWithNewPermissionsBackendEnabled,
DISABLED_WebBluetoothIdsUsedInWebBluetoothScanning) { WebBluetoothIdsUsedInWebBluetoothScanning) {
// Grant permission to scan for Bluetooth devices again, and compare the ID // The request to scan should be automatically accepted. Store the detected
// assigned to the scanned device against the one that was stored previously. // assigned to the scanned device against the one that was stored previously.
ASSERT_TRUE(content::ExecJs(web_contents_, R"( ASSERT_TRUE(content::ExecJs(web_contents_, R"(
var requestLEScanPromise = navigator.bluetooth.requestLEScan({ var requestLEScanPromise = navigator.bluetooth.requestLEScan({
acceptAllAdvertisements: true}); acceptAllAdvertisements: true});
)")); )"));
RunPromptEventHandler(content::BluetoothScanningPrompt::Event::kAllow);
ASSERT_TRUE(content::ExecJs(web_contents_, "requestLEScanPromise")); ASSERT_TRUE(content::ExecJs(web_contents_, "requestLEScanPromise"));
ASSERT_TRUE(content::ExecJs(web_contents_, R"( ASSERT_TRUE(content::ExecJs(web_contents_, R"(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment