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

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

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

Powered by Google App Engine
This is Rietveld 408576698