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

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

Issue 14335017: content: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 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/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 13 matching lines...) Expand all
24 const char kAccessTokenString[] = "accessToken"; 24 const char kAccessTokenString[] = "accessToken";
25 25
26 // Using #define so we can easily paste this into various other strings. 26 // Using #define so we can easily paste this into various other strings.
27 #define REFERENCE_ACCESS_TOKEN "2:k7j3G6LaL6u_lafw:4iXOeOpTh1glSXe" 27 #define REFERENCE_ACCESS_TOKEN "2:k7j3G6LaL6u_lafw:4iXOeOpTh1glSXe"
28 28
29 // Stops the specified (nested) message loop when the listener is called back. 29 // Stops the specified (nested) message loop when the listener is called back.
30 class MessageLoopQuitListener 30 class MessageLoopQuitListener
31 : public LocationProviderBase::ListenerInterface { 31 : public LocationProviderBase::ListenerInterface {
32 public: 32 public:
33 MessageLoopQuitListener() 33 MessageLoopQuitListener()
34 : client_message_loop_(MessageLoop::current()), 34 : client_message_loop_(base::MessageLoop::current()),
35 updated_provider_(NULL), 35 updated_provider_(NULL),
36 movement_provider_(NULL) { 36 movement_provider_(NULL) {
37 CHECK(client_message_loop_); 37 CHECK(client_message_loop_);
38 } 38 }
39 // ListenerInterface 39 // ListenerInterface
40 virtual void LocationUpdateAvailable( 40 virtual void LocationUpdateAvailable(
41 LocationProviderBase* provider) OVERRIDE { 41 LocationProviderBase* provider) OVERRIDE {
42 EXPECT_EQ(client_message_loop_, MessageLoop::current()); 42 EXPECT_EQ(client_message_loop_, base::MessageLoop::current());
43 updated_provider_ = provider; 43 updated_provider_ = provider;
44 client_message_loop_->Quit(); 44 client_message_loop_->Quit();
45 } 45 }
46 MessageLoop* client_message_loop_; 46 base::MessageLoop* client_message_loop_;
47 LocationProviderBase* updated_provider_; 47 LocationProviderBase* updated_provider_;
48 LocationProviderBase* movement_provider_; 48 LocationProviderBase* movement_provider_;
49 }; 49 };
50 50
51 // A mock implementation of DeviceDataProviderImplBase for testing. Adapted from 51 // A mock implementation of DeviceDataProviderImplBase for testing. Adapted from
52 // http://gears.googlecode.com/svn/trunk/gears/geolocation/geolocation_test.cc 52 // http://gears.googlecode.com/svn/trunk/gears/geolocation/geolocation_test.cc
53 template<typename DataType> 53 template<typename DataType>
54 class MockDeviceDataProviderImpl 54 class MockDeviceDataProviderImpl
55 : public DeviceDataProviderImplBase<DataType> { 55 : public DeviceDataProviderImplBase<DataType> {
56 public: 56 public:
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 ASSERT_TRUE(JsonFieldEquals("signalToNoiseRatio", *expected_json, 317 ASSERT_TRUE(JsonFieldEquals("signalToNoiseRatio", *expected_json,
318 *actual_json)); 318 *actual_json));
319 } 319 }
320 } else { 320 } else {
321 ASSERT_FALSE(request_json->HasKey("wifiAccessPoints")); 321 ASSERT_FALSE(request_json->HasKey("wifiAccessPoints"));
322 } 322 }
323 EXPECT_TRUE(request_url.is_valid()); 323 EXPECT_TRUE(request_url.is_valid());
324 } 324 }
325 325
326 GURL test_server_url_; 326 GURL test_server_url_;
327 MessageLoop main_message_loop_; 327 base::MessageLoop main_message_loop_;
328 scoped_refptr<FakeAccessTokenStore> access_token_store_; 328 scoped_refptr<FakeAccessTokenStore> access_token_store_;
329 net::TestURLFetcherFactory url_fetcher_factory_; 329 net::TestURLFetcherFactory url_fetcher_factory_;
330 scoped_refptr<MockDeviceDataProviderImpl<WifiData> > wifi_data_provider_; 330 scoped_refptr<MockDeviceDataProviderImpl<WifiData> > wifi_data_provider_;
331 }; 331 };
332 332
333 TEST_F(GeolocationNetworkProviderTest, CreateDestroy) { 333 TEST_F(GeolocationNetworkProviderTest, CreateDestroy) {
334 // Test fixture members were SetUp correctly. 334 // Test fixture members were SetUp correctly.
335 EXPECT_EQ(&main_message_loop_, MessageLoop::current()); 335 EXPECT_EQ(&main_message_loop_, base::MessageLoop::current());
336 scoped_ptr<LocationProviderBase> provider(CreateProvider(true)); 336 scoped_ptr<LocationProviderBase> provider(CreateProvider(true));
337 EXPECT_TRUE(NULL != provider.get()); 337 EXPECT_TRUE(NULL != provider.get());
338 provider.reset(); 338 provider.reset();
339 SUCCEED(); 339 SUCCEED();
340 } 340 }
341 341
342 TEST_F(GeolocationNetworkProviderTest, StartProvider) { 342 TEST_F(GeolocationNetworkProviderTest, StartProvider) {
343 scoped_ptr<LocationProviderBase> provider(CreateProvider(true)); 343 scoped_ptr<LocationProviderBase> provider(CreateProvider(true));
344 EXPECT_TRUE(provider->StartProvider(false)); 344 EXPECT_TRUE(provider->StartProvider(false));
345 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id(); 345 net::TestURLFetcher* fetcher = get_url_fetcher_and_advance_id();
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1))); 575 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(1)));
576 } else { 576 } else {
577 const int evicted = i - kCacheSize; 577 const int evicted = i - kCacheSize;
578 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted))); 578 EXPECT_FALSE(cache.FindPosition(CreateReferenceWifiScanData(evicted)));
579 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1))); 579 EXPECT_TRUE(cache.FindPosition(CreateReferenceWifiScanData(evicted + 1)));
580 } 580 }
581 } 581 }
582 } 582 }
583 583
584 } // namespace content 584 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698