OLD | NEW |
1 // Copyright (c) 2012 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 "content/public/common/geoposition.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 ON_CALL(*this, SetHighAccuracy(true)) | 56 ON_CALL(*this, SetHighAccuracy(true)) |
57 .WillByDefault(Return(true)); | 57 .WillByDefault(Return(true)); |
58 ON_CALL(*this, SetHighAccuracy(false)) | 58 ON_CALL(*this, SetHighAccuracy(false)) |
59 .WillByDefault(Return(false)); | 59 .WillByDefault(Return(false)); |
60 } | 60 } |
61 }; | 61 }; |
62 | 62 |
63 class LocationProviderListenerLoopQuitter | 63 class LocationProviderListenerLoopQuitter |
64 : public LocationProviderBase::ListenerInterface { | 64 : public LocationProviderBase::ListenerInterface { |
65 public: | 65 public: |
66 explicit LocationProviderListenerLoopQuitter(MessageLoop* message_loop) | 66 explicit LocationProviderListenerLoopQuitter(base::MessageLoop* message_loop) |
67 : message_loop_to_quit_(message_loop) { | 67 : message_loop_to_quit_(message_loop) { |
68 CHECK(message_loop_to_quit_ != NULL); | 68 CHECK(message_loop_to_quit_ != NULL); |
69 } | 69 } |
70 virtual void LocationUpdateAvailable(LocationProviderBase* provider) { | 70 virtual void LocationUpdateAvailable(LocationProviderBase* provider) { |
71 EXPECT_EQ(MessageLoop::current(), message_loop_to_quit_); | 71 EXPECT_EQ(base::MessageLoop::current(), message_loop_to_quit_); |
72 provider_ = provider; | 72 provider_ = provider; |
73 message_loop_to_quit_->Quit(); | 73 message_loop_to_quit_->Quit(); |
74 } | 74 } |
75 | 75 |
76 MessageLoop* message_loop_to_quit_; | 76 base::MessageLoop* message_loop_to_quit_; |
77 LocationProviderBase* provider_; | 77 LocationProviderBase* provider_; |
78 }; | 78 }; |
79 | 79 |
80 class GeolocationProviderWin7Tests : public testing::Test { | 80 class GeolocationProviderWin7Tests : public testing::Test { |
81 public: | 81 public: |
82 GeolocationProviderWin7Tests(): location_listener_(&main_message_loop_) { | 82 GeolocationProviderWin7Tests(): location_listener_(&main_message_loop_) { |
83 } | 83 } |
84 | 84 |
85 virtual void SetUp() { | 85 virtual void SetUp() { |
86 api_ = MockWin7LocationApi::CreateMock(); | 86 api_ = MockWin7LocationApi::CreateMock(); |
87 provider_ = new Win7LocationProvider(api_); | 87 provider_ = new Win7LocationProvider(api_); |
88 provider_->RegisterListener(&location_listener_); | 88 provider_->RegisterListener(&location_listener_); |
89 } | 89 } |
90 virtual void TearDown() { | 90 virtual void TearDown() { |
91 provider_->UnregisterListener(&location_listener_); | 91 provider_->UnregisterListener(&location_listener_); |
92 provider_->StopProvider(); | 92 provider_->StopProvider(); |
93 delete provider_; | 93 delete provider_; |
94 main_message_loop_.RunUntilIdle(); | 94 main_message_loop_.RunUntilIdle(); |
95 } | 95 } |
96 | 96 |
97 protected: | 97 protected: |
98 MockWin7LocationApi* api_; | 98 MockWin7LocationApi* api_; |
99 LocationProviderListenerLoopQuitter location_listener_; | 99 LocationProviderListenerLoopQuitter location_listener_; |
100 MessageLoop main_message_loop_; | 100 base::MessageLoop main_message_loop_; |
101 Win7LocationProvider* provider_; | 101 Win7LocationProvider* provider_; |
102 }; | 102 }; |
103 | 103 |
104 TEST_F(GeolocationProviderWin7Tests, StartStop) { | 104 TEST_F(GeolocationProviderWin7Tests, StartStop) { |
105 EXPECT_CALL(*api_, SetHighAccuracy(true)) | 105 EXPECT_CALL(*api_, SetHighAccuracy(true)) |
106 .WillOnce(Return(true)); | 106 .WillOnce(Return(true)); |
107 EXPECT_TRUE(provider_->StartProvider(true)); | 107 EXPECT_TRUE(provider_->StartProvider(true)); |
108 provider_->StopProvider(); | 108 provider_->StopProvider(); |
109 EXPECT_CALL(*api_, SetHighAccuracy(false)) | 109 EXPECT_CALL(*api_, SetHighAccuracy(false)) |
110 .WillOnce(Return(true)); | 110 .WillOnce(Return(true)); |
(...skipping 20 matching lines...) Expand all Loading... |
131 EXPECT_CALL(*api_, SetHighAccuracy(true)) | 131 EXPECT_CALL(*api_, SetHighAccuracy(true)) |
132 .WillOnce(Return(true)); | 132 .WillOnce(Return(true)); |
133 EXPECT_TRUE(provider_->StartProvider(true)); | 133 EXPECT_TRUE(provider_->StartProvider(true)); |
134 main_message_loop_.Run(); | 134 main_message_loop_.Run(); |
135 Geoposition position; | 135 Geoposition position; |
136 provider_->GetPosition(&position); | 136 provider_->GetPosition(&position); |
137 EXPECT_FALSE(position.Validate()); | 137 EXPECT_FALSE(position.Validate()); |
138 } | 138 } |
139 | 139 |
140 } // namespace content | 140 } // namespace content |
OLD | NEW |