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 "modules/cachestorage/Cache.h" | 5 #include "modules/cachestorage/Cache.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/ScriptFunction.h" | 8 #include "bindings/core/v8/ScriptFunction.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 class CacheStorageTest : public ::testing::Test { | 224 class CacheStorageTest : public ::testing::Test { |
225 public: | 225 public: |
226 CacheStorageTest() | 226 CacheStorageTest() |
227 : m_page(DummyPageHolder::create(IntSize(1, 1))) { } | 227 : m_page(DummyPageHolder::create(IntSize(1, 1))) { } |
228 | 228 |
229 Cache* createCache(ScopedFetcherForTests* fetcher, WebServiceWorkerCache* we
bCache) | 229 Cache* createCache(ScopedFetcherForTests* fetcher, WebServiceWorkerCache* we
bCache) |
230 { | 230 { |
231 return Cache::create(fetcher->weakPtr(), adoptPtr(webCache)); | 231 return Cache::create(fetcher->weakPtr(), adoptPtr(webCache)); |
232 } | 232 } |
233 | 233 |
234 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume
nt().frame()); } | 234 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc
ument().frame()); } |
235 ExecutionContext* executionContext() { return scriptState()->executionContex
t(); } | 235 ExecutionContext* getExecutionContext() { return getScriptState()->getExecut
ionContext(); } |
236 v8::Isolate* isolate() { return scriptState()->isolate(); } | 236 v8::Isolate* isolate() { return getScriptState()->isolate(); } |
237 v8::Local<v8::Context> context() { return scriptState()->context(); } | 237 v8::Local<v8::Context> context() { return getScriptState()->context(); } |
238 | 238 |
239 Request* newRequestFromUrl(const String& url) | 239 Request* newRequestFromUrl(const String& url) |
240 { | 240 { |
241 TrackExceptionState exceptionState; | 241 TrackExceptionState exceptionState; |
242 Request* request = Request::create(scriptState(), url, exceptionState); | 242 Request* request = Request::create(getScriptState(), url, exceptionState
); |
243 EXPECT_FALSE(exceptionState.hadException()); | 243 EXPECT_FALSE(exceptionState.hadException()); |
244 return exceptionState.hadException() ? 0 : request; | 244 return exceptionState.hadException() ? 0 : request; |
245 } | 245 } |
246 | 246 |
247 // Convenience methods for testing the returned promises. | 247 // Convenience methods for testing the returned promises. |
248 ScriptValue getRejectValue(ScriptPromise& promise) | 248 ScriptValue getRejectValue(ScriptPromise& promise) |
249 { | 249 { |
250 ScriptValue onReject; | 250 ScriptValue onReject; |
251 promise.then(UnreachableFunction::create(scriptState()), TestFunction::c
reate(scriptState(), &onReject)); | 251 promise.then(UnreachableFunction::create(getScriptState()), TestFunction
::create(getScriptState(), &onReject)); |
252 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 252 v8::MicrotasksScope::PerformCheckpoint(isolate()); |
253 return onReject; | 253 return onReject; |
254 } | 254 } |
255 | 255 |
256 std::string getRejectString(ScriptPromise& promise) | 256 std::string getRejectString(ScriptPromise& promise) |
257 { | 257 { |
258 ScriptValue onReject = getRejectValue(promise); | 258 ScriptValue onReject = getRejectValue(promise); |
259 return toCoreString(onReject.v8Value()->ToString(context()).ToLocalCheck
ed()).ascii().data(); | 259 return toCoreString(onReject.v8Value()->ToString(context()).ToLocalCheck
ed()).ascii().data(); |
260 } | 260 } |
261 | 261 |
262 ScriptValue getResolveValue(ScriptPromise& promise) | 262 ScriptValue getResolveValue(ScriptPromise& promise) |
263 { | 263 { |
264 ScriptValue onResolve; | 264 ScriptValue onResolve; |
265 promise.then(TestFunction::create(scriptState(), &onResolve), Unreachabl
eFunction::create(scriptState())); | 265 promise.then(TestFunction::create(getScriptState(), &onResolve), Unreach
ableFunction::create(getScriptState())); |
266 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 266 v8::MicrotasksScope::PerformCheckpoint(isolate()); |
267 return onResolve; | 267 return onResolve; |
268 } | 268 } |
269 | 269 |
270 std::string getResolveString(ScriptPromise& promise) | 270 std::string getResolveString(ScriptPromise& promise) |
271 { | 271 { |
272 ScriptValue onResolve = getResolveValue(promise); | 272 ScriptValue onResolve = getResolveValue(promise); |
273 return toCoreString(onResolve.v8Value()->ToString(context()).ToLocalChec
ked()).ascii().data(); | 273 return toCoreString(onResolve.v8Value()->ToString(context()).ToLocalChec
ked()).ascii().data(); |
274 } | 274 } |
275 | 275 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 335 |
336 RequestInfo requestToRequestInfo(Request* value) | 336 RequestInfo requestToRequestInfo(Request* value) |
337 { | 337 { |
338 RequestInfo info; | 338 RequestInfo info; |
339 info.setRequest(value); | 339 info.setRequest(value); |
340 return info; | 340 return info; |
341 } | 341 } |
342 | 342 |
343 TEST_F(CacheStorageTest, Basics) | 343 TEST_F(CacheStorageTest, Basics) |
344 { | 344 { |
345 ScriptState::Scope scope(scriptState()); | 345 ScriptState::Scope scope(getScriptState()); |
346 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); | 346 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); |
347 ErrorWebCacheForTests* testCache; | 347 ErrorWebCacheForTests* testCache; |
348 Cache* cache = createCache(fetcher.get(), testCache = new NotImplementedErro
rCache()); | 348 Cache* cache = createCache(fetcher.get(), testCache = new NotImplementedErro
rCache()); |
349 ASSERT(cache); | 349 ASSERT(cache); |
350 | 350 |
351 const String url = "http://www.cachetest.org/"; | 351 const String url = "http://www.cachetest.org/"; |
352 | 352 |
353 CacheQueryOptions options; | 353 CacheQueryOptions options; |
354 ScriptPromise matchPromise = cache->match(scriptState(), stringToRequestInfo
(url), options, exceptionState()); | 354 ScriptPromise matchPromise = cache->match(getScriptState(), stringToRequestI
nfo(url), options, exceptionState()); |
355 EXPECT_EQ(kNotImplementedString, getRejectString(matchPromise)); | 355 EXPECT_EQ(kNotImplementedString, getRejectString(matchPromise)); |
356 | 356 |
357 cache = createCache(fetcher.get(), testCache = new ErrorWebCacheForTests(Web
ServiceWorkerCacheErrorNotFound)); | 357 cache = createCache(fetcher.get(), testCache = new ErrorWebCacheForTests(Web
ServiceWorkerCacheErrorNotFound)); |
358 matchPromise = cache->match(scriptState(), stringToRequestInfo(url), options
, exceptionState()); | 358 matchPromise = cache->match(getScriptState(), stringToRequestInfo(url), opti
ons, exceptionState()); |
359 ScriptValue scriptValue = getResolveValue(matchPromise); | 359 ScriptValue scriptValue = getResolveValue(matchPromise); |
360 EXPECT_TRUE(scriptValue.isUndefined()); | 360 EXPECT_TRUE(scriptValue.isUndefined()); |
361 | 361 |
362 cache = createCache(fetcher.get(), testCache = new ErrorWebCacheForTests(Web
ServiceWorkerCacheErrorExists)); | 362 cache = createCache(fetcher.get(), testCache = new ErrorWebCacheForTests(Web
ServiceWorkerCacheErrorExists)); |
363 matchPromise = cache->match(scriptState(), stringToRequestInfo(url), options
, exceptionState()); | 363 matchPromise = cache->match(getScriptState(), stringToRequestInfo(url), opti
ons, exceptionState()); |
364 EXPECT_EQ("InvalidAccessError: Entry already exists.", getRejectString(match
Promise)); | 364 EXPECT_EQ("InvalidAccessError: Entry already exists.", getRejectString(match
Promise)); |
365 } | 365 } |
366 | 366 |
367 // Tests that arguments are faithfully passed on calls to Cache methods, except
for methods which use batch operations, | 367 // Tests that arguments are faithfully passed on calls to Cache methods, except
for methods which use batch operations, |
368 // which are tested later. | 368 // which are tested later. |
369 TEST_F(CacheStorageTest, BasicArguments) | 369 TEST_F(CacheStorageTest, BasicArguments) |
370 { | 370 { |
371 ScriptState::Scope scope(scriptState()); | 371 ScriptState::Scope scope(getScriptState()); |
372 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); | 372 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); |
373 ErrorWebCacheForTests* testCache; | 373 ErrorWebCacheForTests* testCache; |
374 Cache* cache = createCache(fetcher.get(), testCache = new NotImplementedErro
rCache()); | 374 Cache* cache = createCache(fetcher.get(), testCache = new NotImplementedErro
rCache()); |
375 ASSERT(cache); | 375 ASSERT(cache); |
376 | 376 |
377 const String url = "http://www.cache.arguments.test/"; | 377 const String url = "http://www.cache.arguments.test/"; |
378 testCache->setExpectedUrl(&url); | 378 testCache->setExpectedUrl(&url); |
379 | 379 |
380 WebServiceWorkerCache::QueryParams expectedQueryParams; | 380 WebServiceWorkerCache::QueryParams expectedQueryParams; |
381 expectedQueryParams.ignoreVary = true; | 381 expectedQueryParams.ignoreVary = true; |
382 expectedQueryParams.cacheName = "this is a cache name"; | 382 expectedQueryParams.cacheName = "this is a cache name"; |
383 testCache->setExpectedQueryParams(&expectedQueryParams); | 383 testCache->setExpectedQueryParams(&expectedQueryParams); |
384 | 384 |
385 CacheQueryOptions options; | 385 CacheQueryOptions options; |
386 options.setIgnoreVary(1); | 386 options.setIgnoreVary(1); |
387 options.setCacheName(expectedQueryParams.cacheName); | 387 options.setCacheName(expectedQueryParams.cacheName); |
388 | 388 |
389 Request* request = newRequestFromUrl(url); | 389 Request* request = newRequestFromUrl(url); |
390 ASSERT(request); | 390 ASSERT(request); |
391 ScriptPromise matchResult = cache->match(scriptState(), requestToRequestInfo
(request), options, exceptionState()); | 391 ScriptPromise matchResult = cache->match(getScriptState(), requestToRequestI
nfo(request), options, exceptionState()); |
392 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 392 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
393 EXPECT_EQ(kNotImplementedString, getRejectString(matchResult)); | 393 EXPECT_EQ(kNotImplementedString, getRejectString(matchResult)); |
394 | 394 |
395 ScriptPromise stringMatchResult = cache->match(scriptState(), stringToReques
tInfo(url), options, exceptionState()); | 395 ScriptPromise stringMatchResult = cache->match(getScriptState(), stringToReq
uestInfo(url), options, exceptionState()); |
396 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 396 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
397 EXPECT_EQ(kNotImplementedString, getRejectString(stringMatchResult)); | 397 EXPECT_EQ(kNotImplementedString, getRejectString(stringMatchResult)); |
398 | 398 |
399 request = newRequestFromUrl(url); | 399 request = newRequestFromUrl(url); |
400 ASSERT(request); | 400 ASSERT(request); |
401 ScriptPromise matchAllResult = cache->matchAll(scriptState(), requestToReque
stInfo(request), options, exceptionState()); | 401 ScriptPromise matchAllResult = cache->matchAll(getScriptState(), requestToRe
questInfo(request), options, exceptionState()); |
402 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); | 402 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); |
403 EXPECT_EQ(kNotImplementedString, getRejectString(matchAllResult)); | 403 EXPECT_EQ(kNotImplementedString, getRejectString(matchAllResult)); |
404 | 404 |
405 ScriptPromise stringMatchAllResult = cache->matchAll(scriptState(), stringTo
RequestInfo(url), options, exceptionState()); | 405 ScriptPromise stringMatchAllResult = cache->matchAll(getScriptState(), strin
gToRequestInfo(url), options, exceptionState()); |
406 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); | 406 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); |
407 EXPECT_EQ(kNotImplementedString, getRejectString(stringMatchAllResult)); | 407 EXPECT_EQ(kNotImplementedString, getRejectString(stringMatchAllResult)); |
408 | 408 |
409 ScriptPromise keysResult1 = cache->keys(scriptState(), exceptionState()); | 409 ScriptPromise keysResult1 = cache->keys(getScriptState(), exceptionState()); |
410 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); | 410 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); |
411 EXPECT_EQ(kNotImplementedString, getRejectString(keysResult1)); | 411 EXPECT_EQ(kNotImplementedString, getRejectString(keysResult1)); |
412 | 412 |
413 request = newRequestFromUrl(url); | 413 request = newRequestFromUrl(url); |
414 ASSERT(request); | 414 ASSERT(request); |
415 ScriptPromise keysResult2 = cache->keys(scriptState(), requestToRequestInfo(
request), options, exceptionState()); | 415 ScriptPromise keysResult2 = cache->keys(getScriptState(), requestToRequestIn
fo(request), options, exceptionState()); |
416 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); | 416 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); |
417 EXPECT_EQ(kNotImplementedString, getRejectString(keysResult2)); | 417 EXPECT_EQ(kNotImplementedString, getRejectString(keysResult2)); |
418 | 418 |
419 ScriptPromise stringKeysResult2 = cache->keys(scriptState(), stringToRequest
Info(url), options, exceptionState()); | 419 ScriptPromise stringKeysResult2 = cache->keys(getScriptState(), stringToRequ
estInfo(url), options, exceptionState()); |
420 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); | 420 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); |
421 EXPECT_EQ(kNotImplementedString, getRejectString(stringKeysResult2)); | 421 EXPECT_EQ(kNotImplementedString, getRejectString(stringKeysResult2)); |
422 } | 422 } |
423 | 423 |
424 // Tests that arguments are faithfully passed to API calls that degrade to batch
operations. | 424 // Tests that arguments are faithfully passed to API calls that degrade to batch
operations. |
425 TEST_F(CacheStorageTest, BatchOperationArguments) | 425 TEST_F(CacheStorageTest, BatchOperationArguments) |
426 { | 426 { |
427 ScriptState::Scope scope(scriptState()); | 427 ScriptState::Scope scope(getScriptState()); |
428 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); | 428 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); |
429 ErrorWebCacheForTests* testCache; | 429 ErrorWebCacheForTests* testCache; |
430 Cache* cache = createCache(fetcher.get(), testCache = new NotImplementedErro
rCache()); | 430 Cache* cache = createCache(fetcher.get(), testCache = new NotImplementedErro
rCache()); |
431 ASSERT(cache); | 431 ASSERT(cache); |
432 | 432 |
433 WebServiceWorkerCache::QueryParams expectedQueryParams; | 433 WebServiceWorkerCache::QueryParams expectedQueryParams; |
434 expectedQueryParams.cacheName = "this is another cache name"; | 434 expectedQueryParams.cacheName = "this is another cache name"; |
435 testCache->setExpectedQueryParams(&expectedQueryParams); | 435 testCache->setExpectedQueryParams(&expectedQueryParams); |
436 | 436 |
437 CacheQueryOptions options; | 437 CacheQueryOptions options; |
438 options.setCacheName(expectedQueryParams.cacheName); | 438 options.setCacheName(expectedQueryParams.cacheName); |
439 | 439 |
440 const String url = "http://batch.operations.test/"; | 440 const String url = "http://batch.operations.test/"; |
441 Request* request = newRequestFromUrl(url); | 441 Request* request = newRequestFromUrl(url); |
442 ASSERT(request); | 442 ASSERT(request); |
443 | 443 |
444 WebServiceWorkerResponse webResponse; | 444 WebServiceWorkerResponse webResponse; |
445 webResponse.setURL(KURL(ParsedURLString, url)); | 445 webResponse.setURL(KURL(ParsedURLString, url)); |
446 Response* response = Response::create(executionContext(), webResponse); | 446 Response* response = Response::create(getExecutionContext(), webResponse); |
447 | 447 |
448 WebVector<WebServiceWorkerCache::BatchOperation> expectedDeleteOperations(si
ze_t(1)); | 448 WebVector<WebServiceWorkerCache::BatchOperation> expectedDeleteOperations(si
ze_t(1)); |
449 { | 449 { |
450 WebServiceWorkerCache::BatchOperation deleteOperation; | 450 WebServiceWorkerCache::BatchOperation deleteOperation; |
451 deleteOperation.operationType = WebServiceWorkerCache::OperationTypeDele
te; | 451 deleteOperation.operationType = WebServiceWorkerCache::OperationTypeDele
te; |
452 request->populateWebServiceWorkerRequest(deleteOperation.request); | 452 request->populateWebServiceWorkerRequest(deleteOperation.request); |
453 deleteOperation.matchParams = expectedQueryParams; | 453 deleteOperation.matchParams = expectedQueryParams; |
454 expectedDeleteOperations[0] = deleteOperation; | 454 expectedDeleteOperations[0] = deleteOperation; |
455 } | 455 } |
456 testCache->setExpectedBatchOperations(&expectedDeleteOperations); | 456 testCache->setExpectedBatchOperations(&expectedDeleteOperations); |
457 | 457 |
458 ScriptPromise deleteResult = cache->deleteFunction(scriptState(), requestToR
equestInfo(request), options, exceptionState()); | 458 ScriptPromise deleteResult = cache->deleteFunction(getScriptState(), request
ToRequestInfo(request), options, exceptionState()); |
459 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 459 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
460 EXPECT_EQ(kNotImplementedString, getRejectString(deleteResult)); | 460 EXPECT_EQ(kNotImplementedString, getRejectString(deleteResult)); |
461 | 461 |
462 ScriptPromise stringDeleteResult = cache->deleteFunction(scriptState(), stri
ngToRequestInfo(url), options, exceptionState()); | 462 ScriptPromise stringDeleteResult = cache->deleteFunction(getScriptState(), s
tringToRequestInfo(url), options, exceptionState()); |
463 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 463 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
464 EXPECT_EQ(kNotImplementedString, getRejectString(stringDeleteResult)); | 464 EXPECT_EQ(kNotImplementedString, getRejectString(stringDeleteResult)); |
465 | 465 |
466 WebVector<WebServiceWorkerCache::BatchOperation> expectedPutOperations(size_
t(1)); | 466 WebVector<WebServiceWorkerCache::BatchOperation> expectedPutOperations(size_
t(1)); |
467 { | 467 { |
468 WebServiceWorkerCache::BatchOperation putOperation; | 468 WebServiceWorkerCache::BatchOperation putOperation; |
469 putOperation.operationType = WebServiceWorkerCache::OperationTypePut; | 469 putOperation.operationType = WebServiceWorkerCache::OperationTypePut; |
470 request->populateWebServiceWorkerRequest(putOperation.request); | 470 request->populateWebServiceWorkerRequest(putOperation.request); |
471 response->populateWebServiceWorkerResponse(putOperation.response); | 471 response->populateWebServiceWorkerResponse(putOperation.response); |
472 expectedPutOperations[0] = putOperation; | 472 expectedPutOperations[0] = putOperation; |
473 } | 473 } |
474 testCache->setExpectedBatchOperations(&expectedPutOperations); | 474 testCache->setExpectedBatchOperations(&expectedPutOperations); |
475 | 475 |
476 request = newRequestFromUrl(url); | 476 request = newRequestFromUrl(url); |
477 ASSERT(request); | 477 ASSERT(request); |
478 ScriptPromise putResult = cache->put(scriptState(), requestToRequestInfo(req
uest), response->clone(exceptionState()), exceptionState()); | 478 ScriptPromise putResult = cache->put(getScriptState(), requestToRequestInfo(
request), response->clone(exceptionState()), exceptionState()); |
479 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 479 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
480 EXPECT_EQ(kNotImplementedString, getRejectString(putResult)); | 480 EXPECT_EQ(kNotImplementedString, getRejectString(putResult)); |
481 | 481 |
482 ScriptPromise stringPutResult = cache->put(scriptState(), stringToRequestInf
o(url), response, exceptionState()); | 482 ScriptPromise stringPutResult = cache->put(getScriptState(), stringToRequest
Info(url), response, exceptionState()); |
483 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 483 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
484 EXPECT_EQ(kNotImplementedString, getRejectString(stringPutResult)); | 484 EXPECT_EQ(kNotImplementedString, getRejectString(stringPutResult)); |
485 | 485 |
486 // FIXME: test add & addAll. | 486 // FIXME: test add & addAll. |
487 } | 487 } |
488 | 488 |
489 class MatchTestCache : public NotImplementedErrorCache { | 489 class MatchTestCache : public NotImplementedErrorCache { |
490 public: | 490 public: |
491 MatchTestCache(WebServiceWorkerResponse& response) | 491 MatchTestCache(WebServiceWorkerResponse& response) |
492 : m_response(response) { } | 492 : m_response(response) { } |
493 | 493 |
494 // From WebServiceWorkerCache: | 494 // From WebServiceWorkerCache: |
495 void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceWorkerReq
uest& webRequest, const QueryParams& queryParams) override | 495 void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceWorkerReq
uest& webRequest, const QueryParams& queryParams) override |
496 { | 496 { |
497 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 497 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
498 return callbacks->onSuccess(m_response); | 498 return callbacks->onSuccess(m_response); |
499 } | 499 } |
500 | 500 |
501 private: | 501 private: |
502 WebServiceWorkerResponse& m_response; | 502 WebServiceWorkerResponse& m_response; |
503 }; | 503 }; |
504 | 504 |
505 TEST_F(CacheStorageTest, MatchResponseTest) | 505 TEST_F(CacheStorageTest, MatchResponseTest) |
506 { | 506 { |
507 ScriptState::Scope scope(scriptState()); | 507 ScriptState::Scope scope(getScriptState()); |
508 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); | 508 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); |
509 const String requestUrl = "http://request.url/"; | 509 const String requestUrl = "http://request.url/"; |
510 const String responseUrl = "http://match.response.test/"; | 510 const String responseUrl = "http://match.response.test/"; |
511 | 511 |
512 WebServiceWorkerResponse webResponse; | 512 WebServiceWorkerResponse webResponse; |
513 webResponse.setURL(KURL(ParsedURLString, responseUrl)); | 513 webResponse.setURL(KURL(ParsedURLString, responseUrl)); |
514 webResponse.setResponseType(WebServiceWorkerResponseTypeDefault); | 514 webResponse.setResponseType(WebServiceWorkerResponseTypeDefault); |
515 | 515 |
516 Cache* cache = createCache(fetcher.get(), new MatchTestCache(webResponse)); | 516 Cache* cache = createCache(fetcher.get(), new MatchTestCache(webResponse)); |
517 CacheQueryOptions options; | 517 CacheQueryOptions options; |
518 | 518 |
519 ScriptPromise result = cache->match(scriptState(), stringToRequestInfo(reque
stUrl), options, exceptionState()); | 519 ScriptPromise result = cache->match(getScriptState(), stringToRequestInfo(re
questUrl), options, exceptionState()); |
520 ScriptValue scriptValue = getResolveValue(result); | 520 ScriptValue scriptValue = getResolveValue(result); |
521 Response* response = V8Response::toImplWithTypeCheck(isolate(), scriptValue.
v8Value()); | 521 Response* response = V8Response::toImplWithTypeCheck(isolate(), scriptValue.
v8Value()); |
522 ASSERT_TRUE(response); | 522 ASSERT_TRUE(response); |
523 EXPECT_EQ(responseUrl, response->url()); | 523 EXPECT_EQ(responseUrl, response->url()); |
524 } | 524 } |
525 | 525 |
526 class KeysTestCache : public NotImplementedErrorCache { | 526 class KeysTestCache : public NotImplementedErrorCache { |
527 public: | 527 public: |
528 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) | 528 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) |
529 : m_requests(requests) { } | 529 : m_requests(requests) { } |
530 | 530 |
531 void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebServiceWor
kerRequest* webRequest, const QueryParams& queryParams) override | 531 void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebServiceWor
kerRequest* webRequest, const QueryParams& queryParams) override |
532 { | 532 { |
533 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 533 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
534 return callbacks->onSuccess(m_requests); | 534 return callbacks->onSuccess(m_requests); |
535 } | 535 } |
536 | 536 |
537 private: | 537 private: |
538 WebVector<WebServiceWorkerRequest>& m_requests; | 538 WebVector<WebServiceWorkerRequest>& m_requests; |
539 }; | 539 }; |
540 | 540 |
541 TEST_F(CacheStorageTest, KeysResponseTest) | 541 TEST_F(CacheStorageTest, KeysResponseTest) |
542 { | 542 { |
543 ScriptState::Scope scope(scriptState()); | 543 ScriptState::Scope scope(getScriptState()); |
544 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); | 544 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); |
545 const String url1 = "http://first.request/"; | 545 const String url1 = "http://first.request/"; |
546 const String url2 = "http://second.request/"; | 546 const String url2 = "http://second.request/"; |
547 | 547 |
548 Vector<String> expectedUrls(size_t(2)); | 548 Vector<String> expectedUrls(size_t(2)); |
549 expectedUrls[0] = url1; | 549 expectedUrls[0] = url1; |
550 expectedUrls[1] = url2; | 550 expectedUrls[1] = url2; |
551 | 551 |
552 WebVector<WebServiceWorkerRequest> webRequests(size_t(2)); | 552 WebVector<WebServiceWorkerRequest> webRequests(size_t(2)); |
553 webRequests[0].setURL(KURL(ParsedURLString, url1)); | 553 webRequests[0].setURL(KURL(ParsedURLString, url1)); |
554 webRequests[1].setURL(KURL(ParsedURLString, url2)); | 554 webRequests[1].setURL(KURL(ParsedURLString, url2)); |
555 | 555 |
556 Cache* cache = createCache(fetcher.get(), new KeysTestCache(webRequests)); | 556 Cache* cache = createCache(fetcher.get(), new KeysTestCache(webRequests)); |
557 | 557 |
558 ScriptPromise result = cache->keys(scriptState(), exceptionState()); | 558 ScriptPromise result = cache->keys(getScriptState(), exceptionState()); |
559 ScriptValue scriptValue = getResolveValue(result); | 559 ScriptValue scriptValue = getResolveValue(result); |
560 | 560 |
561 Vector<v8::Local<v8::Value>> requests = toImplArray<Vector<v8::Local<v8::Val
ue>>>(scriptValue.v8Value(), 0, isolate(), exceptionState()); | 561 Vector<v8::Local<v8::Value>> requests = toImplArray<Vector<v8::Local<v8::Val
ue>>>(scriptValue.v8Value(), 0, isolate(), exceptionState()); |
562 EXPECT_EQ(expectedUrls.size(), requests.size()); | 562 EXPECT_EQ(expectedUrls.size(), requests.size()); |
563 for (int i = 0, minsize = std::min(expectedUrls.size(), requests.size()); i
< minsize; ++i) { | 563 for (int i = 0, minsize = std::min(expectedUrls.size(), requests.size()); i
< minsize; ++i) { |
564 Request* request = V8Request::toImplWithTypeCheck(isolate(), requests[i]
); | 564 Request* request = V8Request::toImplWithTypeCheck(isolate(), requests[i]
); |
565 EXPECT_TRUE(request); | 565 EXPECT_TRUE(request); |
566 if (request) | 566 if (request) |
567 EXPECT_EQ(expectedUrls[i], request->url()); | 567 EXPECT_EQ(expectedUrls[i], request->url()); |
568 } | 568 } |
(...skipping 15 matching lines...) Expand all Loading... |
584 OwnPtr<CacheBatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 584 OwnPtr<CacheBatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
585 return callbacks->onSuccess(); | 585 return callbacks->onSuccess(); |
586 } | 586 } |
587 | 587 |
588 private: | 588 private: |
589 WebVector<WebServiceWorkerResponse>& m_responses; | 589 WebVector<WebServiceWorkerResponse>& m_responses; |
590 }; | 590 }; |
591 | 591 |
592 TEST_F(CacheStorageTest, MatchAllAndBatchResponseTest) | 592 TEST_F(CacheStorageTest, MatchAllAndBatchResponseTest) |
593 { | 593 { |
594 ScriptState::Scope scope(scriptState()); | 594 ScriptState::Scope scope(getScriptState()); |
595 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); | 595 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); |
596 const String url1 = "http://first.response/"; | 596 const String url1 = "http://first.response/"; |
597 const String url2 = "http://second.response/"; | 597 const String url2 = "http://second.response/"; |
598 | 598 |
599 Vector<String> expectedUrls(size_t(2)); | 599 Vector<String> expectedUrls(size_t(2)); |
600 expectedUrls[0] = url1; | 600 expectedUrls[0] = url1; |
601 expectedUrls[1] = url2; | 601 expectedUrls[1] = url2; |
602 | 602 |
603 WebVector<WebServiceWorkerResponse> webResponses(size_t(2)); | 603 WebVector<WebServiceWorkerResponse> webResponses(size_t(2)); |
604 webResponses[0].setURL(KURL(ParsedURLString, url1)); | 604 webResponses[0].setURL(KURL(ParsedURLString, url1)); |
605 webResponses[0].setResponseType(WebServiceWorkerResponseTypeDefault); | 605 webResponses[0].setResponseType(WebServiceWorkerResponseTypeDefault); |
606 webResponses[1].setURL(KURL(ParsedURLString, url2)); | 606 webResponses[1].setURL(KURL(ParsedURLString, url2)); |
607 webResponses[1].setResponseType(WebServiceWorkerResponseTypeDefault); | 607 webResponses[1].setResponseType(WebServiceWorkerResponseTypeDefault); |
608 | 608 |
609 Cache* cache = createCache(fetcher.get(), new MatchAllAndBatchTestCache(webR
esponses)); | 609 Cache* cache = createCache(fetcher.get(), new MatchAllAndBatchTestCache(webR
esponses)); |
610 | 610 |
611 CacheQueryOptions options; | 611 CacheQueryOptions options; |
612 ScriptPromise result = cache->matchAll(scriptState(), stringToRequestInfo("h
ttp://some.url/"), options, exceptionState()); | 612 ScriptPromise result = cache->matchAll(getScriptState(), stringToRequestInfo
("http://some.url/"), options, exceptionState()); |
613 ScriptValue scriptValue = getResolveValue(result); | 613 ScriptValue scriptValue = getResolveValue(result); |
614 | 614 |
615 Vector<v8::Local<v8::Value>> responses = toImplArray<Vector<v8::Local<v8::Va
lue>>>(scriptValue.v8Value(), 0, isolate(), exceptionState()); | 615 Vector<v8::Local<v8::Value>> responses = toImplArray<Vector<v8::Local<v8::Va
lue>>>(scriptValue.v8Value(), 0, isolate(), exceptionState()); |
616 EXPECT_EQ(expectedUrls.size(), responses.size()); | 616 EXPECT_EQ(expectedUrls.size(), responses.size()); |
617 for (int i = 0, minsize = std::min(expectedUrls.size(), responses.size()); i
< minsize; ++i) { | 617 for (int i = 0, minsize = std::min(expectedUrls.size(), responses.size()); i
< minsize; ++i) { |
618 Response* response = V8Response::toImplWithTypeCheck(isolate(), response
s[i]); | 618 Response* response = V8Response::toImplWithTypeCheck(isolate(), response
s[i]); |
619 EXPECT_TRUE(response); | 619 EXPECT_TRUE(response); |
620 if (response) | 620 if (response) |
621 EXPECT_EQ(expectedUrls[i], response->url()); | 621 EXPECT_EQ(expectedUrls[i], response->url()); |
622 } | 622 } |
623 | 623 |
624 result = cache->deleteFunction(scriptState(), stringToRequestInfo("http://so
me.url/"), options, exceptionState()); | 624 result = cache->deleteFunction(getScriptState(), stringToRequestInfo("http:/
/some.url/"), options, exceptionState()); |
625 scriptValue = getResolveValue(result); | 625 scriptValue = getResolveValue(result); |
626 EXPECT_TRUE(scriptValue.v8Value()->IsBoolean()); | 626 EXPECT_TRUE(scriptValue.v8Value()->IsBoolean()); |
627 EXPECT_EQ(true, scriptValue.v8Value().As<v8::Boolean>()->Value()); | 627 EXPECT_EQ(true, scriptValue.v8Value().As<v8::Boolean>()->Value()); |
628 } | 628 } |
629 | 629 |
630 TEST_F(CacheStorageTest, Add) | 630 TEST_F(CacheStorageTest, Add) |
631 { | 631 { |
632 ScriptState::Scope scope(scriptState()); | 632 ScriptState::Scope scope(getScriptState()); |
633 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); | 633 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c
reate(); |
634 const String url = "http://www.cacheadd.test/"; | 634 const String url = "http://www.cacheadd.test/"; |
635 const String contentType = "text/plain"; | 635 const String contentType = "text/plain"; |
636 const String content = "hello cache"; | 636 const String content = "hello cache"; |
637 | 637 |
638 ErrorWebCacheForTests* testCache; | 638 ErrorWebCacheForTests* testCache; |
639 Cache* cache = createCache(fetcher.get(), testCache = new NotImplementedErro
rCache()); | 639 Cache* cache = createCache(fetcher.get(), testCache = new NotImplementedErro
rCache()); |
640 | 640 |
641 fetcher->setExpectedFetchUrl(&url); | 641 fetcher->setExpectedFetchUrl(&url); |
642 | 642 |
643 Request* request = newRequestFromUrl(url); | 643 Request* request = newRequestFromUrl(url); |
644 Response* response = Response::create(executionContext(), FetchFormDataConsu
merHandle::create(content), contentType, ResponseInit(), exceptionState()); | 644 Response* response = Response::create(getExecutionContext(), FetchFormDataCo
nsumerHandle::create(content), contentType, ResponseInit(), exceptionState()); |
645 fetcher->setResponse(response); | 645 fetcher->setResponse(response); |
646 | 646 |
647 WebVector<WebServiceWorkerCache::BatchOperation> expectedPutOperations(size_
t(1)); | 647 WebVector<WebServiceWorkerCache::BatchOperation> expectedPutOperations(size_
t(1)); |
648 { | 648 { |
649 WebServiceWorkerCache::BatchOperation putOperation; | 649 WebServiceWorkerCache::BatchOperation putOperation; |
650 putOperation.operationType = WebServiceWorkerCache::OperationTypePut; | 650 putOperation.operationType = WebServiceWorkerCache::OperationTypePut; |
651 request->populateWebServiceWorkerRequest(putOperation.request); | 651 request->populateWebServiceWorkerRequest(putOperation.request); |
652 response->populateWebServiceWorkerResponse(putOperation.response); | 652 response->populateWebServiceWorkerResponse(putOperation.response); |
653 expectedPutOperations[0] = putOperation; | 653 expectedPutOperations[0] = putOperation; |
654 } | 654 } |
655 testCache->setExpectedBatchOperations(&expectedPutOperations); | 655 testCache->setExpectedBatchOperations(&expectedPutOperations); |
656 | 656 |
657 ScriptPromise addResult = cache->add(scriptState(), requestToRequestInfo(req
uest), exceptionState()); | 657 ScriptPromise addResult = cache->add(getScriptState(), requestToRequestInfo(
request), exceptionState()); |
658 | 658 |
659 EXPECT_EQ(kNotImplementedString, getRejectString(addResult)); | 659 EXPECT_EQ(kNotImplementedString, getRejectString(addResult)); |
660 EXPECT_EQ(1, fetcher->fetchCount()); | 660 EXPECT_EQ(1, fetcher->fetchCount()); |
661 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 661 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
662 } | 662 } |
663 | 663 |
664 } // namespace | 664 } // namespace |
665 } // namespace blink | 665 } // namespace blink |
OLD | NEW |