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

Unified Diff: content/browser/bluetooth/frame_connected_bluetooth_devices_unittest.cc

Issue 2050803002: Better way to implement FrameConnectedBluetoothDevicesTest Base URL: https://chromium.googlesource.com/chromium/src.git@patch_ortuno
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/bluetooth/web_bluetooth_service_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « no previous file | content/browser/bluetooth/web_bluetooth_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698