| 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 | 7 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScriptFunction.h" | 9 #include "bindings/core/v8/ScriptFunction.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 10 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptValue.h" | 11 #include "bindings/core/v8/ScriptValue.h" |
| 11 #include "bindings/core/v8/V8Binding.h" | 12 #include "bindings/core/v8/V8Binding.h" |
| 12 #include "bindings/modules/v8/V8Request.h" | 13 #include "bindings/modules/v8/V8Request.h" |
| 13 #include "bindings/modules/v8/V8Response.h" | 14 #include "bindings/modules/v8/V8Response.h" |
| 14 #include "core/dom/Document.h" | 15 #include "core/dom/Document.h" |
| 15 #include "core/frame/Frame.h" | 16 #include "core/frame/Frame.h" |
| 16 #include "core/testing/DummyPageHolder.h" | 17 #include "core/testing/DummyPageHolder.h" |
| 17 #include "modules/serviceworkers/Cache.h" | |
| 18 #include "modules/serviceworkers/Request.h" | 18 #include "modules/serviceworkers/Request.h" |
| 19 #include "modules/serviceworkers/Response.h" | 19 #include "modules/serviceworkers/Response.h" |
| 20 #include "public/platform/WebServiceWorkerCache.h" | 20 #include "public/platform/WebServiceWorkerCache.h" |
| 21 #include "wtf/OwnPtr.h" | 21 #include "wtf/OwnPtr.h" |
| 22 | 22 |
| 23 #include <algorithm> | 23 #include <algorithm> |
| 24 #include <gtest/gtest.h> | 24 #include <gtest/gtest.h> |
| 25 | 25 |
| 26 namespace blink { | 26 namespace blink { |
| 27 namespace { | 27 namespace { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // Lifetime is that of the text fixture. | 250 // Lifetime is that of the text fixture. |
| 251 OwnPtr<DummyPageHolder> m_page; | 251 OwnPtr<DummyPageHolder> m_page; |
| 252 | 252 |
| 253 // Lifetime is per test instance. | 253 // Lifetime is per test instance. |
| 254 OwnPtr<ScriptState::Scope> m_scriptScope; | 254 OwnPtr<ScriptState::Scope> m_scriptScope; |
| 255 }; | 255 }; |
| 256 | 256 |
| 257 TEST_F(ServiceWorkerCacheTest, Basics) | 257 TEST_F(ServiceWorkerCacheTest, Basics) |
| 258 { | 258 { |
| 259 ErrorWebCacheForTests* testCache; | 259 ErrorWebCacheForTests* testCache; |
| 260 RefPtrWillBeRawPtr<Cache> cache = Cache::fromWebServiceWorkerCache(testCache
= new NotImplementedErrorCache()); | 260 Cache* cache = Cache::fromWebServiceWorkerCache(testCache = new NotImplement
edErrorCache()); |
| 261 ASSERT(cache); | 261 ASSERT(cache); |
| 262 | 262 |
| 263 const String url = "http://www.cachetest.org/"; | 263 const String url = "http://www.cachetest.org/"; |
| 264 | 264 |
| 265 ScriptPromise matchPromise = cache->match(scriptState(), url, Dictionary()); | 265 ScriptPromise matchPromise = cache->match(scriptState(), url, Dictionary()); |
| 266 expectNotImplemented(matchPromise); | 266 expectNotImplemented(matchPromise); |
| 267 | 267 |
| 268 cache = Cache::fromWebServiceWorkerCache(testCache = new ErrorWebCacheForTes
ts(WebServiceWorkerCacheErrorNotFound)); | 268 cache = Cache::fromWebServiceWorkerCache(testCache = new ErrorWebCacheForTes
ts(WebServiceWorkerCacheErrorNotFound)); |
| 269 matchPromise = cache->match(scriptState(), url, Dictionary()); | 269 matchPromise = cache->match(scriptState(), url, Dictionary()); |
| 270 EXPECT_EQ("NotFoundError: Entry was not found.", getRejectString(matchPromis
e)); | 270 EXPECT_EQ("NotFoundError: Entry was not found.", getRejectString(matchPromis
e)); |
| 271 | 271 |
| 272 cache = Cache::fromWebServiceWorkerCache(testCache = new ErrorWebCacheForTes
ts(WebServiceWorkerCacheErrorExists)); | 272 cache = Cache::fromWebServiceWorkerCache(testCache = new ErrorWebCacheForTes
ts(WebServiceWorkerCacheErrorExists)); |
| 273 matchPromise = cache->match(scriptState(), url, Dictionary()); | 273 matchPromise = cache->match(scriptState(), url, Dictionary()); |
| 274 EXPECT_EQ("InvalidAccessError: Entry already exists.", getRejectString(match
Promise)); | 274 EXPECT_EQ("InvalidAccessError: Entry already exists.", getRejectString(match
Promise)); |
| 275 } | 275 } |
| 276 | 276 |
| 277 // Tests that arguments are faithfully passed on calls to Cache methods, except
for methods which use batch operations, | 277 // Tests that arguments are faithfully passed on calls to Cache methods, except
for methods which use batch operations, |
| 278 // which are tested later. | 278 // which are tested later. |
| 279 TEST_F(ServiceWorkerCacheTest, BasicArguments) | 279 TEST_F(ServiceWorkerCacheTest, BasicArguments) |
| 280 { | 280 { |
| 281 ErrorWebCacheForTests* testCache; | 281 ErrorWebCacheForTests* testCache; |
| 282 RefPtrWillBeRawPtr<Cache> cache = Cache::fromWebServiceWorkerCache(testCache
= new NotImplementedErrorCache()); | 282 Cache* cache = Cache::fromWebServiceWorkerCache(testCache = new NotImplement
edErrorCache()); |
| 283 ASSERT(cache); | 283 ASSERT(cache); |
| 284 | 284 |
| 285 const String url = "http://www.cache.arguments.test/"; | 285 const String url = "http://www.cache.arguments.test/"; |
| 286 testCache->setExpectedUrl(&url); | 286 testCache->setExpectedUrl(&url); |
| 287 | 287 |
| 288 WebServiceWorkerCache::QueryParams expectedQueryParams; | 288 WebServiceWorkerCache::QueryParams expectedQueryParams; |
| 289 expectedQueryParams.ignoreVary = true; | 289 expectedQueryParams.ignoreVary = true; |
| 290 expectedQueryParams.cacheName = "this is a cache name"; | 290 expectedQueryParams.cacheName = "this is a cache name"; |
| 291 testCache->setExpectedQueryParams(&expectedQueryParams); | 291 testCache->setExpectedQueryParams(&expectedQueryParams); |
| 292 | 292 |
| 293 Dictionary queryParamsDict = Dictionary::createEmpty(isolate()); | 293 Dictionary queryParamsDict = Dictionary::createEmpty(isolate()); |
| 294 queryParamsDict.set("ignoreVary", 1); | 294 queryParamsDict.set("ignoreVary", 1); |
| 295 queryParamsDict.set("cacheName", expectedQueryParams.cacheName); | 295 queryParamsDict.set("cacheName", expectedQueryParams.cacheName); |
| 296 | 296 |
| 297 TrackExceptionState exceptionState; | 297 TrackExceptionState exceptionState; |
| 298 const RefPtrWillBeRawPtr<Request> request = Request::create(executionContext
(), url, exceptionState); | 298 const Request* request = Request::create(executionContext(), url, exceptionS
tate); |
| 299 ASSERT(request); | 299 ASSERT(request); |
| 300 ASSERT_FALSE(exceptionState.hadException()); | 300 ASSERT_FALSE(exceptionState.hadException()); |
| 301 | 301 |
| 302 ScriptPromise matchResult = cache->match(scriptState(), request.get(), query
ParamsDict); | 302 ScriptPromise matchResult = cache->match(scriptState(), request, queryParams
Dict); |
| 303 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 303 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 304 expectNotImplemented(matchResult); | 304 expectNotImplemented(matchResult); |
| 305 | 305 |
| 306 ScriptPromise stringMatchResult = cache->match(scriptState(), url, queryPara
msDict); | 306 ScriptPromise stringMatchResult = cache->match(scriptState(), url, queryPara
msDict); |
| 307 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 307 EXPECT_EQ("dispatchMatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 308 expectNotImplemented(stringMatchResult); | 308 expectNotImplemented(stringMatchResult); |
| 309 | 309 |
| 310 ScriptPromise matchAllResult = cache->matchAll(scriptState(), request.get(),
queryParamsDict); | 310 ScriptPromise matchAllResult = cache->matchAll(scriptState(), request, query
ParamsDict); |
| 311 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); | 311 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); |
| 312 expectNotImplemented(matchAllResult); | 312 expectNotImplemented(matchAllResult); |
| 313 | 313 |
| 314 ScriptPromise stringMatchAllResult = cache->matchAll(scriptState(), url, que
ryParamsDict); | 314 ScriptPromise stringMatchAllResult = cache->matchAll(scriptState(), url, que
ryParamsDict); |
| 315 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); | 315 EXPECT_EQ("dispatchMatchAll", testCache->getAndClearLastErrorWebCacheMethodC
alled()); |
| 316 expectNotImplemented(stringMatchAllResult); | 316 expectNotImplemented(stringMatchAllResult); |
| 317 | 317 |
| 318 ScriptPromise keysResult1 = cache->keys(scriptState()); | 318 ScriptPromise keysResult1 = cache->keys(scriptState()); |
| 319 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); | 319 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); |
| 320 expectNotImplemented(keysResult1); | 320 expectNotImplemented(keysResult1); |
| 321 | 321 |
| 322 ScriptPromise keysResult2 = cache->keys(scriptState(), request.get(), queryP
aramsDict); | 322 ScriptPromise keysResult2 = cache->keys(scriptState(), request, queryParamsD
ict); |
| 323 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); | 323 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); |
| 324 expectNotImplemented(keysResult2); | 324 expectNotImplemented(keysResult2); |
| 325 | 325 |
| 326 ScriptPromise stringKeysResult2 = cache->keys(scriptState(), url, queryParam
sDict); | 326 ScriptPromise stringKeysResult2 = cache->keys(scriptState(), url, queryParam
sDict); |
| 327 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); | 327 EXPECT_EQ("dispatchKeys", testCache->getAndClearLastErrorWebCacheMethodCalle
d()); |
| 328 expectNotImplemented(stringKeysResult2); | 328 expectNotImplemented(stringKeysResult2); |
| 329 } | 329 } |
| 330 | 330 |
| 331 // Tests that arguments are faithfully passed to API calls that degrade to batch
operations. | 331 // Tests that arguments are faithfully passed to API calls that degrade to batch
operations. |
| 332 TEST_F(ServiceWorkerCacheTest, BatchOperationArguments) | 332 TEST_F(ServiceWorkerCacheTest, BatchOperationArguments) |
| 333 { | 333 { |
| 334 ErrorWebCacheForTests* testCache; | 334 ErrorWebCacheForTests* testCache; |
| 335 RefPtrWillBeRawPtr<Cache> cache = Cache::fromWebServiceWorkerCache(testCache
= new NotImplementedErrorCache()); | 335 Cache* cache = Cache::fromWebServiceWorkerCache(testCache = new NotImplement
edErrorCache()); |
| 336 ASSERT(cache); | 336 ASSERT(cache); |
| 337 | 337 |
| 338 WebServiceWorkerCache::QueryParams expectedQueryParams; | 338 WebServiceWorkerCache::QueryParams expectedQueryParams; |
| 339 expectedQueryParams.prefixMatch = true; | 339 expectedQueryParams.prefixMatch = true; |
| 340 expectedQueryParams.cacheName = "this is another cache name"; | 340 expectedQueryParams.cacheName = "this is another cache name"; |
| 341 testCache->setExpectedQueryParams(&expectedQueryParams); | 341 testCache->setExpectedQueryParams(&expectedQueryParams); |
| 342 | 342 |
| 343 Dictionary queryParamsDict = Dictionary::createEmpty(isolate()); | 343 Dictionary queryParamsDict = Dictionary::createEmpty(isolate()); |
| 344 queryParamsDict.set("prefixMatch", 1); | 344 queryParamsDict.set("prefixMatch", 1); |
| 345 queryParamsDict.set("cacheName", expectedQueryParams.cacheName); | 345 queryParamsDict.set("cacheName", expectedQueryParams.cacheName); |
| 346 | 346 |
| 347 const String url = "http://batch.operations.test/"; | 347 const String url = "http://batch.operations.test/"; |
| 348 TrackExceptionState exceptionState; | 348 TrackExceptionState exceptionState; |
| 349 const RefPtrWillBeRawPtr<Request> request = Request::create(executionContext
(), url, exceptionState); | 349 const Request* request = Request::create(executionContext(), url, exceptionS
tate); |
| 350 ASSERT(request); | 350 ASSERT(request); |
| 351 ASSERT_FALSE(exceptionState.hadException()); | 351 ASSERT_FALSE(exceptionState.hadException()); |
| 352 | 352 |
| 353 WebServiceWorkerResponse webResponse; | 353 WebServiceWorkerResponse webResponse; |
| 354 webResponse.setURL(KURL(ParsedURLString, url)); | 354 webResponse.setURL(KURL(ParsedURLString, url)); |
| 355 const RefPtrWillBeRawPtr<Response> response = Response::create(webResponse); | 355 const Response* response = Response::create(webResponse); |
| 356 | 356 |
| 357 WebVector<WebServiceWorkerCache::BatchOperation> expectedDeleteOperations(si
ze_t(1)); | 357 WebVector<WebServiceWorkerCache::BatchOperation> expectedDeleteOperations(si
ze_t(1)); |
| 358 { | 358 { |
| 359 WebServiceWorkerCache::BatchOperation deleteOperation; | 359 WebServiceWorkerCache::BatchOperation deleteOperation; |
| 360 deleteOperation.operationType = WebServiceWorkerCache::WebServiceWorkerC
acheOperationTypeDelete; | 360 deleteOperation.operationType = WebServiceWorkerCache::WebServiceWorkerC
acheOperationTypeDelete; |
| 361 request->populateWebServiceWorkerRequest(deleteOperation.request); | 361 request->populateWebServiceWorkerRequest(deleteOperation.request); |
| 362 deleteOperation.matchParams = expectedQueryParams; | 362 deleteOperation.matchParams = expectedQueryParams; |
| 363 expectedDeleteOperations[0] = deleteOperation; | 363 expectedDeleteOperations[0] = deleteOperation; |
| 364 } | 364 } |
| 365 testCache->setExpectedBatchOperations(&expectedDeleteOperations); | 365 testCache->setExpectedBatchOperations(&expectedDeleteOperations); |
| 366 | 366 |
| 367 ScriptPromise deleteResult = cache->deleteFunction(scriptState(), request.ge
t(), queryParamsDict); | 367 ScriptPromise deleteResult = cache->deleteFunction(scriptState(), request, q
ueryParamsDict); |
| 368 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 368 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 369 expectNotImplemented(deleteResult); | 369 expectNotImplemented(deleteResult); |
| 370 | 370 |
| 371 ScriptPromise stringDeleteResult = cache->deleteFunction(scriptState(), url,
queryParamsDict); | 371 ScriptPromise stringDeleteResult = cache->deleteFunction(scriptState(), url,
queryParamsDict); |
| 372 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 372 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 373 expectNotImplemented(stringDeleteResult); | 373 expectNotImplemented(stringDeleteResult); |
| 374 | 374 |
| 375 WebVector<WebServiceWorkerCache::BatchOperation> expectedPutOperations(size_
t(1)); | 375 WebVector<WebServiceWorkerCache::BatchOperation> expectedPutOperations(size_
t(1)); |
| 376 { | 376 { |
| 377 WebServiceWorkerCache::BatchOperation putOperation; | 377 WebServiceWorkerCache::BatchOperation putOperation; |
| 378 putOperation.operationType = WebServiceWorkerCache::WebServiceWorkerCach
eOperationTypePut; | 378 putOperation.operationType = WebServiceWorkerCache::WebServiceWorkerCach
eOperationTypePut; |
| 379 request->populateWebServiceWorkerRequest(putOperation.request); | 379 request->populateWebServiceWorkerRequest(putOperation.request); |
| 380 response->populateWebServiceWorkerResponse(putOperation.response); | 380 response->populateWebServiceWorkerResponse(putOperation.response); |
| 381 expectedPutOperations[0] = putOperation; | 381 expectedPutOperations[0] = putOperation; |
| 382 } | 382 } |
| 383 testCache->setExpectedBatchOperations(&expectedPutOperations); | 383 testCache->setExpectedBatchOperations(&expectedPutOperations); |
| 384 | 384 |
| 385 ScriptPromise putResult = cache->put(scriptState(), request.get(), response.
get()); | 385 ScriptPromise putResult = cache->put(scriptState(), request, response); |
| 386 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 386 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 387 expectNotImplemented(putResult); | 387 expectNotImplemented(putResult); |
| 388 | 388 |
| 389 ScriptPromise stringPutResult = cache->put(scriptState(), url, response.get(
)); | 389 ScriptPromise stringPutResult = cache->put(scriptState(), url, response); |
| 390 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 390 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
| 391 expectNotImplemented(stringPutResult); | 391 expectNotImplemented(stringPutResult); |
| 392 | 392 |
| 393 // FIXME: test add & addAll. | 393 // FIXME: test add & addAll. |
| 394 } | 394 } |
| 395 | 395 |
| 396 class MatchTestCache : public NotImplementedErrorCache { | 396 class MatchTestCache : public NotImplementedErrorCache { |
| 397 public: | 397 public: |
| 398 MatchTestCache(WebServiceWorkerResponse& response) | 398 MatchTestCache(WebServiceWorkerResponse& response) |
| 399 : m_response(response) { } | 399 : m_response(response) { } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 410 }; | 410 }; |
| 411 | 411 |
| 412 TEST_F(ServiceWorkerCacheTest, MatchResponseTest) | 412 TEST_F(ServiceWorkerCacheTest, MatchResponseTest) |
| 413 { | 413 { |
| 414 const String requestUrl = "http://request.url/"; | 414 const String requestUrl = "http://request.url/"; |
| 415 const String responseUrl = "http://match.response.test/"; | 415 const String responseUrl = "http://match.response.test/"; |
| 416 | 416 |
| 417 WebServiceWorkerResponse webResponse; | 417 WebServiceWorkerResponse webResponse; |
| 418 webResponse.setURL(KURL(ParsedURLString, responseUrl)); | 418 webResponse.setURL(KURL(ParsedURLString, responseUrl)); |
| 419 | 419 |
| 420 RefPtrWillBeRawPtr<Cache> cache = Cache::fromWebServiceWorkerCache(new Match
TestCache(webResponse)); | 420 Cache* cache = Cache::fromWebServiceWorkerCache(new MatchTestCache(webRespon
se)); |
| 421 | 421 |
| 422 ScriptPromise result = cache->match(scriptState(), requestUrl, Dictionary())
; | 422 ScriptPromise result = cache->match(scriptState(), requestUrl, Dictionary())
; |
| 423 ScriptValue scriptValue = getResolveValue(result); | 423 ScriptValue scriptValue = getResolveValue(result); |
| 424 Response* response = V8Response::toNativeWithTypeCheck(isolate(), scriptValu
e.v8Value()); | 424 Response* response = V8Response::toImplWithTypeCheck(isolate(), scriptValue.
v8Value()); |
| 425 ASSERT_TRUE(response); | 425 ASSERT_TRUE(response); |
| 426 EXPECT_EQ(responseUrl, response->url()); | 426 EXPECT_EQ(responseUrl, response->url()); |
| 427 } | 427 } |
| 428 | 428 |
| 429 class KeysTestCache : public NotImplementedErrorCache { | 429 class KeysTestCache : public NotImplementedErrorCache { |
| 430 public: | 430 public: |
| 431 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) | 431 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) |
| 432 : m_requests(requests) { } | 432 : m_requests(requests) { } |
| 433 | 433 |
| 434 virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebSe
rviceWorkerRequest* webRequest, const QueryParams& queryParams) OVERRIDE | 434 virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebSe
rviceWorkerRequest* webRequest, const QueryParams& queryParams) OVERRIDE |
| (...skipping 12 matching lines...) Expand all Loading... |
| 447 const String url2 = "http://second.request/"; | 447 const String url2 = "http://second.request/"; |
| 448 | 448 |
| 449 Vector<String> expectedUrls(size_t(2)); | 449 Vector<String> expectedUrls(size_t(2)); |
| 450 expectedUrls[0] = url1; | 450 expectedUrls[0] = url1; |
| 451 expectedUrls[1] = url2; | 451 expectedUrls[1] = url2; |
| 452 | 452 |
| 453 WebVector<WebServiceWorkerRequest> webRequests(size_t(2)); | 453 WebVector<WebServiceWorkerRequest> webRequests(size_t(2)); |
| 454 webRequests[0].setURL(KURL(ParsedURLString, url1)); | 454 webRequests[0].setURL(KURL(ParsedURLString, url1)); |
| 455 webRequests[1].setURL(KURL(ParsedURLString, url2)); | 455 webRequests[1].setURL(KURL(ParsedURLString, url2)); |
| 456 | 456 |
| 457 RefPtrWillBeRawPtr<Cache> cache = Cache::fromWebServiceWorkerCache(new KeysT
estCache(webRequests)); | 457 Cache* cache = Cache::fromWebServiceWorkerCache(new KeysTestCache(webRequest
s)); |
| 458 | 458 |
| 459 ScriptPromise result = cache->keys(scriptState()); | 459 ScriptPromise result = cache->keys(scriptState()); |
| 460 ScriptValue scriptValue = getResolveValue(result); | 460 ScriptValue scriptValue = getResolveValue(result); |
| 461 | 461 |
| 462 Vector<v8::Handle<v8::Value> > requests = toNativeArray<v8::Handle<v8::Value
> >(scriptValue.v8Value(), 0, isolate()); | 462 Vector<v8::Handle<v8::Value> > requests = toImplArray<v8::Handle<v8::Value>
>(scriptValue.v8Value(), 0, isolate()); |
| 463 EXPECT_EQ(expectedUrls.size(), requests.size()); | 463 EXPECT_EQ(expectedUrls.size(), requests.size()); |
| 464 for (int i = 0, minsize = std::min(expectedUrls.size(), requests.size()); i
< minsize; ++i) { | 464 for (int i = 0, minsize = std::min(expectedUrls.size(), requests.size()); i
< minsize; ++i) { |
| 465 Request* request = V8Request::toNativeWithTypeCheck(isolate(), requests[
i]); | 465 Request* request = V8Request::toImplWithTypeCheck(isolate(), requests[i]
); |
| 466 EXPECT_TRUE(request); | 466 EXPECT_TRUE(request); |
| 467 if (request) | 467 if (request) |
| 468 EXPECT_EQ(expectedUrls[i], request->url()); | 468 EXPECT_EQ(expectedUrls[i], request->url()); |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 | 471 |
| 472 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { | 472 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { |
| 473 public: | 473 public: |
| 474 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) | 474 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) |
| 475 : m_responses(responses) { } | 475 : m_responses(responses) { } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 496 const String url2 = "http://second.response/"; | 496 const String url2 = "http://second.response/"; |
| 497 | 497 |
| 498 Vector<String> expectedUrls(size_t(2)); | 498 Vector<String> expectedUrls(size_t(2)); |
| 499 expectedUrls[0] = url1; | 499 expectedUrls[0] = url1; |
| 500 expectedUrls[1] = url2; | 500 expectedUrls[1] = url2; |
| 501 | 501 |
| 502 WebVector<WebServiceWorkerResponse> webResponses(size_t(2)); | 502 WebVector<WebServiceWorkerResponse> webResponses(size_t(2)); |
| 503 webResponses[0].setURL(KURL(ParsedURLString, url1)); | 503 webResponses[0].setURL(KURL(ParsedURLString, url1)); |
| 504 webResponses[1].setURL(KURL(ParsedURLString, url2)); | 504 webResponses[1].setURL(KURL(ParsedURLString, url2)); |
| 505 | 505 |
| 506 RefPtrWillBeRawPtr<Cache> cache = Cache::fromWebServiceWorkerCache(new Match
AllAndBatchTestCache(webResponses)); | 506 Cache* cache = Cache::fromWebServiceWorkerCache(new MatchAllAndBatchTestCach
e(webResponses)); |
| 507 | 507 |
| 508 ScriptPromise result = cache->matchAll(scriptState(), "http://some.url/", Di
ctionary()); | 508 ScriptPromise result = cache->matchAll(scriptState(), "http://some.url/", Di
ctionary()); |
| 509 ScriptValue scriptValue = getResolveValue(result); | 509 ScriptValue scriptValue = getResolveValue(result); |
| 510 | 510 |
| 511 Vector<v8::Handle<v8::Value> > responses = toNativeArray<v8::Handle<v8::Valu
e> >(scriptValue.v8Value(), 0, isolate()); | 511 Vector<v8::Handle<v8::Value> > responses = toImplArray<v8::Handle<v8::Value>
>(scriptValue.v8Value(), 0, isolate()); |
| 512 EXPECT_EQ(expectedUrls.size(), responses.size()); | 512 EXPECT_EQ(expectedUrls.size(), responses.size()); |
| 513 for (int i = 0, minsize = std::min(expectedUrls.size(), responses.size()); i
< minsize; ++i) { | 513 for (int i = 0, minsize = std::min(expectedUrls.size(), responses.size()); i
< minsize; ++i) { |
| 514 Response* response = V8Response::toNativeWithTypeCheck(isolate(), respon
ses[i]); | 514 Response* response = V8Response::toImplWithTypeCheck(isolate(), response
s[i]); |
| 515 EXPECT_TRUE(response); | 515 EXPECT_TRUE(response); |
| 516 if (response) | 516 if (response) |
| 517 EXPECT_EQ(expectedUrls[i], response->url()); | 517 EXPECT_EQ(expectedUrls[i], response->url()); |
| 518 } | 518 } |
| 519 | 519 |
| 520 result = cache->deleteFunction(scriptState(), "http://some.url/", Dictionary
()); | 520 result = cache->deleteFunction(scriptState(), "http://some.url/", Dictionary
()); |
| 521 scriptValue = getResolveValue(result); | 521 scriptValue = getResolveValue(result); |
| 522 responses = toNativeArray<v8::Handle<v8::Value> >(scriptValue.v8Value(), 0,
isolate()); | 522 responses = toImplArray<v8::Handle<v8::Value> >(scriptValue.v8Value(), 0, is
olate()); |
| 523 EXPECT_EQ(expectedUrls.size(), responses.size()); | 523 EXPECT_EQ(expectedUrls.size(), responses.size()); |
| 524 for (int i = 0, minsize = std::min(expectedUrls.size(), responses.size()); i
< minsize; ++i) { | 524 for (int i = 0, minsize = std::min(expectedUrls.size(), responses.size()); i
< minsize; ++i) { |
| 525 Response* response = V8Response::toNativeWithTypeCheck(isolate(), respon
ses[i]); | 525 Response* response = V8Response::toImplWithTypeCheck(isolate(), response
s[i]); |
| 526 EXPECT_TRUE(response); | 526 EXPECT_TRUE(response); |
| 527 if (response) | 527 if (response) |
| 528 EXPECT_EQ(expectedUrls[i], response->url()); | 528 EXPECT_EQ(expectedUrls[i], response->url()); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 } // namespace | 532 } // namespace |
| 533 } // namespace blink | 533 } // namespace blink |
| OLD | NEW |