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

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

Issue 2098553002: Geolocation: extract ContentBrowserClient methods specific to Geolocation into a class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a TODO Created 4 years, 6 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
« no previous file with comments | « content/browser/geolocation/location_arbitrator_impl.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/geolocation/location_arbitrator_impl_unittest.cc
diff --git a/content/browser/geolocation/location_arbitrator_impl_unittest.cc b/content/browser/geolocation/location_arbitrator_impl_unittest.cc
index b5429c86d47a650add0b6250771865b3b026ee70..a389a1dc30ca4e29145e4ae7dc346175f7b06b74 100644
--- a/content/browser/geolocation/location_arbitrator_impl_unittest.cc
+++ b/content/browser/geolocation/location_arbitrator_impl_unittest.cc
@@ -66,37 +66,39 @@ void SetReferencePosition(MockLocationProvider* provider) {
namespace {
-class GeolocationContentBrowserClient : public TestContentBrowserClient {
+class FakeDelegate : public GeolocationProvider::Delegate {
public:
- GeolocationContentBrowserClient() {}
+ FakeDelegate() = default;
+ bool UseNetworkLocationProviders() override { return use_network_; }
void set_use_network(bool use_network) { use_network_ = use_network; }
LocationProvider* OverrideSystemLocationProvider() override {
- provider_ = new MockLocationProvider;
- return provider_;
+ if (!system_location_provider_)
+ system_location_provider_ = base::WrapUnique(new MockLocationProvider);
+ return system_location_provider_.get();
}
- bool UseNetworkLocationProviders() override { return use_network_; }
-
- // This provider does not own the object. It is returned by
- // GeolocationLocationAribtratorTest::GetSystemLocationProviderOverride().
- // The caller takes ownership. This is just a reference we can use for
- // mocking purposes.
- MockLocationProvider* provider_ = nullptr;
+ LocationProvider* system_location_provider() const {
+ return system_location_provider_.get();
+ }
private:
bool use_network_ = true;
+ std::unique_ptr<LocationProvider> system_location_provider_;
- DISALLOW_COPY_AND_ASSIGN(GeolocationContentBrowserClient);
+ DISALLOW_COPY_AND_ASSIGN(FakeDelegate);
};
class TestingLocationArbitrator : public LocationArbitratorImpl {
public:
TestingLocationArbitrator(
const LocationArbitratorImpl::LocationUpdateCallback& callback,
- AccessTokenStore* access_token_store)
- : LocationArbitratorImpl(callback),
+ AccessTokenStore* access_token_store,
+ GeolocationProvider::Delegate* delegate,
+ bool is_fake_delegate)
+ : LocationArbitratorImpl(callback, delegate),
+ is_fake_delegate_(is_fake_delegate),
cell_(nullptr),
gps_(nullptr),
access_token_store_(access_token_store) {}
@@ -121,6 +123,19 @@ class TestingLocationArbitrator : public LocationArbitratorImpl {
return base::WrapUnique(gps_);
}
+ FakeDelegate* GetFakeDelegate() {
+ DCHECK(is_fake_delegate_);
+ return static_cast<FakeDelegate*>(GetDelegateForTesting());
+ }
+
+ LocationProvider* GetLocationProvider() {
+ if (is_fake_delegate_)
+ return GetFakeDelegate()->system_location_provider();
+ return GetDelegateForTesting()->OverrideSystemLocationProvider();
+ }
+
+ const bool is_fake_delegate_;
+
// Two location providers, with nice short names to make the tests more
// readable. Note |gps_| will only be set when there is a high accuracy
// observer registered (and |cell_| when there's at least one observer of any
@@ -141,12 +156,20 @@ class GeolocationLocationArbitratorTest : public testing::Test {
void SetUp() override {
access_token_store_ = new NiceMock<FakeAccessTokenStore>;
observer_.reset(new MockLocationObserver);
- LocationArbitratorImpl::LocationUpdateCallback callback =
+ }
+
+ // There are two types of test cases: those using FakeDelegate and the ones
+ // exercising whatever the embedder provides. Test cases call this method to
+ // choose the appropriate one.
+ void InitializeArbitrator(bool use_fake_delegate) {
+ delegate_.reset(use_fake_delegate ? new FakeDelegate()
+ : new GeolocationProvider::Delegate);
+ const LocationArbitratorImpl::LocationUpdateCallback callback =
base::Bind(&MockLocationObserver::OnLocationUpdate,
base::Unretained(observer_.get()));
- arbitrator_.reset(new TestingLocationArbitrator(
- callback, access_token_store_.get()));
- override_content_browser_client_.reset(new GeolocationContentBrowserClient);
+ arbitrator_.reset(
+ new TestingLocationArbitrator(callback, access_token_store_.get(),
+ delegate_.get(), use_fake_delegate));
}
// testing::Test
@@ -177,25 +200,27 @@ class GeolocationLocationArbitratorTest : public testing::Test {
}
MockLocationProvider* GetSystemLocationProviderOverride() {
- return override_content_browser_client_->provider_;
+ return static_cast<MockLocationProvider*>(
+ arbitrator_->GetLocationProvider());
}
scoped_refptr<FakeAccessTokenStore> access_token_store_;
std::unique_ptr<MockLocationObserver> observer_;
std::unique_ptr<TestingLocationArbitrator> arbitrator_;
+ std::unique_ptr<GeolocationProvider::Delegate> delegate_;
base::MessageLoop loop_;
- std::unique_ptr<GeolocationContentBrowserClient>
- override_content_browser_client_;
};
TEST_F(GeolocationLocationArbitratorTest, CreateDestroy) {
EXPECT_TRUE(access_token_store_.get());
+ InitializeArbitrator(true /* use_fake_delegate */);
EXPECT_TRUE(arbitrator_);
arbitrator_.reset();
SUCCEED();
}
TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) {
+ InitializeArbitrator(false /* use_fake_delegate */);
EXPECT_FALSE(arbitrator_->HasPermissionBeenGranted());
arbitrator_->OnPermissionGranted();
EXPECT_TRUE(arbitrator_->HasPermissionBeenGranted());
@@ -207,6 +232,7 @@ TEST_F(GeolocationLocationArbitratorTest, OnPermissionGranted) {
}
TEST_F(GeolocationLocationArbitratorTest, NormalUsage) {
+ InitializeArbitrator(false /* use_fake_delegate */);
ASSERT_TRUE(access_token_store_.get());
ASSERT_TRUE(arbitrator_);
@@ -243,18 +269,17 @@ TEST_F(GeolocationLocationArbitratorTest, NormalUsage) {
}
TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) {
- override_content_browser_client_->set_use_network(false);
- SetBrowserClientForTesting(override_content_browser_client_.get());
+ InitializeArbitrator(true /* use_fake_delegate */);
+ arbitrator_->GetFakeDelegate()->set_use_network(false);
ASSERT_TRUE(arbitrator_);
EXPECT_FALSE(cell());
EXPECT_FALSE(gps());
- EXPECT_FALSE(GetSystemLocationProviderOverride());
arbitrator_->StartProviders(false);
ASSERT_FALSE(cell());
EXPECT_FALSE(gps());
- EXPECT_TRUE(GetSystemLocationProviderOverride());
+ ASSERT_TRUE(GetSystemLocationProviderOverride());
EXPECT_EQ(MockLocationProvider::LOW_ACCURACY,
GetSystemLocationProviderOverride()->state_);
EXPECT_FALSE(observer_->last_position_.Validate());
@@ -277,13 +302,12 @@ TEST_F(GeolocationLocationArbitratorTest, CustomSystemProviderOnly) {
TEST_F(GeolocationLocationArbitratorTest,
CustomSystemAndDefaultNetworkProviders) {
- override_content_browser_client_->set_use_network(true);
- content::SetBrowserClientForTesting(override_content_browser_client_.get());
+ InitializeArbitrator(true /* use_fake_delegate */);
+ arbitrator_->GetFakeDelegate()->set_use_network(true);
ASSERT_TRUE(arbitrator_);
EXPECT_FALSE(cell());
EXPECT_FALSE(gps());
- EXPECT_FALSE(GetSystemLocationProviderOverride());
arbitrator_->StartProviders(false);
EXPECT_TRUE(access_token_store_->access_token_map_.empty());
@@ -292,7 +316,7 @@ TEST_F(GeolocationLocationArbitratorTest,
ASSERT_TRUE(cell());
EXPECT_FALSE(gps());
- EXPECT_TRUE(GetSystemLocationProviderOverride());
+ ASSERT_TRUE(GetSystemLocationProviderOverride());
EXPECT_EQ(MockLocationProvider::LOW_ACCURACY,
GetSystemLocationProviderOverride()->state_);
EXPECT_EQ(MockLocationProvider::LOW_ACCURACY, cell()->state_);
@@ -314,6 +338,7 @@ TEST_F(GeolocationLocationArbitratorTest,
}
TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) {
+ InitializeArbitrator(false /* use_fake_delegate */);
arbitrator_->StartProviders(false);
access_token_store_->NotifyDelegateTokensLoaded();
ASSERT_TRUE(cell());
@@ -331,6 +356,7 @@ TEST_F(GeolocationLocationArbitratorTest, SetObserverOptions) {
}
TEST_F(GeolocationLocationArbitratorTest, Arbitration) {
+ InitializeArbitrator(false /* use_fake_delegate */);
arbitrator_->StartProviders(false);
access_token_store_->NotifyDelegateTokensLoaded();
ASSERT_TRUE(cell());
@@ -408,6 +434,7 @@ TEST_F(GeolocationLocationArbitratorTest, Arbitration) {
}
TEST_F(GeolocationLocationArbitratorTest, TwoOneShotsIsNewPositionBetter) {
+ InitializeArbitrator(false /* use_fake_delegate */);
arbitrator_->StartProviders(false);
access_token_store_->NotifyDelegateTokensLoaded();
ASSERT_TRUE(cell());
« no previous file with comments | « content/browser/geolocation/location_arbitrator_impl.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698