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" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // Stops the specified (nested) message loop when the callback is called. | 61 // Stops the specified (nested) message loop when the callback is called. |
62 class MessageLoopQuitter { | 62 class MessageLoopQuitter { |
63 public: | 63 public: |
64 explicit MessageLoopQuitter(base::MessageLoop* message_loop) | 64 explicit MessageLoopQuitter(base::MessageLoop* message_loop) |
65 : message_loop_to_quit_(message_loop), | 65 : message_loop_to_quit_(message_loop), |
66 callback_(base::Bind(&MessageLoopQuitter::OnWifiDataUpdate, | 66 callback_(base::Bind(&MessageLoopQuitter::OnWifiDataUpdate, |
67 base::Unretained(this))) { | 67 base::Unretained(this))) { |
68 CHECK(message_loop_to_quit_ != NULL); | 68 CHECK(message_loop_to_quit_ != NULL); |
69 } | 69 } |
70 | 70 |
71 void OnWifiDataUpdate(WifiDataProviderManager* manager) { | 71 void OnWifiDataUpdate() { |
72 // Provider should call back on client's thread. | 72 // Provider should call back on client's thread. |
73 EXPECT_EQ(base::MessageLoop::current(), message_loop_to_quit_); | 73 EXPECT_EQ(base::MessageLoop::current(), message_loop_to_quit_); |
74 message_loop_to_quit_->QuitNow(); | 74 message_loop_to_quit_->QuitNow(); |
75 } | 75 } |
76 base::MessageLoop* message_loop_to_quit_; | 76 base::MessageLoop* message_loop_to_quit_; |
77 WifiDataProviderManager::WifiDataUpdateCallback callback_; | 77 WifiDataProviderManager::WifiDataUpdateCallback callback_; |
78 }; | 78 }; |
79 | 79 |
80 class WifiDataProviderCommonWithMock : public WifiDataProviderCommon { | 80 class WifiDataProviderCommonWithMock : public WifiDataProviderCommon { |
81 public: | 81 public: |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 main_message_loop_.Run(); | 212 main_message_loop_.Run(); |
213 EXPECT_EQ(wlan_api_->calls_, 1); | 213 EXPECT_EQ(wlan_api_->calls_, 1); |
214 WifiData data; | 214 WifiData data; |
215 EXPECT_TRUE(provider_->GetData(&data)); | 215 EXPECT_TRUE(provider_->GetData(&data)); |
216 EXPECT_EQ(1, static_cast<int>(data.access_point_data.size())); | 216 EXPECT_EQ(1, static_cast<int>(data.access_point_data.size())); |
217 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); |
218 } | 218 } |
219 | 219 |
220 TEST_F(GeolocationWifiDataProviderCommonTest, RegisterUnregister) { | 220 TEST_F(GeolocationWifiDataProviderCommonTest, RegisterUnregister) { |
221 MessageLoopQuitter loop_quitter(&main_message_loop_); | 221 MessageLoopQuitter loop_quitter(&main_message_loop_); |
222 WifiDataProviderManager::SetFactory(CreateWifiDataProviderCommonWithMock); | 222 WifiDataProviderManager::SetFactoryForTesting( |
| 223 CreateWifiDataProviderCommonWithMock); |
223 WifiDataProviderManager::Register(&loop_quitter.callback_); | 224 WifiDataProviderManager::Register(&loop_quitter.callback_); |
224 main_message_loop_.Run(); | 225 main_message_loop_.Run(); |
225 WifiDataProviderManager::Unregister(&loop_quitter.callback_); | 226 WifiDataProviderManager::Unregister(&loop_quitter.callback_); |
226 WifiDataProviderManager::ResetFactory(); | 227 WifiDataProviderManager::ResetFactoryForTesting(); |
227 } | 228 } |
228 | 229 |
229 } // namespace content | 230 } // namespace content |
OLD | NEW |