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

Side by Side Diff: blimp/client/core/geolocation/geolocation_feature_unittest.cc

Issue 2331513002: Checks to see if the position is valid before OnLocationUpdate call. (Closed)
Patch Set: Fixes up tests. 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "blimp/client/core/geolocation/geolocation_feature.h" 5 #include "blimp/client/core/geolocation/geolocation_feature.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "blimp/common/create_blimp_message.h" 11 #include "blimp/common/create_blimp_message.h"
12 #include "blimp/common/proto/blimp_message.pb.h" 12 #include "blimp/common/proto/blimp_message.pb.h"
13 #include "blimp/net/test_common.h" 13 #include "blimp/net/test_common.h"
14 #include "device/geolocation/geoposition.h" 14 #include "device/geolocation/geoposition.h"
15 #include "device/geolocation/location_provider.h" 15 #include "device/geolocation/location_provider.h"
16 #include "device/geolocation/mock_location_provider.h" 16 #include "device/geolocation/mock_location_provider.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/base/test_completion_callback.h" 18 #include "net/base/test_completion_callback.h"
19 #include "net/test/gtest_util.h" 19 #include "net/test/gtest_util.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 using testing::InSequence; 22 using testing::InSequence;
23 using testing::Invoke; 23 using testing::Invoke;
24 using testing::ReturnRef;
24 using testing::SaveArg; 25 using testing::SaveArg;
25 using testing::StrictMock; 26 using testing::StrictMock;
26 using testing::_; 27 using testing::_;
27 28
28 namespace blimp { 29 namespace blimp {
29 namespace client { 30 namespace client {
30 31
31 const double kLatitude = -42.0; 32 const double kLatitude = -42.0;
32 const double kLongitude = 17.3; 33 const double kLongitude = 17.3;
33 const double kAltitude = 123.4; 34 const double kAltitude = 123.4;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 EXPECT_CALL( 173 EXPECT_CALL(
173 *out_processor_, 174 *out_processor_,
174 MockableProcessMessage( 175 MockableProcessMessage(
175 EqualsError(GeolocationErrorMessage::POSITION_UNAVAILABLE), _)); 176 EqualsError(GeolocationErrorMessage::POSITION_UNAVAILABLE), _));
176 EXPECT_CALL(*out_processor_, 177 EXPECT_CALL(*out_processor_,
177 MockableProcessMessage( 178 MockableProcessMessage(
178 EqualsError(GeolocationErrorMessage::PERMISSION_DENIED), _)); 179 EqualsError(GeolocationErrorMessage::PERMISSION_DENIED), _));
179 EXPECT_CALL( 180 EXPECT_CALL(
180 *out_processor_, 181 *out_processor_,
181 MockableProcessMessage(EqualsError(GeolocationErrorMessage::TIMEOUT), _)); 182 MockableProcessMessage(EqualsError(GeolocationErrorMessage::TIMEOUT), _));
183 EXPECT_CALL(*location_provider_, GetPosition()).Times(3)
184 .WillRepeatedly(ReturnRef(position_));
182 185
183 device::Geoposition err_position; 186 device::Geoposition err_position;
184 err_position.error_code = 187 err_position.error_code =
185 device::Geoposition::ErrorCode::ERROR_CODE_POSITION_UNAVAILABLE; 188 device::Geoposition::ErrorCode::ERROR_CODE_POSITION_UNAVAILABLE;
186 callback_.Run(location_provider_, err_position); 189 callback_.Run(location_provider_, err_position);
187 190
188 err_position.error_code = 191 err_position.error_code =
189 device::Geoposition::ErrorCode::ERROR_CODE_PERMISSION_DENIED; 192 device::Geoposition::ErrorCode::ERROR_CODE_PERMISSION_DENIED;
190 callback_.Run(location_provider_, err_position); 193 callback_.Run(location_provider_, err_position);
191 194
192 err_position.error_code = device::Geoposition::ErrorCode::ERROR_CODE_TIMEOUT; 195 err_position.error_code = device::Geoposition::ErrorCode::ERROR_CODE_TIMEOUT;
193 callback_.Run(location_provider_, err_position); 196 callback_.Run(location_provider_, err_position);
194 } 197 }
195 198
196 TEST_F(GeolocationFeatureTest, NoRepeatSendsWithMessagePending) { 199 TEST_F(GeolocationFeatureTest, NoRepeatSendsWithMessagePending) {
197 EXPECT_CALL(*out_processor_, 200 EXPECT_CALL(*out_processor_,
198 MockableProcessMessage(EqualsDefaultGeoposition(), _)); 201 MockableProcessMessage(EqualsDefaultGeoposition(), _));
199 callback_.Run(location_provider_, position_); 202 callback_.Run(location_provider_, position_);
200 callback_.Run(location_provider_, position_); 203 callback_.Run(location_provider_, position_);
201 callback_.Run(location_provider_, position_); 204 callback_.Run(location_provider_, position_);
202 } 205 }
203 206
204 TEST_F(GeolocationFeatureTest, MessageSendsAfterAcknowledgement) { 207 TEST_F(GeolocationFeatureTest, MessageSendsAfterAcknowledgement) {
205 EXPECT_CALL(*out_processor_, 208 EXPECT_CALL(*out_processor_,
206 MockableProcessMessage(EqualsDefaultGeoposition(), _)) 209 MockableProcessMessage(EqualsDefaultGeoposition(), _))
207 .WillOnce(Invoke( 210 .WillOnce(Invoke(
208 this, &GeolocationFeatureTest_MessageSendsAfterAcknowledgement_Test:: 211 this, &GeolocationFeatureTest_MessageSendsAfterAcknowledgement_Test::
209 ReportProcessMessageSuccess)); 212 ReportProcessMessageSuccess));
213
210 device::Geoposition position; 214 device::Geoposition position;
211 position.latitude = 1.0; 215 position.latitude = 1.0;
212 position.longitude = 1.0; 216 position.longitude = 1.0;
213 position.altitude = 1.0; 217 position.altitude = 1.0;
214 position.accuracy = 1.0; 218 position.accuracy = 1.0;
219 position.timestamp = base::Time::Now();
220 EXPECT_CALL(*location_provider_, GetPosition()).WillOnce(ReturnRef(position));
221
215 EXPECT_CALL(*out_processor_, 222 EXPECT_CALL(*out_processor_,
216 MockableProcessMessage(EqualGeoposition(1.0, 1.0, 1.0, 1.0), _)); 223 MockableProcessMessage(EqualGeoposition(1.0, 1.0, 1.0, 1.0), _));
217 callback_.Run(location_provider_, position_); 224 callback_.Run(location_provider_, position_);
218 callback_.Run(location_provider_, position); 225 callback_.Run(location_provider_, position);
219 } 226 }
220 227
221 TEST_F(GeolocationFeatureTest, ProcessMessageHandlesNullCallback) { 228 TEST_F(GeolocationFeatureTest, ProcessMessageHandlesNullCallback) {
222 EXPECT_CALL(*location_provider_, OnPermissionGranted()); 229 EXPECT_CALL(*location_provider_, OnPermissionGranted());
223 230
224 GeolocationMessage* geolocation_message; 231 GeolocationMessage* geolocation_message;
225 std::unique_ptr<BlimpMessage> message = 232 std::unique_ptr<BlimpMessage> message =
226 CreateBlimpMessage(&geolocation_message); 233 CreateBlimpMessage(&geolocation_message);
227 geolocation_message->mutable_request_refresh(); 234 geolocation_message->mutable_request_refresh();
228 235
229 feature_->ProcessMessage(std::move(message), net::CompletionCallback()); 236 feature_->ProcessMessage(std::move(message), net::CompletionCallback());
230 } 237 }
231 238
232 } // namespace client 239 } // namespace client
233 } // namespace blimp 240 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698