| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ | |
| 6 #define CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 | |
| 10 #include "base/ref_counted.h" | |
| 11 #include "base/scoped_ptr.h" | |
| 12 #include "base/threading/thread.h" | |
| 13 #include "chrome/common/geoposition.h" | |
| 14 #include "content/browser/geolocation/location_provider.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 | |
| 17 // Mock implementation of a location provider for testing. | |
| 18 class MockLocationProvider : public LocationProviderBase { | |
| 19 public: | |
| 20 // Will update |*self_ref| to point to |this| on construction, and to NULL | |
| 21 // on destruction. | |
| 22 explicit MockLocationProvider(MockLocationProvider** self_ref); | |
| 23 ~MockLocationProvider(); | |
| 24 | |
| 25 // Updates listeners with the new position. | |
| 26 void HandlePositionChanged(const Geoposition& position); | |
| 27 | |
| 28 // LocationProviderBase implementation. | |
| 29 virtual bool StartProvider(bool high_accuracy); | |
| 30 virtual void StopProvider(); | |
| 31 virtual void GetPosition(Geoposition* position); | |
| 32 virtual void OnPermissionGranted(const GURL& requesting_frame); | |
| 33 | |
| 34 Geoposition position_; | |
| 35 enum { STOPPED, LOW_ACCURACY, HIGH_ACCURACY } state_; | |
| 36 GURL permission_granted_url_; | |
| 37 MockLocationProvider** self_ref_; | |
| 38 | |
| 39 scoped_refptr<base::MessageLoopProxy> provider_loop_; | |
| 40 | |
| 41 // Set when an instance of the mock is created via a factory function. | |
| 42 static MockLocationProvider* instance_; | |
| 43 | |
| 44 DISALLOW_COPY_AND_ASSIGN(MockLocationProvider); | |
| 45 }; | |
| 46 | |
| 47 // Factory functions for the various sorts of mock location providers, | |
| 48 // for use with GeolocationArbitrator::SetProviderFactoryForTest (i.e. | |
| 49 // not intended for test code to use to get access to the mock, you can use | |
| 50 // MockLocationProvider::instance_ for this, or make a custom factory method). | |
| 51 | |
| 52 // Creates a mock location provider with no default behavior. | |
| 53 LocationProviderBase* NewMockLocationProvider(); | |
| 54 // Creates a mock location provider that automatically notifies its | |
| 55 // listeners with a valid location when StartProvider is called. | |
| 56 LocationProviderBase* NewAutoSuccessMockLocationProvider(); | |
| 57 // Creates a mock location provider that automatically notifies its | |
| 58 // listeners with an error when StartProvider is called. | |
| 59 LocationProviderBase* NewAutoFailMockLocationProvider(); | |
| 60 // Similar to NewAutoSuccessMockLocationProvider but mimicks the behavior of | |
| 61 // the Network Location provider, in deferring making location updates until | |
| 62 // a permission request has been confirmed. | |
| 63 LocationProviderBase* NewAutoSuccessMockNetworkLocationProvider(); | |
| 64 | |
| 65 #endif // CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ | |
| OLD | NEW |