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/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 MOCK_METHOD0(PollingInterval, int()); | 54 MOCK_METHOD0(PollingInterval, int()); |
55 MOCK_METHOD0(NoWifiInterval, int()); | 55 MOCK_METHOD0(NoWifiInterval, int()); |
56 | 56 |
57 virtual void UpdatePollingInterval(bool) {} | 57 virtual void UpdatePollingInterval(bool) {} |
58 }; | 58 }; |
59 | 59 |
60 // Stops the specified (nested) message loop when the listener is called back. | 60 // Stops the specified (nested) message loop when the listener is called back. |
61 class MessageLoopQuitListener | 61 class MessageLoopQuitListener |
62 : public WifiDataProviderCommon::ListenerInterface { | 62 : public WifiDataProviderCommon::ListenerInterface { |
63 public: | 63 public: |
64 explicit MessageLoopQuitListener(MessageLoop* message_loop) | 64 explicit MessageLoopQuitListener(base::MessageLoop* message_loop) |
65 : message_loop_to_quit_(message_loop) { | 65 : message_loop_to_quit_(message_loop) { |
66 CHECK(message_loop_to_quit_ != NULL); | 66 CHECK(message_loop_to_quit_ != NULL); |
67 } | 67 } |
68 // ListenerInterface | 68 // ListenerInterface |
69 virtual void DeviceDataUpdateAvailable( | 69 virtual void DeviceDataUpdateAvailable( |
70 DeviceDataProvider<WifiData>* provider) OVERRIDE { | 70 DeviceDataProvider<WifiData>* provider) OVERRIDE { |
71 // Provider should call back on client's thread. | 71 // Provider should call back on client's thread. |
72 EXPECT_EQ(MessageLoop::current(), message_loop_to_quit_); | 72 EXPECT_EQ(base::MessageLoop::current(), message_loop_to_quit_); |
73 provider_ = provider; | 73 provider_ = provider; |
74 message_loop_to_quit_->QuitNow(); | 74 message_loop_to_quit_->QuitNow(); |
75 } | 75 } |
76 MessageLoop* message_loop_to_quit_; | 76 base::MessageLoop* message_loop_to_quit_; |
77 DeviceDataProvider<WifiData>* provider_; | 77 DeviceDataProvider<WifiData>* provider_; |
78 }; | 78 }; |
79 | 79 |
80 | 80 |
81 class WifiDataProviderCommonWithMock : public WifiDataProviderCommon { | 81 class WifiDataProviderCommonWithMock : public WifiDataProviderCommon { |
82 public: | 82 public: |
83 WifiDataProviderCommonWithMock() | 83 WifiDataProviderCommonWithMock() |
84 : new_wlan_api_(new MockWlanApi), | 84 : new_wlan_api_(new MockWlanApi), |
85 new_polling_policy_(new MockPollingPolicy) {} | 85 new_polling_policy_(new MockPollingPolicy) {} |
86 | 86 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 polling_policy_ = provider_->new_polling_policy_.get(); | 120 polling_policy_ = provider_->new_polling_policy_.get(); |
121 provider_->AddListener(&quit_listener_); | 121 provider_->AddListener(&quit_listener_); |
122 } | 122 } |
123 virtual void TearDown() { | 123 virtual void TearDown() { |
124 provider_->RemoveListener(&quit_listener_); | 124 provider_->RemoveListener(&quit_listener_); |
125 provider_->StopDataProvider(); | 125 provider_->StopDataProvider(); |
126 provider_ = NULL; | 126 provider_ = NULL; |
127 } | 127 } |
128 | 128 |
129 protected: | 129 protected: |
130 MessageLoop main_message_loop_; | 130 base::MessageLoop main_message_loop_; |
131 MessageLoopQuitListener quit_listener_; | 131 MessageLoopQuitListener quit_listener_; |
132 scoped_refptr<WifiDataProviderCommonWithMock> provider_; | 132 scoped_refptr<WifiDataProviderCommonWithMock> provider_; |
133 MockWlanApi* wlan_api_; | 133 MockWlanApi* wlan_api_; |
134 MockPollingPolicy* polling_policy_; | 134 MockPollingPolicy* polling_policy_; |
135 }; | 135 }; |
136 | 136 |
137 TEST_F(GeolocationWifiDataProviderCommonTest, CreateDestroy) { | 137 TEST_F(GeolocationWifiDataProviderCommonTest, CreateDestroy) { |
138 // Test fixture members were SetUp correctly. | 138 // Test fixture members were SetUp correctly. |
139 EXPECT_EQ(&main_message_loop_, MessageLoop::current()); | 139 EXPECT_EQ(&main_message_loop_, base::MessageLoop::current()); |
140 EXPECT_TRUE(NULL != provider_.get()); | 140 EXPECT_TRUE(NULL != provider_.get()); |
141 EXPECT_TRUE(NULL != wlan_api_); | 141 EXPECT_TRUE(NULL != wlan_api_); |
142 } | 142 } |
143 | 143 |
144 TEST_F(GeolocationWifiDataProviderCommonTest, StartThread) { | 144 TEST_F(GeolocationWifiDataProviderCommonTest, StartThread) { |
145 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) | 145 EXPECT_CALL(*wlan_api_, GetAccessPointData(_)) |
146 .Times(AtLeast(1)); | 146 .Times(AtLeast(1)); |
147 EXPECT_CALL(*polling_policy_, PollingInterval()) | 147 EXPECT_CALL(*polling_policy_, PollingInterval()) |
148 .Times(AtLeast(1)); | 148 .Times(AtLeast(1)); |
149 EXPECT_TRUE(provider_->StartDataProvider()); | 149 EXPECT_TRUE(provider_->StartDataProvider()); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 StartThreadViaDeviceDataProvider) { | 224 StartThreadViaDeviceDataProvider) { |
225 MessageLoopQuitListener quit_listener(&main_message_loop_); | 225 MessageLoopQuitListener quit_listener(&main_message_loop_); |
226 WifiDataProvider::SetFactory(CreateWifiDataProviderCommonWithMock); | 226 WifiDataProvider::SetFactory(CreateWifiDataProviderCommonWithMock); |
227 DeviceDataProvider<WifiData>::Register(&quit_listener); | 227 DeviceDataProvider<WifiData>::Register(&quit_listener); |
228 main_message_loop_.Run(); | 228 main_message_loop_.Run(); |
229 DeviceDataProvider<WifiData>::Unregister(&quit_listener); | 229 DeviceDataProvider<WifiData>::Unregister(&quit_listener); |
230 DeviceDataProvider<WifiData>::ResetFactory(); | 230 DeviceDataProvider<WifiData>::ResetFactory(); |
231 } | 231 } |
232 | 232 |
233 } // namespace content | 233 } // namespace content |
OLD | NEW |