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

Unified Diff: chrome/browser/geolocation/wifi_data_provider_common_unittest.cc

Issue 2971006: Landing patch 2825039 (Closed)
Patch Set: Tests passed Created 10 years, 5 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
Index: chrome/browser/geolocation/wifi_data_provider_common_unittest.cc
diff --git a/chrome/browser/geolocation/wifi_data_provider_common_unittest.cc b/chrome/browser/geolocation/wifi_data_provider_common_unittest.cc
index be165a7cdac4191bbc0532304974455200011e45..6947d41e5e527c75198d1758a92738b952381c4f 100644
--- a/chrome/browser/geolocation/wifi_data_provider_common_unittest.cc
+++ b/chrome/browser/geolocation/wifi_data_provider_common_unittest.cc
@@ -9,21 +9,50 @@
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+using testing::_;
+using testing::AtLeast;
+using testing::DoDefault;
+using testing::Invoke;
+using testing::Return;
+
class MockWlanApi : public WifiDataProviderCommon::WlanApiInterface {
public:
MockWlanApi() : calls_(0), bool_return_(true) {
ANNOTATE_BENIGN_RACE(&calls_, "This is a test-only data race on a counter");
+ ON_CALL(*this, GetAccessPointData(_))
+ .WillByDefault(Invoke(this, &MockWlanApi::GetAccessPointDataInternal));
}
- virtual bool GetAccessPointData(WifiData::AccessPointDataSet* data) {
+
+ MOCK_METHOD1(GetAccessPointData, bool(WifiData::AccessPointDataSet* data));
+
+ int calls_;
+ bool bool_return_;
+ WifiData::AccessPointDataSet data_out_;
+
+ private:
+ bool GetAccessPointDataInternal(WifiData::AccessPointDataSet* data) {
++calls_;
*data = data_out_;
return bool_return_;
}
- int calls_;
- bool bool_return_;
- WifiData::AccessPointDataSet data_out_;
+};
+
+class MockPollingPolicy :public PollingPolicyInterface {
+ public:
+ MockPollingPolicy() {
+ ON_CALL(*this,PollingInterval())
+ .WillByDefault(Return(1));
+ ON_CALL(*this,NoWifiInterval())
+ .WillByDefault(Return(1));
+ }
+
+ MOCK_METHOD0(PollingInterval, int());
+ MOCK_METHOD0(NoWifiInterval, int());
+
+ virtual void UpdatePollingInterval(bool) {}
};
// Stops the specified (nested) message loop when the listener is called back.
@@ -46,10 +75,12 @@ class MessageLoopQuitListener
DeviceDataProvider<WifiData>* provider_;
};
+
class WifiDataProviderCommonWithMock : public WifiDataProviderCommon {
public:
WifiDataProviderCommonWithMock()
- : new_wlan_api_(new MockWlanApi) {}
+ : new_wlan_api_(new MockWlanApi),
+ new_polling_policy_(new MockPollingPolicy) {}
// WifiDataProviderCommon
virtual WlanApiInterface* NewWlanApi() {
@@ -57,15 +88,16 @@ class WifiDataProviderCommonWithMock : public WifiDataProviderCommon {
return new_wlan_api_.release();
}
virtual PollingPolicyInterface* NewPollingPolicy() {
- return new GenericPollingPolicy<1, 2, 3>;
+ CHECK(new_polling_policy_ != NULL);
+ return new_polling_policy_.release();
}
scoped_ptr<MockWlanApi> new_wlan_api_;
+ scoped_ptr<MockPollingPolicy> new_polling_policy_;
DISALLOW_COPY_AND_ASSIGN(WifiDataProviderCommonWithMock);
};
-
WifiDataProviderImplBase* CreateWifiDataProviderCommonWithMock() {
return new WifiDataProviderCommonWithMock;
}
@@ -73,19 +105,28 @@ WifiDataProviderImplBase* CreateWifiDataProviderCommonWithMock() {
// Main test fixture
class GeolocationWifiDataProviderCommonTest : public testing::Test {
public:
+ GeolocationWifiDataProviderCommonTest()
+ : quit_listener_(&main_message_loop_) {
+ }
+
virtual void SetUp() {
provider_ = new WifiDataProviderCommonWithMock;
wlan_api_ = provider_->new_wlan_api_.get();
+ polling_policy_ = provider_->new_polling_policy_.get();
+ provider_->AddListener(&quit_listener_);
}
virtual void TearDown() {
+ provider_->RemoveListener(&quit_listener_);
provider_->StopDataProvider();
provider_ = NULL;
}
protected:
MessageLoop main_message_loop_;
+ MessageLoopQuitListener quit_listener_;
scoped_refptr<WifiDataProviderCommonWithMock> provider_;
MockWlanApi* wlan_api_;
+ MockPollingPolicy* polling_policy_;
};
TEST_F(GeolocationWifiDataProviderCommonTest, CreateDestroy) {
@@ -96,14 +137,52 @@ TEST_F(GeolocationWifiDataProviderCommonTest, CreateDestroy) {
}
TEST_F(GeolocationWifiDataProviderCommonTest, StartThread) {
+ EXPECT_CALL(*wlan_api_, GetAccessPointData(_))
+ .Times(AtLeast(1));
+ EXPECT_CALL(*polling_policy_, PollingInterval())
+ .Times(AtLeast(1));
EXPECT_TRUE(provider_->StartDataProvider());
provider_->StopDataProvider();
SUCCEED();
}
+TEST_F(GeolocationWifiDataProviderCommonTest, NoWifi){
+ EXPECT_CALL(*polling_policy_, NoWifiInterval())
+ .Times(AtLeast(1));
+ EXPECT_CALL(*wlan_api_, GetAccessPointData(_))
+ .WillRepeatedly(Return(false));
+ provider_->StartDataProvider();
+ main_message_loop_.Run();
+}
+
+TEST_F(GeolocationWifiDataProviderCommonTest, IntermittentWifi){
+ EXPECT_CALL(*polling_policy_, PollingInterval())
+ .Times(AtLeast(1));
+ EXPECT_CALL(*polling_policy_, NoWifiInterval())
+ .Times(1);
+ EXPECT_CALL(*wlan_api_, GetAccessPointData(_))
+ .WillOnce(Return(true))
+ .WillOnce(Return(false))
+ .WillRepeatedly(DoDefault());
+
+ AccessPointData single_access_point;
+ single_access_point.channel = 2;
+ single_access_point.mac_address = 3;
+ single_access_point.radio_signal_strength = 4;
+ single_access_point.signal_to_noise = 5;
+ single_access_point.ssid = ASCIIToUTF16("foossid");
+ wlan_api_->data_out_.insert(single_access_point);
+
+ provider_->StartDataProvider();
+ main_message_loop_.Run();
+ main_message_loop_.Run();
+}
+
TEST_F(GeolocationWifiDataProviderCommonTest, DoAnEmptyScan) {
- MessageLoopQuitListener quit_listener(&main_message_loop_);
- provider_->AddListener(&quit_listener);
+ EXPECT_CALL(*wlan_api_, GetAccessPointData(_))
+ .Times(AtLeast(1));
+ EXPECT_CALL(*polling_policy_, PollingInterval())
+ .Times(AtLeast(1));
EXPECT_TRUE(provider_->StartDataProvider());
main_message_loop_.Run();
// Check we had at least one call. The worker thread may have raced ahead
@@ -112,12 +191,13 @@ TEST_F(GeolocationWifiDataProviderCommonTest, DoAnEmptyScan) {
WifiData data;
EXPECT_TRUE(provider_->GetData(&data));
EXPECT_EQ(0, static_cast<int>(data.access_point_data.size()));
- provider_->RemoveListener(&quit_listener);
}
TEST_F(GeolocationWifiDataProviderCommonTest, DoScanWithResults) {
- MessageLoopQuitListener quit_listener(&main_message_loop_);
- provider_->AddListener(&quit_listener);
+ EXPECT_CALL(*wlan_api_, GetAccessPointData(_))
+ .Times(AtLeast(1));
+ EXPECT_CALL(*polling_policy_, PollingInterval())
+ .Times(AtLeast(1));
AccessPointData single_access_point;
single_access_point.channel = 2;
single_access_point.mac_address = 3;
@@ -133,9 +213,9 @@ TEST_F(GeolocationWifiDataProviderCommonTest, DoScanWithResults) {
EXPECT_TRUE(provider_->GetData(&data));
EXPECT_EQ(1, static_cast<int>(data.access_point_data.size()));
EXPECT_EQ(single_access_point.ssid, data.access_point_data.begin()->ssid);
- provider_->RemoveListener(&quit_listener);
}
+// TODO(Joth) Convert to gmock style
TEST_F(GeolocationWifiDataProviderCommonTest,
StartThreadViaDeviceDataProvider) {
MessageLoopQuitListener quit_listener(&main_message_loop_);
« no previous file with comments | « chrome/browser/geolocation/wifi_data_provider_common.cc ('k') | chrome/browser/geolocation/wifi_data_provider_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698