| 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 <Objbase.h> |
| 6 |
| 5 #include <algorithm> | 7 #include <algorithm> |
| 6 #include <cmath> | 8 #include <cmath> |
| 7 #include <Objbase.h> | |
| 8 | 9 |
| 9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "base/win_util.h" | 15 #include "base/win_util.h" |
| 15 #include "chrome/common/geoposition.h" | 16 #include "chrome/common/geoposition.h" |
| 16 #include "chrome/browser/browser_thread.h" | |
| 17 #include "chrome/browser/geolocation/win7_location_api_win.h" | 17 #include "chrome/browser/geolocation/win7_location_api_win.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 using testing::_; | 21 using testing::_; |
| 22 using testing::AtLeast; | 22 using testing::AtLeast; |
| 23 using testing::DoDefault; | 23 using testing::DoDefault; |
| 24 using testing::Invoke; | 24 using testing::Invoke; |
| 25 using testing::Return; | 25 using testing::Return; |
| 26 | 26 |
| 27 class MockLatLongReport : public ILatLongReport { | 27 class MockLatLongReport : public ILatLongReport { |
| 28 public: | 28 public: |
| 29 MockLatLongReport() : ref_count_(1) { | 29 MockLatLongReport() : ref_count_(1) { |
| 30 ON_CALL(*this, GetAltitude(_)) | 30 ON_CALL(*this, GetAltitude(_)) |
| 31 .WillByDefault(Invoke(this, &MockLatLongReport::GetAltitudeValid)); | 31 .WillByDefault(Invoke(this, &MockLatLongReport::GetAltitudeValid)); |
| 32 ON_CALL(*this, GetAltitudeError(_)) | 32 ON_CALL(*this, GetAltitudeError(_)) |
| 33 .WillByDefault(Invoke(this, | 33 .WillByDefault(Invoke(this, |
| 34 &MockLatLongReport::GetAltitudeErrorValid)); | 34 &MockLatLongReport::GetAltitudeErrorValid)); |
| 35 ON_CALL(*this, GetErrorRadius(_)) | 35 ON_CALL(*this, GetErrorRadius(_)) |
| 36 .WillByDefault(Invoke(this, &MockLatLongReport::GetErrorRadiusValid)); | 36 .WillByDefault(Invoke(this, &MockLatLongReport::GetErrorRadiusValid)); |
| 37 ON_CALL(*this, GetLatitude(_)) | 37 ON_CALL(*this, GetLatitude(_)) |
| 38 .WillByDefault(Invoke(this, &MockLatLongReport::GetLatitudeValid)); | 38 .WillByDefault(Invoke(this, &MockLatLongReport::GetLatitudeValid)); |
| 39 ON_CALL(*this, GetLongitude(_)) | 39 ON_CALL(*this, GetLongitude(_)) |
| 40 .WillByDefault(Invoke(this, &MockLatLongReport::GetLongitudeValid)); | 40 .WillByDefault(Invoke(this, &MockLatLongReport::GetLongitudeValid)); |
| 41 ON_CALL(*this, GetValue(_,_)) | 41 ON_CALL(*this, GetValue(_, _)) |
| 42 .WillByDefault(Invoke(this, &MockLatLongReport::GetValueValid)); | 42 .WillByDefault(Invoke(this, &MockLatLongReport::GetValueValid)); |
| 43 ON_CALL(*this, Release()) | 43 ON_CALL(*this, Release()) |
| 44 .WillByDefault(Invoke(this, &MockLatLongReport::ReleaseInternal)); | 44 .WillByDefault(Invoke(this, &MockLatLongReport::ReleaseInternal)); |
| 45 ON_CALL(*this, AddRef()) | 45 ON_CALL(*this, AddRef()) |
| 46 .WillByDefault(Invoke(this, &MockLatLongReport::AddRefInternal)); | 46 .WillByDefault(Invoke(this, &MockLatLongReport::AddRefInternal)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // ILatLongReport | 49 // ILatLongReport |
| 50 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, | 50 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, |
| 51 GetAltitude, | 51 GetAltitude, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 ULONG AddRefInternal() { | 114 ULONG AddRefInternal() { |
| 115 return InterlockedIncrement(&ref_count_); | 115 return InterlockedIncrement(&ref_count_); |
| 116 } | 116 } |
| 117 ULONG ReleaseInternal() { | 117 ULONG ReleaseInternal() { |
| 118 LONG new_ref_count = InterlockedDecrement(&ref_count_); | 118 LONG new_ref_count = InterlockedDecrement(&ref_count_); |
| 119 if (0 == new_ref_count) | 119 if (0 == new_ref_count) |
| 120 delete this; | 120 delete this; |
| 121 return new_ref_count; | 121 return new_ref_count; |
| 122 } | 122 } |
| 123 | 123 |
| 124 LONG ref_count_; | 124 LONG ref_count_; |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 class MockReport : public ILocationReport { | 127 class MockReport : public ILocationReport { |
| 128 public: | 128 public: |
| 129 MockReport() : ref_count_(1) { | 129 MockReport() : ref_count_(1) { |
| 130 mock_lat_long_report_ = | 130 mock_lat_long_report_ = |
| 131 new MockLatLongReport(); | 131 new MockLatLongReport(); |
| 132 ON_CALL(*this, QueryInterface(_, _)) | 132 ON_CALL(*this, QueryInterface(_, _)) |
| 133 .WillByDefault(Invoke(this, &MockReport::QueryInterfaceValid)); | 133 .WillByDefault(Invoke(this, &MockReport::QueryInterfaceValid)); |
| 134 ON_CALL(*this, Release()) | 134 ON_CALL(*this, Release()) |
| 135 .WillByDefault(Invoke(this, &MockReport::ReleaseInternal)); | 135 .WillByDefault(Invoke(this, &MockReport::ReleaseInternal)); |
| 136 ON_CALL(*this, AddRef()) | 136 ON_CALL(*this, AddRef()) |
| 137 .WillByDefault(Invoke(this, &MockReport::AddRefInternal)); | 137 .WillByDefault(Invoke(this, &MockReport::AddRefInternal)); |
| 138 } | 138 } |
| 139 | 139 |
| 140 // ILocationReport | 140 // ILocationReport |
| 141 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, | 141 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, |
| 142 GetSensorID, | 142 GetSensorID, |
| 143 HRESULT(SENSOR_ID*)); | 143 HRESULT(SENSOR_ID*)); |
| 144 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, | 144 MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, |
| 145 GetTimestamp, | 145 GetTimestamp, |
| 146 HRESULT(SYSTEMTIME*)); | 146 HRESULT(SYSTEMTIME*)); |
| 147 MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE, | 147 MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE, |
| 148 GetValue, | 148 GetValue, |
| 149 HRESULT(REFPROPERTYKEY, PROPVARIANT*)); | 149 HRESULT(REFPROPERTYKEY, PROPVARIANT*)); |
| 150 // IUnknown | 150 // IUnknown |
| 151 MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE, | 151 MOCK_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE, |
| 152 QueryInterface, | 152 QueryInterface, |
| 153 HRESULT(REFIID, void**)); | 153 HRESULT(REFIID, void**)); |
| 154 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, | 154 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, |
| 155 AddRef, | 155 AddRef, |
| 156 ULONG()); | 156 ULONG()); |
| 157 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, | 157 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, |
| 158 Release, | 158 Release, |
| 159 ULONG()); | 159 ULONG()); |
| 160 | 160 |
| 161 MockLatLongReport* mock_lat_long_report_; | 161 MockLatLongReport* mock_lat_long_report_; |
| 162 | 162 |
| 163 private: | 163 private: |
| 164 ~MockReport() { | 164 ~MockReport() { |
| 165 mock_lat_long_report_->Release(); | 165 mock_lat_long_report_->Release(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 ULONG AddRefInternal() { | 168 ULONG AddRefInternal() { |
| 169 return InterlockedIncrement(&ref_count_); | 169 return InterlockedIncrement(&ref_count_); |
| 170 } | 170 } |
| 171 ULONG ReleaseInternal() { | 171 ULONG ReleaseInternal() { |
| 172 LONG new_ref_count = InterlockedDecrement(&ref_count_); | 172 LONG new_ref_count = InterlockedDecrement(&ref_count_); |
| 173 if (0 == new_ref_count) | 173 if (0 == new_ref_count) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, | 235 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, |
| 236 AddRef, | 236 AddRef, |
| 237 ULONG()); | 237 ULONG()); |
| 238 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, | 238 MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, |
| 239 Release, | 239 Release, |
| 240 ULONG()); | 240 ULONG()); |
| 241 | 241 |
| 242 MockReport* mock_report_; | 242 MockReport* mock_report_; |
| 243 | 243 |
| 244 private: | 244 private: |
| 245 ~MockLocation() { | 245 ~MockLocation() { |
| 246 mock_report_->Release(); | 246 mock_report_->Release(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 HRESULT GetReportValid(REFIID report_type, | 249 HRESULT GetReportValid(REFIID report_type, |
| 250 ILocationReport** location_report) { | 250 ILocationReport** location_report) { |
| 251 *location_report = reinterpret_cast<ILocationReport*>(mock_report_); | 251 *location_report = reinterpret_cast<ILocationReport*>(mock_report_); |
| 252 mock_report_->AddRef(); | 252 mock_report_->AddRef(); |
| 253 return S_OK; | 253 return S_OK; |
| 254 } | 254 } |
| 255 ULONG AddRefInternal() { | 255 ULONG AddRefInternal() { |
| 256 return InterlockedIncrement(&ref_count_); | 256 return InterlockedIncrement(&ref_count_); |
| 257 } | 257 } |
| 258 ULONG ReleaseInternal() { | 258 ULONG ReleaseInternal() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 281 } | 281 } |
| 282 virtual void SetUp() { | 282 virtual void SetUp() { |
| 283 api_.reset(CreateMock()); | 283 api_.reset(CreateMock()); |
| 284 report_ = locator_->mock_report_; | 284 report_ = locator_->mock_report_; |
| 285 lat_long_report_ = report_->mock_lat_long_report_; | 285 lat_long_report_ = report_->mock_lat_long_report_; |
| 286 } | 286 } |
| 287 virtual void TearDown() { | 287 virtual void TearDown() { |
| 288 locator_->Release(); | 288 locator_->Release(); |
| 289 api_.reset(); | 289 api_.reset(); |
| 290 } | 290 } |
| 291 ~GeolocationApiWin7Tests(){ | 291 ~GeolocationApiWin7Tests() { |
| 292 } | 292 } |
| 293 protected: | 293 protected: |
| 294 Win7LocationApi* CreateMock() { | 294 Win7LocationApi* CreateMock() { |
| 295 MockLocation* locator = new MockLocation(); | 295 MockLocation* locator = new MockLocation(); |
| 296 locator_ = locator; | 296 locator_ = locator; |
| 297 return new Win7LocationApi(NULL, | 297 return new Win7LocationApi(NULL, |
| 298 &MockPropVariantToDoubleFunction, | 298 &MockPropVariantToDoubleFunction, |
| 299 locator); | 299 locator); |
| 300 } | 300 } |
| 301 | 301 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 326 TEST_F(GeolocationApiWin7Tests, GetInvalidPosition) { | 326 TEST_F(GeolocationApiWin7Tests, GetInvalidPosition) { |
| 327 EXPECT_CALL(*lat_long_report_, GetLatitude(_)) | 327 EXPECT_CALL(*lat_long_report_, GetLatitude(_)) |
| 328 .Times(AtLeast(1)) | 328 .Times(AtLeast(1)) |
| 329 .WillRepeatedly(Return(HRESULT_FROM_WIN32(ERROR_NO_DATA))); | 329 .WillRepeatedly(Return(HRESULT_FROM_WIN32(ERROR_NO_DATA))); |
| 330 EXPECT_CALL(*locator_, GetReport(_, _)) | 330 EXPECT_CALL(*locator_, GetReport(_, _)) |
| 331 .Times(AtLeast(1)); | 331 .Times(AtLeast(1)); |
| 332 Geoposition position; | 332 Geoposition position; |
| 333 api_->GetPosition(&position); | 333 api_->GetPosition(&position); |
| 334 EXPECT_FALSE(position.IsValidFix()); | 334 EXPECT_FALSE(position.IsValidFix()); |
| 335 } | 335 } |
| OLD | NEW |