OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "device/geolocation/geolocation_provider_impl.h" | 5 #include "device/geolocation/geolocation_provider_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "device/geolocation/access_token_store.h" | 19 #include "device/geolocation/access_token_store.h" |
20 #include "device/geolocation/mock_location_arbitrator.h" | 20 #include "device/geolocation/mock_location_arbitrator.h" |
Kevin M
2016/08/10 23:16:19
Does this build? MockLocationArbitrator subclasses
CJ
2016/08/11 22:16:53
Done.
| |
21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 using testing::MakeMatcher; | 24 using testing::MakeMatcher; |
25 using testing::Matcher; | 25 using testing::Matcher; |
26 using testing::MatcherInterface; | 26 using testing::MatcherInterface; |
27 using testing::MatchResultListener; | 27 using testing::MatchResultListener; |
28 | 28 |
29 namespace device { | 29 namespace device { |
Kevin M
2016/08/10 23:16:19
Use an anonymous namespace under device?
CJ
2016/08/11 22:16:53
Done.
| |
30 | 30 |
31 class LocationProviderForTestArbitrator : public GeolocationProviderImpl { | 31 class LocationProviderForTestArbitrator : public GeolocationProviderImpl { |
32 public: | 32 public: |
33 LocationProviderForTestArbitrator() : mock_arbitrator_(NULL) {} | 33 LocationProviderForTestArbitrator() : mock_arbitrator_(NULL) {} |
34 ~LocationProviderForTestArbitrator() override {} | 34 ~LocationProviderForTestArbitrator() override {} |
35 | 35 |
36 // Only valid for use on the geolocation thread. | 36 // Only valid for use on the geolocation thread. |
37 MockLocationArbitrator* mock_arbitrator() const { return mock_arbitrator_; } | 37 MockLocationArbitrator* mock_arbitrator() const { return mock_arbitrator_; } |
38 | 38 |
39 protected: | 39 protected: |
40 // GeolocationProviderImpl implementation: | 40 // GeolocationProviderImpl implementation: |
41 std::unique_ptr<LocationArbitrator> CreateArbitrator() override; | 41 std::unique_ptr<LocationProvider> CreateArbitrator() override; |
42 | 42 |
43 private: | 43 private: |
44 // An alias to the arbitrator stored in the super class, where it is owned. | 44 // An alias to the arbitrator stored in the super class, where it is owned. |
45 MockLocationArbitrator* mock_arbitrator_; | 45 MockLocationArbitrator* mock_arbitrator_; |
46 }; | 46 }; |
47 | 47 |
48 std::unique_ptr<LocationArbitrator> | 48 std::unique_ptr<LocationProvider> |
49 LocationProviderForTestArbitrator::CreateArbitrator() { | 49 LocationProviderForTestArbitrator::CreateArbitrator() { |
50 DCHECK(mock_arbitrator_ == NULL); | 50 DCHECK(mock_arbitrator_ == NULL); |
51 mock_arbitrator_ = new MockLocationArbitrator; | 51 mock_arbitrator_ = new MockLocationArbitrator; |
52 return base::WrapUnique(mock_arbitrator_); | 52 return base::WrapUnique(mock_arbitrator_); |
53 } | 53 } |
54 | 54 |
55 class GeolocationObserver { | 55 class GeolocationObserver { |
56 public: | 56 public: |
57 virtual ~GeolocationObserver() {} | 57 virtual ~GeolocationObserver() {} |
58 virtual void OnLocationUpdate(const Geoposition& position) = 0; | 58 virtual void OnLocationUpdate(const Geoposition& position) = 0; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 base::Bind(&MockGeolocationObserver::OnLocationUpdate, | 242 base::Bind(&MockGeolocationObserver::OnLocationUpdate, |
243 base::Unretained(&mock_observer)); | 243 base::Unretained(&mock_observer)); |
244 std::unique_ptr<GeolocationProvider::Subscription> subscription = | 244 std::unique_ptr<GeolocationProvider::Subscription> subscription = |
245 provider()->AddLocationUpdateCallback(callback, false); | 245 provider()->AddLocationUpdateCallback(callback, false); |
246 subscription.reset(); | 246 subscription.reset(); |
247 // Wait for the providers to be stopped now that all clients are gone. | 247 // Wait for the providers to be stopped now that all clients are gone. |
248 EXPECT_FALSE(ProvidersStarted()); | 248 EXPECT_FALSE(ProvidersStarted()); |
249 } | 249 } |
250 | 250 |
251 } // namespace device | 251 } // namespace device |
OLD | NEW |