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

Side by Side Diff: third_party/WebKit/Source/web/WebEmbeddedWorkerImplTest.cpp

Issue 2733283004: Expose WebServiceWorkerNetworkProvider on DataSource (Closed)
Patch Set: consistency Created 3 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "public/web/WebEmbeddedWorker.h" 5 #include "public/web/WebEmbeddedWorker.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "platform/testing/URLTestHelpers.h" 8 #include "platform/testing/URLTestHelpers.h"
9 #include "platform/testing/UnitTestHelpers.h" 9 #include "platform/testing/UnitTestHelpers.h"
10 #include "public/platform/Platform.h" 10 #include "public/platform/Platform.h"
(...skipping 10 matching lines...) Expand all
21 namespace blink { 21 namespace blink {
22 namespace { 22 namespace {
23 23
24 class MockServiceWorkerContextClient : public WebServiceWorkerContextClient { 24 class MockServiceWorkerContextClient : public WebServiceWorkerContextClient {
25 public: 25 public:
26 MockServiceWorkerContextClient() : m_hasAssociatedRegistration(true) {} 26 MockServiceWorkerContextClient() : m_hasAssociatedRegistration(true) {}
27 ~MockServiceWorkerContextClient() override {} 27 ~MockServiceWorkerContextClient() override {}
28 MOCK_METHOD0(workerReadyForInspection, void()); 28 MOCK_METHOD0(workerReadyForInspection, void());
29 MOCK_METHOD0(workerContextFailedToStart, void()); 29 MOCK_METHOD0(workerContextFailedToStart, void());
30 MOCK_METHOD0(workerScriptLoaded, void()); 30 MOCK_METHOD0(workerScriptLoaded, void());
31 MOCK_METHOD1(createServiceWorkerNetworkProvider, 31 MOCK_METHOD0(createServiceWorkerNetworkProvider,
32 WebServiceWorkerNetworkProvider*(WebDataSource*)); 32 WebServiceWorkerNetworkProvider*());
33 MOCK_METHOD0(createServiceWorkerProvider, WebServiceWorkerProvider*()); 33 MOCK_METHOD0(createServiceWorkerProvider, WebServiceWorkerProvider*());
34 bool hasAssociatedRegistration() override { 34 bool hasAssociatedRegistration() override {
35 return m_hasAssociatedRegistration; 35 return m_hasAssociatedRegistration;
36 } 36 }
37 void setHasAssociatedRegistration(bool hasAssociatedRegistration) { 37 void setHasAssociatedRegistration(bool hasAssociatedRegistration) {
38 m_hasAssociatedRegistration = hasAssociatedRegistration; 38 m_hasAssociatedRegistration = hasAssociatedRegistration;
39 } 39 }
40 void getClient(const WebString&, 40 void getClient(const WebString&,
41 std::unique_ptr<WebServiceWorkerClientCallbacks>) override { 41 std::unique_ptr<WebServiceWorkerClientCallbacks>) override {
42 NOTREACHED(); 42 NOTREACHED();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 m_worker->terminateWorkerContext(); 136 m_worker->terminateWorkerContext();
137 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 137 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
138 } 138 }
139 139
140 TEST_F(WebEmbeddedWorkerImplTest, TerminateWhileLoadingScript) { 140 TEST_F(WebEmbeddedWorkerImplTest, TerminateWhileLoadingScript) {
141 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1); 141 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
142 m_worker->startWorkerContext(m_startData); 142 m_worker->startWorkerContext(m_startData);
143 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 143 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
144 144
145 // Load the shadow page. 145 // Load the shadow page.
146 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) 146 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider())
147 .WillOnce(::testing::Return(nullptr)); 147 .WillOnce(::testing::Return(nullptr));
148 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 148 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
149 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 149 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
150 150
151 // Terminate before loading the script. 151 // Terminate before loading the script.
152 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1); 152 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
153 m_worker->terminateWorkerContext(); 153 m_worker->terminateWorkerContext();
154 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 154 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
155 } 155 }
156 156
157 TEST_F(WebEmbeddedWorkerImplTest, TerminateWhilePausedAfterDownload) { 157 TEST_F(WebEmbeddedWorkerImplTest, TerminateWhilePausedAfterDownload) {
158 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1); 158 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
159 m_startData.pauseAfterDownloadMode = 159 m_startData.pauseAfterDownloadMode =
160 WebEmbeddedWorkerStartData::PauseAfterDownload; 160 WebEmbeddedWorkerStartData::PauseAfterDownload;
161 m_worker->startWorkerContext(m_startData); 161 m_worker->startWorkerContext(m_startData);
162 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 162 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
163 163
164 // Load the shadow page. 164 // Load the shadow page.
165 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) 165 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider())
166 .WillOnce(::testing::Return(nullptr)); 166 .WillOnce(::testing::Return(nullptr));
167 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 167 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
168 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 168 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
169 169
170 // Load the script. 170 // Load the script.
171 EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(1); 171 EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(1);
172 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0); 172 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0);
173 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 173 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
174 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 174 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
175 175
(...skipping 15 matching lines...) Expand all
191 error.domain = "WebEmbeddedWorkerImplTest"; 191 error.domain = "WebEmbeddedWorkerImplTest";
192 Platform::current()->getURLLoaderMockFactory()->registerErrorURL( 192 Platform::current()->getURLLoaderMockFactory()->registerErrorURL(
193 scriptURL, response, error); 193 scriptURL, response, error);
194 m_startData.scriptURL = scriptURL; 194 m_startData.scriptURL = scriptURL;
195 195
196 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1); 196 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
197 m_worker->startWorkerContext(m_startData); 197 m_worker->startWorkerContext(m_startData);
198 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 198 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
199 199
200 // Load the shadow page. 200 // Load the shadow page.
201 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) 201 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider())
202 .WillOnce(::testing::Return(nullptr)); 202 .WillOnce(::testing::Return(nullptr));
203 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 203 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
204 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 204 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
205 205
206 // Load the script. 206 // Load the script.
207 EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(0); 207 EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(0);
208 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0); 208 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0);
209 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1); 209 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
210 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 210 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
211 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 211 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
212 } 212 }
213 213
214 TEST_F(WebEmbeddedWorkerImplTest, NoRegistration) { 214 TEST_F(WebEmbeddedWorkerImplTest, NoRegistration) {
215 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1); 215 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
216 m_startData.pauseAfterDownloadMode = 216 m_startData.pauseAfterDownloadMode =
217 WebEmbeddedWorkerStartData::PauseAfterDownload; 217 WebEmbeddedWorkerStartData::PauseAfterDownload;
218 m_worker->startWorkerContext(m_startData); 218 m_worker->startWorkerContext(m_startData);
219 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 219 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
220 220
221 // Load the shadow page. 221 // Load the shadow page.
222 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) 222 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider())
223 .WillOnce(::testing::Return(nullptr)); 223 .WillOnce(::testing::Return(nullptr));
224 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 224 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
225 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 225 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
226 226
227 // Load the script. 227 // Load the script.
228 m_mockClient->setHasAssociatedRegistration(false); 228 m_mockClient->setHasAssociatedRegistration(false);
229 EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(0); 229 EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(0);
230 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0); 230 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0);
231 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1); 231 EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
232 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 232 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
233 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 233 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
234 } 234 }
235 235
236 // The running worker is detected as a memory leak. crbug.com/586897 236 // The running worker is detected as a memory leak. crbug.com/586897
237 #if defined(ADDRESS_SANITIZER) 237 #if defined(ADDRESS_SANITIZER)
238 #define MAYBE_DontPauseAfterDownload DISABLED_DontPauseAfterDownload 238 #define MAYBE_DontPauseAfterDownload DISABLED_DontPauseAfterDownload
239 #else 239 #else
240 #define MAYBE_DontPauseAfterDownload DontPauseAfterDownload 240 #define MAYBE_DontPauseAfterDownload DontPauseAfterDownload
241 #endif 241 #endif
242 242
243 TEST_F(WebEmbeddedWorkerImplTest, MAYBE_DontPauseAfterDownload) { 243 TEST_F(WebEmbeddedWorkerImplTest, MAYBE_DontPauseAfterDownload) {
244 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1); 244 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
245 m_worker->startWorkerContext(m_startData); 245 m_worker->startWorkerContext(m_startData);
246 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 246 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
247 247
248 // Load the shadow page. 248 // Load the shadow page.
249 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) 249 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider())
250 .WillOnce(::testing::Return(nullptr)); 250 .WillOnce(::testing::Return(nullptr));
251 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 251 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
252 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 252 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
253 253
254 // Load the script. 254 // Load the script.
255 EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(1); 255 EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(1);
256 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) 256 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider())
257 .WillOnce(::testing::Return(nullptr)); 257 .WillOnce(::testing::Return(nullptr));
258 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 258 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
259 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 259 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
260 } 260 }
261 261
262 // The running worker is detected as a memory leak. crbug.com/586897 262 // The running worker is detected as a memory leak. crbug.com/586897
263 #if defined(ADDRESS_SANITIZER) 263 #if defined(ADDRESS_SANITIZER)
264 #define MAYBE_PauseAfterDownload DISABLED_PauseAfterDownload 264 #define MAYBE_PauseAfterDownload DISABLED_PauseAfterDownload
265 #else 265 #else
266 #define MAYBE_PauseAfterDownload PauseAfterDownload 266 #define MAYBE_PauseAfterDownload PauseAfterDownload
267 #endif 267 #endif
268 268
269 TEST_F(WebEmbeddedWorkerImplTest, MAYBE_PauseAfterDownload) { 269 TEST_F(WebEmbeddedWorkerImplTest, MAYBE_PauseAfterDownload) {
270 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1); 270 EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
271 m_startData.pauseAfterDownloadMode = 271 m_startData.pauseAfterDownloadMode =
272 WebEmbeddedWorkerStartData::PauseAfterDownload; 272 WebEmbeddedWorkerStartData::PauseAfterDownload;
273 m_worker->startWorkerContext(m_startData); 273 m_worker->startWorkerContext(m_startData);
274 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 274 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
275 275
276 // Load the shadow page. 276 // Load the shadow page.
277 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_)) 277 EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider())
278 .WillOnce(::testing::Return(nullptr)); 278 .WillOnce(::testing::Return(nullptr));
279 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 279 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
280 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 280 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
281 281
282 // Load the script. 282 // Load the script.
283 EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(1); 283 EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(1);
284 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0); 284 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0);
285 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 285 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
286 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 286 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
287 287
288 // Resume after download. 288 // Resume after download.
289 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()) 289 EXPECT_CALL(*m_mockClient, createServiceWorkerProvider())
290 .WillOnce(::testing::Return(nullptr)); 290 .WillOnce(::testing::Return(nullptr));
291 m_worker->resumeAfterDownload(); 291 m_worker->resumeAfterDownload();
292 ::testing::Mock::VerifyAndClearExpectations(m_mockClient); 292 ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
293 } 293 }
294 294
295 } // namespace blink 295 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebEmbeddedWorkerImpl.cpp ('k') | third_party/WebKit/Source/web/WebSharedWorkerImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698