Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: content/browser/geolocation/location_arbitrator_unittest.cc

Issue 10316007: Make the Geoposition helper class public (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix forward-declaration of struct as class. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "content/browser/geolocation/arbitrator_dependency_factory.h" 6 #include "content/browser/geolocation/arbitrator_dependency_factory.h"
7 #include "content/browser/geolocation/fake_access_token_store.h" 7 #include "content/browser/geolocation/fake_access_token_store.h"
8 #include "content/browser/geolocation/geolocation_observer.h" 8 #include "content/browser/geolocation/geolocation_observer.h"
9 #include "content/browser/geolocation/location_arbitrator.h" 9 #include "content/browser/geolocation/location_arbitrator.h"
10 #include "content/browser/geolocation/location_provider.h" 10 #include "content/browser/geolocation/location_provider.h"
11 #include "content/browser/geolocation/mock_location_provider.h" 11 #include "content/browser/geolocation/mock_location_provider.h"
12 #include "content/common/geoposition.h" 12 #include "content/public/common/geoposition.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using content::AccessTokenStore; 16 using content::AccessTokenStore;
17 using content::FakeAccessTokenStore; 17 using content::FakeAccessTokenStore;
18 using content::Geoposition;
18 using ::testing::NiceMock; 19 using ::testing::NiceMock;
19 20
20 namespace { 21 namespace {
21 22
22 class MockLocationObserver : public GeolocationObserver { 23 class MockLocationObserver : public GeolocationObserver {
23 public: 24 public:
24 void InvalidateLastPosition() { 25 void InvalidateLastPosition() {
25 last_position_.latitude = 100; 26 last_position_.latitude = 100;
26 last_position_.error_code = Geoposition::ERROR_CODE_NONE; 27 last_position_.error_code = Geoposition::ERROR_CODE_NONE;
27 ASSERT_FALSE(last_position_.IsInitialized()); 28 ASSERT_FALSE(last_position_.Validate());
28 } 29 }
29 // Delegate 30 // Delegate
30 virtual void OnLocationUpdate(const Geoposition& position) { 31 virtual void OnLocationUpdate(const Geoposition& position) {
31 last_position_ = position; 32 last_position_ = position;
32 } 33 }
33 34
34 Geoposition last_position_; 35 Geoposition last_position_;
35 }; 36 };
36 37
37 double g_fake_time_now_secs = 1; 38 double g_fake_time_now_secs = 1;
38 39
39 base::Time GetTimeNowForTest() { 40 base::Time GetTimeNowForTest() {
40 return base::Time::FromDoubleT(g_fake_time_now_secs); 41 return base::Time::FromDoubleT(g_fake_time_now_secs);
41 } 42 }
42 43
43 void AdvanceTimeNow(const base::TimeDelta& delta) { 44 void AdvanceTimeNow(const base::TimeDelta& delta) {
44 g_fake_time_now_secs += delta.InSecondsF(); 45 g_fake_time_now_secs += delta.InSecondsF();
45 } 46 }
46 47
47 void SetPositionFix(MockLocationProvider* provider, 48 void SetPositionFix(MockLocationProvider* provider,
48 double latitude, 49 double latitude,
49 double longitude, 50 double longitude,
50 double accuracy) { 51 double accuracy) {
51 Geoposition position; 52 Geoposition position;
52 position.error_code = Geoposition::ERROR_CODE_NONE; 53 position.error_code = Geoposition::ERROR_CODE_NONE;
53 position.latitude = latitude; 54 position.latitude = latitude;
54 position.longitude = longitude; 55 position.longitude = longitude;
55 position.accuracy = accuracy; 56 position.accuracy = accuracy;
56 position.timestamp = GetTimeNowForTest(); 57 position.timestamp = GetTimeNowForTest();
57 ASSERT_TRUE(position.IsInitialized()); 58 ASSERT_TRUE(position.Validate());
58 ASSERT_TRUE(position.IsValidFix());
59 provider->HandlePositionChanged(position); 59 provider->HandlePositionChanged(position);
60 } 60 }
61 61
62 void SetReferencePosition(MockLocationProvider* provider) { 62 void SetReferencePosition(MockLocationProvider* provider) {
63 SetPositionFix(provider, 51.0, -0.1, 400); 63 SetPositionFix(provider, 51.0, -0.1, 400);
64 } 64 }
65 65
66 class MockDependencyFactory : public GeolocationArbitratorDependencyFactory { 66 class MockDependencyFactory : public GeolocationArbitratorDependencyFactory {
67 public: 67 public:
68 explicit MockDependencyFactory(AccessTokenStore* access_token_store) 68 explicit MockDependencyFactory(AccessTokenStore* access_token_store)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // testing::Test 119 // testing::Test
120 virtual void TearDown() { 120 virtual void TearDown() {
121 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); 121 GeolocationArbitrator::SetDependencyFactoryForTest(NULL);
122 dependency_factory_ = NULL; 122 dependency_factory_ = NULL;
123 } 123 }
124 124
125 void CheckLastPositionInfo(double latitude, 125 void CheckLastPositionInfo(double latitude,
126 double longitude, 126 double longitude,
127 double accuracy) { 127 double accuracy) {
128 Geoposition geoposition = observer_->last_position_; 128 Geoposition geoposition = observer_->last_position_;
129 EXPECT_TRUE(geoposition.IsValidFix()); 129 EXPECT_TRUE(geoposition.Validate());
130 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude); 130 EXPECT_DOUBLE_EQ(latitude, geoposition.latitude);
131 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude); 131 EXPECT_DOUBLE_EQ(longitude, geoposition.longitude);
132 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy); 132 EXPECT_DOUBLE_EQ(accuracy, geoposition.accuracy);
133 } 133 }
134 134
135 base::TimeDelta SwitchOnFreshnessCliff() { 135 base::TimeDelta SwitchOnFreshnessCliff() {
136 // Add 1, to ensure it meets any greater-than test. 136 // Add 1, to ensure it meets any greater-than test.
137 return base::TimeDelta::FromMilliseconds( 137 return base::TimeDelta::FromMilliseconds(
138 GeolocationArbitrator::kFixStaleTimeoutMilliseconds + 1); 138 GeolocationArbitrator::kFixStaleTimeoutMilliseconds + 1);
139 } 139 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 180
181 EXPECT_TRUE(access_token_store_->access_token_set_.empty()); 181 EXPECT_TRUE(access_token_store_->access_token_set_.empty());
182 EXPECT_TRUE(access_token_store_->access_token_set_.empty()); 182 EXPECT_TRUE(access_token_store_->access_token_set_.empty());
183 183
184 access_token_store_->NotifyDelegateTokensLoaded(); 184 access_token_store_->NotifyDelegateTokensLoaded();
185 ASSERT_TRUE(cell()); 185 ASSERT_TRUE(cell());
186 EXPECT_TRUE(gps()); 186 EXPECT_TRUE(gps());
187 EXPECT_TRUE(cell()->has_listeners()); 187 EXPECT_TRUE(cell()->has_listeners());
188 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); 188 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
189 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); 189 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_);
190 EXPECT_FALSE(observer_->last_position_.IsInitialized()); 190 EXPECT_FALSE(observer_->last_position_.Validate());
191 EXPECT_EQ(content::Geoposition::ERROR_CODE_NONE,
192 observer_->last_position_.error_code);
191 193
192 SetReferencePosition(cell()); 194 SetReferencePosition(cell());
193 195
194 EXPECT_TRUE(observer_->last_position_.IsInitialized()); 196 EXPECT_TRUE(observer_->last_position_.Validate() ||
197 observer_->last_position_.error_code !=
198 content::Geoposition::ERROR_CODE_NONE);
195 EXPECT_EQ(cell()->position_.latitude, 199 EXPECT_EQ(cell()->position_.latitude,
196 observer_->last_position_.latitude); 200 observer_->last_position_.latitude);
197 201
198 EXPECT_FALSE(cell()->is_permission_granted_); 202 EXPECT_FALSE(cell()->is_permission_granted_);
199 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); 203 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
200 arbitrator_->OnPermissionGranted(); 204 arbitrator_->OnPermissionGranted();
201 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); 205 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
202 EXPECT_TRUE(cell()->is_permission_granted_); 206 EXPECT_TRUE(cell()->is_permission_granted_);
203 } 207 }
204 208
(...skipping 14 matching lines...) Expand all
219 223
220 TEST_F(GeolocationLocationArbitratorTest, Arbitration) { 224 TEST_F(GeolocationLocationArbitratorTest, Arbitration) {
221 arbitrator_->StartProviders(GeolocationObserverOptions(false)); 225 arbitrator_->StartProviders(GeolocationObserverOptions(false));
222 access_token_store_->NotifyDelegateTokensLoaded(); 226 access_token_store_->NotifyDelegateTokensLoaded();
223 ASSERT_TRUE(cell()); 227 ASSERT_TRUE(cell());
224 ASSERT_TRUE(gps()); 228 ASSERT_TRUE(gps());
225 229
226 SetPositionFix(cell(), 1, 2, 150); 230 SetPositionFix(cell(), 1, 2, 150);
227 231
228 // First position available 232 // First position available
229 EXPECT_TRUE(observer_->last_position_.IsValidFix()); 233 EXPECT_TRUE(observer_->last_position_.Validate());
230 CheckLastPositionInfo(1, 2, 150); 234 CheckLastPositionInfo(1, 2, 150);
231 235
232 SetPositionFix(gps(), 3, 4, 50); 236 SetPositionFix(gps(), 3, 4, 50);
233 237
234 // More accurate fix available 238 // More accurate fix available
235 CheckLastPositionInfo(3, 4, 50); 239 CheckLastPositionInfo(3, 4, 50);
236 240
237 SetPositionFix(cell(), 5, 6, 150); 241 SetPositionFix(cell(), 5, 6, 150);
238 242
239 // New fix is available but it's less accurate, older fix should be kept. 243 // New fix is available but it's less accurate, older fix should be kept.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 CheckLastPositionInfo(3.5657104, 139.690341, 300); 291 CheckLastPositionInfo(3.5657104, 139.690341, 300);
288 292
289 // 2 minutes later 293 // 2 minutes later
290 AdvanceTimeNow(base::TimeDelta::FromMinutes(2)); 294 AdvanceTimeNow(base::TimeDelta::FromMinutes(2));
291 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. 295 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell.
292 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); 296 SetPositionFix(cell(), 3.5658700, 139.069979, 1000);
293 CheckLastPositionInfo(3.5658700, 139.069979, 1000); 297 CheckLastPositionInfo(3.5658700, 139.069979, 1000);
294 } 298 }
295 299
296 } // namespace 300 } // namespace
OLDNEW
« no previous file with comments | « content/browser/geolocation/location_arbitrator.cc ('k') | content/browser/geolocation/location_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698