| OLD | NEW |
| 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 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/run_loop.h" |
| 12 #include "blimp/common/create_blimp_message.h" | 14 #include "blimp/common/create_blimp_message.h" |
| 13 #include "blimp/common/proto/blimp_message.pb.h" | 15 #include "blimp/common/proto/blimp_message.pb.h" |
| 14 #include "blimp/common/proto/geolocation.pb.h" | 16 #include "blimp/common/proto/geolocation.pb.h" |
| 15 #include "blimp/net/test_common.h" | 17 #include "blimp/net/test_common.h" |
| 16 #include "device/geolocation/geolocation_delegate.h" | 18 #include "device/geolocation/geolocation_delegate.h" |
| 17 #include "device/geolocation/geoposition.h" | 19 #include "device/geolocation/geoposition.h" |
| 18 #include "device/geolocation/location_provider.h" | 20 #include "device/geolocation/location_provider.h" |
| 19 #include "net/base/test_completion_callback.h" | 21 #include "net/base/test_completion_callback.h" |
| 20 #include "net/test/gtest_util.h" | 22 #include "net/test/gtest_util.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 GeolocationCoordinatesMessage* coordinates_message = | 36 GeolocationCoordinatesMessage* coordinates_message = |
| 35 geolocation_message->mutable_coordinates(); | 37 geolocation_message->mutable_coordinates(); |
| 36 coordinates_message->set_latitude(-42.0); | 38 coordinates_message->set_latitude(-42.0); |
| 37 coordinates_message->set_longitude(17.3); | 39 coordinates_message->set_longitude(17.3); |
| 38 coordinates_message->set_altitude(123.4); | 40 coordinates_message->set_altitude(123.4); |
| 39 coordinates_message->set_accuracy(73.7); | 41 coordinates_message->set_accuracy(73.7); |
| 40 | 42 |
| 41 net::TestCompletionCallback cb; | 43 net::TestCompletionCallback cb; |
| 42 processor->ProcessMessage(std::move(message), cb.callback()); | 44 processor->ProcessMessage(std::move(message), cb.callback()); |
| 43 EXPECT_EQ(net::OK, cb.WaitForResult()); | 45 EXPECT_EQ(net::OK, cb.WaitForResult()); |
| 46 base::RunLoop().RunUntilIdle(); |
| 44 } | 47 } |
| 45 | 48 |
| 46 void SendMockErrorMessage(BlimpMessageProcessor* processor, | 49 void SendMockErrorMessage(BlimpMessageProcessor* processor, |
| 47 GeolocationErrorMessage::ErrorCode error, | 50 GeolocationErrorMessage::ErrorCode error, |
| 48 std::string error_message) { | 51 std::string error_message) { |
| 49 GeolocationMessage* geolocation_message; | 52 GeolocationMessage* geolocation_message; |
| 50 std::unique_ptr<BlimpMessage> message = | 53 std::unique_ptr<BlimpMessage> message = |
| 51 CreateBlimpMessage(&geolocation_message); | 54 CreateBlimpMessage(&geolocation_message); |
| 52 GeolocationErrorMessage* geolocation_error_message = | 55 GeolocationErrorMessage* geolocation_error_message = |
| 53 geolocation_message->mutable_error(); | 56 geolocation_message->mutable_error(); |
| 54 geolocation_error_message->set_error_code(error); | 57 geolocation_error_message->set_error_code(error); |
| 55 geolocation_error_message->set_error_message(error_message); | 58 geolocation_error_message->set_error_message(error_message); |
| 56 | 59 |
| 57 net::TestCompletionCallback cb; | 60 net::TestCompletionCallback cb; |
| 58 processor->ProcessMessage(std::move(message), cb.callback()); | 61 processor->ProcessMessage(std::move(message), cb.callback()); |
| 59 EXPECT_EQ(net::OK, cb.WaitForResult()); | 62 EXPECT_EQ(net::OK, cb.WaitForResult()); |
| 63 base::RunLoop().RunUntilIdle(); |
| 60 } | 64 } |
| 61 | 65 |
| 62 void SendMalformedMessage(BlimpMessageProcessor* processor) { | 66 void SendMalformedMessage(BlimpMessageProcessor* processor) { |
| 63 GeolocationMessage* geolocation_message; | 67 GeolocationMessage* geolocation_message; |
| 64 std::unique_ptr<BlimpMessage> message = | 68 std::unique_ptr<BlimpMessage> message = |
| 65 CreateBlimpMessage(&geolocation_message); | 69 CreateBlimpMessage(&geolocation_message); |
| 66 | 70 |
| 67 net::TestCompletionCallback cb; | 71 net::TestCompletionCallback cb; |
| 68 processor->ProcessMessage(std::move(message), cb.callback()); | 72 processor->ProcessMessage(std::move(message), cb.callback()); |
| 69 EXPECT_EQ(net::OK, cb.WaitForResult()); | 73 EXPECT_EQ(net::OK, cb.WaitForResult()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 114 |
| 111 void OnLocationUpdate(const device::LocationProvider* provider, | 115 void OnLocationUpdate(const device::LocationProvider* provider, |
| 112 const device::Geoposition& geoposition) { | 116 const device::Geoposition& geoposition) { |
| 113 received_position = geoposition; | 117 received_position = geoposition; |
| 114 } | 118 } |
| 115 | 119 |
| 116 protected: | 120 protected: |
| 117 // This is a raw pointer to a class that is owned by the GeolocationFeature. | 121 // This is a raw pointer to a class that is owned by the GeolocationFeature. |
| 118 MockBlimpMessageProcessor* out_processor_; | 122 MockBlimpMessageProcessor* out_processor_; |
| 119 | 123 |
| 124 // Runs tasks posted during the processing of incoming messages. |
| 125 base::MessageLoop message_loop_; |
| 126 |
| 120 EngineGeolocationFeature feature_; | 127 EngineGeolocationFeature feature_; |
| 121 std::unique_ptr<device::LocationProvider> location_provider_; | 128 std::unique_ptr<device::LocationProvider> location_provider_; |
| 122 device::LocationProvider::LocationProviderUpdateCallback mock_callback_; | 129 device::LocationProvider::LocationProviderUpdateCallback mock_callback_; |
| 123 device::Geoposition received_position; | 130 device::Geoposition received_position; |
| 124 }; | 131 }; |
| 125 | 132 |
| 126 TEST_F(EngineGeolocationFeatureTest, LocationReceived) { | 133 TEST_F(EngineGeolocationFeatureTest, LocationReceived) { |
| 127 SendMockLocationMessage(&feature_); | 134 SendMockLocationMessage(&feature_); |
| 128 EXPECT_EQ(device::Geoposition::ERROR_CODE_NONE, | 135 EXPECT_EQ(device::Geoposition::ERROR_CODE_NONE, |
| 129 received_position.error_code); | 136 received_position.error_code); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 GeolocationSetInterestLevelMessage::NO_INTEREST), | 205 GeolocationSetInterestLevelMessage::NO_INTEREST), |
| 199 _)) | 206 _)) |
| 200 .Times(1); | 207 .Times(1); |
| 201 | 208 |
| 202 location_provider_->StartProvider(true); | 209 location_provider_->StartProvider(true); |
| 203 location_provider_->OnPermissionGranted(); | 210 location_provider_->OnPermissionGranted(); |
| 204 } | 211 } |
| 205 | 212 |
| 206 } // namespace engine | 213 } // namespace engine |
| 207 } // namespace blimp | 214 } // namespace blimp |
| OLD | NEW |