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

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

Issue 2354773003: Make stylesheet owner node a reference instead of pointer. (Closed)
Patch Set: const 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 30 matching lines...) Expand all
41 class Document; 41 class Document;
42 42
43 namespace { 43 namespace {
44 44
45 class CSSStyleSheetResourceTest : public ::testing::Test { 45 class CSSStyleSheetResourceTest : public ::testing::Test {
46 protected: 46 protected:
47 CSSStyleSheetResourceTest() 47 CSSStyleSheetResourceTest()
48 { 48 {
49 m_originalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create ()); 49 m_originalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create ());
50 m_page = DummyPageHolder::create(); 50 m_page = DummyPageHolder::create();
51 document()->setURL(KURL(KURL(), "https://localhost/")); 51 document().setURL(KURL(KURL(), "https://localhost/"));
52 } 52 }
53 53
54 ~CSSStyleSheetResourceTest() override 54 ~CSSStyleSheetResourceTest() override
55 { 55 {
56 replaceMemoryCacheForTesting(m_originalMemoryCache.release()); 56 replaceMemoryCacheForTesting(m_originalMemoryCache.release());
57 } 57 }
58 58
59 Document* document() { return &m_page->document(); } 59 Document& document() { return m_page->document(); }
60 60
61 Persistent<MemoryCache> m_originalMemoryCache; 61 Persistent<MemoryCache> m_originalMemoryCache;
62 std::unique_ptr<DummyPageHolder> m_page; 62 std::unique_ptr<DummyPageHolder> m_page;
63 }; 63 };
64 64
65 TEST_F(CSSStyleSheetResourceTest, PruneCanCauseEviction) 65 TEST_F(CSSStyleSheetResourceTest, PruneCanCauseEviction)
66 { 66 {
67 { 67 {
68 // We need this scope to remove all references. 68 // We need this scope to remove all references.
69 KURL imageURL(KURL(), "https://localhost/image"); 69 KURL imageURL(KURL(), "https://localhost/image");
70 KURL cssURL(KURL(), "https://localhost/style.css"); 70 KURL cssURL(KURL(), "https://localhost/style.css");
71 71
72 // We need to disable loading because we manually give a response to 72 // We need to disable loading because we manually give a response to
73 // the image resource. 73 // the image resource.
74 document()->fetcher()->setAutoLoadImages(false); 74 document().fetcher()->setAutoLoadImages(false);
75 75
76 CSSStyleSheetResource* cssResource = CSSStyleSheetResource::createForTes t(ResourceRequest(cssURL), "utf-8"); 76 CSSStyleSheetResource* cssResource = CSSStyleSheetResource::createForTes t(ResourceRequest(cssURL), "utf-8");
77 memoryCache()->add(cssResource); 77 memoryCache()->add(cssResource);
78 cssResource->responseReceived(ResourceResponse(cssURL, "style/css", 0, n ullAtom, String()), nullptr); 78 cssResource->responseReceived(ResourceResponse(cssURL, "style/css", 0, n ullAtom, String()), nullptr);
79 cssResource->finish(); 79 cssResource->finish();
80 80
81 StyleSheetContents* contents = StyleSheetContents::create(CSSParserConte xt(HTMLStandardMode, nullptr)); 81 StyleSheetContents* contents = StyleSheetContents::create(CSSParserConte xt(HTMLStandardMode, nullptr));
82 CSSStyleSheet* sheet = CSSStyleSheet::create(contents, document()); 82 CSSStyleSheet* sheet = CSSStyleSheet::create(contents, document());
83 EXPECT_TRUE(sheet); 83 EXPECT_TRUE(sheet);
84 CSSCrossfadeValue* crossfade = CSSCrossfadeValue::create( 84 CSSCrossfadeValue* crossfade = CSSCrossfadeValue::create(
85 CSSImageValue::create(String("image"), imageURL), 85 CSSImageValue::create(String("image"), imageURL),
86 CSSImageValue::create(String("image"), imageURL), 86 CSSImageValue::create(String("image"), imageURL),
87 CSSPrimitiveValue::create(1.0, CSSPrimitiveValue::UnitType::Number)) ; 87 CSSPrimitiveValue::create(1.0, CSSPrimitiveValue::UnitType::Number)) ;
88 Vector<std::unique_ptr<CSSParserSelector>> selectors; 88 Vector<std::unique_ptr<CSSParserSelector>> selectors;
89 selectors.append(wrapUnique(new CSSParserSelector())); 89 selectors.append(wrapUnique(new CSSParserSelector()));
90 selectors[0]->setMatch(CSSSelector::Id); 90 selectors[0]->setMatch(CSSSelector::Id);
91 selectors[0]->setValue("foo"); 91 selectors[0]->setValue("foo");
92 CSSProperty property(CSSPropertyBackground, *crossfade); 92 CSSProperty property(CSSPropertyBackground, *crossfade);
93 contents->parserAppendRule( 93 contents->parserAppendRule(
94 StyleRule::create(CSSSelectorList::adoptSelectorVector(selectors), I mmutableStylePropertySet::create(&property, 1, HTMLStandardMode))); 94 StyleRule::create(CSSSelectorList::adoptSelectorVector(selectors), I mmutableStylePropertySet::create(&property, 1, HTMLStandardMode)));
95 95
96 crossfade->loadSubimages(document()); 96 // TODO(rune@opera.com): loadSubimages should take Document&.
97 crossfade->loadSubimages(&document());
97 Resource* imageResource = memoryCache()->resourceForURL(imageURL, Memory Cache::defaultCacheIdentifier()); 98 Resource* imageResource = memoryCache()->resourceForURL(imageURL, Memory Cache::defaultCacheIdentifier());
98 ASSERT_TRUE(imageResource); 99 ASSERT_TRUE(imageResource);
99 ResourceResponse imageResponse; 100 ResourceResponse imageResponse;
100 imageResponse.setURL(imageURL); 101 imageResponse.setURL(imageURL);
101 imageResponse.setHTTPHeaderField("cache-control", "no-store"); 102 imageResponse.setHTTPHeaderField("cache-control", "no-store");
102 imageResource->responseReceived(imageResponse, nullptr); 103 imageResource->responseReceived(imageResponse, nullptr);
103 104
104 contents->checkLoaded(); 105 contents->checkLoaded();
105 cssResource->saveParsedStyleSheet(contents); 106 cssResource->saveParsedStyleSheet(contents);
106 107
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // The underlying |contents| for the stylesheet resource must have a 150 // The underlying |contents| for the stylesheet resource must have a
150 // matching reference status. 151 // matching reference status.
151 EXPECT_TRUE(memoryCache()->contains(imageResource)); 152 EXPECT_TRUE(memoryCache()->contains(imageResource));
152 EXPECT_FALSE(memoryCache()->contains(cssResource)); 153 EXPECT_FALSE(memoryCache()->contains(cssResource));
153 EXPECT_FALSE(contents->isReferencedFromResource()); 154 EXPECT_FALSE(contents->isReferencedFromResource());
154 EXPECT_FALSE(cssResource->restoreParsedStyleSheet(parserContext)); 155 EXPECT_FALSE(cssResource->restoreParsedStyleSheet(parserContext));
155 } 156 }
156 157
157 } // namespace 158 } // namespace
158 } // namespace blink 159 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSStyleSheet.cpp ('k') | third_party/WebKit/Source/core/css/CSSTestHelper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698