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

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

Issue 1858753003: Remove RawPtr from core/css (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 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 { 64 {
65 { 65 {
66 // We need this scope to remove all references. 66 // We need this scope to remove all references.
67 KURL imageURL(KURL(), "https://localhost/image"); 67 KURL imageURL(KURL(), "https://localhost/image");
68 KURL cssURL(KURL(), "https://localhost/style.css"); 68 KURL cssURL(KURL(), "https://localhost/style.css");
69 69
70 // We need to disable loading because we manually give a response to 70 // We need to disable loading because we manually give a response to
71 // the image resource. 71 // the image resource.
72 document()->fetcher()->setAutoLoadImages(false); 72 document()->fetcher()->setAutoLoadImages(false);
73 73
74 RawPtr<CSSStyleSheetResource> cssResource = CSSStyleSheetResource::creat eForTest(ResourceRequest(cssURL), "utf-8"); 74 CSSStyleSheetResource* cssResource = CSSStyleSheetResource::createForTes t(ResourceRequest(cssURL), "utf-8");
75 memoryCache()->add(cssResource.get()); 75 memoryCache()->add(cssResource);
76 cssResource->responseReceived(ResourceResponse(cssURL, "style/css", 0, n ullAtom, String()), nullptr); 76 cssResource->responseReceived(ResourceResponse(cssURL, "style/css", 0, n ullAtom, String()), nullptr);
77 cssResource->finish(); 77 cssResource->finish();
78 78
79 RawPtr<StyleSheetContents> contents = StyleSheetContents::create(CSSPars erContext(HTMLStandardMode, nullptr)); 79 StyleSheetContents* contents = StyleSheetContents::create(CSSParserConte xt(HTMLStandardMode, nullptr));
80 RawPtr<CSSStyleSheet> sheet = CSSStyleSheet::create(contents, document() ); 80 CSSStyleSheet* sheet = CSSStyleSheet::create(contents, document());
81 EXPECT_TRUE(sheet); 81 EXPECT_TRUE(sheet);
82 RawPtr<CSSCrossfadeValue> crossfade = CSSCrossfadeValue::create( 82 CSSCrossfadeValue* crossfade = CSSCrossfadeValue::create(
83 CSSImageValue::create(String("image"), imageURL), 83 CSSImageValue::create(String("image"), imageURL),
84 CSSImageValue::create(String("image"), imageURL), 84 CSSImageValue::create(String("image"), imageURL),
85 CSSPrimitiveValue::create(1.0, CSSPrimitiveValue::UnitType::Number)) ; 85 CSSPrimitiveValue::create(1.0, CSSPrimitiveValue::UnitType::Number)) ;
86 Vector<OwnPtr<CSSParserSelector>> selectors; 86 Vector<OwnPtr<CSSParserSelector>> selectors;
87 selectors.append(adoptPtr(new CSSParserSelector())); 87 selectors.append(adoptPtr(new CSSParserSelector()));
88 selectors[0]->setMatch(CSSSelector::Id); 88 selectors[0]->setMatch(CSSSelector::Id);
89 selectors[0]->setValue("foo"); 89 selectors[0]->setValue("foo");
90 CSSProperty property(CSSPropertyBackground, crossfade); 90 CSSProperty property(CSSPropertyBackground, crossfade);
91 contents->parserAppendRule( 91 contents->parserAppendRule(
92 StyleRule::create(CSSSelectorList::adoptSelectorVector(selectors), I mmutableStylePropertySet::create(&property, 1, HTMLStandardMode))); 92 StyleRule::create(CSSSelectorList::adoptSelectorVector(selectors), I mmutableStylePropertySet::create(&property, 1, HTMLStandardMode)));
93 93
94 crossfade->loadSubimages(document()); 94 crossfade->loadSubimages(document());
95 RawPtr<Resource> imageResource = memoryCache()->resourceForURL(imageURL, MemoryCache::defaultCacheIdentifier()); 95 Resource* imageResource = memoryCache()->resourceForURL(imageURL, Memory Cache::defaultCacheIdentifier());
96 ASSERT_TRUE(imageResource); 96 ASSERT_TRUE(imageResource);
97 ResourceResponse imageResponse; 97 ResourceResponse imageResponse;
98 imageResponse.setURL(imageURL); 98 imageResponse.setURL(imageURL);
99 imageResponse.setHTTPHeaderField("cache-control", "no-store"); 99 imageResponse.setHTTPHeaderField("cache-control", "no-store");
100 imageResource->responseReceived(imageResponse, nullptr); 100 imageResource->responseReceived(imageResponse, nullptr);
101 101
102 contents->checkLoaded(); 102 contents->checkLoaded();
103 cssResource->saveParsedStyleSheet(contents); 103 cssResource->saveParsedStyleSheet(contents);
104 104
105 memoryCache()->update(cssResource.get(), cssResource->size(), cssResourc e->size(), false); 105 memoryCache()->update(cssResource, cssResource->size(), cssResource->siz e(), false);
106 memoryCache()->update(imageResource.get(), imageResource->size(), imageR esource->size(), false); 106 memoryCache()->update(imageResource, imageResource->size(), imageResourc e->size(), false);
107 if (!memoryCache()->isInSameLRUListForTest(cssResource.get(), imageResou rce.get())) { 107 if (!memoryCache()->isInSameLRUListForTest(cssResource, imageResource)) {
108 // We assume that the LRU list is determined by |size / accessCount| . 108 // We assume that the LRU list is determined by |size / accessCount| .
109 for (size_t i = 0; i < cssResource->size() + 1; ++i) 109 for (size_t i = 0; i < cssResource->size() + 1; ++i)
110 memoryCache()->update(cssResource.get(), cssResource->size(), cs sResource->size(), true); 110 memoryCache()->update(cssResource, cssResource->size(), cssResou rce->size(), true);
111 for (size_t i = 0; i < imageResource->size() + 1; ++i) 111 for (size_t i = 0; i < imageResource->size() + 1; ++i)
112 memoryCache()->update(imageResource.get(), imageResource->size() , imageResource->size(), true); 112 memoryCache()->update(imageResource, imageResource->size(), imag eResource->size(), true);
113 } 113 }
114 ASSERT_TRUE(memoryCache()->isInSameLRUListForTest(cssResource.get(), ima geResource.get())); 114 ASSERT_TRUE(memoryCache()->isInSameLRUListForTest(cssResource, imageReso urce));
115 } 115 }
116 Heap::collectAllGarbage(); 116 Heap::collectAllGarbage();
117 // This operation should not lead to crash! 117 // This operation should not lead to crash!
118 memoryCache()->pruneAll(); 118 memoryCache()->pruneAll();
119 } 119 }
120 120
121 TEST_F(CSSStyleSheetResourceTest, DuplicateResourceNotCached) 121 TEST_F(CSSStyleSheetResourceTest, DuplicateResourceNotCached)
122 { 122 {
123 const char url[] = "https://localhost/style.css"; 123 const char url[] = "https://localhost/style.css";
124 KURL imageURL(KURL(), url); 124 KURL imageURL(KURL(), url);
125 KURL cssURL(KURL(), url); 125 KURL cssURL(KURL(), url);
126 126
127 // Emulate using <img> to do async stylesheet preloads. 127 // Emulate using <img> to do async stylesheet preloads.
128 128
129 RawPtr<Resource> imageResource = ImageResource::create(ResourceRequest(image URL), nullptr); 129 Resource* imageResource = ImageResource::create(ResourceRequest(imageURL), n ullptr);
130 ASSERT_TRUE(imageResource); 130 ASSERT_TRUE(imageResource);
131 memoryCache()->add(imageResource.get()); 131 memoryCache()->add(imageResource);
132 ASSERT_TRUE(memoryCache()->contains(imageResource.get())); 132 ASSERT_TRUE(memoryCache()->contains(imageResource));
133 133
134 RawPtr<CSSStyleSheetResource> cssResource = CSSStyleSheetResource::createFor Test(ResourceRequest(cssURL), "utf-8"); 134 CSSStyleSheetResource* cssResource = CSSStyleSheetResource::createForTest(Re sourceRequest(cssURL), "utf-8");
135 cssResource->responseReceived(ResourceResponse(cssURL, "style/css", 0, nullA tom, String()), nullptr); 135 cssResource->responseReceived(ResourceResponse(cssURL, "style/css", 0, nullA tom, String()), nullptr);
136 cssResource->finish(); 136 cssResource->finish();
137 137
138 RawPtr<StyleSheetContents> contents = StyleSheetContents::create(CSSParserCo ntext(HTMLStandardMode, nullptr)); 138 StyleSheetContents* contents = StyleSheetContents::create(CSSParserContext(H TMLStandardMode, nullptr));
139 RawPtr<CSSStyleSheet> sheet = CSSStyleSheet::create(contents, document()); 139 CSSStyleSheet* sheet = CSSStyleSheet::create(contents, document());
140 EXPECT_TRUE(sheet); 140 EXPECT_TRUE(sheet);
141 141
142 contents->checkLoaded(); 142 contents->checkLoaded();
143 cssResource->saveParsedStyleSheet(contents); 143 cssResource->saveParsedStyleSheet(contents);
144 144
145 // Verify that the cache will have a mapping for |imageResource| at |url|. 145 // Verify that the cache will have a mapping for |imageResource| at |url|.
146 // The underlying |contents| for the stylesheet resource must have a 146 // The underlying |contents| for the stylesheet resource must have a
147 // matching cache status. 147 // matching cache status.
148 ASSERT_TRUE(memoryCache()->contains(imageResource.get())); 148 ASSERT_TRUE(memoryCache()->contains(imageResource));
149 ASSERT_FALSE(memoryCache()->contains(cssResource.get())); 149 ASSERT_FALSE(memoryCache()->contains(cssResource));
150 ASSERT_FALSE(contents->isInMemoryCache()); 150 ASSERT_FALSE(contents->isInMemoryCache());
151 } 151 }
152 152
153 } // namespace 153 } // namespace
154 } // namespace blink 154 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698