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

Side by Side Diff: blimp/engine/feature/geolocation/engine_geolocation_feature_unittest.cc

Issue 2328453003: Makes use of EngineGeolocationFeature weak_ptr threadsafe. (Closed)
Patch Set: Addresses Wez's #23 comments. Created 4 years, 2 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/engine/feature/geolocation/engine_geolocation_feature.h" 5 #include "blimp/engine/feature/geolocation/engine_geolocation_feature.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 location_provider_(feature_.CreateGeolocationDelegate() 103 location_provider_(feature_.CreateGeolocationDelegate()
104 ->OverrideSystemLocationProvider()), 104 ->OverrideSystemLocationProvider()),
105 mock_callback_( 105 mock_callback_(
106 base::Bind(&EngineGeolocationFeatureTest::OnLocationUpdate, 106 base::Bind(&EngineGeolocationFeatureTest::OnLocationUpdate,
107 base::Unretained(this))) {} 107 base::Unretained(this))) {}
108 108
109 void SetUp() override { 109 void SetUp() override {
110 out_processor_ = new MockBlimpMessageProcessor(); 110 out_processor_ = new MockBlimpMessageProcessor();
111 feature_.set_outgoing_message_processor(base::WrapUnique(out_processor_)); 111 feature_.set_outgoing_message_processor(base::WrapUnique(out_processor_));
112 location_provider_->SetUpdateCallback(mock_callback_); 112 location_provider_->SetUpdateCallback(mock_callback_);
113 base::RunLoop().RunUntilIdle();
113 } 114 }
114 115
115 void OnLocationUpdate(const device::LocationProvider* provider, 116 void OnLocationUpdate(const device::LocationProvider* provider,
116 const device::Geoposition& geoposition) { 117 const device::Geoposition& geoposition) {
117 received_position = geoposition; 118 received_position = geoposition;
118 } 119 }
119 120
120 protected: 121 protected:
121 // This is a raw pointer to a class that is owned by the GeolocationFeature. 122 // This is a raw pointer to a class that is owned by the GeolocationFeature.
122 MockBlimpMessageProcessor* out_processor_; 123 MockBlimpMessageProcessor* out_processor_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 EXPECT_CALL(*out_processor_, 172 EXPECT_CALL(*out_processor_,
172 MockableProcessMessage( 173 MockableProcessMessage(
173 EqualsUpdatedRequestLevel( 174 EqualsUpdatedRequestLevel(
174 GeolocationSetInterestLevelMessage::NO_INTEREST), 175 GeolocationSetInterestLevelMessage::NO_INTEREST),
175 _)) 176 _))
176 .Times(1); 177 .Times(1);
177 178
178 location_provider_->StartProvider(true); 179 location_provider_->StartProvider(true);
179 location_provider_->StartProvider(false); 180 location_provider_->StartProvider(false);
180 location_provider_->StopProvider(); 181 location_provider_->StopProvider();
182 base::RunLoop().RunUntilIdle();
181 } 183 }
182 184
183 TEST_F(EngineGeolocationFeatureTest, UnexpectedMessageReceived) { 185 TEST_F(EngineGeolocationFeatureTest, UnexpectedMessageReceived) {
184 std::unique_ptr<BlimpMessage> message = CreateUnexpectedMessage(); 186 std::unique_ptr<BlimpMessage> message = CreateUnexpectedMessage();
185 net::TestCompletionCallback cb; 187 net::TestCompletionCallback cb;
186 feature_.ProcessMessage(std::move(message), cb.callback()); 188 feature_.ProcessMessage(std::move(message), cb.callback());
187 189
188 EXPECT_EQ(net::ERR_UNEXPECTED, cb.WaitForResult()); 190 EXPECT_EQ(net::ERR_UNEXPECTED, cb.WaitForResult());
189 } 191 }
190 192
191 TEST_F(EngineGeolocationFeatureTest, 193 TEST_F(EngineGeolocationFeatureTest,
192 OnPermissionGrantedTriggersRefreshRequest) { 194 OnPermissionGrantedTriggersRefreshRequest) {
193 EXPECT_CALL(*out_processor_, 195 EXPECT_CALL(*out_processor_,
194 MockableProcessMessage( 196 MockableProcessMessage(
195 EqualsUpdatedRequestLevel( 197 EqualsUpdatedRequestLevel(
196 GeolocationSetInterestLevelMessage::HIGH_ACCURACY), 198 GeolocationSetInterestLevelMessage::HIGH_ACCURACY),
197 _)) 199 _))
198 .Times(1); 200 .Times(1);
199 201
200 EXPECT_CALL(*out_processor_, 202 EXPECT_CALL(*out_processor_,
201 MockableProcessMessage(EqualsRequestRefresh(), _)) 203 MockableProcessMessage(EqualsRequestRefresh(), _))
202 .Times(1); 204 .Times(1);
203 EXPECT_CALL(*out_processor_,
204 MockableProcessMessage(
205 EqualsUpdatedRequestLevel(
206 GeolocationSetInterestLevelMessage::NO_INTEREST),
207 _))
208 .Times(1);
209 205
210 location_provider_->StartProvider(true); 206 location_provider_->StartProvider(true);
211 location_provider_->OnPermissionGranted(); 207 location_provider_->OnPermissionGranted();
208 base::RunLoop().RunUntilIdle();
212 } 209 }
213 210
214 } // namespace engine 211 } // namespace engine
215 } // namespace blimp 212 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698