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

Unified Diff: content/browser/geolocation/geolocation_provider_unittest.cc

Issue 273523007: Dispatch geolocation IPCs on the UI thread. Aside from simplifying the code to avoid a lot of threa… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/geolocation/geolocation_provider_unittest.cc
===================================================================
--- content/browser/geolocation/geolocation_provider_unittest.cc (revision 269778)
+++ content/browser/geolocation/geolocation_provider_unittest.cc (working copy)
@@ -114,7 +114,7 @@
protected:
GeolocationProviderTest()
: message_loop_(),
- io_thread_(BrowserThread::IO, &message_loop_),
+ ui_thread_(BrowserThread::UI, &message_loop_),
provider_(new LocationProviderForTestArbitrator) {
}
@@ -131,7 +131,7 @@
void GetProvidersStarted(bool* started);
base::MessageLoop message_loop_;
- TestBrowserThread io_thread_;
+ TestBrowserThread ui_thread_;
scoped_ptr<LocationProviderForTestArbitrator> provider_;
};
@@ -167,19 +167,25 @@
// Regression test for http://crbug.com/59377
TEST_F(GeolocationProviderTest, OnPermissionGrantedWithoutObservers) {
- EXPECT_FALSE(provider()->LocationServicesOptedIn());
+ EXPECT_FALSE(provider()->user_did_opt_into_location_services_for_testing());
provider()->UserDidOptIntoLocationServices();
- EXPECT_TRUE(provider()->LocationServicesOptedIn());
+ EXPECT_TRUE(provider()->user_did_opt_into_location_services_for_testing());
}
+void DummyFunction(const Geoposition& position) {
+}
+
TEST_F(GeolocationProviderTest, StartStop) {
EXPECT_FALSE(provider()->IsRunning());
- GeolocationProviderImpl::LocationUpdateCallback null_callback;
- provider()->AddLocationUpdateCallback(null_callback, false);
+ GeolocationProviderImpl::LocationUpdateCallback callback =
+ base::Bind(&DummyFunction);
+ scoped_ptr<content::GeolocationProvider::Subscription> subscription =
+ provider()->AddLocationUpdateCallback(callback, false);
EXPECT_TRUE(provider()->IsRunning());
EXPECT_TRUE(ProvidersStarted());
- provider()->RemoveLocationUpdateCallback(null_callback);
+ subscription.reset();
+
EXPECT_FALSE(ProvidersStarted());
EXPECT_TRUE(provider()->IsRunning());
}
@@ -196,11 +202,12 @@
&MockGeolocationObserver::OnLocationUpdate,
base::Unretained(&first_observer));
EXPECT_CALL(first_observer, OnLocationUpdate(GeopositionEq(first_position)));
- provider()->AddLocationUpdateCallback(first_callback, false);
+ scoped_ptr<content::GeolocationProvider::Subscription> subscription =
+ provider()->AddLocationUpdateCallback(first_callback, false);
SendMockLocation(first_position);
base::MessageLoop::current()->Run();
- provider()->RemoveLocationUpdateCallback(first_callback);
+ subscription.reset();
Geoposition second_position;
second_position.latitude = 13;
@@ -216,7 +223,8 @@
GeolocationProviderImpl::LocationUpdateCallback second_callback = base::Bind(
&MockGeolocationObserver::OnLocationUpdate,
base::Unretained(&second_observer));
- provider()->AddLocationUpdateCallback(second_callback, false);
+ scoped_ptr<content::GeolocationProvider::Subscription> subscription2 =
+ provider()->AddLocationUpdateCallback(second_callback, false);
base::MessageLoop::current()->RunUntilIdle();
// The second observer should receive the new position now.
@@ -225,7 +233,7 @@
SendMockLocation(second_position);
base::MessageLoop::current()->Run();
- provider()->RemoveLocationUpdateCallback(second_callback);
+ subscription2.reset();
EXPECT_FALSE(ProvidersStarted());
}
@@ -240,8 +248,9 @@
GeolocationProviderImpl::LocationUpdateCallback callback = base::Bind(
&MockGeolocationObserver::OnLocationUpdate,
base::Unretained(&mock_observer));
- provider()->AddLocationUpdateCallback(callback, false);
- provider()->RemoveLocationUpdateCallback(callback);
+ scoped_ptr<content::GeolocationProvider::Subscription> subscription =
+ provider()->AddLocationUpdateCallback(callback, false);
+ subscription.reset();
// Wait for the providers to be stopped now that all clients are gone.
EXPECT_FALSE(ProvidersStarted());
}
« no previous file with comments | « content/browser/geolocation/geolocation_provider_impl.cc ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698