| Index: device/geolocation/rate_limiting_location_provider_proxy_unittest.cc
|
| diff --git a/device/geolocation/rate_limiting_location_provider_proxy_unittest.cc b/device/geolocation/rate_limiting_location_provider_proxy_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4ab6398b6f1f34efa7ad50c1bd6a1b1736cf1182
|
| --- /dev/null
|
| +++ b/device/geolocation/rate_limiting_location_provider_proxy_unittest.cc
|
| @@ -0,0 +1,94 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "device/geolocation/rate_limiting_location_provider_proxy.h"
|
| +
|
| +#include <memory>
|
| +#include <utility>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "device/geolocation/mock_location_provider.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using ::testing::ReturnRef;
|
| +using ::testing::SaveArg;
|
| +using ::testing::StrictMock;
|
| +using ::testing::_;
|
| +
|
| +namespace device {
|
| +
|
| +class RateLimitingLocationProviderProxyTest : public testing::Test {
|
| + public:
|
| + RateLimitingLocationProviderProxyTest()
|
| + : location_provider_(new StrictMock<MockLocationProvider>),
|
| + proxy_callback_(
|
| + base::Bind(&RateLimitingLocationProviderProxyTest::OnLocationUpdate,
|
| + base::Unretained(this))) {
|
| + EXPECT_CALL(*location_provider_, SetUpdateCallback(_))
|
| + .WillOnce(SaveArg<0>(&provider_callback_));
|
| + provider_proxy_ = base::MakeUnique<RateLimitingLocationProviderProxy>(
|
| + base::WrapUnique(location_provider_));
|
| + provider_proxy_->SetUpdateCallback(proxy_callback_);
|
| + }
|
| +
|
| + protected:
|
| + Geoposition cur_position_;
|
| + StrictMock<MockLocationProvider>* location_provider_ = nullptr;
|
| + LocationProvider::LocationProviderUpdateCallback proxy_callback_;
|
| + LocationProvider::LocationProviderUpdateCallback provider_callback_;
|
| + std::unique_ptr<RateLimitingLocationProviderProxy> provider_proxy_;
|
| +
|
| + void OnLocationUpdate(const LocationProvider* provider,
|
| + const Geoposition& position) {
|
| + cur_position_ = position;
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(RateLimitingLocationProviderProxyTest);
|
| +};
|
| +
|
| +TEST_F(RateLimitingLocationProviderProxyTest, StartLocationProvider) {
|
| + EXPECT_CALL(*location_provider_, StartProvider(false));
|
| + EXPECT_CALL(*location_provider_, StartProvider(true));
|
| +
|
| + provider_proxy_->StartProvider(false);
|
| + provider_proxy_->StartProvider(true);
|
| +}
|
| +
|
| +TEST_F(RateLimitingLocationProviderProxyTest, StopLocationProvider) {
|
| + EXPECT_CALL(*location_provider_, StopProvider());
|
| +
|
| + provider_proxy_->StopProvider();
|
| +}
|
| +
|
| +TEST_F(RateLimitingLocationProviderProxyTest, GetPosition) {
|
| + Geoposition position;
|
| + position.latitude = 38.0;
|
| + EXPECT_CALL(*location_provider_, GetPosition()).WillOnce(ReturnRef(position));
|
| + Geoposition received_position = provider_proxy_->GetPosition();
|
| + EXPECT_EQ(38.0, received_position.latitude);
|
| +}
|
| +
|
| +TEST_F(RateLimitingLocationProviderProxyTest, PermissionGranted) {
|
| + EXPECT_CALL(*location_provider_, OnPermissionGranted());
|
| +
|
| + provider_proxy_->OnPermissionGranted();
|
| +}
|
| +
|
| +TEST_F(RateLimitingLocationProviderProxyTest, LocationUpdated) {
|
| + Geoposition position;
|
| + position.latitude = 5.0;
|
| + position.longitude = 4.0;
|
| + position.altitude = 3.0;
|
| + position.accuracy = 2.0;
|
| + provider_callback_.Run(provider_proxy_.get(), position);
|
| + EXPECT_EQ(5.0, cur_position_.latitude);
|
| + EXPECT_EQ(4.0, cur_position_.longitude);
|
| + EXPECT_EQ(3.0, cur_position_.altitude);
|
| + EXPECT_EQ(2.0, cur_position_.accuracy);
|
| +}
|
| +
|
| +} // namespace device
|
|
|