Index: content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc |
diff --git a/content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc b/content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc |
index 42e689d8d340f722dd550410e09d5763141a52d1..3ded10156d1b8a9986259c51ada8c0164191133f 100644 |
--- a/content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc |
+++ b/content/browser/bluetooth/bluetooth_device_chooser_controller_unittest.cc |
@@ -3,11 +3,139 @@ |
// found in the LICENSE file. |
#include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" |
+ |
+#include "base/memory/ptr_util.h" |
+#include "base/memory/ref_counted.h" |
+ |
+#include "base/bind.h" |
+#include "base/callback.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" |
+#include "device/bluetooth/test/mock_bluetooth_adapter.h" |
+#include "device/bluetooth/test/mock_bluetooth_device.h" |
+#include "device/bluetooth/test/mock_bluetooth_discovery_session.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "base/macros.h" |
+#include "base/optional.h" |
+ |
+#include "content/browser/bad_message.h" |
+#include "content/browser/bluetooth/bluetooth_allowed_devices_map.h" |
+#include "content/common/content_export.h" |
+#include "content/public/browser/web_contents_observer.h" |
+ |
+#include "device/bluetooth/bluetooth_gatt_connection.h" |
+#include "device/bluetooth/bluetooth_gatt_notify_session.h" |
+#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
+#include "device/bluetooth/bluetooth_remote_gatt_service.h" |
+ |
+#include "mojo/public/cpp/bindings/binding.h" |
+ |
+#include "device/bluetooth/bluetooth_advertisement.h" |
+#include "device/bluetooth/bluetooth_device.h" |
+#include "device/bluetooth/bluetooth_export.h" |
+ |
namespace content { |
-class BluetoothDeviceChooserControllerTest : public testing::Test {}; |
+// class BluetoothDeviceChooserControllerTest : public testing::Test {}; |
+typedef testing::NiceMock<device::MockBluetoothAdapter> |
+ NiceMockBluetoothAdapter; |
+typedef testing::NiceMock<device::MockBluetoothDevice> NiceMockBluetoothDevice; |
+typedef testing::NiceMock<device::MockBluetoothDiscoverySession> |
+ NiceMockBluetoothDiscoverySession; |
+ |
+namespace { |
+ |
+const WebBluetoothDeviceId kDeviceId("000000000000000000000A=="); |
+constexpr char kDeviceAddress[] = "0"; |
+constexpr char kDeviceName[] = "Device0"; |
+ |
+} // namespace |
+ |
+class BluetoothDeviceChooserControllerTest |
+ : public RenderViewHostImplTestHarness { |
+ public: |
+ BluetoothDeviceChooserControllerTest() |
+ : adapter_(new NiceMockBluetoothAdapter()), |
+ device_(adapter_.get(), |
+ 0 /* class */, |
+ kDeviceName, |
+ kDeviceAddress, |
+ false /* paired */, |
+ false /* connected */), |
+ weak_ptr_factory_(this) {} |
+ |
+ ~BluetoothDeviceChooserControllerTest() override {} |
+ |
+ void SetUp() override { |
+ RenderViewHostImplTestHarness::SetUp(); |
+ |
+ service_ = |
+ contents()->GetMainFrame()->CreateWebBluetoothServiceForTesting(); |
+ |
+ controller_ = new BluetoothDeviceChooserController( |
+ service_, contents()->GetMainFrame(), adapter_.get()); |
+ } |
+ |
+ void TearDown() override { |
+ service_ = nullptr; |
+ if (controller_) |
+ delete controller_; |
+ RenderViewHostImplTestHarness::TearDown(); |
+ } |
+ |
+ void AdapterDiscoveringChanged(bool discovering) { |
+ service_->ChangeAdapterDiscoveringForTesting(adapter_.get(), discovering); |
+ } |
+ |
+ bool IsDiscoverySessionActive() { |
+ return service_->IsDiscoverySessionActiveForTesting(); |
+ } |
+ |
+ void GetDevice() { |
+ // blink::mojom::WebBluetoothRequestDeviceOptionsPtr options; |
+ // blink::mojom::WebBluetoothRequestDeviceOptionsPtr empty_options_; |
+ // VoidSyncCallbackHelper* helper = VoidSyncCallbackHelper::create(); |
+ |
+ // controller_->GetDevice(blink::mojom::WebBluetoothRequestDeviceOptions::New(),//, |
+ // helper->getSuccessCallback(), helper->getErrorCallback()); |
+ |
+ // base::Bind(&BluetoothDeviceChooserControllerTest::OnGetDeviceFailed, |
+ // weak_ptr_factory_.GetWeakPtr(), nullptr)); |
+ |
+ // service_->OnGetDeviceSuccess, |
+ } |
+ |
+#if 0 |
+void OnGetDeviceSuccess( |
+ const blink::RequestDeviceCallback& callback, |
+ blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
+ const std::string& device_address) { |
+ LOG(ERROR) << "[DJKim] OnGetDeviceSuccess"; |
+} |
+ |
+void OnGetDeviceFailed( |
+ const blink::RequestDeviceCallback& callback, |
+ blink::mojom::WebBluetoothResult result) { |
+ LOG(ERROR) << "[DJKim] OnGetDeviceFailed"; |
+} |
+#endif |
+ |
+ protected: |
+ WebBluetoothServiceImpl* service_; |
+ |
+ private: |
+ scoped_refptr<NiceMockBluetoothAdapter> adapter_; |
+ NiceMockBluetoothDevice device_; |
+ BluetoothDeviceChooserController* controller_; |
+ base::WeakPtrFactory<BluetoothDeviceChooserControllerTest> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceChooserControllerTest); |
+}; |
TEST_F(BluetoothDeviceChooserControllerTest, CalculateSignalStrengthLevel) { |
EXPECT_EQ( |
@@ -36,4 +164,10 @@ TEST_F(BluetoothDeviceChooserControllerTest, CalculateSignalStrengthLevel) { |
4, BluetoothDeviceChooserController::CalculateSignalStrengthLevel(127)); |
} |
+TEST_F(BluetoothDeviceChooserControllerTest, AdapterDiscoveringChanged) { |
+ GetDevice(); |
+ AdapterDiscoveringChanged(true); |
+ EXPECT_TRUE(IsDiscoverySessionActive()); |
+} |
+ |
} // namespace content |