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