OLD | NEW |
---|---|
1 | 1 |
2 // Copyright 2014 The Chromium Authors. All rights reserved. | 2 // Copyright 2014 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 | 5 |
6 #include "modules/serviceworkers/ServiceWorkerContainer.h" | 6 #include "modules/serviceworkers/ServiceWorkerContainer.h" |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 | 122 |
123 // Service Worker-specific tests. | 123 // Service Worker-specific tests. |
124 | 124 |
125 class NotReachedWebServiceWorkerProvider : public WebServiceWorkerProvider { | 125 class NotReachedWebServiceWorkerProvider : public WebServiceWorkerProvider { |
126 public: | 126 public: |
127 ~NotReachedWebServiceWorkerProvider() override {} | 127 ~NotReachedWebServiceWorkerProvider() override {} |
128 | 128 |
129 void registerServiceWorker( | 129 void registerServiceWorker( |
130 const WebURL& pattern, | 130 const WebURL& pattern, |
131 const WebURL& scriptURL, | 131 const WebURL& scriptURL, |
132 bool useCache, | |
132 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) | 133 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) |
133 override { | 134 override { |
134 ADD_FAILURE() | 135 ADD_FAILURE() |
135 << "the provider should not be called to register a Service Worker"; | 136 << "the provider should not be called to register a Service Worker"; |
136 } | 137 } |
137 | 138 |
138 bool validateScopeAndScriptURL(const WebURL& scope, | 139 bool validateScopeAndScriptURL(const WebURL& scope, |
139 const WebURL& scriptURL, | 140 const WebURL& scriptURL, |
140 WebString* errorMessage) { | 141 WebString* errorMessage) { |
141 return true; | 142 return true; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 // StubWebServiceWorkerProvider dies. | 273 // StubWebServiceWorkerProvider dies. |
273 std::unique_ptr<WebServiceWorkerProvider> provider() { | 274 std::unique_ptr<WebServiceWorkerProvider> provider() { |
274 return WTF::wrapUnique(new WebServiceWorkerProviderImpl(*this)); | 275 return WTF::wrapUnique(new WebServiceWorkerProviderImpl(*this)); |
275 } | 276 } |
276 | 277 |
277 size_t registerCallCount() { return m_registerCallCount; } | 278 size_t registerCallCount() { return m_registerCallCount; } |
278 const WebURL& registerScope() { return m_registerScope; } | 279 const WebURL& registerScope() { return m_registerScope; } |
279 const WebURL& registerScriptURL() { return m_registerScriptURL; } | 280 const WebURL& registerScriptURL() { return m_registerScriptURL; } |
280 size_t getRegistrationCallCount() { return m_getRegistrationCallCount; } | 281 size_t getRegistrationCallCount() { return m_getRegistrationCallCount; } |
281 const WebURL& getRegistrationURL() { return m_getRegistrationURL; } | 282 const WebURL& getRegistrationURL() { return m_getRegistrationURL; } |
283 bool useCache() const { return m_useCache; } | |
282 | 284 |
283 private: | 285 private: |
284 class WebServiceWorkerProviderImpl : public WebServiceWorkerProvider { | 286 class WebServiceWorkerProviderImpl : public WebServiceWorkerProvider { |
285 public: | 287 public: |
286 WebServiceWorkerProviderImpl(StubWebServiceWorkerProvider& owner) | 288 WebServiceWorkerProviderImpl(StubWebServiceWorkerProvider& owner) |
287 : m_owner(owner) {} | 289 : m_owner(owner) {} |
288 | 290 |
289 ~WebServiceWorkerProviderImpl() override {} | 291 ~WebServiceWorkerProviderImpl() override {} |
290 | 292 |
291 void registerServiceWorker( | 293 void registerServiceWorker( |
292 const WebURL& pattern, | 294 const WebURL& pattern, |
293 const WebURL& scriptURL, | 295 const WebURL& scriptURL, |
296 bool useCache, | |
294 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) | 297 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) |
295 override { | 298 override { |
296 m_owner.m_registerCallCount++; | 299 m_owner.m_registerCallCount++; |
297 m_owner.m_registerScope = pattern; | 300 m_owner.m_registerScope = pattern; |
298 m_owner.m_registerScriptURL = scriptURL; | 301 m_owner.m_registerScriptURL = scriptURL; |
302 m_owner.m_useCache = useCache; | |
299 m_registrationCallbacksToDelete.push_back(std::move(callbacks)); | 303 m_registrationCallbacksToDelete.push_back(std::move(callbacks)); |
300 } | 304 } |
301 | 305 |
302 void getRegistration( | 306 void getRegistration( |
303 const WebURL& documentURL, | 307 const WebURL& documentURL, |
304 std::unique_ptr<WebServiceWorkerGetRegistrationCallbacks> callbacks) | 308 std::unique_ptr<WebServiceWorkerGetRegistrationCallbacks> callbacks) |
305 override { | 309 override { |
306 m_owner.m_getRegistrationCallCount++; | 310 m_owner.m_getRegistrationCallCount++; |
307 m_owner.m_getRegistrationURL = documentURL; | 311 m_owner.m_getRegistrationURL = documentURL; |
308 m_getRegistrationCallbacksToDelete.push_back(std::move(callbacks)); | 312 m_getRegistrationCallbacksToDelete.push_back(std::move(callbacks)); |
(...skipping 12 matching lines...) Expand all Loading... | |
321 Vector<std::unique_ptr<WebServiceWorkerGetRegistrationCallbacks>> | 325 Vector<std::unique_ptr<WebServiceWorkerGetRegistrationCallbacks>> |
322 m_getRegistrationCallbacksToDelete; | 326 m_getRegistrationCallbacksToDelete; |
323 }; | 327 }; |
324 | 328 |
325 private: | 329 private: |
326 size_t m_registerCallCount; | 330 size_t m_registerCallCount; |
327 WebURL m_registerScope; | 331 WebURL m_registerScope; |
328 WebURL m_registerScriptURL; | 332 WebURL m_registerScriptURL; |
329 size_t m_getRegistrationCallCount; | 333 size_t m_getRegistrationCallCount; |
330 WebURL m_getRegistrationURL; | 334 WebURL m_getRegistrationURL; |
335 bool m_useCache; | |
331 }; | 336 }; |
332 | 337 |
333 TEST_F(ServiceWorkerContainerTest, | 338 TEST_F(ServiceWorkerContainerTest, |
334 RegisterUnregister_NonHttpsSecureOriginDelegatesToProvider) { | 339 RegisterUnregister_NonHttpsSecureOriginDelegatesToProvider) { |
335 setPageURL("http://localhost/x/index.html"); | 340 setPageURL("http://localhost/x/index.html"); |
336 | 341 |
337 StubWebServiceWorkerProvider stubProvider; | 342 StubWebServiceWorkerProvider stubProvider; |
338 provide(stubProvider.provider()); | 343 provide(stubProvider.provider()); |
339 | 344 |
340 ServiceWorkerContainer* container = ServiceWorkerContainer::create( | 345 ServiceWorkerContainer* container = ServiceWorkerContainer::create( |
341 getExecutionContext(), getNavigatorServiceWorker()); | 346 getExecutionContext(), getNavigatorServiceWorker()); |
342 | 347 |
343 // register | 348 // register |
344 { | 349 { |
345 ScriptState::Scope scriptScope(getScriptState()); | 350 ScriptState::Scope scriptScope(getScriptState()); |
346 RegistrationOptions options; | 351 RegistrationOptions options; |
347 options.setScope("y/"); | 352 options.setScope("y/"); |
348 container->registerServiceWorker(getScriptState(), "/x/y/worker.js", | 353 container->registerServiceWorker(getScriptState(), "/x/y/worker.js", |
349 options); | 354 options); |
350 | 355 |
351 EXPECT_EQ(1ul, stubProvider.registerCallCount()); | 356 EXPECT_EQ(1ul, stubProvider.registerCallCount()); |
352 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), | 357 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), |
353 stubProvider.registerScope()); | 358 stubProvider.registerScope()); |
354 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/worker.js")), | 359 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/worker.js")), |
355 stubProvider.registerScriptURL()); | 360 stubProvider.registerScriptURL()); |
361 EXPECT_EQ(false, stubProvider.useCache()); | |
nhiroki
2017/03/28 06:49:51
Can you use EXPECT_FALSE?
EXPECT_FALSE(stubProv
yuryu
2017/07/20 10:15:12
Acknowledged.
| |
356 } | 362 } |
357 } | 363 } |
358 | 364 |
359 TEST_F(ServiceWorkerContainerTest, | 365 TEST_F(ServiceWorkerContainerTest, |
360 GetRegistration_OmittedDocumentURLDefaultsToPageURL) { | 366 GetRegistration_OmittedDocumentURLDefaultsToPageURL) { |
361 setPageURL("http://localhost/x/index.html"); | 367 setPageURL("http://localhost/x/index.html"); |
362 | 368 |
363 StubWebServiceWorkerProvider stubProvider; | 369 StubWebServiceWorkerProvider stubProvider; |
364 provide(stubProvider.provider()); | 370 provide(stubProvider.provider()); |
365 | 371 |
366 ServiceWorkerContainer* container = ServiceWorkerContainer::create( | 372 ServiceWorkerContainer* container = ServiceWorkerContainer::create( |
367 getExecutionContext(), getNavigatorServiceWorker()); | 373 getExecutionContext(), getNavigatorServiceWorker()); |
368 | 374 |
369 { | 375 { |
370 ScriptState::Scope scriptScope(getScriptState()); | 376 ScriptState::Scope scriptScope(getScriptState()); |
371 container->getRegistration(getScriptState(), ""); | 377 container->getRegistration(getScriptState(), ""); |
372 EXPECT_EQ(1ul, stubProvider.getRegistrationCallCount()); | 378 EXPECT_EQ(1ul, stubProvider.getRegistrationCallCount()); |
373 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/index.html")), | 379 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/index.html")), |
374 stubProvider.getRegistrationURL()); | 380 stubProvider.getRegistrationURL()); |
375 } | 381 } |
376 } | 382 } |
377 | 383 |
384 TEST_F(ServiceWorkerContainerTest, | |
385 RegisterUnregister_UseCacheOptionDelegatesToProvider) { | |
386 setPageURL("http://localhost/x/index.html"); | |
387 | |
388 StubWebServiceWorkerProvider stubProvider; | |
389 provide(stubProvider.provider()); | |
390 | |
391 ServiceWorkerContainer* container = ServiceWorkerContainer::create( | |
392 getExecutionContext(), getNavigatorServiceWorker()); | |
393 | |
394 // register | |
395 { | |
396 ScriptState::Scope scriptScope(getScriptState()); | |
397 RegistrationOptions options; | |
398 options.setUseCache(true); | |
399 container->registerServiceWorker(getScriptState(), "/x/y/worker.js", | |
400 options); | |
401 | |
402 EXPECT_EQ(1ul, stubProvider.registerCallCount()); | |
403 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")), | |
404 stubProvider.registerScope()); | |
405 EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/worker.js")), | |
406 stubProvider.registerScriptURL()); | |
407 EXPECT_EQ(true, stubProvider.useCache()); | |
nhiroki
2017/03/28 06:49:51
EXPECT_TRUE(stubProvider.useCache());
yuryu
2017/07/20 10:15:12
Acknowledged.
| |
408 } | |
409 } | |
410 | |
378 } // namespace | 411 } // namespace |
379 } // namespace blink | 412 } // namespace blink |
OLD | NEW |