| Index: content/browser/bluetooth/frame_connected_bluetooth_devices_unittest.cc
|
| diff --git a/content/browser/bluetooth/frame_connected_bluetooth_devices_unittest.cc b/content/browser/bluetooth/frame_connected_bluetooth_devices_unittest.cc
|
| index 339f8806b518f129cf68f37ea44a78f353d357ed..b51e77bad695197ccb5cdfa90289d9f2474cb2e8 100644
|
| --- a/content/browser/bluetooth/frame_connected_bluetooth_devices_unittest.cc
|
| +++ b/content/browser/bluetooth/frame_connected_bluetooth_devices_unittest.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "base/memory/ptr_util.h"
|
| #include "base/memory/ref_counted.h"
|
| +#include "content/browser/bluetooth/web_bluetooth_service_impl.h"
|
| #include "content/test/test_render_view_host.h"
|
| #include "content/test/test_web_contents.h"
|
| #include "device/bluetooth/bluetooth_gatt_connection.h"
|
| @@ -37,6 +38,8 @@ constexpr char kDeviceId1[] = "1";
|
| constexpr char kDeviceAddress1[] = "1";
|
| constexpr char kDeviceName1[] = "Device1";
|
|
|
| +} // namespace
|
| +
|
| class FrameConnectedBluetoothDevicesTest
|
| : public RenderViewHostImplTestHarness {
|
| public:
|
| @@ -65,13 +68,27 @@ class FrameConnectedBluetoothDevicesTest
|
|
|
| void SetUp() override {
|
| RenderViewHostImplTestHarness::SetUp();
|
| - map0_.reset(new FrameConnectedBluetoothDevices(contents()->GetMainFrame()));
|
| - map1_.reset(new FrameConnectedBluetoothDevices(contents()->GetMainFrame()));
|
| +
|
| + // TODO(nick): This test used to work by creating two
|
| + // FrameConnectedBluetoothDevices instances on the same RenderFrameHost. But
|
| + // that would never possibly happen in reality! To get two
|
| + // FrameConnectedBluetoothDevices on the same WebContents, we should create
|
| + // a child frame.
|
| + contents()->GetMainFrame()->InitializeRenderFrameIfNeeded();
|
| + TestRenderFrameHost* subframe =
|
| + contents()->GetMainFrame()->AppendChild("bluetooth_frame");
|
| + subframe->InitializeRenderFrameIfNeeded();
|
| +
|
| + // Simulate two frames each connected to a bluetooth service.
|
| + service0_ =
|
| + contents()->GetMainFrame()->CreateWebBluetoothServiceForTesting();
|
| + map0_ = service0_->connected_devices_.get();
|
| +
|
| + service1_ = subframe->CreateWebBluetoothServiceForTesting();
|
| + map1_ = service1_->connected_devices_.get();
|
| }
|
|
|
| void TearDown() override {
|
| - map1_.reset();
|
| - map0_.reset();
|
| RenderViewHostImplTestHarness::TearDown();
|
| }
|
|
|
| @@ -81,9 +98,22 @@ class FrameConnectedBluetoothDevicesTest
|
| new NiceMockBluetoothGattConnection(adapter_.get(), address));
|
| }
|
|
|
| + void ResetService0() {
|
| + service0_->ClearState();
|
| + map0_ = nullptr;
|
| + }
|
| +
|
| + void ResetService1() {
|
| + service1_->ClearState();
|
| + map1_ = nullptr;
|
| + }
|
| +
|
| protected:
|
| - std::unique_ptr<FrameConnectedBluetoothDevices> map0_;
|
| - std::unique_ptr<FrameConnectedBluetoothDevices> map1_;
|
| + FrameConnectedBluetoothDevices* map0_;
|
| + WebBluetoothServiceImpl* service0_;
|
| +
|
| + FrameConnectedBluetoothDevices* map1_;
|
| + WebBluetoothServiceImpl* service1_;
|
|
|
| private:
|
| scoped_refptr<NiceMockBluetoothAdapter> adapter_;
|
| @@ -91,8 +121,6 @@ class FrameConnectedBluetoothDevicesTest
|
| NiceMockBluetoothDevice device1_;
|
| };
|
|
|
| -} // namespace
|
| -
|
| TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Once) {
|
| map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
|
|
|
| @@ -330,7 +358,7 @@ TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleDevices) {
|
|
|
| EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
|
|
|
| - map0_.reset();
|
| + ResetService0();
|
|
|
| EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
|
| }
|
| @@ -344,12 +372,12 @@ TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleMaps) {
|
|
|
| EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
|
|
|
| - map0_.reset();
|
| + ResetService0();
|
|
|
| // WebContents should still be connected because of map1_.
|
| EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
|
|
|
| - map1_.reset();
|
| + ResetService1();
|
|
|
| EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
|
| }
|
| @@ -359,15 +387,7 @@ TEST_F(FrameConnectedBluetoothDevicesTest,
|
| // Tests that we don't crash when FrameConnectedBluetoothDevices contains
|
| // at least one device, and it is destroyed while WebContentsImpl is being
|
| // destroyed.
|
| -
|
| map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
|
| - // A FrameConnectedBluetoothDevices instance is usually owned by a
|
| - // WebBluetoothServiceImpl instance which is owned by a RenderFrameHost which
|
| - // is owned by WebContentsImpl. In order to avoid adding unnecessary
|
| - // complexity to WebBluetoothServiceImpl just so we can perform this test we
|
| - // add the map directly to a frame and then delete WebContents.
|
| - contents()->GetMainFrame()->SetFrameConnectedBluetoothDevices(
|
| - std::move(map0_));
|
| DeleteContents();
|
| }
|
|
|
|
|