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 "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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 int gps_read_ret_; | 46 int gps_read_ret_; |
47 Geoposition get_position_; | 47 Geoposition get_position_; |
48 static MockLibGps* g_instance_; | 48 static MockLibGps* g_instance_; |
49 }; | 49 }; |
50 | 50 |
51 class LocaionProviderListenerLoopQuitter | 51 class LocaionProviderListenerLoopQuitter |
52 : public LocationProviderBase::ListenerInterface { | 52 : public LocationProviderBase::ListenerInterface { |
53 // LocationProviderBase::ListenerInterface | 53 // LocationProviderBase::ListenerInterface |
54 virtual void LocationUpdateAvailable( | 54 virtual void LocationUpdateAvailable( |
55 LocationProviderBase* provider) OVERRIDE { | 55 LocationProviderBase* provider) OVERRIDE { |
56 MessageLoop::current()->Quit(); | 56 base::MessageLoop::current()->Quit(); |
57 } | 57 } |
58 }; | 58 }; |
59 | 59 |
60 class GeolocationGpsProviderLinuxTests : public testing::Test { | 60 class GeolocationGpsProviderLinuxTests : public testing::Test { |
61 public: | 61 public: |
62 GeolocationGpsProviderLinuxTests(); | 62 GeolocationGpsProviderLinuxTests(); |
63 virtual ~GeolocationGpsProviderLinuxTests(); | 63 virtual ~GeolocationGpsProviderLinuxTests(); |
64 | 64 |
65 static LibGps* NewMockLibGps() { | 65 static LibGps* NewMockLibGps() { |
66 return new MockLibGps(); | 66 return new MockLibGps(); |
67 } | 67 } |
68 static LibGps* NoLibGpsFactory() { | 68 static LibGps* NoLibGpsFactory() { |
69 return NULL; | 69 return NULL; |
70 } | 70 } |
71 | 71 |
72 protected: | 72 protected: |
73 MessageLoop message_loop_; | 73 base::MessageLoop message_loop_; |
74 BrowserThreadImpl ui_thread_; | 74 BrowserThreadImpl ui_thread_; |
75 LocaionProviderListenerLoopQuitter location_listener_; | 75 LocaionProviderListenerLoopQuitter location_listener_; |
76 scoped_ptr<GpsLocationProviderLinux> provider_; | 76 scoped_ptr<GpsLocationProviderLinux> provider_; |
77 }; | 77 }; |
78 | 78 |
79 void CheckValidPosition(const Geoposition& expected, | 79 void CheckValidPosition(const Geoposition& expected, |
80 const Geoposition& actual) { | 80 const Geoposition& actual) { |
81 EXPECT_TRUE(actual.Validate()); | 81 EXPECT_TRUE(actual.Validate()); |
82 EXPECT_DOUBLE_EQ(expected.latitude, actual.latitude); | 82 EXPECT_DOUBLE_EQ(expected.latitude, actual.latitude); |
83 EXPECT_DOUBLE_EQ(expected.longitude, actual.longitude); | 83 EXPECT_DOUBLE_EQ(expected.longitude, actual.longitude); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 EXPECT_FALSE(position.Validate()); | 144 EXPECT_FALSE(position.Validate()); |
145 EXPECT_EQ(Geoposition::ERROR_CODE_POSITION_UNAVAILABLE, position.error_code); | 145 EXPECT_EQ(Geoposition::ERROR_CODE_POSITION_UNAVAILABLE, position.error_code); |
146 MockLibGps::g_instance_->get_position_.error_code = | 146 MockLibGps::g_instance_->get_position_.error_code = |
147 Geoposition::ERROR_CODE_NONE; | 147 Geoposition::ERROR_CODE_NONE; |
148 MockLibGps::g_instance_->get_position_.latitude = 4.5; | 148 MockLibGps::g_instance_->get_position_.latitude = 4.5; |
149 MockLibGps::g_instance_->get_position_.longitude = -34.1; | 149 MockLibGps::g_instance_->get_position_.longitude = -34.1; |
150 MockLibGps::g_instance_->get_position_.accuracy = 345; | 150 MockLibGps::g_instance_->get_position_.accuracy = 345; |
151 MockLibGps::g_instance_->get_position_.timestamp = | 151 MockLibGps::g_instance_->get_position_.timestamp = |
152 base::Time::FromDoubleT(200); | 152 base::Time::FromDoubleT(200); |
153 EXPECT_TRUE(MockLibGps::g_instance_->get_position_.Validate()); | 153 EXPECT_TRUE(MockLibGps::g_instance_->get_position_.Validate()); |
154 MessageLoop::current()->Run(); | 154 base::MessageLoop::current()->Run(); |
155 EXPECT_EQ(1, MockLibGps::g_instance_->get_position_calls_); | 155 EXPECT_EQ(1, MockLibGps::g_instance_->get_position_calls_); |
156 EXPECT_EQ(1, MockLibGps::g_instance_->gps_open_calls_); | 156 EXPECT_EQ(1, MockLibGps::g_instance_->gps_open_calls_); |
157 EXPECT_EQ(1, MockLibGps::g_instance_->gps_read_calls_); | 157 EXPECT_EQ(1, MockLibGps::g_instance_->gps_read_calls_); |
158 provider_->GetPosition(&position); | 158 provider_->GetPosition(&position); |
159 CheckValidPosition(MockLibGps::g_instance_->get_position_, position); | 159 CheckValidPosition(MockLibGps::g_instance_->get_position_, position); |
160 | 160 |
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 base::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 void EnableGpsOpenCallback() { | 171 void EnableGpsOpenCallback() { |
172 CHECK(MockLibGps::g_instance_); | 172 CHECK(MockLibGps::g_instance_); |
173 MockLibGps::g_instance_->gps_open_ret_ = 0; | 173 MockLibGps::g_instance_->gps_open_ret_ = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
187 MockLibGps::g_instance_->get_position_.error_code = | 187 MockLibGps::g_instance_->get_position_.error_code = |
188 Geoposition::ERROR_CODE_NONE; | 188 Geoposition::ERROR_CODE_NONE; |
189 MockLibGps::g_instance_->get_position_.latitude = 4.5; | 189 MockLibGps::g_instance_->get_position_.latitude = 4.5; |
190 MockLibGps::g_instance_->get_position_.longitude = -34.1; | 190 MockLibGps::g_instance_->get_position_.longitude = -34.1; |
191 MockLibGps::g_instance_->get_position_.accuracy = 345; | 191 MockLibGps::g_instance_->get_position_.accuracy = 345; |
192 MockLibGps::g_instance_->get_position_.timestamp = | 192 MockLibGps::g_instance_->get_position_.timestamp = |
193 base::Time::FromDoubleT(200); | 193 base::Time::FromDoubleT(200); |
194 EXPECT_TRUE(MockLibGps::g_instance_->get_position_.Validate()); | 194 EXPECT_TRUE(MockLibGps::g_instance_->get_position_.Validate()); |
195 // This task makes gps_open() and LibGps::Start() to succeed after | 195 // This task makes gps_open() and LibGps::Start() to succeed after |
196 // 1500ms. | 196 // 1500ms. |
197 MessageLoop::current()->PostDelayedTask( | 197 base::MessageLoop::current()->PostDelayedTask( |
198 FROM_HERE, | 198 FROM_HERE, |
199 base::Bind(&EnableGpsOpenCallback), | 199 base::Bind(&EnableGpsOpenCallback), |
200 base::TimeDelta::FromMilliseconds(1500)); | 200 base::TimeDelta::FromMilliseconds(1500)); |
201 MessageLoop::current()->Run(); | 201 base::MessageLoop::current()->Run(); |
202 provider_->GetPosition(&position); | 202 provider_->GetPosition(&position); |
203 EXPECT_TRUE(position.Validate()); | 203 EXPECT_TRUE(position.Validate()); |
204 // 3 gps_open() calls are expected (2 failures and 1 success) | 204 // 3 gps_open() calls are expected (2 failures and 1 success) |
205 EXPECT_EQ(1, MockLibGps::g_instance_->get_position_calls_); | 205 EXPECT_EQ(1, MockLibGps::g_instance_->get_position_calls_); |
206 EXPECT_EQ(3, MockLibGps::g_instance_->gps_open_calls_); | 206 EXPECT_EQ(3, MockLibGps::g_instance_->gps_open_calls_); |
207 EXPECT_EQ(1, MockLibGps::g_instance_->gps_read_calls_); | 207 EXPECT_EQ(1, MockLibGps::g_instance_->gps_read_calls_); |
208 } | 208 } |
209 | 209 |
210 #endif // #if defined(OS_CHROMEOS) | 210 #endif // #if defined(OS_CHROMEOS) |
211 | 211 |
212 } // namespace content | 212 } // namespace content |
OLD | NEW |