| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 v8::MicrotasksScope::PerformCheckpoint(isolate()); | 251 v8::MicrotasksScope::PerformCheckpoint(isolate()); |
| 252 return onResolve; | 252 return onResolve; |
| 253 } | 253 } |
| 254 | 254 |
| 255 std::string getResolveString(ScriptPromise& promise) | 255 std::string getResolveString(ScriptPromise& promise) |
| 256 { | 256 { |
| 257 ScriptValue onResolve = getResolveValue(promise); | 257 ScriptValue onResolve = getResolveValue(promise); |
| 258 return toCoreString(onResolve.v8Value()->ToString(context()).ToLocalChec
ked()).ascii().data(); | 258 return toCoreString(onResolve.v8Value()->ToString(context()).ToLocalChec
ked()).ascii().data(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 ExceptionState& exceptionState() | |
| 262 { | |
| 263 return m_exceptionState; | |
| 264 } | |
| 265 | |
| 266 private: | 261 private: |
| 267 // A ScriptFunction that creates a test failure if it is ever called. | 262 // A ScriptFunction that creates a test failure if it is ever called. |
| 268 class UnreachableFunction : public ScriptFunction { | 263 class UnreachableFunction : public ScriptFunction { |
| 269 public: | 264 public: |
| 270 static v8::Local<v8::Function> create(ScriptState* scriptState) | 265 static v8::Local<v8::Function> create(ScriptState* scriptState) |
| 271 { | 266 { |
| 272 UnreachableFunction* self = new UnreachableFunction(scriptState); | 267 UnreachableFunction* self = new UnreachableFunction(scriptState); |
| 273 return self->bindToV8Function(); | 268 return self->bindToV8Function(); |
| 274 } | 269 } |
| 275 | 270 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 300 } | 295 } |
| 301 | 296 |
| 302 private: | 297 private: |
| 303 TestFunction(ScriptState* scriptState, ScriptValue* outValue) : ScriptFu
nction(scriptState), m_value(outValue) { } | 298 TestFunction(ScriptState* scriptState, ScriptValue* outValue) : ScriptFu
nction(scriptState), m_value(outValue) { } |
| 304 | 299 |
| 305 ScriptValue* m_value; | 300 ScriptValue* m_value; |
| 306 }; | 301 }; |
| 307 | 302 |
| 308 // Lifetime is that of the text fixture. | 303 // Lifetime is that of the text fixture. |
| 309 std::unique_ptr<DummyPageHolder> m_page; | 304 std::unique_ptr<DummyPageHolder> m_page; |
| 310 | |
| 311 NonThrowableExceptionState m_exceptionState; | |
| 312 }; | 305 }; |
| 313 | 306 |
| 314 RequestInfo stringToRequestInfo(const String& value) | 307 RequestInfo stringToRequestInfo(const String& value) |
| 315 { | 308 { |
| 316 RequestInfo info; | 309 RequestInfo info; |
| 317 info.setUSVString(value); | 310 info.setUSVString(value); |
| 318 return info; | 311 return info; |
| 319 } | 312 } |
| 320 | 313 |
| 321 RequestInfo requestToRequestInfo(Request* value) | 314 RequestInfo requestToRequestInfo(Request* value) |
| 322 { | 315 { |
| 323 RequestInfo info; | 316 RequestInfo info; |
| 324 info.setRequest(value); | 317 info.setRequest(value); |
| 325 return info; | 318 return info; |
| 326 } | 319 } |
| 327 | 320 |
| 328 TEST_F(CacheStorageTest, Basics) | 321 TEST_F(CacheStorageTest, Basics) |
| 329 { | 322 { |
| 330 ScriptState::Scope scope(getScriptState()); | 323 ScriptState::Scope scope(getScriptState()); |
| 324 NonThrowableExceptionState exceptionState; |
| 331 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); | 325 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); |
| 332 ErrorWebCacheForTests* testCache; | 326 ErrorWebCacheForTests* testCache; |
| 333 Cache* cache = createCache(fetcher, testCache = new NotImplementedErrorCache
()); | 327 Cache* cache = createCache(fetcher, testCache = new NotImplementedErrorCache
()); |
| 334 ASSERT(cache); | 328 ASSERT(cache); |
| 335 | 329 |
| 336 const String url = "http://www.cachetest.org/"; | 330 const String url = "http://www.cachetest.org/"; |
| 337 | 331 |
| 338 CacheQueryOptions options; | 332 CacheQueryOptions options; |
| 339 ScriptPromise matchPromise = cache->match(getScriptState(), stringToRequestI
nfo(url), options, exceptionState()); | 333 ScriptPromise matchPromise = cache->match(getScriptState(), stringToRequestI
nfo(url), options, exceptionState); |
| 340 EXPECT_EQ(kNotImplementedString, getRejectString(matchPromise)); | 334 EXPECT_EQ(kNotImplementedString, getRejectString(matchPromise)); |
| 341 | 335 |
| 342 cache = createCache(fetcher, testCache = new ErrorWebCacheForTests(WebServic
eWorkerCacheErrorNotFound)); | 336 cache = createCache(fetcher, testCache = new ErrorWebCacheForTests(WebServic
eWorkerCacheErrorNotFound)); |
| 343 matchPromise = cache->match(getScriptState(), stringToRequestInfo(url), opti
ons, exceptionState()); | 337 matchPromise = cache->match(getScriptState(), stringToRequestInfo(url), opti
ons, exceptionState); |
| 344 ScriptValue scriptValue = getResolveValue(matchPromise); | 338 ScriptValue scriptValue = getResolveValue(matchPromise); |
| 345 EXPECT_TRUE(scriptValue.isUndefined()); | 339 EXPECT_TRUE(scriptValue.isUndefined()); |
| 346 | 340 |
| 347 cache = createCache(fetcher, testCache = new ErrorWebCacheForTests(WebServic
eWorkerCacheErrorExists)); | 341 cache = createCache(fetcher, testCache = new ErrorWebCacheForTests(WebServic
eWorkerCacheErrorExists)); |
| 348 matchPromise = cache->match(getScriptState(), stringToRequestInfo(url), opti
ons, exceptionState()); | 342 matchPromise = cache->match(getScriptState(), stringToRequestInfo(url), opti
ons, exceptionState); |
| 349 EXPECT_EQ("InvalidAccessError: Entry already exists.", getRejectString(match
Promise)); | 343 EXPECT_EQ("InvalidAccessError: Entry already exists.", getRejectString(match
Promise)); |
| 350 } | 344 } |
| 351 | 345 |
| 352 // Tests that arguments are faithfully passed on calls to Cache methods, except
for methods which use batch operations, | 346 // Tests that arguments are faithfully passed on calls to Cache methods, except
for methods which use batch operations, |
| 353 // which are tested later. | 347 // which are tested later. |
| 354 TEST_F(CacheStorageTest, BasicArguments) | 348 TEST_F(CacheStorageTest, BasicArguments) |
| 355 { | 349 { |
| 356 ScriptState::Scope scope(getScriptState()); | 350 ScriptState::Scope scope(getScriptState()); |
| 351 NonThrowableExceptionState exceptionState; |
| 357 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); | 352 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); |
| 358 ErrorWebCacheForTests* testCache; | 353 ErrorWebCacheForTests* testCache; |
| 359 Cache* cache = createCache(fetcher, testCache = new NotImplementedErrorCache
()); | 354 Cache* cache = createCache(fetcher, testCache = new NotImplementedErrorCache
()); |
| 360 ASSERT(cache); | 355 ASSERT(cache); |
| 361 | 356 |
| 362 const String url = "http://www.cache.arguments.test/"; | 357 const String url = "http://www.cache.arguments.test/"; |
| 363 testCache->setExpectedUrl(&url); | 358 testCache->setExpectedUrl(&url); |
| 364 | 359 |
| 365 WebServiceWorkerCache::QueryParams expectedQueryParams; | 360 WebServiceWorkerCache::QueryParams expectedQueryParams; |
| 366 expectedQueryParams.ignoreVary = true; | 361 expectedQueryParams.ignoreVary = true; |
| 367 expectedQueryParams.cacheName = "this is a cache name"; | 362 expectedQueryParams.cacheName = "this is a cache name"; |
| 368 testCache->setExpectedQueryParams(&expectedQueryParams); | 363 testCache->setExpectedQueryParams(&expectedQueryParams); |
| 369 | 364 |
| 370 CacheQueryOptions options; | 365 CacheQueryOptions options; |
| 371 options.setIgnoreVary(1); | 366 options.setIgnoreVary(1); |
| 372 options.setCacheName(expectedQueryParams.cacheName); | 367 options.setCacheName(expectedQueryParams.cacheName); |
| 373 | 368 |
| 374 Request* request = newRequestFromUrl(url); | 369 Request* request = newRequestFromUrl(url); |
| 375 ASSERT(request); | 370 ASSERT(request); |
| 376 ScriptPromise matchResult = cache->match(getScriptState(), requestToRequestI
nfo(request), options, exceptionState()); | 371 ScriptPromise matchResult = cache->match(getScriptState(), requestToRequestI
nfo(request), options, exceptionState); |
| 377 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 372 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 378 EXPECT_EQ(kNotImplementedString, getRejectString(matchResult)); | 373 EXPECT_EQ(kNotImplementedString, getRejectString(matchResult)); |
| 379 | 374 |
| 380 ScriptPromise stringMatchResult = cache->match(getScriptState(), stringToReq
uestInfo(url), options, exceptionState()); | 375 ScriptPromise stringMatchResult = cache->match(getScriptState(), stringToReq
uestInfo(url), options, exceptionState); |
| 381 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 376 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 382 EXPECT_EQ(kNotImplementedString, getRejectString(stringMatchResult)); | 377 EXPECT_EQ(kNotImplementedString, getRejectString(stringMatchResult)); |
| 383 | 378 |
| 384 request = newRequestFromUrl(url); | 379 request = newRequestFromUrl(url); |
| 385 ASSERT(request); | 380 ASSERT(request); |
| 386 ScriptPromise matchAllResult = cache->matchAll(getScriptState(), requestToRe
questInfo(request), options, exceptionState()); | 381 ScriptPromise matchAllResult = cache->matchAll(getScriptState(), requestToRe
questInfo(request), options, exceptionState); |
| 387 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); | 382 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); |
| 388 EXPECT_EQ(kNotImplementedString, getRejectString(matchAllResult)); | 383 EXPECT_EQ(kNotImplementedString, getRejectString(matchAllResult)); |
| 389 | 384 |
| 390 ScriptPromise stringMatchAllResult = cache->matchAll(getScriptState(), strin
gToRequestInfo(url), options, exceptionState()); | 385 ScriptPromise stringMatchAllResult = cache->matchAll(getScriptState(), strin
gToRequestInfo(url), options, exceptionState); |
| 391 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); | 386 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); |
| 392 EXPECT_EQ(kNotImplementedString, getRejectString(stringMatchAllResult)); | 387 EXPECT_EQ(kNotImplementedString, getRejectString(stringMatchAllResult)); |
| 393 | 388 |
| 394 ScriptPromise keysResult1 = cache->keys(getScriptState(), exceptionState()); | 389 ScriptPromise keysResult1 = cache->keys(getScriptState(), exceptionState); |
| 395 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); | 390 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); |
| 396 EXPECT_EQ(kNotImplementedString, getRejectString(keysResult1)); | 391 EXPECT_EQ(kNotImplementedString, getRejectString(keysResult1)); |
| 397 | 392 |
| 398 request = newRequestFromUrl(url); | 393 request = newRequestFromUrl(url); |
| 399 ASSERT(request); | 394 ASSERT(request); |
| 400 ScriptPromise keysResult2 = cache->keys(getScriptState(), requestToRequestIn
fo(request), options, exceptionState()); | 395 ScriptPromise keysResult2 = cache->keys(getScriptState(), requestToRequestIn
fo(request), options, exceptionState); |
| 401 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); | 396 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); |
| 402 EXPECT_EQ(kNotImplementedString, getRejectString(keysResult2)); | 397 EXPECT_EQ(kNotImplementedString, getRejectString(keysResult2)); |
| 403 | 398 |
| 404 ScriptPromise stringKeysResult2 = cache->keys(getScriptState(), stringToRequ
estInfo(url), options, exceptionState()); | 399 ScriptPromise stringKeysResult2 = cache->keys(getScriptState(), stringToRequ
estInfo(url), options, exceptionState); |
| 405 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); | 400 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); |
| 406 EXPECT_EQ(kNotImplementedString, getRejectString(stringKeysResult2)); | 401 EXPECT_EQ(kNotImplementedString, getRejectString(stringKeysResult2)); |
| 407 } | 402 } |
| 408 | 403 |
| 409 // Tests that arguments are faithfully passed to API calls that degrade to batch
operations. | 404 // Tests that arguments are faithfully passed to API calls that degrade to batch
operations. |
| 410 TEST_F(CacheStorageTest, BatchOperationArguments) | 405 TEST_F(CacheStorageTest, BatchOperationArguments) |
| 411 { | 406 { |
| 412 ScriptState::Scope scope(getScriptState()); | 407 ScriptState::Scope scope(getScriptState()); |
| 408 NonThrowableExceptionState exceptionState; |
| 413 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); | 409 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); |
| 414 ErrorWebCacheForTests* testCache; | 410 ErrorWebCacheForTests* testCache; |
| 415 Cache* cache = createCache(fetcher, testCache = new NotImplementedErrorCache
()); | 411 Cache* cache = createCache(fetcher, testCache = new NotImplementedErrorCache
()); |
| 416 ASSERT(cache); | 412 ASSERT(cache); |
| 417 | 413 |
| 418 WebServiceWorkerCache::QueryParams expectedQueryParams; | 414 WebServiceWorkerCache::QueryParams expectedQueryParams; |
| 419 expectedQueryParams.cacheName = "this is another cache name"; | 415 expectedQueryParams.cacheName = "this is another cache name"; |
| 420 testCache->setExpectedQueryParams(&expectedQueryParams); | 416 testCache->setExpectedQueryParams(&expectedQueryParams); |
| 421 | 417 |
| 422 CacheQueryOptions options; | 418 CacheQueryOptions options; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 433 WebVector<WebServiceWorkerCache::BatchOperation> expectedDeleteOperations(si
ze_t(1)); | 429 WebVector<WebServiceWorkerCache::BatchOperation> expectedDeleteOperations(si
ze_t(1)); |
| 434 { | 430 { |
| 435 WebServiceWorkerCache::BatchOperation deleteOperation; | 431 WebServiceWorkerCache::BatchOperation deleteOperation; |
| 436 deleteOperation.operationType = WebServiceWorkerCache::OperationTypeDele
te; | 432 deleteOperation.operationType = WebServiceWorkerCache::OperationTypeDele
te; |
| 437 request->populateWebServiceWorkerRequest(deleteOperation.request); | 433 request->populateWebServiceWorkerRequest(deleteOperation.request); |
| 438 deleteOperation.matchParams = expectedQueryParams; | 434 deleteOperation.matchParams = expectedQueryParams; |
| 439 expectedDeleteOperations[0] = deleteOperation; | 435 expectedDeleteOperations[0] = deleteOperation; |
| 440 } | 436 } |
| 441 testCache->setExpectedBatchOperations(&expectedDeleteOperations); | 437 testCache->setExpectedBatchOperations(&expectedDeleteOperations); |
| 442 | 438 |
| 443 ScriptPromise deleteResult = cache->deleteFunction(getScriptState(), request
ToRequestInfo(request), options, exceptionState()); | 439 ScriptPromise deleteResult = cache->deleteFunction(getScriptState(), request
ToRequestInfo(request), options, exceptionState); |
| 444 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 440 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 445 EXPECT_EQ(kNotImplementedString, getRejectString(deleteResult)); | 441 EXPECT_EQ(kNotImplementedString, getRejectString(deleteResult)); |
| 446 | 442 |
| 447 ScriptPromise stringDeleteResult = cache->deleteFunction(getScriptState(), s
tringToRequestInfo(url), options, exceptionState()); | 443 ScriptPromise stringDeleteResult = cache->deleteFunction(getScriptState(), s
tringToRequestInfo(url), options, exceptionState); |
| 448 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 444 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 449 EXPECT_EQ(kNotImplementedString, getRejectString(stringDeleteResult)); | 445 EXPECT_EQ(kNotImplementedString, getRejectString(stringDeleteResult)); |
| 450 | 446 |
| 451 WebVector<WebServiceWorkerCache::BatchOperation> expectedPutOperations(size_
t(1)); | 447 WebVector<WebServiceWorkerCache::BatchOperation> expectedPutOperations(size_
t(1)); |
| 452 { | 448 { |
| 453 WebServiceWorkerCache::BatchOperation putOperation; | 449 WebServiceWorkerCache::BatchOperation putOperation; |
| 454 putOperation.operationType = WebServiceWorkerCache::OperationTypePut; | 450 putOperation.operationType = WebServiceWorkerCache::OperationTypePut; |
| 455 request->populateWebServiceWorkerRequest(putOperation.request); | 451 request->populateWebServiceWorkerRequest(putOperation.request); |
| 456 response->populateWebServiceWorkerResponse(putOperation.response); | 452 response->populateWebServiceWorkerResponse(putOperation.response); |
| 457 expectedPutOperations[0] = putOperation; | 453 expectedPutOperations[0] = putOperation; |
| 458 } | 454 } |
| 459 testCache->setExpectedBatchOperations(&expectedPutOperations); | 455 testCache->setExpectedBatchOperations(&expectedPutOperations); |
| 460 | 456 |
| 461 request = newRequestFromUrl(url); | 457 request = newRequestFromUrl(url); |
| 462 ASSERT(request); | 458 ASSERT(request); |
| 463 ScriptPromise putResult = cache->put(getScriptState(), requestToRequestInfo(
request), response->clone(getScriptState(), exceptionState()), exceptionState())
; | 459 ScriptPromise putResult = cache->put(getScriptState(), requestToRequestInfo(
request), response->clone(getScriptState(), exceptionState), exceptionState); |
| 464 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 460 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 465 EXPECT_EQ(kNotImplementedString, getRejectString(putResult)); | 461 EXPECT_EQ(kNotImplementedString, getRejectString(putResult)); |
| 466 | 462 |
| 467 ScriptPromise stringPutResult = cache->put(getScriptState(), stringToRequest
Info(url), response, exceptionState()); | 463 ScriptPromise stringPutResult = cache->put(getScriptState(), stringToRequest
Info(url), response, exceptionState); |
| 468 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 464 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 469 EXPECT_EQ(kNotImplementedString, getRejectString(stringPutResult)); | 465 EXPECT_EQ(kNotImplementedString, getRejectString(stringPutResult)); |
| 470 | 466 |
| 471 // FIXME: test add & addAll. | 467 // FIXME: test add & addAll. |
| 472 } | 468 } |
| 473 | 469 |
| 474 class MatchTestCache : public NotImplementedErrorCache { | 470 class MatchTestCache : public NotImplementedErrorCache { |
| 475 public: | 471 public: |
| 476 MatchTestCache(WebServiceWorkerResponse& response) | 472 MatchTestCache(WebServiceWorkerResponse& response) |
| 477 : m_response(response) { } | 473 : m_response(response) { } |
| 478 | 474 |
| 479 // From WebServiceWorkerCache: | 475 // From WebServiceWorkerCache: |
| 480 void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceWorkerReq
uest& webRequest, const QueryParams& queryParams) override | 476 void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceWorkerReq
uest& webRequest, const QueryParams& queryParams) override |
| 481 { | 477 { |
| 482 std::unique_ptr<CacheMatchCallbacks> ownedCallbacks(wrapUnique(callbacks
)); | 478 std::unique_ptr<CacheMatchCallbacks> ownedCallbacks(wrapUnique(callbacks
)); |
| 483 return callbacks->onSuccess(m_response); | 479 return callbacks->onSuccess(m_response); |
| 484 } | 480 } |
| 485 | 481 |
| 486 private: | 482 private: |
| 487 WebServiceWorkerResponse& m_response; | 483 WebServiceWorkerResponse& m_response; |
| 488 }; | 484 }; |
| 489 | 485 |
| 490 TEST_F(CacheStorageTest, MatchResponseTest) | 486 TEST_F(CacheStorageTest, MatchResponseTest) |
| 491 { | 487 { |
| 492 ScriptState::Scope scope(getScriptState()); | 488 ScriptState::Scope scope(getScriptState()); |
| 489 NonThrowableExceptionState exceptionState; |
| 493 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); | 490 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); |
| 494 const String requestUrl = "http://request.url/"; | 491 const String requestUrl = "http://request.url/"; |
| 495 const String responseUrl = "http://match.response.test/"; | 492 const String responseUrl = "http://match.response.test/"; |
| 496 | 493 |
| 497 WebServiceWorkerResponse webResponse; | 494 WebServiceWorkerResponse webResponse; |
| 498 webResponse.setURL(KURL(ParsedURLString, responseUrl)); | 495 webResponse.setURL(KURL(ParsedURLString, responseUrl)); |
| 499 webResponse.setResponseType(WebServiceWorkerResponseTypeDefault); | 496 webResponse.setResponseType(WebServiceWorkerResponseTypeDefault); |
| 500 | 497 |
| 501 Cache* cache = createCache(fetcher, new MatchTestCache(webResponse)); | 498 Cache* cache = createCache(fetcher, new MatchTestCache(webResponse)); |
| 502 CacheQueryOptions options; | 499 CacheQueryOptions options; |
| 503 | 500 |
| 504 ScriptPromise result = cache->match(getScriptState(), stringToRequestInfo(re
questUrl), options, exceptionState()); | 501 ScriptPromise result = cache->match(getScriptState(), stringToRequestInfo(re
questUrl), options, exceptionState); |
| 505 ScriptValue scriptValue = getResolveValue(result); | 502 ScriptValue scriptValue = getResolveValue(result); |
| 506 Response* response = V8Response::toImplWithTypeCheck(isolate(), scriptValue.
v8Value()); | 503 Response* response = V8Response::toImplWithTypeCheck(isolate(), scriptValue.
v8Value()); |
| 507 ASSERT_TRUE(response); | 504 ASSERT_TRUE(response); |
| 508 EXPECT_EQ(responseUrl, response->url()); | 505 EXPECT_EQ(responseUrl, response->url()); |
| 509 } | 506 } |
| 510 | 507 |
| 511 class KeysTestCache : public NotImplementedErrorCache { | 508 class KeysTestCache : public NotImplementedErrorCache { |
| 512 public: | 509 public: |
| 513 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) | 510 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) |
| 514 : m_requests(requests) { } | 511 : m_requests(requests) { } |
| 515 | 512 |
| 516 void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebServiceWor
kerRequest& webRequest, const QueryParams& queryParams) override | 513 void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebServiceWor
kerRequest& webRequest, const QueryParams& queryParams) override |
| 517 { | 514 { |
| 518 std::unique_ptr<CacheWithRequestsCallbacks> ownedCallbacks(wrapUnique(ca
llbacks)); | 515 std::unique_ptr<CacheWithRequestsCallbacks> ownedCallbacks(wrapUnique(ca
llbacks)); |
| 519 return callbacks->onSuccess(m_requests); | 516 return callbacks->onSuccess(m_requests); |
| 520 } | 517 } |
| 521 | 518 |
| 522 private: | 519 private: |
| 523 WebVector<WebServiceWorkerRequest>& m_requests; | 520 WebVector<WebServiceWorkerRequest>& m_requests; |
| 524 }; | 521 }; |
| 525 | 522 |
| 526 TEST_F(CacheStorageTest, KeysResponseTest) | 523 TEST_F(CacheStorageTest, KeysResponseTest) |
| 527 { | 524 { |
| 528 ScriptState::Scope scope(getScriptState()); | 525 ScriptState::Scope scope(getScriptState()); |
| 526 NonThrowableExceptionState exceptionState; |
| 529 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); | 527 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); |
| 530 const String url1 = "http://first.request/"; | 528 const String url1 = "http://first.request/"; |
| 531 const String url2 = "http://second.request/"; | 529 const String url2 = "http://second.request/"; |
| 532 | 530 |
| 533 Vector<String> expectedUrls(size_t(2)); | 531 Vector<String> expectedUrls(size_t(2)); |
| 534 expectedUrls[0] = url1; | 532 expectedUrls[0] = url1; |
| 535 expectedUrls[1] = url2; | 533 expectedUrls[1] = url2; |
| 536 | 534 |
| 537 WebVector<WebServiceWorkerRequest> webRequests(size_t(2)); | 535 WebVector<WebServiceWorkerRequest> webRequests(size_t(2)); |
| 538 webRequests[0].setURL(KURL(ParsedURLString, url1)); | 536 webRequests[0].setURL(KURL(ParsedURLString, url1)); |
| 539 webRequests[1].setURL(KURL(ParsedURLString, url2)); | 537 webRequests[1].setURL(KURL(ParsedURLString, url2)); |
| 540 | 538 |
| 541 Cache* cache = createCache(fetcher, new KeysTestCache(webRequests)); | 539 Cache* cache = createCache(fetcher, new KeysTestCache(webRequests)); |
| 542 | 540 |
| 543 ScriptPromise result = cache->keys(getScriptState(), exceptionState()); | 541 ScriptPromise result = cache->keys(getScriptState(), exceptionState); |
| 544 ScriptValue scriptValue = getResolveValue(result); | 542 ScriptValue scriptValue = getResolveValue(result); |
| 545 | 543 |
| 546 Vector<v8::Local<v8::Value>> requests = toImplArray<Vector<v8::Local<v8::Val
ue>>>(scriptValue.v8Value(), 0, isolate(), exceptionState()); | 544 Vector<v8::Local<v8::Value>> requests = toImplArray<Vector<v8::Local<v8::Val
ue>>>(scriptValue.v8Value(), 0, isolate(), exceptionState); |
| 547 EXPECT_EQ(expectedUrls.size(), requests.size()); | 545 EXPECT_EQ(expectedUrls.size(), requests.size()); |
| 548 for (int i = 0, minsize = std::min(expectedUrls.size(), requests.size()); i
< minsize; ++i) { | 546 for (int i = 0, minsize = std::min(expectedUrls.size(), requests.size()); i
< minsize; ++i) { |
| 549 Request* request = V8Request::toImplWithTypeCheck(isolate(), requests[i]
); | 547 Request* request = V8Request::toImplWithTypeCheck(isolate(), requests[i]
); |
| 550 EXPECT_TRUE(request); | 548 EXPECT_TRUE(request); |
| 551 if (request) | 549 if (request) |
| 552 EXPECT_EQ(expectedUrls[i], request->url()); | 550 EXPECT_EQ(expectedUrls[i], request->url()); |
| 553 } | 551 } |
| 554 } | 552 } |
| 555 | 553 |
| 556 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { | 554 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 570 return callbacks->onSuccess(); | 568 return callbacks->onSuccess(); |
| 571 } | 569 } |
| 572 | 570 |
| 573 private: | 571 private: |
| 574 WebVector<WebServiceWorkerResponse>& m_responses; | 572 WebVector<WebServiceWorkerResponse>& m_responses; |
| 575 }; | 573 }; |
| 576 | 574 |
| 577 TEST_F(CacheStorageTest, MatchAllAndBatchResponseTest) | 575 TEST_F(CacheStorageTest, MatchAllAndBatchResponseTest) |
| 578 { | 576 { |
| 579 ScriptState::Scope scope(getScriptState()); | 577 ScriptState::Scope scope(getScriptState()); |
| 578 NonThrowableExceptionState exceptionState; |
| 580 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); | 579 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); |
| 581 const String url1 = "http://first.response/"; | 580 const String url1 = "http://first.response/"; |
| 582 const String url2 = "http://second.response/"; | 581 const String url2 = "http://second.response/"; |
| 583 | 582 |
| 584 Vector<String> expectedUrls(size_t(2)); | 583 Vector<String> expectedUrls(size_t(2)); |
| 585 expectedUrls[0] = url1; | 584 expectedUrls[0] = url1; |
| 586 expectedUrls[1] = url2; | 585 expectedUrls[1] = url2; |
| 587 | 586 |
| 588 WebVector<WebServiceWorkerResponse> webResponses(size_t(2)); | 587 WebVector<WebServiceWorkerResponse> webResponses(size_t(2)); |
| 589 webResponses[0].setURL(KURL(ParsedURLString, url1)); | 588 webResponses[0].setURL(KURL(ParsedURLString, url1)); |
| 590 webResponses[0].setResponseType(WebServiceWorkerResponseTypeDefault); | 589 webResponses[0].setResponseType(WebServiceWorkerResponseTypeDefault); |
| 591 webResponses[1].setURL(KURL(ParsedURLString, url2)); | 590 webResponses[1].setURL(KURL(ParsedURLString, url2)); |
| 592 webResponses[1].setResponseType(WebServiceWorkerResponseTypeDefault); | 591 webResponses[1].setResponseType(WebServiceWorkerResponseTypeDefault); |
| 593 | 592 |
| 594 Cache* cache = createCache(fetcher, new MatchAllAndBatchTestCache(webRespons
es)); | 593 Cache* cache = createCache(fetcher, new MatchAllAndBatchTestCache(webRespons
es)); |
| 595 | 594 |
| 596 CacheQueryOptions options; | 595 CacheQueryOptions options; |
| 597 ScriptPromise result = cache->matchAll(getScriptState(), stringToRequestInfo
("http://some.url/"), options, exceptionState()); | 596 ScriptPromise result = cache->matchAll(getScriptState(), stringToRequestInfo
("http://some.url/"), options, exceptionState); |
| 598 ScriptValue scriptValue = getResolveValue(result); | 597 ScriptValue scriptValue = getResolveValue(result); |
| 599 | 598 |
| 600 Vector<v8::Local<v8::Value>> responses = toImplArray<Vector<v8::Local<v8::Va
lue>>>(scriptValue.v8Value(), 0, isolate(), exceptionState()); | 599 Vector<v8::Local<v8::Value>> responses = toImplArray<Vector<v8::Local<v8::Va
lue>>>(scriptValue.v8Value(), 0, isolate(), exceptionState); |
| 601 EXPECT_EQ(expectedUrls.size(), responses.size()); | 600 EXPECT_EQ(expectedUrls.size(), responses.size()); |
| 602 for (int i = 0, minsize = std::min(expectedUrls.size(), responses.size()); i
< minsize; ++i) { | 601 for (int i = 0, minsize = std::min(expectedUrls.size(), responses.size()); i
< minsize; ++i) { |
| 603 Response* response = V8Response::toImplWithTypeCheck(isolate(), response
s[i]); | 602 Response* response = V8Response::toImplWithTypeCheck(isolate(), response
s[i]); |
| 604 EXPECT_TRUE(response); | 603 EXPECT_TRUE(response); |
| 605 if (response) | 604 if (response) |
| 606 EXPECT_EQ(expectedUrls[i], response->url()); | 605 EXPECT_EQ(expectedUrls[i], response->url()); |
| 607 } | 606 } |
| 608 | 607 |
| 609 result = cache->deleteFunction(getScriptState(), stringToRequestInfo("http:/
/some.url/"), options, exceptionState()); | 608 result = cache->deleteFunction(getScriptState(), stringToRequestInfo("http:/
/some.url/"), options, exceptionState); |
| 610 scriptValue = getResolveValue(result); | 609 scriptValue = getResolveValue(result); |
| 611 EXPECT_TRUE(scriptValue.v8Value()->IsBoolean()); | 610 EXPECT_TRUE(scriptValue.v8Value()->IsBoolean()); |
| 612 EXPECT_EQ(true, scriptValue.v8Value().As<v8::Boolean>()->Value()); | 611 EXPECT_EQ(true, scriptValue.v8Value().As<v8::Boolean>()->Value()); |
| 613 } | 612 } |
| 614 | 613 |
| 615 TEST_F(CacheStorageTest, Add) | 614 TEST_F(CacheStorageTest, Add) |
| 616 { | 615 { |
| 617 ScriptState::Scope scope(getScriptState()); | 616 ScriptState::Scope scope(getScriptState()); |
| 617 NonThrowableExceptionState exceptionState; |
| 618 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); | 618 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); |
| 619 const String url = "http://www.cacheadd.test/"; | 619 const String url = "http://www.cacheadd.test/"; |
| 620 const String contentType = "text/plain"; | 620 const String contentType = "text/plain"; |
| 621 const String content = "hello cache"; | 621 const String content = "hello cache"; |
| 622 | 622 |
| 623 ErrorWebCacheForTests* testCache; | 623 ErrorWebCacheForTests* testCache; |
| 624 Cache* cache = createCache(fetcher, testCache = new NotImplementedErrorCache
()); | 624 Cache* cache = createCache(fetcher, testCache = new NotImplementedErrorCache
()); |
| 625 | 625 |
| 626 fetcher->setExpectedFetchUrl(&url); | 626 fetcher->setExpectedFetchUrl(&url); |
| 627 | 627 |
| 628 Request* request = newRequestFromUrl(url); | 628 Request* request = newRequestFromUrl(url); |
| 629 Response* response = Response::create(getScriptState(), new BodyStreamBuffer
(getScriptState(), FetchFormDataConsumerHandle::create(content)), contentType, R
esponseInit(), exceptionState()); | 629 Response* response = Response::create(getScriptState(), new BodyStreamBuffer
(getScriptState(), FetchFormDataConsumerHandle::create(content)), contentType, R
esponseInit(), exceptionState); |
| 630 fetcher->setResponse(response); | 630 fetcher->setResponse(response); |
| 631 | 631 |
| 632 WebVector<WebServiceWorkerCache::BatchOperation> expectedPutOperations(size_
t(1)); | 632 WebVector<WebServiceWorkerCache::BatchOperation> expectedPutOperations(size_
t(1)); |
| 633 { | 633 { |
| 634 WebServiceWorkerCache::BatchOperation putOperation; | 634 WebServiceWorkerCache::BatchOperation putOperation; |
| 635 putOperation.operationType = WebServiceWorkerCache::OperationTypePut; | 635 putOperation.operationType = WebServiceWorkerCache::OperationTypePut; |
| 636 request->populateWebServiceWorkerRequest(putOperation.request); | 636 request->populateWebServiceWorkerRequest(putOperation.request); |
| 637 response->populateWebServiceWorkerResponse(putOperation.response); | 637 response->populateWebServiceWorkerResponse(putOperation.response); |
| 638 expectedPutOperations[0] = putOperation; | 638 expectedPutOperations[0] = putOperation; |
| 639 } | 639 } |
| 640 testCache->setExpectedBatchOperations(&expectedPutOperations); | 640 testCache->setExpectedBatchOperations(&expectedPutOperations); |
| 641 | 641 |
| 642 ScriptPromise addResult = cache->add(getScriptState(), requestToRequestInfo(
request), exceptionState()); | 642 ScriptPromise addResult = cache->add(getScriptState(), requestToRequestInfo(
request), exceptionState); |
| 643 | 643 |
| 644 EXPECT_EQ(kNotImplementedString, getRejectString(addResult)); | 644 EXPECT_EQ(kNotImplementedString, getRejectString(addResult)); |
| 645 EXPECT_EQ(1, fetcher->fetchCount()); | 645 EXPECT_EQ(1, fetcher->fetchCount()); |
| 646 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 646 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 647 } | 647 } |
| 648 | 648 |
| 649 } // namespace | 649 } // namespace |
| 650 |
| 650 } // namespace blink | 651 } // namespace blink |
| OLD | NEW |