OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/browser_thread_impl.h" | 5 #include "content/browser/browser_thread_impl.h" |
6 #include "content/browser/geolocation/gps_location_provider_linux.h" | 6 #include "content/browser/geolocation/gps_location_provider_linux.h" |
7 #include "content/browser/geolocation/libgps_wrapper_linux.h" | 7 #include "content/browser/geolocation/libgps_wrapper_linux.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // Movement. This will block for up to half a second. | 161 // Movement. This will block for up to half a second. |
162 MockLibGps::g_instance_->get_position_.latitude += 0.01; | 162 MockLibGps::g_instance_->get_position_.latitude += 0.01; |
163 MessageLoop::current()->Run(); | 163 MessageLoop::current()->Run(); |
164 provider_->GetPosition(&position); | 164 provider_->GetPosition(&position); |
165 EXPECT_EQ(2, MockLibGps::g_instance_->get_position_calls_); | 165 EXPECT_EQ(2, MockLibGps::g_instance_->get_position_calls_); |
166 EXPECT_EQ(1, MockLibGps::g_instance_->gps_open_calls_); | 166 EXPECT_EQ(1, MockLibGps::g_instance_->gps_open_calls_); |
167 EXPECT_EQ(2, MockLibGps::g_instance_->gps_read_calls_); | 167 EXPECT_EQ(2, MockLibGps::g_instance_->gps_read_calls_); |
168 CheckValidPosition(MockLibGps::g_instance_->get_position_, position); | 168 CheckValidPosition(MockLibGps::g_instance_->get_position_, position); |
169 } | 169 } |
170 | 170 |
171 class EnableGpsOpenTask : public Task { | 171 void EnableGpsOpenCallback() { |
172 public: | 172 CHECK(MockLibGps::g_instance_); |
173 virtual void Run() { | 173 MockLibGps::g_instance_->gps_open_ret_ = 0; |
174 CHECK(MockLibGps::g_instance_); | 174 } |
175 MockLibGps::g_instance_->gps_open_ret_ = 0; | |
176 } | |
177 }; | |
178 | 175 |
179 TEST_F(GeolocationGpsProviderLinuxTests, LibGpsReconnect) { | 176 TEST_F(GeolocationGpsProviderLinuxTests, LibGpsReconnect) { |
180 // Setup gpsd reconnect interval to be 1000ms to speed up test. | 177 // Setup gpsd reconnect interval to be 1000ms to speed up test. |
181 provider_->SetGpsdReconnectIntervalMillis(1000); | 178 provider_->SetGpsdReconnectIntervalMillis(1000); |
182 provider_->SetPollPeriodMovingMillis(200); | 179 provider_->SetPollPeriodMovingMillis(200); |
183 const bool ok = provider_->StartProvider(true); | 180 const bool ok = provider_->StartProvider(true); |
184 EXPECT_TRUE(ok); | 181 EXPECT_TRUE(ok); |
185 ASSERT_TRUE(MockLibGps::g_instance_); | 182 ASSERT_TRUE(MockLibGps::g_instance_); |
186 // Let gps_open() fails, and so will LibGps::Start(). | 183 // Let gps_open() fails, and so will LibGps::Start(). |
187 // Reconnect will happen in 1000ms. | 184 // Reconnect will happen in 1000ms. |
188 MockLibGps::g_instance_->gps_open_ret_ = 1; | 185 MockLibGps::g_instance_->gps_open_ret_ = 1; |
189 Geoposition position; | 186 Geoposition position; |
190 MockLibGps::g_instance_->get_position_.error_code = | 187 MockLibGps::g_instance_->get_position_.error_code = |
191 Geoposition::ERROR_CODE_NONE; | 188 Geoposition::ERROR_CODE_NONE; |
192 MockLibGps::g_instance_->get_position_.latitude = 4.5; | 189 MockLibGps::g_instance_->get_position_.latitude = 4.5; |
193 MockLibGps::g_instance_->get_position_.longitude = -34.1; | 190 MockLibGps::g_instance_->get_position_.longitude = -34.1; |
194 MockLibGps::g_instance_->get_position_.accuracy = 345; | 191 MockLibGps::g_instance_->get_position_.accuracy = 345; |
195 MockLibGps::g_instance_->get_position_.timestamp = | 192 MockLibGps::g_instance_->get_position_.timestamp = |
196 base::Time::FromDoubleT(200); | 193 base::Time::FromDoubleT(200); |
197 EXPECT_TRUE(MockLibGps::g_instance_->get_position_.IsValidFix()); | 194 EXPECT_TRUE(MockLibGps::g_instance_->get_position_.IsValidFix()); |
198 // This task makes gps_open() and LibGps::Start() to succeed after | 195 // This task makes gps_open() and LibGps::Start() to succeed after |
199 // 1500ms. | 196 // 1500ms. |
200 MessageLoop::current()->PostDelayedTask( | 197 MessageLoop::current()->PostDelayedTask( |
201 FROM_HERE, new EnableGpsOpenTask(), 1500); | 198 FROM_HERE, base::Bind(&EnableGpsOpenCallback), 1500); |
202 MessageLoop::current()->Run(); | 199 MessageLoop::current()->Run(); |
203 provider_->GetPosition(&position); | 200 provider_->GetPosition(&position); |
204 EXPECT_TRUE(position.IsInitialized()); | 201 EXPECT_TRUE(position.IsInitialized()); |
205 EXPECT_TRUE(position.IsValidFix()); | 202 EXPECT_TRUE(position.IsValidFix()); |
206 // 3 gps_open() calls are expected (2 failures and 1 success) | 203 // 3 gps_open() calls are expected (2 failures and 1 success) |
207 EXPECT_EQ(1, MockLibGps::g_instance_->get_position_calls_); | 204 EXPECT_EQ(1, MockLibGps::g_instance_->get_position_calls_); |
208 EXPECT_EQ(3, MockLibGps::g_instance_->gps_open_calls_); | 205 EXPECT_EQ(3, MockLibGps::g_instance_->gps_open_calls_); |
209 EXPECT_EQ(1, MockLibGps::g_instance_->gps_read_calls_); | 206 EXPECT_EQ(1, MockLibGps::g_instance_->gps_read_calls_); |
210 } | 207 } |
211 | 208 |
212 #endif // #if defined(OS_CHROMEOS) | 209 #endif // #if defined(OS_CHROMEOS) |
213 | 210 |
214 } // namespace | 211 } // namespace |
OLD | NEW |