| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "device/geolocation/wifi_data_provider_linux.h" | 5 #include "content/browser/geolocation/wifi_data_provider_linux.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "dbus/message.h" | 15 #include "dbus/message.h" |
| 16 #include "dbus/mock_bus.h" | 16 #include "dbus/mock_bus.h" |
| 17 #include "dbus/mock_object_proxy.h" | 17 #include "dbus/mock_object_proxy.h" |
| 18 #include "dbus/object_path.h" | 18 #include "dbus/object_path.h" |
| 19 #include "dbus/object_proxy.h" | 19 #include "dbus/object_proxy.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 using ::testing::_; | 23 using ::testing::_; |
| 24 using ::testing::Invoke; | 24 using ::testing::Invoke; |
| 25 using ::testing::Return; | 25 using ::testing::Return; |
| 26 using ::testing::Unused; | 26 using ::testing::Unused; |
| 27 | 27 |
| 28 namespace device { | 28 namespace content { |
| 29 | 29 |
| 30 class GeolocationWifiDataProviderLinuxTest : public testing::Test { | 30 class GeolocationWifiDataProviderLinuxTest : public testing::Test { |
| 31 void SetUp() override { | 31 void SetUp() override { |
| 32 // Create a mock bus. | 32 // Create a mock bus. |
| 33 dbus::Bus::Options options; | 33 dbus::Bus::Options options; |
| 34 options.bus_type = dbus::Bus::SYSTEM; | 34 options.bus_type = dbus::Bus::SYSTEM; |
| 35 mock_bus_ = new dbus::MockBus(options); | 35 mock_bus_ = new dbus::MockBus(options); |
| 36 | 36 |
| 37 // Create a mock proxy that behaves as NetworkManager. | 37 // Create a mock proxy that behaves as NetworkManager. |
| 38 mock_network_manager_proxy_ = | 38 mock_network_manager_proxy_ = |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return()); | 99 EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return()); |
| 100 | 100 |
| 101 // Create the wlan API with the mock bus object injected. | 101 // Create the wlan API with the mock bus object injected. |
| 102 wifi_provider_linux_ = new WifiDataProviderLinux; | 102 wifi_provider_linux_ = new WifiDataProviderLinux; |
| 103 wlan_api_.reset( | 103 wlan_api_.reset( |
| 104 wifi_provider_linux_->NewWlanApiForTesting(mock_bus_.get())); | 104 wifi_provider_linux_->NewWlanApiForTesting(mock_bus_.get())); |
| 105 ASSERT_TRUE(wlan_api_.get()); | 105 ASSERT_TRUE(wlan_api_.get()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 protected: | 108 protected: |
| 109 // WifiDataProvider requires a task runner to be present. The |message_loop_| | 109 // WifiDataProvider requires a task runner to be present. The |thread_bundle_| |
| 110 // is defined here, as it should outlive |wifi_provider_linux_|. | 110 // is defined here, as it should outlive |wifi_provider_linux_|. |
| 111 base::MessageLoopForUI message_loop_; | 111 TestBrowserThreadBundle thread_bundle_; |
| 112 scoped_refptr<dbus::MockBus> mock_bus_; | 112 scoped_refptr<dbus::MockBus> mock_bus_; |
| 113 scoped_refptr<dbus::MockObjectProxy> mock_network_manager_proxy_; | 113 scoped_refptr<dbus::MockObjectProxy> mock_network_manager_proxy_; |
| 114 scoped_refptr<dbus::MockObjectProxy> mock_access_point_proxy_; | 114 scoped_refptr<dbus::MockObjectProxy> mock_access_point_proxy_; |
| 115 scoped_refptr<dbus::MockObjectProxy> mock_device_proxy_; | 115 scoped_refptr<dbus::MockObjectProxy> mock_device_proxy_; |
| 116 scoped_refptr<WifiDataProviderLinux> wifi_provider_linux_; | 116 scoped_refptr<WifiDataProviderLinux> wifi_provider_linux_; |
| 117 std::unique_ptr<WifiDataProviderCommon::WlanApiInterface> wlan_api_; | 117 std::unique_ptr<WifiDataProviderCommon::WlanApiInterface> wlan_api_; |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 // Creates a response for |mock_network_manager_proxy_|. | 120 // Creates a response for |mock_network_manager_proxy_|. |
| 121 dbus::Response* CreateNetworkManagerProxyResponse( | 121 dbus::Response* CreateNetworkManagerProxyResponse( |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 227 |
| 228 // Check the contents of the access point data. | 228 // Check the contents of the access point data. |
| 229 // The expected values come from CreateAccessPointProxyResponse() above. | 229 // The expected values come from CreateAccessPointProxyResponse() above. |
| 230 EXPECT_EQ("test", base::UTF16ToUTF8(access_point_data.ssid)); | 230 EXPECT_EQ("test", base::UTF16ToUTF8(access_point_data.ssid)); |
| 231 EXPECT_EQ("00-11-22-33-44-55", | 231 EXPECT_EQ("00-11-22-33-44-55", |
| 232 base::UTF16ToUTF8(access_point_data.mac_address)); | 232 base::UTF16ToUTF8(access_point_data.mac_address)); |
| 233 EXPECT_EQ(-50, access_point_data.radio_signal_strength); | 233 EXPECT_EQ(-50, access_point_data.radio_signal_strength); |
| 234 EXPECT_EQ(4, access_point_data.channel); | 234 EXPECT_EQ(4, access_point_data.channel); |
| 235 } | 235 } |
| 236 | 236 |
| 237 } // namespace device | 237 } // namespace content |
| OLD | NEW |