Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: third_party/WebKit/Source/modules/cachestorage/CacheTest.cpp

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 27
28 #include <algorithm> 28 #include <algorithm>
29 #include <string> 29 #include <string>
30 30
31 namespace blink { 31 namespace blink {
32 32
33 namespace { 33 namespace {
34 34
35 const char kNotImplementedString[] = "NotSupportedError: Method is not implement ed."; 35 const char kNotImplementedString[] = "NotSupportedError: Method is not implement ed.";
36 36
37 class ScopedFetcherForTests final : public NoBaseWillBeGarbageCollectedFinalized <ScopedFetcherForTests>, public GlobalFetch::ScopedFetcher { 37 class ScopedFetcherForTests final : public GarbageCollectedFinalized<ScopedFetch erForTests>, public GlobalFetch::ScopedFetcher {
38 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ScopedFetcherForTests); 38 USING_GARBAGE_COLLECTED_MIXIN(ScopedFetcherForTests);
39 public: 39 public:
40 static PassOwnPtrWillBeRawPtr<ScopedFetcherForTests> create() 40 static RawPtr<ScopedFetcherForTests> create()
41 { 41 {
42 return adoptPtrWillBeNoop(new ScopedFetcherForTests); 42 return adoptPtrWillBeNoop(new ScopedFetcherForTests);
43 } 43 }
44 44
45 ScriptPromise fetch(ScriptState* scriptState, const RequestInfo& requestInfo , const Dictionary&, ExceptionState&) override 45 ScriptPromise fetch(ScriptState* scriptState, const RequestInfo& requestInfo , const Dictionary&, ExceptionState&) override
46 { 46 {
47 ++m_fetchCount; 47 ++m_fetchCount;
48 if (m_expectedUrl) { 48 if (m_expectedUrl) {
49 String fetchedUrl; 49 String fetchedUrl;
50 if (requestInfo.isRequest()) 50 if (requestInfo.isRequest())
51 EXPECT_EQ(*m_expectedUrl, requestInfo.getAsRequest()->url()); 51 EXPECT_EQ(*m_expectedUrl, requestInfo.getAsRequest()->url());
52 else 52 else
53 EXPECT_EQ(*m_expectedUrl, requestInfo.getAsUSVString()); 53 EXPECT_EQ(*m_expectedUrl, requestInfo.getAsUSVString());
54 } 54 }
55 55
56 if (m_response) { 56 if (m_response) {
57 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scri ptState); 57 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scri ptState);
58 const ScriptPromise promise = resolver->promise(); 58 const ScriptPromise promise = resolver->promise();
59 resolver->resolve(m_response); 59 resolver->resolve(m_response);
60 m_response = nullptr; 60 m_response = nullptr;
61 return promise; 61 return promise;
62 } 62 }
63 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Unexpected call to fetch, no response available.")) ; 63 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Unexpected call to fetch, no response available.")) ;
64 } 64 }
65 65
66 WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher> weakPtr() 66 RawPtr<GlobalFetch::ScopedFetcher> weakPtr()
67 { 67 {
68 #if ENABLE(OILPAN) 68 #if ENABLE(OILPAN)
69 return this; 69 return this;
70 #else 70 #else
71 return m_weakFactory.createWeakPtr(); 71 return m_weakFactory.createWeakPtr();
72 #endif 72 #endif
73 } 73 }
74 74
75 // This does not take ownership of its parameter. The provided sample object is used to check the parameter when called. 75 // This does not take ownership of its parameter. The provided sample object is used to check the parameter when called.
76 void setExpectedFetchUrl(const String* expectedUrl) { m_expectedUrl = expect edUrl; } 76 void setExpectedFetchUrl(const String* expectedUrl) { m_expectedUrl = expect edUrl; }
(...skipping 12 matching lines...) Expand all
89 : m_fetchCount(0) 89 : m_fetchCount(0)
90 , m_expectedUrl(nullptr) 90 , m_expectedUrl(nullptr)
91 #if !ENABLE(OILPAN) 91 #if !ENABLE(OILPAN)
92 , m_weakFactory(this) 92 , m_weakFactory(this)
93 #endif 93 #endif
94 { 94 {
95 } 95 }
96 96
97 int m_fetchCount; 97 int m_fetchCount;
98 const String* m_expectedUrl; 98 const String* m_expectedUrl;
99 PersistentWillBeMember<Response> m_response; 99 Member<Response> m_response;
100 100
101 #if !ENABLE(OILPAN) 101 #if !ENABLE(OILPAN)
102 WeakPtrFactory<GlobalFetch::ScopedFetcher> m_weakFactory; 102 WeakPtrFactory<GlobalFetch::ScopedFetcher> m_weakFactory;
103 #endif 103 #endif
104 }; 104 };
105 105
106 // A test implementation of the WebServiceWorkerCache interface which returns a (provided) error for every operation, and optionally checks arguments 106 // A test implementation of the WebServiceWorkerCache interface which returns a (provided) error for every operation, and optionally checks arguments
107 // to methods against provided arguments. Also used as a base class for test spe cific caches. 107 // to methods against provided arguments. Also used as a base class for test spe cific caches.
108 class ErrorWebCacheForTests : public WebServiceWorkerCache { 108 class ErrorWebCacheForTests : public WebServiceWorkerCache {
109 public: 109 public:
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(getScriptState()); 345 ScriptState::Scope scope(getScriptState());
346 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c reate(); 346 RawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
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(getScriptState(), stringToRequestI nfo(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(getScriptState(), stringToRequestInfo(url), opti ons, 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(getScriptState(), stringToRequestInfo(url), opti ons, 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(getScriptState()); 371 ScriptState::Scope scope(getScriptState());
372 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c reate(); 372 RawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
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";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 418
419 ScriptPromise stringKeysResult2 = cache->keys(getScriptState(), stringToRequ estInfo(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(getScriptState()); 427 ScriptState::Scope scope(getScriptState());
428 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c reate(); 428 RawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
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);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(getScriptState()); 507 ScriptState::Scope scope(getScriptState());
508 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c reate(); 508 RawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
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
(...skipping 15 matching lines...) Expand all
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(getScriptState()); 543 ScriptState::Scope scope(getScriptState());
544 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c reate(); 544 RawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
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));
(...skipping 30 matching lines...) Expand all
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(getScriptState()); 594 ScriptState::Scope scope(getScriptState());
595 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c reate(); 595 RawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
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);
(...skipping 17 matching lines...) Expand all
623 623
624 result = cache->deleteFunction(getScriptState(), stringToRequestInfo("http:/ /some.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(getScriptState()); 632 ScriptState::Scope scope(getScriptState());
633 OwnPtrWillBeRawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::c reate(); 633 RawPtr<ScopedFetcherForTests> fetcher = ScopedFetcherForTests::create();
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);
(...skipping 12 matching lines...) Expand all
656 656
657 ScriptPromise addResult = cache->add(getScriptState(), requestToRequestInfo( request), 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698