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

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: 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 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 provider_proxy_(base::MakeUnique<RateLimitingLocationProviderProxy>()) {
31 provider_proxy_->SetLocationProviderForTest(
32 base::WrapUnique(location_provider_));
33 provider_proxy_->SetUpdateCallback(proxy_callback_);
34
35 EXPECT_CALL(*location_provider_, SetUpdateCallback(_))
36 .WillOnce(SaveArg<0>(&provider_callback_));
37 location_provider_->SetUpdateCallback(
38 base::Bind(&RateLimitingLocationProviderProxyTest::OnLocationUpdate,
39 base::Unretained(this)));
40 }
41
42 protected:
43 Geoposition cur_position_;
44 StrictMock<MockLocationProvider>* location_provider_ = nullptr;
45 LocationProvider::LocationProviderUpdateCallback proxy_callback_;
46 LocationProvider::LocationProviderUpdateCallback provider_callback_;
47 std::unique_ptr<RateLimitingLocationProviderProxy> provider_proxy_;
48
49 void OnLocationUpdate(const LocationProvider* provider,
50 const Geoposition& position) {
51 cur_position_ = position;
52 }
53
54 private:
55 DISALLOW_COPY_AND_ASSIGN(RateLimitingLocationProviderProxyTest);
56 };
57
58 TEST_F(RateLimitingLocationProviderProxyTest, StartLocationProvider) {
59 EXPECT_CALL(*location_provider_, StartProvider(false));
60 EXPECT_CALL(*location_provider_, StartProvider(true));
61
62 provider_proxy_->StartProvider(false);
63 provider_proxy_->StartProvider(true);
64 }
65
66 TEST_F(RateLimitingLocationProviderProxyTest, StopLocationProvider) {
67 EXPECT_CALL(*location_provider_, StopProvider());
68
69 provider_proxy_->StopProvider();
70 }
71
72 TEST_F(RateLimitingLocationProviderProxyTest, GetPosition) {
73 Geoposition position;
74 position.latitude = 38.0;
75 EXPECT_CALL(*location_provider_, GetPosition()).WillOnce(ReturnRef(position));
76 Geoposition received_position = provider_proxy_->GetPosition();
77 EXPECT_EQ(38.0, received_position.latitude);
78 }
79
80 TEST_F(RateLimitingLocationProviderProxyTest, PermissionGranted) {
81 EXPECT_CALL(*location_provider_, OnPermissionGranted());
82
83 provider_proxy_->OnPermissionGranted();
84 }
85
86 TEST_F(RateLimitingLocationProviderProxyTest, LocationUpdated) {
87 Geoposition position;
88 position.latitude = 5.0;
89 position.longitude = 4.0;
90 position.altitude = 3.0;
91 position.accuracy = 2.0;
92 provider_callback_.Run(provider_proxy_.get(), position);
93 EXPECT_EQ(5.0, cur_position_.latitude);
94 EXPECT_EQ(4.0, cur_position_.longitude);
95 EXPECT_EQ(3.0, cur_position_.altitude);
96 EXPECT_EQ(2.0, cur_position_.accuracy);
97 }
98
99 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698