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

Unified Diff: device/geolocation/rate_limiting_location_provider_proxy_unittest.cc

Issue 2249283003: Hooks together Geolocation Feature in the Client and Engine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lai
Patch Set: Addresses kmarshall's #16 comments. Created 4 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 side-by-side diff with in-line comments
Download patch
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..fd3fb100599a04eaf3d7f8e6e5a0e90c60f6d124
--- /dev/null
+++ b/device/geolocation/rate_limiting_location_provider_proxy_unittest.cc
@@ -0,0 +1,99 @@
+// 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))),
+ provider_proxy_(base::MakeUnique<RateLimitingLocationProviderProxy>()) {
+ provider_proxy_->SetLocationProviderForTest(
+ base::WrapUnique(location_provider_));
+ provider_proxy_->SetUpdateCallback(proxy_callback_);
+
+ EXPECT_CALL(*location_provider_, SetUpdateCallback(_))
+ .WillOnce(SaveArg<0>(&provider_callback_));
+ location_provider_->SetUpdateCallback(
+ base::Bind(&RateLimitingLocationProviderProxyTest::OnLocationUpdate,
+ base::Unretained(this)));
+ }
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698