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

Side by Side Diff: third_party/WebKit/Source/core/fetch/MemoryCacheTest.cpp

Issue 2129093002: Remove ApplicationCache runtime flag (status=stable) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add some unit tests for MemoryCache. Created 4 years, 5 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 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 EXPECT_TRUE(memoryCache()->contains(resource3)); 418 EXPECT_TRUE(memoryCache()->contains(resource3));
419 419
420 HeapVector<Member<Resource>> resources = memoryCache()->resourcesForURL(url) ; 420 HeapVector<Member<Resource>> resources = memoryCache()->resourcesForURL(url) ;
421 EXPECT_EQ(2u, resources.size()); 421 EXPECT_EQ(2u, resources.size());
422 422
423 memoryCache()->evictResources(); 423 memoryCache()->evictResources();
424 EXPECT_FALSE(memoryCache()->contains(resource1)); 424 EXPECT_FALSE(memoryCache()->contains(resource1));
425 EXPECT_FALSE(memoryCache()->contains(resource3)); 425 EXPECT_FALSE(memoryCache()->contains(resource3));
426 } 426 }
427 427
428 TEST_F(MemoryCacheTest, FragmentIdentifier)
429 {
430 FakeResource* resource = FakeResource::create(ResourceRequest("http://test/r esource#foo"), Resource::Raw);
431 memoryCache()->add(resource);
432 ASSERT_TRUE(memoryCache()->contains(resource));
433
434 const KURL url1 = KURL(ParsedURLString, "http://test/resource");
435 EXPECT_EQ(resource, memoryCache()->resourceForURL(url1));
436
437 const KURL url2 = KURL(ParsedURLString, "http://test/resource#foo");
438 EXPECT_EQ(resource, memoryCache()->resourceForURL(url2));
439 }
440
441 TEST_F(MemoryCacheTest, MakeLiveAndDead)
442 {
443 FakeResource* resource = FakeResource::create(ResourceRequest("http://test/r esource"), Resource::Raw);
444 const char data[6] = "abcde";
445 resource->appendData(data, 5u);
446 memoryCache()->add(resource);
447
448 const size_t deadSize = memoryCache()->deadSize();
449 const size_t liveSize = memoryCache()->liveSize();
450
451 memoryCache()->makeLive(resource);
452 ASSERT_EQ(deadSize, memoryCache()->deadSize() + resource->size());
453 ASSERT_EQ(liveSize, memoryCache()->liveSize() - resource->size());
454
455 memoryCache()->makeDead(resource);
456 ASSERT_EQ(deadSize, memoryCache()->deadSize());
457 ASSERT_EQ(liveSize, memoryCache()->liveSize());
458 }
459
460 TEST_F(MemoryCacheTest, RemoveURLFromCache)
461 {
462 FakeResource* resource1 = FakeResource::create(ResourceRequest("http://test/ resource1"), Resource::Raw);
463 memoryCache()->add(resource1);
464 ASSERT_TRUE(memoryCache()->contains(resource1));
465
466 const KURL url1 = KURL(ParsedURLString, "http://test/resource1");
467 memoryCache()->removeURLFromCache(url1);
468 EXPECT_FALSE(memoryCache()->contains(resource1));
469
470 FakeResource* resource2 = FakeResource::create(ResourceRequest("http://test/ resource2#foo"), Resource::Raw);
471 memoryCache()->add(resource2);
472 ASSERT_TRUE(memoryCache()->contains(resource2));
473
474 const KURL url2 = KURL(ParsedURLString, "http://test/resource2#foo");
475 memoryCache()->removeURLFromCache(url2);
476 EXPECT_FALSE(memoryCache()->contains(resource2));
477 }
478
428 } // namespace blink 479 } // namespace blink
OLDNEW
« no previous file with comments | « content/test/test_blink_web_unit_test_support.cc ('k') | third_party/WebKit/Source/core/frame/Window.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698