| 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 "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" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 148 |
| 149 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { | 149 TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) { |
| 150 EXPECT_TRUE(access_token_store_); | 150 EXPECT_TRUE(access_token_store_); |
| 151 EXPECT_TRUE(arbitrator_ != NULL); | 151 EXPECT_TRUE(arbitrator_ != NULL); |
| 152 arbitrator_.reset(); | 152 arbitrator_.reset(); |
| 153 SUCCEED(); | 153 SUCCEED(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { | 156 TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) { |
| 157 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | 157 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); |
| 158 arbitrator_->OnPermissionGranted(GURL("http://frame.test")); | 158 arbitrator_->OnPermissionGranted(); |
| 159 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | 159 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); |
| 160 // Can't check the provider has been notified without going through the | 160 // Can't check the provider has been notified without going through the |
| 161 // motions to create the provider (see next test). | 161 // motions to create the provider (see next test). |
| 162 EXPECT_FALSE(cell()); | 162 EXPECT_FALSE(cell()); |
| 163 EXPECT_FALSE(gps()); | 163 EXPECT_FALSE(gps()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { | 166 TEST_F(GeolocationLocationArbitratorTest, NormalUsage) { |
| 167 ASSERT_TRUE(access_token_store_); | 167 ASSERT_TRUE(access_token_store_); |
| 168 ASSERT_TRUE(arbitrator_ != NULL); | 168 ASSERT_TRUE(arbitrator_ != NULL); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 181 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 181 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
| 182 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 182 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
| 183 EXPECT_FALSE(observer_->last_position_.IsInitialized()); | 183 EXPECT_FALSE(observer_->last_position_.IsInitialized()); |
| 184 | 184 |
| 185 SetReferencePosition(cell()); | 185 SetReferencePosition(cell()); |
| 186 | 186 |
| 187 EXPECT_TRUE(observer_->last_position_.IsInitialized()); | 187 EXPECT_TRUE(observer_->last_position_.IsInitialized()); |
| 188 EXPECT_EQ(cell()->position_.latitude, | 188 EXPECT_EQ(cell()->position_.latitude, |
| 189 observer_->last_position_.latitude); | 189 observer_->last_position_.latitude); |
| 190 | 190 |
| 191 EXPECT_FALSE( | 191 EXPECT_FALSE(cell()->is_permission_granted_); |
| 192 cell()->permission_granted_url_.is_valid()); | |
| 193 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); | 192 EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted()); |
| 194 GURL frame_url("http://frame.test"); | 193 arbitrator_->OnPermissionGranted(); |
| 195 arbitrator_->OnPermissionGranted(frame_url); | |
| 196 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); | 194 EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted()); |
| 197 EXPECT_TRUE( | 195 EXPECT_TRUE(cell()->is_permission_granted_); |
| 198 cell()->permission_granted_url_.is_valid()); | |
| 199 EXPECT_EQ(frame_url, | |
| 200 cell()->permission_granted_url_); | |
| 201 } | 196 } |
| 202 | 197 |
| 203 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { | 198 TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) { |
| 204 arbitrator_->StartProviders(GeolocationObserverOptions(false)); | 199 arbitrator_->StartProviders(GeolocationObserverOptions(false)); |
| 205 access_token_store_->NotifyDelegateTokensLoaded(); | 200 access_token_store_->NotifyDelegateTokensLoaded(); |
| 206 ASSERT_TRUE(cell()); | 201 ASSERT_TRUE(cell()); |
| 207 ASSERT_TRUE(gps()); | 202 ASSERT_TRUE(gps()); |
| 208 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); | 203 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_); |
| 209 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); | 204 EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, gps()->state_); |
| 210 SetReferencePosition(cell()); | 205 SetReferencePosition(cell()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 CheckLastPositionInfo(3.5657104, 139.690341, 300); | 280 CheckLastPositionInfo(3.5657104, 139.690341, 300); |
| 286 | 281 |
| 287 // 2 minutes later | 282 // 2 minutes later |
| 288 AdvanceTimeNow(base::TimeDelta::FromMinutes(2)); | 283 AdvanceTimeNow(base::TimeDelta::FromMinutes(2)); |
| 289 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. | 284 // Arrive in station. Cell moves but GPS is stale. Switch to fresher cell. |
| 290 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); | 285 SetPositionFix(cell(), 3.5658700, 139.069979, 1000); |
| 291 CheckLastPositionInfo(3.5658700, 139.069979, 1000); | 286 CheckLastPositionInfo(3.5658700, 139.069979, 1000); |
| 292 } | 287 } |
| 293 | 288 |
| 294 } // namespace | 289 } // namespace |
| OLD | NEW |