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

Side by Side Diff: content/browser/bluetooth/frame_connected_bluetooth_devices_unittest.cc

Issue 2658473002: Refactor BluetoothAllowedDevicesMap (Closed)
Patch Set: set --similarity=20 when did git cl upload Created 3 years, 10 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
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 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" 5 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h"
6 6
7 #include <memory>
8
7 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
8 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
9 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" 11 #include "content/browser/bluetooth/web_bluetooth_service_impl.h"
12 #include "content/public/browser/bluetooth_allowed_devices_map_base.h"
13 #include "content/public/browser/web_contents_delegate.h"
10 #include "content/test/test_render_view_host.h" 14 #include "content/test/test_render_view_host.h"
11 #include "content/test/test_web_contents.h" 15 #include "content/test/test_web_contents.h"
12 #include "device/bluetooth/bluetooth_gatt_connection.h" 16 #include "device/bluetooth/bluetooth_gatt_connection.h"
13 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 17 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
14 #include "device/bluetooth/test/mock_bluetooth_device.h" 18 #include "device/bluetooth/test/mock_bluetooth_device.h"
15 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" 19 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
16 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
18 22
19 namespace content { 23 namespace content {
(...skipping 11 matching lines...) Expand all
31 namespace { 35 namespace {
32 36
33 const WebBluetoothDeviceId kDeviceId0("000000000000000000000A=="); 37 const WebBluetoothDeviceId kDeviceId0("000000000000000000000A==");
34 constexpr char kDeviceAddress0[] = "0"; 38 constexpr char kDeviceAddress0[] = "0";
35 constexpr char kDeviceName0[] = "Device0"; 39 constexpr char kDeviceName0[] = "Device0";
36 40
37 const WebBluetoothDeviceId kDeviceId1("111111111111111111111A=="); 41 const WebBluetoothDeviceId kDeviceId1("111111111111111111111A==");
38 constexpr char kDeviceAddress1[] = "1"; 42 constexpr char kDeviceAddress1[] = "1";
39 constexpr char kDeviceName1[] = "Device1"; 43 constexpr char kDeviceName1[] = "Device1";
40 44
45 class MockWebContentsDelegate : public WebContentsDelegate {
46 public:
47 BluetoothAllowedDevicesMapBase* GetBluetoothDevicesMap(
48 RenderFrameHost* frame) override {
49 if (!bluetooth_allowed_devices_map_) {
50 bluetooth_allowed_devices_map_.reset(
51 new BluetoothAllowedDevicesMapBase());
52 }
53 return bluetooth_allowed_devices_map_.get();
54 }
55
56 std::unique_ptr<BluetoothAllowedDevicesMapBase>
57 bluetooth_allowed_devices_map_;
58 };
59
41 } // namespace 60 } // namespace
42 61
43 class FrameConnectedBluetoothDevicesTest 62 class FrameConnectedBluetoothDevicesTest
44 : public RenderViewHostImplTestHarness { 63 : public RenderViewHostImplTestHarness {
45 public: 64 public:
46 FrameConnectedBluetoothDevicesTest() 65 FrameConnectedBluetoothDevicesTest()
47 : adapter_(new NiceMockBluetoothAdapter()), 66 : adapter_(new NiceMockBluetoothAdapter()),
48 device0_(adapter_.get(), 67 device0_(adapter_.get(),
49 0 /* class */, 68 0 /* class */,
50 kDeviceName0, 69 kDeviceName0,
(...skipping 11 matching lines...) Expand all
62 .WillByDefault(Return(&device0_)); 81 .WillByDefault(Return(&device0_));
63 ON_CALL(*adapter_, GetDevice(StrEq(kDeviceAddress1))) 82 ON_CALL(*adapter_, GetDevice(StrEq(kDeviceAddress1)))
64 .WillByDefault(Return(&device1_)); 83 .WillByDefault(Return(&device1_));
65 } 84 }
66 85
67 ~FrameConnectedBluetoothDevicesTest() override {} 86 ~FrameConnectedBluetoothDevicesTest() override {}
68 87
69 void SetUp() override { 88 void SetUp() override {
70 RenderViewHostImplTestHarness::SetUp(); 89 RenderViewHostImplTestHarness::SetUp();
71 90
91 contents()->SetDelegate(&mock_web_contents_delegate_);
92
72 // Create subframe to simulate two maps on the same WebContents. 93 // Create subframe to simulate two maps on the same WebContents.
73 contents()->GetMainFrame()->InitializeRenderFrameIfNeeded(); 94 contents()->GetMainFrame()->InitializeRenderFrameIfNeeded();
74 TestRenderFrameHost* subframe = 95 TestRenderFrameHost* subframe =
75 contents()->GetMainFrame()->AppendChild("bluetooth_frame"); 96 contents()->GetMainFrame()->AppendChild("bluetooth_frame");
76 subframe->InitializeRenderFrameIfNeeded(); 97 subframe->InitializeRenderFrameIfNeeded();
77 98
78 // Simulate two frames each connected to a bluetooth service. 99 // Simulate two frames each connected to a bluetooth service.
79 service0_ = 100 service0_ =
80 contents()->GetMainFrame()->CreateWebBluetoothServiceForTesting(); 101 contents()->GetMainFrame()->CreateWebBluetoothServiceForTesting();
81 map0_ = service0_->connected_devices_.get(); 102 map0_ = service0_->connected_devices_.get();
(...skipping 30 matching lines...) Expand all
112 FrameConnectedBluetoothDevices* map0_; 133 FrameConnectedBluetoothDevices* map0_;
113 WebBluetoothServiceImpl* service0_; 134 WebBluetoothServiceImpl* service0_;
114 135
115 FrameConnectedBluetoothDevices* map1_; 136 FrameConnectedBluetoothDevices* map1_;
116 WebBluetoothServiceImpl* service1_; 137 WebBluetoothServiceImpl* service1_;
117 138
118 private: 139 private:
119 scoped_refptr<NiceMockBluetoothAdapter> adapter_; 140 scoped_refptr<NiceMockBluetoothAdapter> adapter_;
120 NiceMockBluetoothDevice device0_; 141 NiceMockBluetoothDevice device0_;
121 NiceMockBluetoothDevice device1_; 142 NiceMockBluetoothDevice device1_;
143 MockWebContentsDelegate mock_web_contents_delegate_;
122 }; 144 };
123 145
124 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Once) { 146 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Once) {
125 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 147 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
126 148
127 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 149 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
128 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 150 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
129 } 151 }
130 152
131 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Twice) { 153 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Twice) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 TEST_F(FrameConnectedBluetoothDevicesTest, 407 TEST_F(FrameConnectedBluetoothDevicesTest,
386 DestroyedByWebContentsImplDestruction) { 408 DestroyedByWebContentsImplDestruction) {
387 // Tests that we don't crash when FrameConnectedBluetoothDevices contains 409 // Tests that we don't crash when FrameConnectedBluetoothDevices contains
388 // at least one device, and it is destroyed while WebContentsImpl is being 410 // at least one device, and it is destroyed while WebContentsImpl is being
389 // destroyed. 411 // destroyed.
390 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 412 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0));
391 DeleteContents(); 413 DeleteContents();
392 } 414 }
393 415
394 } // namespace content 416 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698