| 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/singleton.h" | |
| 6 #include "base/synchronization/waitable_event.h" | 5 #include "base/synchronization/waitable_event.h" |
| 7 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h
" | 6 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h
" |
| 8 #include "content/browser/geolocation/fake_access_token_store.h" | 7 #include "content/browser/geolocation/fake_access_token_store.h" |
| 9 #include "content/browser/geolocation/geolocation_provider.h" | 8 #include "content/browser/geolocation/geolocation_provider.h" |
| 10 #include "content/browser/geolocation/location_arbitrator.h" | 9 #include "content/browser/geolocation/location_arbitrator.h" |
| 11 #include "content/browser/geolocation/mock_location_provider.h" | 10 #include "content/browser/geolocation/mock_location_provider.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "content/test/test_browser_thread.h" |
| 14 | 14 |
| 15 using content::AccessTokenStore; | 15 using content::AccessTokenStore; |
| 16 using content::FakeAccessTokenStore; | 16 using content::FakeAccessTokenStore; |
| 17 using testing::_; | 17 using testing::_; |
| 18 using testing::DoAll; | 18 using testing::DoAll; |
| 19 using testing::DoDefault; | 19 using testing::DoDefault; |
| 20 using testing::Invoke; | 20 using testing::Invoke; |
| 21 using testing::InvokeWithoutArgs; | 21 using testing::InvokeWithoutArgs; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // A GeolocationProvider that can be constructed and destructed for testing. |
| 26 class NonSingletonGeolocationProvider : public GeolocationProvider { |
| 27 public: |
| 28 NonSingletonGeolocationProvider() : GeolocationProvider() { } |
| 29 |
| 30 virtual ~NonSingletonGeolocationProvider() {} |
| 31 }; |
| 32 |
| 25 class GeolocationProviderTest : public testing::Test { | 33 class GeolocationProviderTest : public testing::Test { |
| 26 protected: | 34 protected: |
| 27 GeolocationProviderTest() | 35 GeolocationProviderTest() |
| 28 : provider_(new GeolocationProvider), | 36 : io_thread_(content::BrowserThread::IO, &message_loop_), |
| 37 provider_(new NonSingletonGeolocationProvider), |
| 29 dependency_factory_( | 38 dependency_factory_( |
| 30 new GeolocationArbitratorDependencyFactoryWithLocationProvider( | 39 new GeolocationArbitratorDependencyFactoryWithLocationProvider( |
| 31 &NewAutoSuccessMockNetworkLocationProvider)) | 40 &NewAutoSuccessMockNetworkLocationProvider)) |
| 32 { | 41 { |
| 33 } | 42 } |
| 34 | 43 |
| 35 ~GeolocationProviderTest() { | |
| 36 DefaultSingletonTraits<GeolocationProvider>::Delete(provider_); | |
| 37 } | |
| 38 | |
| 39 // testing::Test | 44 // testing::Test |
| 40 virtual void SetUp() { | 45 virtual void SetUp() { |
| 41 GeolocationArbitrator::SetDependencyFactoryForTest( | 46 GeolocationArbitrator::SetDependencyFactoryForTest( |
| 42 dependency_factory_.get()); | 47 dependency_factory_.get()); |
| 43 } | 48 } |
| 44 | 49 |
| 45 // testing::Test | 50 // testing::Test |
| 46 virtual void TearDown() { | 51 virtual void TearDown() { |
| 47 provider_->Stop(); | 52 provider_->Stop(); |
| 48 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); | 53 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); |
| 49 } | 54 } |
| 50 | 55 |
| 51 // Message loop for main thread, as provider depends on it existing. | 56 // The GeolocationProvider expects to be instantiated on the IO thread. |
| 52 MessageLoop message_loop_; | 57 MessageLoop message_loop_; |
| 58 content::TestBrowserThread io_thread_; |
| 53 | 59 |
| 54 // Object under tests. Owned, but not a scoped_ptr due to specialized | 60 scoped_ptr<NonSingletonGeolocationProvider> provider_; |
| 55 // destruction protocol. | |
| 56 GeolocationProvider* provider_; | |
| 57 | 61 |
| 58 scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; | 62 scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; |
| 59 }; | 63 }; |
| 60 | 64 |
| 61 // Regression test for http://crbug.com/59377 | 65 // Regression test for http://crbug.com/59377 |
| 62 TEST_F(GeolocationProviderTest, OnPermissionGrantedWithoutObservers) { | 66 TEST_F(GeolocationProviderTest, OnPermissionGrantedWithoutObservers) { |
| 63 EXPECT_FALSE(provider_->HasPermissionBeenGranted()); | 67 EXPECT_FALSE(provider_->HasPermissionBeenGranted()); |
| 64 provider_->OnPermissionGranted(); | 68 provider_->OnPermissionGranted(); |
| 65 EXPECT_TRUE(provider_->HasPermissionBeenGranted()); | 69 EXPECT_TRUE(provider_->HasPermissionBeenGranted()); |
| 66 } | 70 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 provider_->RemoveObserver(&null_observer); | 177 provider_->RemoveObserver(&null_observer); |
| 174 // Wait for the providers to be stopped. | 178 // Wait for the providers to be stopped. |
| 175 event.Wait(); | 179 event.Wait(); |
| 176 event.Reset(); | 180 event.Reset(); |
| 177 EXPECT_TRUE(provider_->IsRunning()); | 181 EXPECT_TRUE(provider_->IsRunning()); |
| 178 | 182 |
| 179 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); | 183 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); |
| 180 } | 184 } |
| 181 | 185 |
| 182 } // namespace | 186 } // namespace |
| OLD | NEW |