Commit ff38261d authored by Carlos Frias's avatar Carlos Frias Committed by Commit Bot

bfcache: Fix ChromeBackForwardCacheBrowserTest.WebBluetooth hidden flake

ChromeBackForwardCacheBrowserTest.WebBluetooth Test is flaky.
It is reported as a hidden flake as it passes on retries.

Cause identified:
The test configures a mock Bluetooth adapter first and then performs a
web Bluetooth API call. Although in some executions, it is observed that
the browser has already started the initialization of the default
Bluetooth adapter, when the test configures the mock adapter changing
the adapter pointer, causing that the callbacks from the default adapter
try to use an already released adapter pointer, thus reading from a
nullptr, and crashing the test.

Fix proposed:
Move the MockBluetoothAdapter out from being configured at the specific
test and instead be a class member and configured at test setup.
By doing this the mock adapter is configured from the
beginning avoiding the callback issue observed with the default
Bluetooth adapter.

Bug: 1087190
Change-Id: I3f2e8bd4159f072712f1082f05e35ec24f9b2f5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2220627
Commit-Queue: Carlos Frias <carlos.frias@microsoft.com>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774406}
parent 2495c6ea
......@@ -41,6 +41,28 @@ class ChromeBackForwardCacheBrowserTest : public InProcessBrowserTest {
ChromeBackForwardCacheBrowserTest() = default;
~ChromeBackForwardCacheBrowserTest() override = default;
void SetUp() override {
// Fake the BluetoothAdapter to say it's present.
// Used in WebBluetooth test.
adapter_ =
base::MakeRefCounted<testing::NiceMock<device::MockBluetoothAdapter>>();
device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_);
#if defined(OS_CHROMEOS)
// In CHROMEOS build, even when |adapter_| object is released at TearDown()
// it causes the test to fail on exit with an error indicating |adapter_| is
// leaked.
testing::Mock::AllowLeak(adapter_.get());
#endif
InProcessBrowserTest::SetUp();
}
void TearDown() override {
testing::Mock::VerifyAndClearExpectations(adapter_.get());
adapter_.reset();
InProcessBrowserTest::TearDown();
}
void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
}
......@@ -89,6 +111,7 @@ class ChromeBackForwardCacheBrowserTest : public InProcessBrowserTest {
private:
base::test::ScopedFeatureList scoped_feature_list_;
scoped_refptr<device::MockBluetoothAdapter> adapter_;
DISALLOW_COPY_AND_ASSIGN(ChromeBackForwardCacheBrowserTest);
};
......@@ -180,10 +203,10 @@ IN_PROC_BROWSER_TEST_F(ChromeBackForwardCacheBrowserTest, BasicIframe) {
}
IN_PROC_BROWSER_TEST_F(ChromeBackForwardCacheBrowserTest, WebBluetooth) {
// Fake the BluetoothAdapter to say it's present.
scoped_refptr<device::MockBluetoothAdapter> adapter =
new testing::NiceMock<device::MockBluetoothAdapter>;
device::BluetoothAdapterFactory::SetAdapterForTesting(adapter);
// The test requires a mock Bluetooth adapter to perform a
// WebBluetooth API call. To avoid conflicts with the default Bluetooth
// adapter, e.g. Windows adapter, which is configured during Bluetooth
// initialization, the mock adapter is configured in SetUp().
// WebBluetooth requires HTTPS.
net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
......
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