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 "blimp/common/create_blimp_message.h" | 12 #include "blimp/common/create_blimp_message.h" |
13 #include "blimp/common/proto/blimp_message.pb.h" | 13 #include "blimp/common/proto/blimp_message.pb.h" |
14 #include "blimp/common/proto/geolocation.pb.h" | 14 #include "blimp/common/proto/geolocation.pb.h" |
15 #include "blimp/net/test_common.h" | 15 #include "blimp/net/test_common.h" |
16 #include "device/geolocation/geolocation_delegate.h" | 16 #include "content/public/browser/location_provider.h" |
17 #include "device/geolocation/geoposition.h" | 17 #include "content/public/common/geoposition.h" |
18 #include "device/geolocation/location_provider.h" | |
19 #include "net/base/test_completion_callback.h" | 18 #include "net/base/test_completion_callback.h" |
20 #include "net/test/gtest_util.h" | 19 #include "net/test/gtest_util.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
23 | 22 |
24 using testing::_; | 23 using testing::_; |
25 | 24 |
26 namespace blimp { | 25 namespace blimp { |
27 namespace engine { | 26 namespace engine { |
28 | 27 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 mock_callback_( | 100 mock_callback_( |
102 base::Bind(&EngineGeolocationFeatureTest::OnLocationUpdate, | 101 base::Bind(&EngineGeolocationFeatureTest::OnLocationUpdate, |
103 base::Unretained(this))) {} | 102 base::Unretained(this))) {} |
104 | 103 |
105 void SetUp() override { | 104 void SetUp() override { |
106 out_processor_ = new MockBlimpMessageProcessor(); | 105 out_processor_ = new MockBlimpMessageProcessor(); |
107 feature_.set_outgoing_message_processor(base::WrapUnique(out_processor_)); | 106 feature_.set_outgoing_message_processor(base::WrapUnique(out_processor_)); |
108 location_provider_->SetUpdateCallback(mock_callback_); | 107 location_provider_->SetUpdateCallback(mock_callback_); |
109 } | 108 } |
110 | 109 |
111 void OnLocationUpdate(const device::LocationProvider* provider, | 110 void OnLocationUpdate(const content::LocationProvider* provider, |
112 const device::Geoposition& geoposition) { | 111 const content::Geoposition& geoposition) { |
113 received_position = geoposition; | 112 received_position = geoposition; |
114 } | 113 } |
115 | 114 |
116 protected: | 115 protected: |
117 // This is a raw pointer to a class that is owned by the GeolocationFeature. | 116 // This is a raw pointer to a class that is owned by the GeolocationFeature. |
118 MockBlimpMessageProcessor* out_processor_; | 117 MockBlimpMessageProcessor* out_processor_; |
119 | 118 |
120 EngineGeolocationFeature feature_; | 119 EngineGeolocationFeature feature_; |
121 std::unique_ptr<device::LocationProvider> location_provider_; | 120 std::unique_ptr<content::LocationProvider> location_provider_; |
122 device::LocationProvider::LocationProviderUpdateCallback mock_callback_; | 121 content::LocationProvider::LocationProviderUpdateCallback mock_callback_; |
123 device::Geoposition received_position; | 122 content::Geoposition received_position; |
124 }; | 123 }; |
125 | 124 |
126 TEST_F(EngineGeolocationFeatureTest, LocationReceived) { | 125 TEST_F(EngineGeolocationFeatureTest, LocationReceived) { |
127 SendMockLocationMessage(&feature_); | 126 SendMockLocationMessage(&feature_); |
128 EXPECT_EQ(device::Geoposition::ERROR_CODE_NONE, | 127 EXPECT_EQ(content::Geoposition::ERROR_CODE_NONE, |
129 received_position.error_code); | 128 received_position.error_code); |
130 EXPECT_EQ(-42.0, received_position.latitude); | 129 EXPECT_EQ(-42.0, received_position.latitude); |
131 EXPECT_EQ(17.3, received_position.longitude); | 130 EXPECT_EQ(17.3, received_position.longitude); |
132 EXPECT_EQ(123.4, received_position.altitude); | 131 EXPECT_EQ(123.4, received_position.altitude); |
133 EXPECT_EQ(73.7, received_position.accuracy); | 132 EXPECT_EQ(73.7, received_position.accuracy); |
134 } | 133 } |
135 | 134 |
136 TEST_F(EngineGeolocationFeatureTest, ErrorRecieved) { | 135 TEST_F(EngineGeolocationFeatureTest, ErrorRecieved) { |
137 SendMockErrorMessage(&feature_, GeolocationErrorMessage::PERMISSION_DENIED, | 136 SendMockErrorMessage(&feature_, GeolocationErrorMessage::PERMISSION_DENIED, |
138 "PERMISSION_DENIED"); | 137 "PERMISSION_DENIED"); |
139 EXPECT_EQ(device::Geoposition::ERROR_CODE_PERMISSION_DENIED, | 138 EXPECT_EQ(content::Geoposition::ERROR_CODE_PERMISSION_DENIED, |
140 received_position.error_code); | 139 received_position.error_code); |
141 EXPECT_EQ("PERMISSION_DENIED", received_position.error_message); | 140 EXPECT_EQ("PERMISSION_DENIED", received_position.error_message); |
142 | 141 |
143 SendMockErrorMessage(&feature_, GeolocationErrorMessage::POSITION_UNAVAILABLE, | 142 SendMockErrorMessage(&feature_, GeolocationErrorMessage::POSITION_UNAVAILABLE, |
144 "POSITION_UNAVAILABLE"); | 143 "POSITION_UNAVAILABLE"); |
145 EXPECT_EQ(device::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE, | 144 EXPECT_EQ(content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE, |
146 received_position.error_code); | 145 received_position.error_code); |
147 EXPECT_EQ("POSITION_UNAVAILABLE", received_position.error_message); | 146 EXPECT_EQ("POSITION_UNAVAILABLE", received_position.error_message); |
148 } | 147 } |
149 | 148 |
150 TEST_F(EngineGeolocationFeatureTest, UpdateRequestLevel) { | 149 TEST_F(EngineGeolocationFeatureTest, UpdateRequestLevel) { |
151 EXPECT_CALL(*out_processor_, | 150 EXPECT_CALL(*out_processor_, |
152 MockableProcessMessage( | 151 MockableProcessMessage( |
153 EqualsUpdatedRequestLevel( | 152 EqualsUpdatedRequestLevel( |
154 GeolocationSetInterestLevelMessage::HIGH_ACCURACY), | 153 GeolocationSetInterestLevelMessage::HIGH_ACCURACY), |
155 _)) | 154 _)) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 GeolocationSetInterestLevelMessage::NO_INTEREST), | 196 GeolocationSetInterestLevelMessage::NO_INTEREST), |
198 _)) | 197 _)) |
199 .Times(1); | 198 .Times(1); |
200 | 199 |
201 location_provider_->StartProvider(true); | 200 location_provider_->StartProvider(true); |
202 location_provider_->RequestRefresh(); | 201 location_provider_->RequestRefresh(); |
203 } | 202 } |
204 | 203 |
205 } // namespace engine | 204 } // namespace engine |
206 } // namespace blimp | 205 } // namespace blimp |
OLD | NEW |