OLD | NEW |
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 "config.h" | 5 #include "config.h" |
6 #include "modules/serviceworkers/Cache.h" | 6 #include "modules/cachestorage/Cache.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptFunction.h" | 9 #include "bindings/core/v8/ScriptFunction.h" |
10 #include "bindings/core/v8/ScriptPromise.h" | 10 #include "bindings/core/v8/ScriptPromise.h" |
11 #include "bindings/core/v8/ScriptValue.h" | 11 #include "bindings/core/v8/ScriptValue.h" |
12 #include "bindings/core/v8/V8Binding.h" | 12 #include "bindings/core/v8/V8Binding.h" |
13 #include "bindings/modules/v8/V8Request.h" | 13 #include "bindings/modules/v8/V8Request.h" |
14 #include "bindings/modules/v8/V8Response.h" | 14 #include "bindings/modules/v8/V8Response.h" |
15 #include "core/dom/Document.h" | 15 #include "core/dom/Document.h" |
16 #include "core/frame/Frame.h" | 16 #include "core/frame/Frame.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 const WebVector<BatchOperation>* m_expectedBatchOperations; | 145 const WebVector<BatchOperation>* m_expectedBatchOperations; |
146 | 146 |
147 std::string m_lastErrorWebCacheMethodCalled; | 147 std::string m_lastErrorWebCacheMethodCalled; |
148 }; | 148 }; |
149 | 149 |
150 class NotImplementedErrorCache : public ErrorWebCacheForTests { | 150 class NotImplementedErrorCache : public ErrorWebCacheForTests { |
151 public: | 151 public: |
152 NotImplementedErrorCache() : ErrorWebCacheForTests(WebServiceWorkerCacheErro
rNotImplemented) { } | 152 NotImplementedErrorCache() : ErrorWebCacheForTests(WebServiceWorkerCacheErro
rNotImplemented) { } |
153 }; | 153 }; |
154 | 154 |
155 class ServiceWorkerCacheTest : public ::testing::Test { | 155 class CacheStorageTest : public ::testing::Test { |
156 public: | 156 public: |
157 ServiceWorkerCacheTest() | 157 CacheStorageTest() |
158 : m_page(DummyPageHolder::create(IntSize(1, 1))) { } | 158 : m_page(DummyPageHolder::create(IntSize(1, 1))) { } |
159 | 159 |
160 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume
nt().frame()); } | 160 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume
nt().frame()); } |
161 ExecutionContext* executionContext() { return scriptState()->executionContex
t(); } | 161 ExecutionContext* executionContext() { return scriptState()->executionContex
t(); } |
162 v8::Isolate* isolate() { return scriptState()->isolate(); } | 162 v8::Isolate* isolate() { return scriptState()->isolate(); } |
163 | 163 |
164 Request* newRequestFromUrl(const String& url) | 164 Request* newRequestFromUrl(const String& url) |
165 { | 165 { |
166 TrackExceptionState exceptionState; | 166 TrackExceptionState exceptionState; |
167 Request* request = Request::create(executionContext(), url, exceptionSta
te); | 167 Request* request = Request::create(executionContext(), url, exceptionSta
te); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 return info; | 273 return info; |
274 } | 274 } |
275 | 275 |
276 RequestInfo requestToRequestInfo(Request* value) | 276 RequestInfo requestToRequestInfo(Request* value) |
277 { | 277 { |
278 RequestInfo info; | 278 RequestInfo info; |
279 info.setRequest(value); | 279 info.setRequest(value); |
280 return info; | 280 return info; |
281 } | 281 } |
282 | 282 |
283 TEST_F(ServiceWorkerCacheTest, Basics) | 283 TEST_F(CacheStorageTest, Basics) |
284 { | 284 { |
285 ErrorWebCacheForTests* testCache; | 285 ErrorWebCacheForTests* testCache; |
286 Cache* cache = Cache::create(testCache = new NotImplementedErrorCache()); | 286 Cache* cache = Cache::create(testCache = new NotImplementedErrorCache()); |
287 ASSERT(cache); | 287 ASSERT(cache); |
288 | 288 |
289 const String url = "http://www.cachetest.org/"; | 289 const String url = "http://www.cachetest.org/"; |
290 | 290 |
291 CacheQueryOptions options; | 291 CacheQueryOptions options; |
292 ScriptPromise matchPromise = cache->match(scriptState(), stringToRequestInfo
(url), options, exceptionState()); | 292 ScriptPromise matchPromise = cache->match(scriptState(), stringToRequestInfo
(url), options, exceptionState()); |
293 EXPECT_EQ(kNotImplementedString, getRejectString(matchPromise)); | 293 EXPECT_EQ(kNotImplementedString, getRejectString(matchPromise)); |
294 | 294 |
295 cache = Cache::create(testCache = new ErrorWebCacheForTests(WebServiceWorker
CacheErrorNotFound)); | 295 cache = Cache::create(testCache = new ErrorWebCacheForTests(WebServiceWorker
CacheErrorNotFound)); |
296 matchPromise = cache->match(scriptState(), stringToRequestInfo(url), options
, exceptionState()); | 296 matchPromise = cache->match(scriptState(), stringToRequestInfo(url), options
, exceptionState()); |
297 ScriptValue scriptValue = getResolveValue(matchPromise); | 297 ScriptValue scriptValue = getResolveValue(matchPromise); |
298 EXPECT_TRUE(scriptValue.isUndefined()); | 298 EXPECT_TRUE(scriptValue.isUndefined()); |
299 | 299 |
300 cache = Cache::create(testCache = new ErrorWebCacheForTests(WebServiceWorker
CacheErrorExists)); | 300 cache = Cache::create(testCache = new ErrorWebCacheForTests(WebServiceWorker
CacheErrorExists)); |
301 matchPromise = cache->match(scriptState(), stringToRequestInfo(url), options
, exceptionState()); | 301 matchPromise = cache->match(scriptState(), stringToRequestInfo(url), options
, exceptionState()); |
302 EXPECT_EQ("InvalidAccessError: Entry already exists.", getRejectString(match
Promise)); | 302 EXPECT_EQ("InvalidAccessError: Entry already exists.", getRejectString(match
Promise)); |
303 } | 303 } |
304 | 304 |
305 // Tests that arguments are faithfully passed on calls to Cache methods, except
for methods which use batch operations, | 305 // Tests that arguments are faithfully passed on calls to Cache methods, except
for methods which use batch operations, |
306 // which are tested later. | 306 // which are tested later. |
307 TEST_F(ServiceWorkerCacheTest, BasicArguments) | 307 TEST_F(CacheStorageTest, BasicArguments) |
308 { | 308 { |
309 ErrorWebCacheForTests* testCache; | 309 ErrorWebCacheForTests* testCache; |
310 Cache* cache = Cache::create(testCache = new NotImplementedErrorCache()); | 310 Cache* cache = Cache::create(testCache = new NotImplementedErrorCache()); |
311 ASSERT(cache); | 311 ASSERT(cache); |
312 | 312 |
313 const String url = "http://www.cache.arguments.test/"; | 313 const String url = "http://www.cache.arguments.test/"; |
314 testCache->setExpectedUrl(&url); | 314 testCache->setExpectedUrl(&url); |
315 | 315 |
316 WebServiceWorkerCache::QueryParams expectedQueryParams; | 316 WebServiceWorkerCache::QueryParams expectedQueryParams; |
317 expectedQueryParams.ignoreVary = true; | 317 expectedQueryParams.ignoreVary = true; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 ScriptPromise keysResult2 = cache->keys(scriptState(), requestToRequestInfo(
request), options, exceptionState()); | 351 ScriptPromise keysResult2 = cache->keys(scriptState(), requestToRequestInfo(
request), options, exceptionState()); |
352 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); | 352 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); |
353 EXPECT_EQ(kNotImplementedString, getRejectString(keysResult2)); | 353 EXPECT_EQ(kNotImplementedString, getRejectString(keysResult2)); |
354 | 354 |
355 ScriptPromise stringKeysResult2 = cache->keys(scriptState(), stringToRequest
Info(url), options, exceptionState()); | 355 ScriptPromise stringKeysResult2 = cache->keys(scriptState(), stringToRequest
Info(url), options, exceptionState()); |
356 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); | 356 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); |
357 EXPECT_EQ(kNotImplementedString, getRejectString(stringKeysResult2)); | 357 EXPECT_EQ(kNotImplementedString, getRejectString(stringKeysResult2)); |
358 } | 358 } |
359 | 359 |
360 // Tests that arguments are faithfully passed to API calls that degrade to batch
operations. | 360 // Tests that arguments are faithfully passed to API calls that degrade to batch
operations. |
361 TEST_F(ServiceWorkerCacheTest, BatchOperationArguments) | 361 TEST_F(CacheStorageTest, BatchOperationArguments) |
362 { | 362 { |
363 ErrorWebCacheForTests* testCache; | 363 ErrorWebCacheForTests* testCache; |
364 Cache* cache = Cache::create(testCache = new NotImplementedErrorCache()); | 364 Cache* cache = Cache::create(testCache = new NotImplementedErrorCache()); |
365 ASSERT(cache); | 365 ASSERT(cache); |
366 | 366 |
367 WebServiceWorkerCache::QueryParams expectedQueryParams; | 367 WebServiceWorkerCache::QueryParams expectedQueryParams; |
368 expectedQueryParams.cacheName = "this is another cache name"; | 368 expectedQueryParams.cacheName = "this is another cache name"; |
369 testCache->setExpectedQueryParams(&expectedQueryParams); | 369 testCache->setExpectedQueryParams(&expectedQueryParams); |
370 | 370 |
371 CacheQueryOptions options; | 371 CacheQueryOptions options; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 virtual void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceW
orkerRequest& webRequest, const QueryParams& queryParams) override | 429 virtual void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceW
orkerRequest& webRequest, const QueryParams& queryParams) override |
430 { | 430 { |
431 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 431 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
432 return callbacks->onSuccess(&m_response); | 432 return callbacks->onSuccess(&m_response); |
433 } | 433 } |
434 | 434 |
435 private: | 435 private: |
436 WebServiceWorkerResponse& m_response; | 436 WebServiceWorkerResponse& m_response; |
437 }; | 437 }; |
438 | 438 |
439 TEST_F(ServiceWorkerCacheTest, MatchResponseTest) | 439 TEST_F(CacheStorageTest, MatchResponseTest) |
440 { | 440 { |
441 const String requestUrl = "http://request.url/"; | 441 const String requestUrl = "http://request.url/"; |
442 const String responseUrl = "http://match.response.test/"; | 442 const String responseUrl = "http://match.response.test/"; |
443 | 443 |
444 WebServiceWorkerResponse webResponse; | 444 WebServiceWorkerResponse webResponse; |
445 webResponse.setURL(KURL(ParsedURLString, responseUrl)); | 445 webResponse.setURL(KURL(ParsedURLString, responseUrl)); |
446 webResponse.setResponseType(WebServiceWorkerResponseTypeDefault); | 446 webResponse.setResponseType(WebServiceWorkerResponseTypeDefault); |
447 | 447 |
448 Cache* cache = Cache::create(new MatchTestCache(webResponse)); | 448 Cache* cache = Cache::create(new MatchTestCache(webResponse)); |
449 CacheQueryOptions options; | 449 CacheQueryOptions options; |
(...skipping 13 matching lines...) Expand all Loading... |
463 virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebSe
rviceWorkerRequest* webRequest, const QueryParams& queryParams) override | 463 virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebSe
rviceWorkerRequest* webRequest, const QueryParams& queryParams) override |
464 { | 464 { |
465 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 465 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
466 return callbacks->onSuccess(&m_requests); | 466 return callbacks->onSuccess(&m_requests); |
467 } | 467 } |
468 | 468 |
469 private: | 469 private: |
470 WebVector<WebServiceWorkerRequest>& m_requests; | 470 WebVector<WebServiceWorkerRequest>& m_requests; |
471 }; | 471 }; |
472 | 472 |
473 TEST_F(ServiceWorkerCacheTest, KeysResponseTest) | 473 TEST_F(CacheStorageTest, KeysResponseTest) |
474 { | 474 { |
475 const String url1 = "http://first.request/"; | 475 const String url1 = "http://first.request/"; |
476 const String url2 = "http://second.request/"; | 476 const String url2 = "http://second.request/"; |
477 | 477 |
478 Vector<String> expectedUrls(size_t(2)); | 478 Vector<String> expectedUrls(size_t(2)); |
479 expectedUrls[0] = url1; | 479 expectedUrls[0] = url1; |
480 expectedUrls[1] = url2; | 480 expectedUrls[1] = url2; |
481 | 481 |
482 WebVector<WebServiceWorkerRequest> webRequests(size_t(2)); | 482 WebVector<WebServiceWorkerRequest> webRequests(size_t(2)); |
483 webRequests[0].setURL(KURL(ParsedURLString, url1)); | 483 webRequests[0].setURL(KURL(ParsedURLString, url1)); |
(...skipping 28 matching lines...) Expand all Loading... |
512 virtual void dispatchBatch(CacheWithResponsesCallbacks* callbacks, const Web
Vector<BatchOperation>& batchOperations) override | 512 virtual void dispatchBatch(CacheWithResponsesCallbacks* callbacks, const Web
Vector<BatchOperation>& batchOperations) override |
513 { | 513 { |
514 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 514 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
515 return callbacks->onSuccess(&m_responses); | 515 return callbacks->onSuccess(&m_responses); |
516 } | 516 } |
517 | 517 |
518 private: | 518 private: |
519 WebVector<WebServiceWorkerResponse>& m_responses; | 519 WebVector<WebServiceWorkerResponse>& m_responses; |
520 }; | 520 }; |
521 | 521 |
522 TEST_F(ServiceWorkerCacheTest, MatchAllAndBatchResponseTest) | 522 TEST_F(CacheStorageTest, MatchAllAndBatchResponseTest) |
523 { | 523 { |
524 const String url1 = "http://first.response/"; | 524 const String url1 = "http://first.response/"; |
525 const String url2 = "http://second.response/"; | 525 const String url2 = "http://second.response/"; |
526 | 526 |
527 Vector<String> expectedUrls(size_t(2)); | 527 Vector<String> expectedUrls(size_t(2)); |
528 expectedUrls[0] = url1; | 528 expectedUrls[0] = url1; |
529 expectedUrls[1] = url2; | 529 expectedUrls[1] = url2; |
530 | 530 |
531 WebVector<WebServiceWorkerResponse> webResponses(size_t(2)); | 531 WebVector<WebServiceWorkerResponse> webResponses(size_t(2)); |
532 webResponses[0].setURL(KURL(ParsedURLString, url1)); | 532 webResponses[0].setURL(KURL(ParsedURLString, url1)); |
(...skipping 17 matching lines...) Expand all Loading... |
550 } | 550 } |
551 | 551 |
552 result = cache->deleteFunction(scriptState(), stringToRequestInfo("http://so
me.url/"), options, exceptionState()); | 552 result = cache->deleteFunction(scriptState(), stringToRequestInfo("http://so
me.url/"), options, exceptionState()); |
553 scriptValue = getResolveValue(result); | 553 scriptValue = getResolveValue(result); |
554 EXPECT_TRUE(scriptValue.v8Value()->IsBoolean()); | 554 EXPECT_TRUE(scriptValue.v8Value()->IsBoolean()); |
555 EXPECT_EQ(true, scriptValue.v8Value()->BooleanValue()); | 555 EXPECT_EQ(true, scriptValue.v8Value()->BooleanValue()); |
556 } | 556 } |
557 | 557 |
558 } // namespace | 558 } // namespace |
559 } // namespace blink | 559 } // namespace blink |
OLD | NEW |