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

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

Issue 2862963003: Replace ASSERT with DCHECK in modules/ (Closed)
Patch Set: NOTREACHED instead of DCHECK(false) Created 3 years, 7 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 <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include "bindings/core/v8/ExceptionState.h" 10 #include "bindings/core/v8/ExceptionState.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // correct values being passed. 315 // correct values being passed.
316 class TestFunction : public ScriptFunction { 316 class TestFunction : public ScriptFunction {
317 public: 317 public:
318 static v8::Local<v8::Function> Create(ScriptState* script_state, 318 static v8::Local<v8::Function> Create(ScriptState* script_state,
319 ScriptValue* out_value) { 319 ScriptValue* out_value) {
320 TestFunction* self = new TestFunction(script_state, out_value); 320 TestFunction* self = new TestFunction(script_state, out_value);
321 return self->BindToV8Function(); 321 return self->BindToV8Function();
322 } 322 }
323 323
324 ScriptValue Call(ScriptValue value) override { 324 ScriptValue Call(ScriptValue value) override {
325 ASSERT(!value.IsEmpty()); 325 DCHECK(!value.IsEmpty());
326 *value_ = value; 326 *value_ = value;
327 return value; 327 return value;
328 } 328 }
329 329
330 private: 330 private:
331 TestFunction(ScriptState* script_state, ScriptValue* out_value) 331 TestFunction(ScriptState* script_state, ScriptValue* out_value)
332 : ScriptFunction(script_state), value_(out_value) {} 332 : ScriptFunction(script_state), value_(out_value) {}
333 333
334 ScriptValue* value_; 334 ScriptValue* value_;
335 }; 335 };
(...skipping 14 matching lines...) Expand all
350 return info; 350 return info;
351 } 351 }
352 352
353 TEST_F(CacheStorageTest, Basics) { 353 TEST_F(CacheStorageTest, Basics) {
354 ScriptState::Scope scope(GetScriptState()); 354 ScriptState::Scope scope(GetScriptState());
355 NonThrowableExceptionState exception_state; 355 NonThrowableExceptionState exception_state;
356 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::Create(); 356 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::Create();
357 ErrorWebCacheForTests* test_cache; 357 ErrorWebCacheForTests* test_cache;
358 Cache* cache = 358 Cache* cache =
359 CreateCache(fetcher, test_cache = new NotImplementedErrorCache()); 359 CreateCache(fetcher, test_cache = new NotImplementedErrorCache());
360 ASSERT(cache); 360 DCHECK(cache);
361 361
362 const String url = "http://www.cachetest.org/"; 362 const String url = "http://www.cachetest.org/";
363 363
364 CacheQueryOptions options; 364 CacheQueryOptions options;
365 ScriptPromise match_promise = cache->match( 365 ScriptPromise match_promise = cache->match(
366 GetScriptState(), StringToRequestInfo(url), options, exception_state); 366 GetScriptState(), StringToRequestInfo(url), options, exception_state);
367 EXPECT_EQ(kNotImplementedString, GetRejectString(match_promise)); 367 EXPECT_EQ(kNotImplementedString, GetRejectString(match_promise));
368 368
369 cache = CreateCache(fetcher, test_cache = new ErrorWebCacheForTests( 369 cache = CreateCache(fetcher, test_cache = new ErrorWebCacheForTests(
370 kWebServiceWorkerCacheErrorNotFound)); 370 kWebServiceWorkerCacheErrorNotFound));
(...skipping 12 matching lines...) Expand all
383 383
384 // Tests that arguments are faithfully passed on calls to Cache methods, except 384 // Tests that arguments are faithfully passed on calls to Cache methods, except
385 // for methods which use batch operations, which are tested later. 385 // for methods which use batch operations, which are tested later.
386 TEST_F(CacheStorageTest, BasicArguments) { 386 TEST_F(CacheStorageTest, BasicArguments) {
387 ScriptState::Scope scope(GetScriptState()); 387 ScriptState::Scope scope(GetScriptState());
388 NonThrowableExceptionState exception_state; 388 NonThrowableExceptionState exception_state;
389 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::Create(); 389 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::Create();
390 ErrorWebCacheForTests* test_cache; 390 ErrorWebCacheForTests* test_cache;
391 Cache* cache = 391 Cache* cache =
392 CreateCache(fetcher, test_cache = new NotImplementedErrorCache()); 392 CreateCache(fetcher, test_cache = new NotImplementedErrorCache());
393 ASSERT(cache); 393 DCHECK(cache);
394 394
395 const String url = "http://www.cache.arguments.test/"; 395 const String url = "http://www.cache.arguments.test/";
396 test_cache->SetExpectedUrl(&url); 396 test_cache->SetExpectedUrl(&url);
397 397
398 WebServiceWorkerCache::QueryParams expected_query_params; 398 WebServiceWorkerCache::QueryParams expected_query_params;
399 expected_query_params.ignore_vary = true; 399 expected_query_params.ignore_vary = true;
400 expected_query_params.cache_name = "this is a cache name"; 400 expected_query_params.cache_name = "this is a cache name";
401 test_cache->SetExpectedQueryParams(&expected_query_params); 401 test_cache->SetExpectedQueryParams(&expected_query_params);
402 402
403 CacheQueryOptions options; 403 CacheQueryOptions options;
404 options.setIgnoreVary(1); 404 options.setIgnoreVary(1);
405 options.setCacheName(expected_query_params.cache_name); 405 options.setCacheName(expected_query_params.cache_name);
406 406
407 Request* request = NewRequestFromUrl(url); 407 Request* request = NewRequestFromUrl(url);
408 ASSERT(request); 408 DCHECK(request);
409 ScriptPromise match_result = 409 ScriptPromise match_result =
410 cache->match(GetScriptState(), RequestToRequestInfo(request), options, 410 cache->match(GetScriptState(), RequestToRequestInfo(request), options,
411 exception_state); 411 exception_state);
412 EXPECT_EQ("dispatchMatch", 412 EXPECT_EQ("dispatchMatch",
413 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); 413 test_cache->GetAndClearLastErrorWebCacheMethodCalled());
414 EXPECT_EQ(kNotImplementedString, GetRejectString(match_result)); 414 EXPECT_EQ(kNotImplementedString, GetRejectString(match_result));
415 415
416 ScriptPromise string_match_result = cache->match( 416 ScriptPromise string_match_result = cache->match(
417 GetScriptState(), StringToRequestInfo(url), options, exception_state); 417 GetScriptState(), StringToRequestInfo(url), options, exception_state);
418 EXPECT_EQ("dispatchMatch", 418 EXPECT_EQ("dispatchMatch",
419 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); 419 test_cache->GetAndClearLastErrorWebCacheMethodCalled());
420 EXPECT_EQ(kNotImplementedString, GetRejectString(string_match_result)); 420 EXPECT_EQ(kNotImplementedString, GetRejectString(string_match_result));
421 421
422 request = NewRequestFromUrl(url); 422 request = NewRequestFromUrl(url);
423 ASSERT(request); 423 DCHECK(request);
424 ScriptPromise match_all_result = 424 ScriptPromise match_all_result =
425 cache->matchAll(GetScriptState(), RequestToRequestInfo(request), options, 425 cache->matchAll(GetScriptState(), RequestToRequestInfo(request), options,
426 exception_state); 426 exception_state);
427 EXPECT_EQ("dispatchMatchAll", 427 EXPECT_EQ("dispatchMatchAll",
428 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); 428 test_cache->GetAndClearLastErrorWebCacheMethodCalled());
429 EXPECT_EQ(kNotImplementedString, GetRejectString(match_all_result)); 429 EXPECT_EQ(kNotImplementedString, GetRejectString(match_all_result));
430 430
431 ScriptPromise string_match_all_result = cache->matchAll( 431 ScriptPromise string_match_all_result = cache->matchAll(
432 GetScriptState(), StringToRequestInfo(url), options, exception_state); 432 GetScriptState(), StringToRequestInfo(url), options, exception_state);
433 EXPECT_EQ("dispatchMatchAll", 433 EXPECT_EQ("dispatchMatchAll",
434 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); 434 test_cache->GetAndClearLastErrorWebCacheMethodCalled());
435 EXPECT_EQ(kNotImplementedString, GetRejectString(string_match_all_result)); 435 EXPECT_EQ(kNotImplementedString, GetRejectString(string_match_all_result));
436 436
437 ScriptPromise keys_result1 = cache->keys(GetScriptState(), exception_state); 437 ScriptPromise keys_result1 = cache->keys(GetScriptState(), exception_state);
438 EXPECT_EQ("dispatchKeys", 438 EXPECT_EQ("dispatchKeys",
439 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); 439 test_cache->GetAndClearLastErrorWebCacheMethodCalled());
440 EXPECT_EQ(kNotImplementedString, GetRejectString(keys_result1)); 440 EXPECT_EQ(kNotImplementedString, GetRejectString(keys_result1));
441 441
442 request = NewRequestFromUrl(url); 442 request = NewRequestFromUrl(url);
443 ASSERT(request); 443 DCHECK(request);
444 ScriptPromise keys_result2 = 444 ScriptPromise keys_result2 =
445 cache->keys(GetScriptState(), RequestToRequestInfo(request), options, 445 cache->keys(GetScriptState(), RequestToRequestInfo(request), options,
446 exception_state); 446 exception_state);
447 EXPECT_EQ("dispatchKeys", 447 EXPECT_EQ("dispatchKeys",
448 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); 448 test_cache->GetAndClearLastErrorWebCacheMethodCalled());
449 EXPECT_EQ(kNotImplementedString, GetRejectString(keys_result2)); 449 EXPECT_EQ(kNotImplementedString, GetRejectString(keys_result2));
450 450
451 ScriptPromise string_keys_result2 = cache->keys( 451 ScriptPromise string_keys_result2 = cache->keys(
452 GetScriptState(), StringToRequestInfo(url), options, exception_state); 452 GetScriptState(), StringToRequestInfo(url), options, exception_state);
453 EXPECT_EQ("dispatchKeys", 453 EXPECT_EQ("dispatchKeys",
454 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); 454 test_cache->GetAndClearLastErrorWebCacheMethodCalled());
455 EXPECT_EQ(kNotImplementedString, GetRejectString(string_keys_result2)); 455 EXPECT_EQ(kNotImplementedString, GetRejectString(string_keys_result2));
456 } 456 }
457 457
458 // Tests that arguments are faithfully passed to API calls that degrade to batch 458 // Tests that arguments are faithfully passed to API calls that degrade to batch
459 // operations. 459 // operations.
460 TEST_F(CacheStorageTest, BatchOperationArguments) { 460 TEST_F(CacheStorageTest, BatchOperationArguments) {
461 ScriptState::Scope scope(GetScriptState()); 461 ScriptState::Scope scope(GetScriptState());
462 NonThrowableExceptionState exception_state; 462 NonThrowableExceptionState exception_state;
463 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::Create(); 463 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::Create();
464 ErrorWebCacheForTests* test_cache; 464 ErrorWebCacheForTests* test_cache;
465 Cache* cache = 465 Cache* cache =
466 CreateCache(fetcher, test_cache = new NotImplementedErrorCache()); 466 CreateCache(fetcher, test_cache = new NotImplementedErrorCache());
467 ASSERT(cache); 467 DCHECK(cache);
468 468
469 WebServiceWorkerCache::QueryParams expected_query_params; 469 WebServiceWorkerCache::QueryParams expected_query_params;
470 expected_query_params.cache_name = "this is another cache name"; 470 expected_query_params.cache_name = "this is another cache name";
471 test_cache->SetExpectedQueryParams(&expected_query_params); 471 test_cache->SetExpectedQueryParams(&expected_query_params);
472 472
473 CacheQueryOptions options; 473 CacheQueryOptions options;
474 options.setCacheName(expected_query_params.cache_name); 474 options.setCacheName(expected_query_params.cache_name);
475 475
476 const String url = "http://batch.operations.test/"; 476 const String url = "http://batch.operations.test/";
477 Request* request = NewRequestFromUrl(url); 477 Request* request = NewRequestFromUrl(url);
478 ASSERT(request); 478 DCHECK(request);
479 479
480 WebServiceWorkerResponse web_response; 480 WebServiceWorkerResponse web_response;
481 std::vector<KURL> url_list; 481 std::vector<KURL> url_list;
482 url_list.push_back(KURL(kParsedURLString, url)); 482 url_list.push_back(KURL(kParsedURLString, url));
483 web_response.SetURLList(url_list); 483 web_response.SetURLList(url_list);
484 Response* response = Response::Create(GetScriptState(), web_response); 484 Response* response = Response::Create(GetScriptState(), web_response);
485 485
486 WebVector<WebServiceWorkerCache::BatchOperation> expected_delete_operations( 486 WebVector<WebServiceWorkerCache::BatchOperation> expected_delete_operations(
487 size_t(1)); 487 size_t(1));
488 { 488 {
(...skipping 24 matching lines...) Expand all
513 { 513 {
514 WebServiceWorkerCache::BatchOperation put_operation; 514 WebServiceWorkerCache::BatchOperation put_operation;
515 put_operation.operation_type = WebServiceWorkerCache::kOperationTypePut; 515 put_operation.operation_type = WebServiceWorkerCache::kOperationTypePut;
516 request->PopulateWebServiceWorkerRequest(put_operation.request); 516 request->PopulateWebServiceWorkerRequest(put_operation.request);
517 response->PopulateWebServiceWorkerResponse(put_operation.response); 517 response->PopulateWebServiceWorkerResponse(put_operation.response);
518 expected_put_operations[0] = put_operation; 518 expected_put_operations[0] = put_operation;
519 } 519 }
520 test_cache->SetExpectedBatchOperations(&expected_put_operations); 520 test_cache->SetExpectedBatchOperations(&expected_put_operations);
521 521
522 request = NewRequestFromUrl(url); 522 request = NewRequestFromUrl(url);
523 ASSERT(request); 523 DCHECK(request);
524 ScriptPromise put_result = cache->put( 524 ScriptPromise put_result = cache->put(
525 GetScriptState(), RequestToRequestInfo(request), 525 GetScriptState(), RequestToRequestInfo(request),
526 response->clone(GetScriptState(), exception_state), exception_state); 526 response->clone(GetScriptState(), exception_state), exception_state);
527 EXPECT_EQ("dispatchBatch", 527 EXPECT_EQ("dispatchBatch",
528 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); 528 test_cache->GetAndClearLastErrorWebCacheMethodCalled());
529 EXPECT_EQ(kNotImplementedString, GetRejectString(put_result)); 529 EXPECT_EQ(kNotImplementedString, GetRejectString(put_result));
530 530
531 ScriptPromise string_put_result = cache->put( 531 ScriptPromise string_put_result = cache->put(
532 GetScriptState(), StringToRequestInfo(url), response, exception_state); 532 GetScriptState(), StringToRequestInfo(url), response, exception_state);
533 EXPECT_EQ("dispatchBatch", 533 EXPECT_EQ("dispatchBatch",
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 733
734 EXPECT_EQ(kNotImplementedString, GetRejectString(add_result)); 734 EXPECT_EQ(kNotImplementedString, GetRejectString(add_result));
735 EXPECT_EQ(1, fetcher->FetchCount()); 735 EXPECT_EQ(1, fetcher->FetchCount());
736 EXPECT_EQ("dispatchBatch", 736 EXPECT_EQ("dispatchBatch",
737 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); 737 test_cache->GetAndClearLastErrorWebCacheMethodCalled());
738 } 738 }
739 739
740 } // namespace 740 } // namespace
741 741
742 } // namespace blink 742 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698