| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "content/browser/geolocation/win7_location_provider_win.h" | 6 #include "content/browser/geolocation/win7_location_provider_win.h" |
| 7 #include "content/browser/geolocation/win7_location_api_win.h" | 7 #include "content/browser/geolocation/win7_location_api_win.h" |
| 8 #include "content/public/common/geoposition.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 11 |
| 11 struct Geoposition; | |
| 12 | |
| 13 using testing::_; | 12 using testing::_; |
| 14 using testing::AtLeast; | 13 using testing::AtLeast; |
| 15 using testing::DoDefault; | 14 using testing::DoDefault; |
| 16 using testing::Invoke; | 15 using testing::Invoke; |
| 17 using testing::Return; | 16 using testing::Return; |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 class MockWin7LocationApi : public Win7LocationApi { | 20 class MockWin7LocationApi : public Win7LocationApi { |
| 22 public: | 21 public: |
| 23 static MockWin7LocationApi* CreateMock() { | 22 static MockWin7LocationApi* CreateMock() { |
| 24 return new MockWin7LocationApi(); | 23 return new MockWin7LocationApi(); |
| 25 } | 24 } |
| 26 | 25 |
| 27 // Used to signal when the destructor is called. | 26 // Used to signal when the destructor is called. |
| 28 MOCK_METHOD0(Die, void()); | 27 MOCK_METHOD0(Die, void()); |
| 29 // Win7LocationApi | 28 // Win7LocationApi |
| 30 MOCK_METHOD1(GetPosition, void(Geoposition*)); | 29 MOCK_METHOD1(GetPosition, void(content::Geoposition*)); |
| 31 MOCK_METHOD1(SetHighAccuracy, bool(bool)); | 30 MOCK_METHOD1(SetHighAccuracy, bool(bool)); |
| 32 | 31 |
| 33 virtual ~MockWin7LocationApi() { | 32 virtual ~MockWin7LocationApi() { |
| 34 Die(); | 33 Die(); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void GetPositionValid(Geoposition* position) { | 36 void GetPositionValid(content::Geoposition* position) { |
| 38 position->latitude = 4.5; | 37 position->latitude = 4.5; |
| 39 position->longitude = -34.1; | 38 position->longitude = -34.1; |
| 40 position->accuracy = 0.5; | 39 position->accuracy = 0.5; |
| 41 position->timestamp = base::Time::FromDoubleT(200); | 40 position->timestamp = base::Time::FromDoubleT(200); |
| 42 position->error_code = Geoposition::ERROR_CODE_NONE; | 41 position->error_code = content::Geoposition::ERROR_CODE_NONE; |
| 43 } | 42 } |
| 44 void GetPositionInvalid(Geoposition* position) { | 43 void GetPositionInvalid(content::Geoposition* position) { |
| 45 position->latitude = 4.5; | 44 position->latitude = 4.5; |
| 46 position->longitude = -340000.1; | 45 position->longitude = -340000.1; |
| 47 position->accuracy = 0.5; | 46 position->accuracy = 0.5; |
| 48 position->timestamp = base::Time::FromDoubleT(200); | 47 position->timestamp = base::Time::FromDoubleT(200); |
| 49 position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | 48 position->error_code = |
| 49 content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
| 50 } | 50 } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 MockWin7LocationApi() { | 53 MockWin7LocationApi() { |
| 54 ON_CALL(*this, GetPosition(_)) | 54 ON_CALL(*this, GetPosition(_)) |
| 55 .WillByDefault(Invoke(this, | 55 .WillByDefault(Invoke(this, |
| 56 &MockWin7LocationApi::GetPositionValid)); | 56 &MockWin7LocationApi::GetPositionValid)); |
| 57 ON_CALL(*this, SetHighAccuracy(true)) | 57 ON_CALL(*this, SetHighAccuracy(true)) |
| 58 .WillByDefault(Return(true)); | 58 .WillByDefault(Return(true)); |
| 59 ON_CALL(*this, SetHighAccuracy(false)) | 59 ON_CALL(*this, SetHighAccuracy(false)) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 EXPECT_TRUE(provider_->StartProvider(false)); | 112 EXPECT_TRUE(provider_->StartProvider(false)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 TEST_F(GeolocationProviderWin7Tests, GetValidPosition) { | 115 TEST_F(GeolocationProviderWin7Tests, GetValidPosition) { |
| 116 EXPECT_CALL(*api_, GetPosition(_)) | 116 EXPECT_CALL(*api_, GetPosition(_)) |
| 117 .Times(AtLeast(1)); | 117 .Times(AtLeast(1)); |
| 118 EXPECT_CALL(*api_, SetHighAccuracy(true)) | 118 EXPECT_CALL(*api_, SetHighAccuracy(true)) |
| 119 .WillOnce(Return(true)); | 119 .WillOnce(Return(true)); |
| 120 EXPECT_TRUE(provider_->StartProvider(true)); | 120 EXPECT_TRUE(provider_->StartProvider(true)); |
| 121 main_message_loop_.Run(); | 121 main_message_loop_.Run(); |
| 122 Geoposition position; | 122 content::Geoposition position; |
| 123 provider_->GetPosition(&position); | 123 provider_->GetPosition(&position); |
| 124 EXPECT_TRUE(position.IsValidFix()); | 124 EXPECT_TRUE(position.Validate()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 TEST_F(GeolocationProviderWin7Tests, GetInvalidPosition) { | 127 TEST_F(GeolocationProviderWin7Tests, GetInvalidPosition) { |
| 128 EXPECT_CALL(*api_, GetPosition(_)) | 128 EXPECT_CALL(*api_, GetPosition(_)) |
| 129 .Times(AtLeast(1)) | 129 .Times(AtLeast(1)) |
| 130 .WillRepeatedly(Invoke(api_, | 130 .WillRepeatedly(Invoke(api_, |
| 131 &MockWin7LocationApi::GetPositionInvalid)); | 131 &MockWin7LocationApi::GetPositionInvalid)); |
| 132 EXPECT_CALL(*api_, SetHighAccuracy(true)) | 132 EXPECT_CALL(*api_, SetHighAccuracy(true)) |
| 133 .WillOnce(Return(true)); | 133 .WillOnce(Return(true)); |
| 134 EXPECT_TRUE(provider_->StartProvider(true)); | 134 EXPECT_TRUE(provider_->StartProvider(true)); |
| 135 main_message_loop_.Run(); | 135 main_message_loop_.Run(); |
| 136 Geoposition position; | 136 content::Geoposition position; |
| 137 provider_->GetPosition(&position); | 137 provider_->GetPosition(&position); |
| 138 EXPECT_FALSE(position.IsValidFix()); | 138 EXPECT_FALSE(position.Validate()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // namespace | 141 } // namespace |
| OLD | NEW |