Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: content/browser/geofencing/geofencing_service_unittest.cc

Issue 1549113002: Switch to standard integer types in content/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stdint.h>
6
5 #include "content/browser/geofencing/geofencing_provider.h" 7 #include "content/browser/geofencing/geofencing_provider.h"
6 #include "content/browser/geofencing/geofencing_registration_delegate.h" 8 #include "content/browser/geofencing/geofencing_registration_delegate.h"
7 #include "content/browser/geofencing/geofencing_service.h" 9 #include "content/browser/geofencing/geofencing_service.h"
8 #include "content/public/test/test_browser_thread_bundle.h" 10 #include "content/public/test/test_browser_thread_bundle.h"
9 #include "content/public/test/test_utils.h" 11 #include "content/public/test/test_utils.h"
10 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" 14 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h"
13 15
14 using blink::WebCircularGeofencingRegion; 16 using blink::WebCircularGeofencingRegion;
15 17
16 namespace { 18 namespace {
17 19
18 bool RegionsMatch(const WebCircularGeofencingRegion& expected, 20 bool RegionsMatch(const WebCircularGeofencingRegion& expected,
19 const WebCircularGeofencingRegion& arg) { 21 const WebCircularGeofencingRegion& arg) {
20 return testing::Matches(expected.latitude)(arg.latitude) && 22 return testing::Matches(expected.latitude)(arg.latitude) &&
21 testing::Matches(expected.longitude)(arg.longitude) && 23 testing::Matches(expected.longitude)(arg.longitude) &&
22 testing::Matches(expected.radius)(arg.radius); 24 testing::Matches(expected.radius)(arg.radius);
23 } 25 }
24 26
25 } // namespace 27 } // namespace
26 28
27 namespace content { 29 namespace content {
28 30
29 class MockGeofencingRegistrationDelegate 31 class MockGeofencingRegistrationDelegate
30 : public GeofencingRegistrationDelegate { 32 : public GeofencingRegistrationDelegate {
31 public: 33 public:
32 MOCK_METHOD2(RegistrationFinished, 34 MOCK_METHOD2(RegistrationFinished,
33 void(int64 geofencing_registration_id, GeofencingStatus status)); 35 void(int64_t geofencing_registration_id,
34 MOCK_METHOD1(RegionEntered, void(int64 geofencing_registration_id)); 36 GeofencingStatus status));
35 MOCK_METHOD1(RegionExited, void(int64 geofencing_registration_id)); 37 MOCK_METHOD1(RegionEntered, void(int64_t geofencing_registration_id));
38 MOCK_METHOD1(RegionExited, void(int64_t geofencing_registration_id));
36 }; 39 };
37 40
38 class MockGeofencingProvider : public GeofencingProvider { 41 class MockGeofencingProvider : public GeofencingProvider {
39 public: 42 public:
40 MOCK_METHOD3(RegisterRegion, 43 MOCK_METHOD3(RegisterRegion,
41 void(int64 geofencing_registration_id, 44 void(int64_t geofencing_registration_id,
42 const blink::WebCircularGeofencingRegion& region, 45 const blink::WebCircularGeofencingRegion& region,
43 const StatusCallback& callback)); 46 const StatusCallback& callback));
44 MOCK_METHOD1(UnregisterRegion, void(int64 geofencing_registration_id)); 47 MOCK_METHOD1(UnregisterRegion, void(int64_t geofencing_registration_id));
45 }; 48 };
46 49
47 ACTION_P(QuitRunner, runner) { 50 ACTION_P(QuitRunner, runner) {
48 runner->Quit(); 51 runner->Quit();
49 } 52 }
50 53
51 ACTION_P(SaveRegistrationId, geofencing_registration_id) { 54 ACTION_P(SaveRegistrationId, geofencing_registration_id) {
52 *geofencing_registration_id = arg0; 55 *geofencing_registration_id = arg0;
53 } 56 }
54 57
(...skipping 17 matching lines...) Expand all
72 75
73 void TearDown() override { delete service_; } 76 void TearDown() override { delete service_; }
74 77
75 void SetProviderForTests() { 78 void SetProviderForTests() {
76 provider_ = new MockGeofencingProvider(); 79 provider_ = new MockGeofencingProvider();
77 service_->SetProviderForTesting(make_scoped_ptr(provider_)); 80 service_->SetProviderForTesting(make_scoped_ptr(provider_));
78 } 81 }
79 82
80 int RegistrationCount() { return service_->RegistrationCountForTesting(); } 83 int RegistrationCount() { return service_->RegistrationCountForTesting(); }
81 84
82 int64 RegisterRegionSync(const WebCircularGeofencingRegion& region, 85 int64_t RegisterRegionSync(const WebCircularGeofencingRegion& region,
83 GeofencingStatus provider_status) { 86 GeofencingStatus provider_status) {
84 scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner()); 87 scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner());
85 88
86 // The registration ID that is passed to the provider. 89 // The registration ID that is passed to the provider.
87 int64 provider_registration_id = -1; 90 int64_t provider_registration_id = -1;
88 // The callback that is passed to the provider. 91 // The callback that is passed to the provider.
89 GeofencingProvider::StatusCallback callback; 92 GeofencingProvider::StatusCallback callback;
90 93
91 EXPECT_CALL( 94 EXPECT_CALL(
92 *provider_, 95 *provider_,
93 RegisterRegion( 96 RegisterRegion(
94 testing::_, WebCircularGeofencingRegionEq(region), testing::_)) 97 testing::_, WebCircularGeofencingRegionEq(region), testing::_))
95 .WillOnce(testing::DoAll(SaveRegistrationId(&provider_registration_id), 98 .WillOnce(testing::DoAll(SaveRegistrationId(&provider_registration_id),
96 SaveStatusCallback(&callback))); 99 SaveStatusCallback(&callback)));
97 100
98 int64 geofencing_registration_id = 101 int64_t geofencing_registration_id =
99 service_->RegisterRegion(region, &delegate_); 102 service_->RegisterRegion(region, &delegate_);
100 103
101 // Service should have synchronously called the provider. 104 // Service should have synchronously called the provider.
102 CHECK(!callback.is_null()); 105 CHECK(!callback.is_null());
103 CHECK(provider_registration_id == geofencing_registration_id); 106 CHECK(provider_registration_id == geofencing_registration_id);
104 107
105 // Finish up registration by calling the callback and waiting for the 108 // Finish up registration by calling the callback and waiting for the
106 // delegate to be called. 109 // delegate to be called.
107 EXPECT_CALL( 110 EXPECT_CALL(
108 delegate_, 111 delegate_,
109 RegistrationFinished(geofencing_registration_id, provider_status)) 112 RegistrationFinished(geofencing_registration_id, provider_status))
110 .WillOnce(QuitRunner(runner)); 113 .WillOnce(QuitRunner(runner));
111 callback.Run(provider_status); 114 callback.Run(provider_status);
112 runner->Run(); 115 runner->Run();
113 return geofencing_registration_id; 116 return geofencing_registration_id;
114 } 117 }
115 118
116 protected: 119 protected:
117 TestBrowserThreadBundle threads_; 120 TestBrowserThreadBundle threads_;
118 GeofencingServiceImpl* service_; 121 GeofencingServiceImpl* service_;
119 MockGeofencingProvider* provider_; 122 MockGeofencingProvider* provider_;
120 MockGeofencingRegistrationDelegate delegate_; 123 MockGeofencingRegistrationDelegate delegate_;
121 124
122 WebCircularGeofencingRegion test_region_; 125 WebCircularGeofencingRegion test_region_;
123 }; 126 };
124 127
125 TEST_F(GeofencingServiceTest, RegisterRegion_NoProvider) { 128 TEST_F(GeofencingServiceTest, RegisterRegion_NoProvider) {
126 scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner()); 129 scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner());
127 int64 geofencing_registration_id = 130 int64_t geofencing_registration_id =
128 service_->RegisterRegion(test_region_, &delegate_); 131 service_->RegisterRegion(test_region_, &delegate_);
129 EXPECT_CALL(delegate_, 132 EXPECT_CALL(delegate_,
130 RegistrationFinished( 133 RegistrationFinished(
131 geofencing_registration_id, 134 geofencing_registration_id,
132 GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE)) 135 GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE))
133 .WillOnce(QuitRunner(runner)); 136 .WillOnce(QuitRunner(runner));
134 runner->Run(); 137 runner->Run();
135 EXPECT_EQ(0, RegistrationCount()); 138 EXPECT_EQ(0, RegistrationCount());
136 } 139 }
137 140
(...skipping 26 matching lines...) Expand all
164 167
165 // The callback that is passed to the provider. 168 // The callback that is passed to the provider.
166 GeofencingProvider::StatusCallback callback; 169 GeofencingProvider::StatusCallback callback;
167 170
168 EXPECT_CALL( 171 EXPECT_CALL(
169 *provider_, 172 *provider_,
170 RegisterRegion( 173 RegisterRegion(
171 testing::_, WebCircularGeofencingRegionEq(test_region_), testing::_)) 174 testing::_, WebCircularGeofencingRegionEq(test_region_), testing::_))
172 .WillOnce(SaveStatusCallback(&callback)); 175 .WillOnce(SaveStatusCallback(&callback));
173 176
174 int64 geofencing_registration_id = 177 int64_t geofencing_registration_id =
175 service_->RegisterRegion(test_region_, &delegate_); 178 service_->RegisterRegion(test_region_, &delegate_);
176 179
177 // Service should have synchronously called the provider. 180 // Service should have synchronously called the provider.
178 CHECK(!callback.is_null()); 181 CHECK(!callback.is_null());
179 182
180 // Call unregister before registration is finished. 183 // Call unregister before registration is finished.
181 service_->UnregisterRegion(geofencing_registration_id); 184 service_->UnregisterRegion(geofencing_registration_id);
182 185
183 // Finish up registration by calling the callback and waiting for the 186 // Finish up registration by calling the callback and waiting for the
184 // provider to be called. The delegate should not be called in this case. 187 // provider to be called. The delegate should not be called in this case.
185 EXPECT_CALL(delegate_, RegistrationFinished(testing::_, testing::_)).Times(0); 188 EXPECT_CALL(delegate_, RegistrationFinished(testing::_, testing::_)).Times(0);
186 EXPECT_CALL(*provider_, UnregisterRegion(geofencing_registration_id)) 189 EXPECT_CALL(*provider_, UnregisterRegion(geofencing_registration_id))
187 .WillOnce(QuitRunner(runner)); 190 .WillOnce(QuitRunner(runner));
188 callback.Run(GEOFENCING_STATUS_OK); 191 callback.Run(GEOFENCING_STATUS_OK);
189 runner->Run(); 192 runner->Run();
190 EXPECT_EQ(0, RegistrationCount()); 193 EXPECT_EQ(0, RegistrationCount());
191 } 194 }
192 195
193 } // namespace content 196 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geofencing/geofencing_service.cc ('k') | content/browser/geofencing/mock_geofencing_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698