| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "content/browser/browser_thread.h" | 5 #include "content/browser/browser_thread.h" |
| 6 #include "content/browser/geolocation/gps_location_provider_linux.h" | 6 #include "content/browser/geolocation/gps_location_provider_linux.h" |
| 7 #include "content/browser/geolocation/libgps_wrapper_linux.h" | 7 #include "content/browser/geolocation/libgps_wrapper_linux.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 struct gps_data_t { | 10 struct gps_data_t { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // Need to return a non-NULL value here to indicate success, however we don't | 75 // Need to return a non-NULL value here to indicate success, however we don't |
| 76 // need (or want) a valid pointer as it should never be dereferenced. | 76 // need (or want) a valid pointer as it should never be dereferenced. |
| 77 return static_cast<gps_data_t*>(NULL) + 1; | 77 return static_cast<gps_data_t*>(NULL) + 1; |
| 78 } | 78 } |
| 79 int gps_close_stub(gps_data_t*) { | 79 int gps_close_stub(gps_data_t*) { |
| 80 return 0; | 80 return 0; |
| 81 } | 81 } |
| 82 int gps_poll_stub(gps_data_t*) { | 82 int gps_poll_stub(gps_data_t*) { |
| 83 return 0; | 83 return 0; |
| 84 } | 84 } |
| 85 // v2.34 only | |
| 86 int gps_query_stub(gps_data_t*, const char*, ...) { | |
| 87 return 0; | |
| 88 } | |
| 89 // v2.90+ | 85 // v2.90+ |
| 90 int gps_stream_stub(gps_data_t*, unsigned int, void*) { | 86 int gps_stream_stub(gps_data_t*, unsigned int, void*) { |
| 91 return 0; | 87 return 0; |
| 92 } | 88 } |
| 93 bool gps_waiting_stub(gps_data_t*) { | 89 bool gps_waiting_stub(gps_data_t*) { |
| 94 return 0; | 90 return 0; |
| 95 } | 91 } |
| 96 | 92 |
| 97 void CheckValidPosition(const Geoposition& expected, | 93 void CheckValidPosition(const Geoposition& expected, |
| 98 const Geoposition& actual) { | 94 const Geoposition& actual) { |
| 99 EXPECT_TRUE(actual.IsValidFix()); | 95 EXPECT_TRUE(actual.IsValidFix()); |
| 100 EXPECT_DOUBLE_EQ(expected.latitude, actual.latitude); | 96 EXPECT_DOUBLE_EQ(expected.latitude, actual.latitude); |
| 101 EXPECT_DOUBLE_EQ(expected.longitude, actual.longitude); | 97 EXPECT_DOUBLE_EQ(expected.longitude, actual.longitude); |
| 102 EXPECT_DOUBLE_EQ(expected.accuracy, actual.accuracy); | 98 EXPECT_DOUBLE_EQ(expected.accuracy, actual.accuracy); |
| 103 } | 99 } |
| 104 | 100 |
| 105 MockLibGps* MockLibGps::g_instance_ = NULL; | 101 MockLibGps* MockLibGps::g_instance_ = NULL; |
| 106 | 102 |
| 107 MockLibGps::MockLibGps() | 103 MockLibGps::MockLibGps() |
| 108 : LibGps(new LibGpsLibraryWrapper(NULL, | 104 : LibGps(new LibGpsLibraryWrapper(NULL, |
| 109 gps_open_stub, | 105 gps_open_stub, |
| 110 gps_close_stub, | 106 gps_close_stub, |
| 111 gps_poll_stub, | 107 gps_poll_stub, |
| 112 gps_query_stub, | |
| 113 gps_stream_stub, | 108 gps_stream_stub, |
| 114 gps_waiting_stub)), | 109 gps_waiting_stub)), |
| 115 start_streaming_calls_(0), | 110 start_streaming_calls_(0), |
| 116 start_streaming_ret_(true), | 111 start_streaming_ret_(true), |
| 117 data_waiting_calls_(0), | 112 data_waiting_calls_(0), |
| 118 get_position_calls_(0), | 113 get_position_calls_(0), |
| 119 get_position_ret_(true) { | 114 get_position_ret_(true) { |
| 120 get_position_.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | 115 get_position_.error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
| 121 EXPECT_FALSE(g_instance_); | 116 EXPECT_FALSE(g_instance_); |
| 122 g_instance_ = this; | 117 g_instance_ = this; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 EXPECT_EQ(2, MockLibGps::g_instance_->get_position_calls_); | 180 EXPECT_EQ(2, MockLibGps::g_instance_->get_position_calls_); |
| 186 CheckValidPosition(MockLibGps::g_instance_->get_position_, position); | 181 CheckValidPosition(MockLibGps::g_instance_->get_position_, position); |
| 187 } | 182 } |
| 188 | 183 |
| 189 // TODO(joth): Add a test for LibGps::Start() returning false (i.e. gpsd not | 184 // TODO(joth): Add a test for LibGps::Start() returning false (i.e. gpsd not |
| 190 // running). Need to work around the 10s reconnect delay (either by injecting | 185 // running). Need to work around the 10s reconnect delay (either by injecting |
| 191 // a shorter retry interval, or adapt MessageLoop / Time::Now to be more test | 186 // a shorter retry interval, or adapt MessageLoop / Time::Now to be more test |
| 192 // friendly). | 187 // friendly). |
| 193 | 188 |
| 194 } // namespace | 189 } // namespace |
| OLD | NEW |