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

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

Issue 486203004: Clean up WifiDataProvider(Manager) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't delete the DCHECK Created 6 years, 4 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 | Annotate | Revision Log
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/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/json/json_writer.h" 6 #include "base/json/json_writer.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 base::MessageLoop* client_message_loop_; 46 base::MessageLoop* client_message_loop_;
47 const LocationProvider* updated_provider_; 47 const LocationProvider* updated_provider_;
48 }; 48 };
49 49
50 // A mock implementation of WifiDataProvider for testing. Adapted from 50 // A mock implementation of WifiDataProvider for testing. Adapted from
51 // http://gears.googlecode.com/svn/trunk/gears/geolocation/geolocation_test.cc 51 // http://gears.googlecode.com/svn/trunk/gears/geolocation/geolocation_test.cc
52 class MockWifiDataProvider : public WifiDataProvider { 52 class MockWifiDataProvider : public WifiDataProvider {
53 public: 53 public:
54 // Factory method for use with WifiDataProvider::SetFactory. 54 // Factory method for use with WifiDataProvider::SetFactoryForTesting.
55 static WifiDataProvider* GetInstance() { 55 static WifiDataProvider* GetInstance() {
56 CHECK(instance_); 56 CHECK(instance_);
57 return instance_; 57 return instance_;
58 } 58 }
59 59
60 static MockWifiDataProvider* CreateInstance() { 60 static MockWifiDataProvider* CreateInstance() {
61 CHECK(!instance_); 61 CHECK(!instance_);
62 instance_ = new MockWifiDataProvider; 62 instance_ = new MockWifiDataProvider;
63 return instance_; 63 return instance_;
64 } 64 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 // Main test fixture 111 // Main test fixture
112 class GeolocationNetworkProviderTest : public testing::Test { 112 class GeolocationNetworkProviderTest : public testing::Test {
113 public: 113 public:
114 virtual void SetUp() { 114 virtual void SetUp() {
115 test_server_url_ = GURL(kTestServerUrl); 115 test_server_url_ = GURL(kTestServerUrl);
116 access_token_store_ = new FakeAccessTokenStore; 116 access_token_store_ = new FakeAccessTokenStore;
117 wifi_data_provider_ = MockWifiDataProvider::CreateInstance(); 117 wifi_data_provider_ = MockWifiDataProvider::CreateInstance();
118 } 118 }
119 119
120 virtual void TearDown() { WifiDataProviderManager::ResetFactory(); } 120 virtual void TearDown() { WifiDataProviderManager::ResetFactoryForTesting(); }
121 121
122 LocationProvider* CreateProvider(bool set_permission_granted) { 122 LocationProvider* CreateProvider(bool set_permission_granted) {
123 LocationProvider* provider = NewNetworkLocationProvider( 123 LocationProvider* provider = NewNetworkLocationProvider(
124 access_token_store_.get(), 124 access_token_store_.get(),
125 NULL, // No URLContextGetter needed, as using test urlfecther factory. 125 NULL, // No URLContextGetter needed, as using test urlfecther factory.
126 test_server_url_, 126 test_server_url_,
127 access_token_store_->access_token_set_[test_server_url_]); 127 access_token_store_->access_token_set_[test_server_url_]);
128 if (set_permission_granted) 128 if (set_permission_granted)
129 provider->OnPermissionGranted(); 129 provider->OnPermissionGranted();
130 return provider; 130 return provider;
131 } 131 }
132 132
133 protected: 133 protected:
134 GeolocationNetworkProviderTest() { 134 GeolocationNetworkProviderTest() {
135 // TODO(joth): Really these should be in SetUp, not here, but they take no 135 // TODO(joth): Really these should be in SetUp, not here, but they take no
136 // effect on Mac OS Release builds if done there. I kid not. Figure out why. 136 // effect on Mac OS Release builds if done there. I kid not. Figure out why.
137 WifiDataProviderManager::SetFactory(MockWifiDataProvider::GetInstance); 137 WifiDataProviderManager::SetFactoryForTesting(
138 MockWifiDataProvider::GetInstance);
138 } 139 }
139 140
140 // Returns the current url fetcher (if any) and advances the id ready for the 141 // Returns the current url fetcher (if any) and advances the id ready for the
141 // next test step. 142 // next test step.
142 net::TestURLFetcher* get_url_fetcher_and_advance_id() { 143 net::TestURLFetcher* get_url_fetcher_and_advance_id() {
143 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID( 144 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(
144 NetworkLocationRequest::url_fetcher_id_for_tests); 145 NetworkLocationRequest::url_fetcher_id_for_tests);
145 if (fetcher) 146 if (fetcher)
146 ++NetworkLocationRequest::url_fetcher_id_for_tests; 147 ++NetworkLocationRequest::url_fetcher_id_for_tests;
147 return fetcher; 148 return fetcher;
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1))); 550 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1)));
550 } else { 551 } else {
551 const int evicted = i - kCacheSize; 552 const int evicted = i - kCacheSize;
552 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted))); 553 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted)));
553 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1))); 554 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1)));
554 } 555 }
555 } 556 }
556 } 557 }
557 558
558 } // namespace content 559 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/network_location_provider.cc ('k') | content/browser/geolocation/wifi_data_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698