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

Side by Side 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: Merge with master. Created 4 years, 3 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "device/geolocation/rate_limiting_location_provider_proxy.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "base/bind.h"
11 #include "base/memory/ptr_util.h"
12 #include "device/geolocation/mock_location_provider.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using ::testing::ReturnRef;
17 using ::testing::SaveArg;
18 using ::testing::StrictMock;
19 using ::testing::_;
20
21 namespace device {
22
23 class RateLimitingLocationProviderProxyTest : public testing::Test {
24 public:
25 RateLimitingLocationProviderProxyTest()
26 : location_provider_(new StrictMock<MockLocationProvider>),
27 proxy_callback_(
28 base::Bind(&RateLimitingLocationProviderProxyTest::OnLocationUpdate,
29 base::Unretained(this))) {
30 EXPECT_CALL(*location_provider_, SetUpdateCallback(_))
31 .WillOnce(SaveArg<0>(&provider_callback_));
32 provider_proxy_ = base::MakeUnique<RateLimitingLocationProviderProxy>(
33 base::WrapUnique(location_provider_));
34 provider_proxy_->SetUpdateCallback(proxy_callback_);
35 }
36
37 protected:
38 Geoposition cur_position_;
39 StrictMock<MockLocationProvider>* location_provider_ = nullptr;
40 LocationProvider::LocationProviderUpdateCallback proxy_callback_;
41 LocationProvider::LocationProviderUpdateCallback provider_callback_;
42 std::unique_ptr<RateLimitingLocationProviderProxy> provider_proxy_;
43
44 void OnLocationUpdate(const LocationProvider* provider,
45 const Geoposition& position) {
46 cur_position_ = position;
47 }
48
49 private:
50 DISALLOW_COPY_AND_ASSIGN(RateLimitingLocationProviderProxyTest);
51 };
52
53 TEST_F(RateLimitingLocationProviderProxyTest, StartLocationProvider) {
54 EXPECT_CALL(*location_provider_, StartProvider(false));
55 EXPECT_CALL(*location_provider_, StartProvider(true));
56
57 provider_proxy_->StartProvider(false);
58 provider_proxy_->StartProvider(true);
59 }
60
61 TEST_F(RateLimitingLocationProviderProxyTest, StopLocationProvider) {
62 EXPECT_CALL(*location_provider_, StopProvider());
63
64 provider_proxy_->StopProvider();
65 }
66
67 TEST_F(RateLimitingLocationProviderProxyTest, GetPosition) {
68 Geoposition position;
69 position.latitude = 38.0;
70 EXPECT_CALL(*location_provider_, GetPosition()).WillOnce(ReturnRef(position));
71 Geoposition received_position = provider_proxy_->GetPosition();
72 EXPECT_EQ(38.0, received_position.latitude);
73 }
74
75 TEST_F(RateLimitingLocationProviderProxyTest, PermissionGranted) {
76 EXPECT_CALL(*location_provider_, OnPermissionGranted());
77
78 provider_proxy_->OnPermissionGranted();
79 }
80
81 TEST_F(RateLimitingLocationProviderProxyTest, LocationUpdated) {
82 Geoposition position;
83 position.latitude = 5.0;
84 position.longitude = 4.0;
85 position.altitude = 3.0;
86 position.accuracy = 2.0;
87 provider_callback_.Run(provider_proxy_.get(), position);
88 EXPECT_EQ(5.0, cur_position_.latitude);
89 EXPECT_EQ(4.0, cur_position_.longitude);
90 EXPECT_EQ(3.0, cur_position_.altitude);
91 EXPECT_EQ(2.0, cur_position_.accuracy);
92 }
93
94 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698