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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 10 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
11 #include "content/browser/geolocation/wifi_data_provider_common.h" | 11 #include "content/browser/geolocation/wifi_data_provider_common.h" |
| 12 #include "content/browser/geolocation/wifi_data_provider_manager.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 using testing::_; | 16 using testing::_; |
16 using testing::AtLeast; | 17 using testing::AtLeast; |
17 using testing::DoDefault; | 18 using testing::DoDefault; |
18 using testing::Invoke; | 19 using testing::Invoke; |
19 using testing::Return; | 20 using testing::Return; |
20 | 21 |
21 namespace content { | 22 namespace content { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // Stops the specified (nested) message loop when the callback is called. | 61 // Stops the specified (nested) message loop when the callback is called. |
61 class MessageLoopQuitter { | 62 class MessageLoopQuitter { |
62 public: | 63 public: |
63 explicit MessageLoopQuitter(base::MessageLoop* message_loop) | 64 explicit MessageLoopQuitter(base::MessageLoop* message_loop) |
64 : message_loop_to_quit_(message_loop), | 65 : message_loop_to_quit_(message_loop), |
65 callback_(base::Bind(&MessageLoopQuitter::OnWifiDataUpdate, | 66 callback_(base::Bind(&MessageLoopQuitter::OnWifiDataUpdate, |
66 base::Unretained(this))) { | 67 base::Unretained(this))) { |
67 CHECK(message_loop_to_quit_ != NULL); | 68 CHECK(message_loop_to_quit_ != NULL); |
68 } | 69 } |
69 | 70 |
70 void OnWifiDataUpdate(WifiDataProvider* provider) { | 71 void OnWifiDataUpdate(WifiDataProviderManager* manager) { |
71 // Provider should call back on client's thread. | 72 // Provider should call back on client's thread. |
72 EXPECT_EQ(base::MessageLoop::current(), message_loop_to_quit_); | 73 EXPECT_EQ(base::MessageLoop::current(), message_loop_to_quit_); |
73 message_loop_to_quit_->QuitNow(); | 74 message_loop_to_quit_->QuitNow(); |
74 } | 75 } |
75 base::MessageLoop* message_loop_to_quit_; | 76 base::MessageLoop* message_loop_to_quit_; |
76 WifiDataProvider::WifiDataUpdateCallback callback_; | 77 WifiDataProviderManager::WifiDataUpdateCallback callback_; |
77 }; | 78 }; |
78 | 79 |
79 class WifiDataProviderCommonWithMock : public WifiDataProviderCommon { | 80 class WifiDataProviderCommonWithMock : public WifiDataProviderCommon { |
80 public: | 81 public: |
81 WifiDataProviderCommonWithMock() | 82 WifiDataProviderCommonWithMock() |
82 : new_wlan_api_(new MockWlanApi), | 83 : new_wlan_api_(new MockWlanApi), |
83 new_polling_policy_(new MockPollingPolicy) {} | 84 new_polling_policy_(new MockPollingPolicy) {} |
84 | 85 |
85 // WifiDataProviderCommon | 86 // WifiDataProviderCommon |
86 virtual WlanApiInterface* NewWlanApi() OVERRIDE { | 87 virtual WlanApiInterface* NewWlanApi() OVERRIDE { |
87 CHECK(new_wlan_api_ != NULL); | 88 CHECK(new_wlan_api_ != NULL); |
88 return new_wlan_api_.release(); | 89 return new_wlan_api_.release(); |
89 } | 90 } |
90 virtual WifiPollingPolicy* NewPollingPolicy() OVERRIDE { | 91 virtual WifiPollingPolicy* NewPollingPolicy() OVERRIDE { |
91 CHECK(new_polling_policy_ != NULL); | 92 CHECK(new_polling_policy_ != NULL); |
92 return new_polling_policy_.release(); | 93 return new_polling_policy_.release(); |
93 } | 94 } |
94 | 95 |
95 scoped_ptr<MockWlanApi> new_wlan_api_; | 96 scoped_ptr<MockWlanApi> new_wlan_api_; |
96 scoped_ptr<MockPollingPolicy> new_polling_policy_; | 97 scoped_ptr<MockPollingPolicy> new_polling_policy_; |
97 | 98 |
98 private: | 99 private: |
99 virtual ~WifiDataProviderCommonWithMock() {} | 100 virtual ~WifiDataProviderCommonWithMock() {} |
100 | 101 |
101 DISALLOW_COPY_AND_ASSIGN(WifiDataProviderCommonWithMock); | 102 DISALLOW_COPY_AND_ASSIGN(WifiDataProviderCommonWithMock); |
102 }; | 103 }; |
103 | 104 |
104 WifiDataProviderImplBase* CreateWifiDataProviderCommonWithMock() { | 105 WifiDataProvider* CreateWifiDataProviderCommonWithMock() { |
105 return new WifiDataProviderCommonWithMock; | 106 return new WifiDataProviderCommonWithMock; |
106 } | 107 } |
107 | 108 |
108 // Main test fixture | 109 // Main test fixture |
109 class GeolocationWifiDataProviderCommonTest : public testing::Test { | 110 class GeolocationWifiDataProviderCommonTest : public testing::Test { |
110 public: | 111 public: |
111 GeolocationWifiDataProviderCommonTest() | 112 GeolocationWifiDataProviderCommonTest() |
112 : loop_quitter_(&main_message_loop_) { | 113 : loop_quitter_(&main_message_loop_) { |
113 } | 114 } |
114 | 115 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 main_message_loop_.Run(); | 212 main_message_loop_.Run(); |
212 EXPECT_EQ(wlan_api_->calls_, 1); | 213 EXPECT_EQ(wlan_api_->calls_, 1); |
213 WifiData data; | 214 WifiData data; |
214 EXPECT_TRUE(provider_->GetData(&data)); | 215 EXPECT_TRUE(provider_->GetData(&data)); |
215 EXPECT_EQ(1, static_cast<int>(data.access_point_data.size())); | 216 EXPECT_EQ(1, static_cast<int>(data.access_point_data.size())); |
216 EXPECT_EQ(single_access_point.ssid, data.access_point_data.begin()->ssid); | 217 EXPECT_EQ(single_access_point.ssid, data.access_point_data.begin()->ssid); |
217 } | 218 } |
218 | 219 |
219 TEST_F(GeolocationWifiDataProviderCommonTest, RegisterUnregister) { | 220 TEST_F(GeolocationWifiDataProviderCommonTest, RegisterUnregister) { |
220 MessageLoopQuitter loop_quitter(&main_message_loop_); | 221 MessageLoopQuitter loop_quitter(&main_message_loop_); |
221 WifiDataProvider::SetFactory(CreateWifiDataProviderCommonWithMock); | 222 WifiDataProviderManager::SetFactory(CreateWifiDataProviderCommonWithMock); |
222 WifiDataProvider::Register(&loop_quitter.callback_); | 223 WifiDataProviderManager::Register(&loop_quitter.callback_); |
223 main_message_loop_.Run(); | 224 main_message_loop_.Run(); |
224 WifiDataProvider::Unregister(&loop_quitter.callback_); | 225 WifiDataProviderManager::Unregister(&loop_quitter.callback_); |
225 WifiDataProvider::ResetFactory(); | 226 WifiDataProviderManager::ResetFactory(); |
226 } | 227 } |
227 | 228 |
228 } // namespace content | 229 } // namespace content |
OLD | NEW |