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

Side by Side Diff: third_party/WebKit/Source/core/css/CSSStyleSheetResourceTest.cpp

Issue 2411243004: [WeakMemoryCache] Remove LRU lists, prune order control and live/dead distinction (Closed)
Patch Set: Rebase Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "core/fetch/CSSStyleSheetResource.h" 5 #include "core/fetch/CSSStyleSheetResource.h"
6 6
7 #include "core/css/CSSCrossfadeValue.h" 7 #include "core/css/CSSCrossfadeValue.h"
8 #include "core/css/CSSImageValue.h" 8 #include "core/css/CSSImageValue.h"
9 #include "core/css/CSSPrimitiveValue.h" 9 #include "core/css/CSSPrimitiveValue.h"
10 #include "core/css/CSSProperty.h" 10 #include "core/css/CSSProperty.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 Resource* imageResource = memoryCache()->resourceForURL( 98 Resource* imageResource = memoryCache()->resourceForURL(
99 imageURL, MemoryCache::defaultCacheIdentifier()); 99 imageURL, MemoryCache::defaultCacheIdentifier());
100 ASSERT_TRUE(imageResource); 100 ASSERT_TRUE(imageResource);
101 ResourceResponse imageResponse; 101 ResourceResponse imageResponse;
102 imageResponse.setURL(imageURL); 102 imageResponse.setURL(imageURL);
103 imageResponse.setHTTPHeaderField("cache-control", "no-store"); 103 imageResponse.setHTTPHeaderField("cache-control", "no-store");
104 imageResource->responseReceived(imageResponse, nullptr); 104 imageResource->responseReceived(imageResponse, nullptr);
105 105
106 contents->checkLoaded(); 106 contents->checkLoaded();
107 cssResource->saveParsedStyleSheet(contents); 107 cssResource->saveParsedStyleSheet(contents);
108
109 memoryCache()->update(cssResource, cssResource->size(), cssResource->size(),
110 false);
111 memoryCache()->update(imageResource, imageResource->size(),
112 imageResource->size(), false);
113 if (!memoryCache()->isInSameLRUListForTest(cssResource, imageResource)) {
114 // We assume that the LRU list is determined by |size / accessCount|.
115 for (size_t i = 0; i < cssResource->size() + 1; ++i)
116 memoryCache()->update(cssResource, cssResource->size(),
117 cssResource->size(), true);
118 for (size_t i = 0; i < imageResource->size() + 1; ++i)
119 memoryCache()->update(imageResource, imageResource->size(),
120 imageResource->size(), true);
121 }
122 ASSERT_TRUE(
123 memoryCache()->isInSameLRUListForTest(cssResource, imageResource));
124 } 108 }
125 ThreadState::current()->collectAllGarbage(); 109 ThreadState::current()->collectAllGarbage();
126 // This operation should not lead to crash! 110 // This operation should not lead to crash!
127 memoryCache()->pruneAll(); 111 memoryCache()->pruneAll();
128 } 112 }
129 113
130 TEST_F(CSSStyleSheetResourceTest, DuplicateResourceNotCached) { 114 TEST_F(CSSStyleSheetResourceTest, DuplicateResourceNotCached) {
131 const char url[] = "https://localhost/style.css"; 115 const char url[] = "https://localhost/style.css";
132 KURL imageURL(KURL(), url); 116 KURL imageURL(KURL(), url);
133 KURL cssURL(KURL(), url); 117 KURL cssURL(KURL(), url);
(...skipping 23 matching lines...) Expand all
157 // The underlying |contents| for the stylesheet resource must have a 141 // The underlying |contents| for the stylesheet resource must have a
158 // matching reference status. 142 // matching reference status.
159 EXPECT_TRUE(memoryCache()->contains(imageResource)); 143 EXPECT_TRUE(memoryCache()->contains(imageResource));
160 EXPECT_FALSE(memoryCache()->contains(cssResource)); 144 EXPECT_FALSE(memoryCache()->contains(cssResource));
161 EXPECT_FALSE(contents->isReferencedFromResource()); 145 EXPECT_FALSE(contents->isReferencedFromResource());
162 EXPECT_FALSE(cssResource->restoreParsedStyleSheet(parserContext)); 146 EXPECT_FALSE(cssResource->restoreParsedStyleSheet(parserContext));
163 } 147 }
164 148
165 } // namespace 149 } // namespace
166 } // namespace blink 150 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698