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

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

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 13 matching lines...) Expand all
24 #include "core/testing/DummyPageHolder.h" 24 #include "core/testing/DummyPageHolder.h"
25 #include "platform/heap/Handle.h" 25 #include "platform/heap/Handle.h"
26 #include "platform/heap/Heap.h" 26 #include "platform/heap/Heap.h"
27 #include "platform/network/ResourceRequest.h" 27 #include "platform/network/ResourceRequest.h"
28 #include "platform/testing/URLTestHelpers.h" 28 #include "platform/testing/URLTestHelpers.h"
29 #include "platform/testing/UnitTestHelpers.h" 29 #include "platform/testing/UnitTestHelpers.h"
30 #include "platform/weborigin/KURL.h" 30 #include "platform/weborigin/KURL.h"
31 #include "public/platform/Platform.h" 31 #include "public/platform/Platform.h"
32 #include "public/platform/WebURLResponse.h" 32 #include "public/platform/WebURLResponse.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 #include "wtf/PtrUtil.h"
35 #include "wtf/RefPtr.h" 34 #include "wtf/RefPtr.h"
36 #include "wtf/text/WTFString.h" 35 #include "wtf/text/WTFString.h"
37 #include <memory>
38 36
39 namespace blink { 37 namespace blink {
40 38
41 class Document; 39 class Document;
42 40
43 namespace { 41 namespace {
44 42
45 class CSSStyleSheetResourceTest : public ::testing::Test { 43 class CSSStyleSheetResourceTest : public ::testing::Test {
46 protected: 44 protected:
47 CSSStyleSheetResourceTest() 45 CSSStyleSheetResourceTest()
48 { 46 {
49 m_originalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create ()); 47 m_originalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create ());
50 m_page = DummyPageHolder::create(); 48 m_page = DummyPageHolder::create();
51 document()->setURL(KURL(KURL(), "https://localhost/")); 49 document()->setURL(KURL(KURL(), "https://localhost/"));
52 } 50 }
53 51
54 ~CSSStyleSheetResourceTest() override 52 ~CSSStyleSheetResourceTest() override
55 { 53 {
56 replaceMemoryCacheForTesting(m_originalMemoryCache.release()); 54 replaceMemoryCacheForTesting(m_originalMemoryCache.release());
57 } 55 }
58 56
59 Document* document() { return &m_page->document(); } 57 Document* document() { return &m_page->document(); }
60 58
61 Persistent<MemoryCache> m_originalMemoryCache; 59 Persistent<MemoryCache> m_originalMemoryCache;
62 std::unique_ptr<DummyPageHolder> m_page; 60 OwnPtr<DummyPageHolder> m_page;
63 }; 61 };
64 62
65 TEST_F(CSSStyleSheetResourceTest, PruneCanCauseEviction) 63 TEST_F(CSSStyleSheetResourceTest, PruneCanCauseEviction)
66 { 64 {
67 { 65 {
68 // We need this scope to remove all references. 66 // We need this scope to remove all references.
69 KURL imageURL(KURL(), "https://localhost/image"); 67 KURL imageURL(KURL(), "https://localhost/image");
70 KURL cssURL(KURL(), "https://localhost/style.css"); 68 KURL cssURL(KURL(), "https://localhost/style.css");
71 69
72 // 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
73 // the image resource. 71 // the image resource.
74 document()->fetcher()->setAutoLoadImages(false); 72 document()->fetcher()->setAutoLoadImages(false);
75 73
76 CSSStyleSheetResource* cssResource = CSSStyleSheetResource::createForTes t(ResourceRequest(cssURL), "utf-8"); 74 CSSStyleSheetResource* cssResource = CSSStyleSheetResource::createForTes t(ResourceRequest(cssURL), "utf-8");
77 memoryCache()->add(cssResource); 75 memoryCache()->add(cssResource);
78 cssResource->responseReceived(ResourceResponse(cssURL, "style/css", 0, n ullAtom, String()), nullptr); 76 cssResource->responseReceived(ResourceResponse(cssURL, "style/css", 0, n ullAtom, String()), nullptr);
79 cssResource->finish(); 77 cssResource->finish();
80 78
81 StyleSheetContents* contents = StyleSheetContents::create(CSSParserConte xt(HTMLStandardMode, nullptr)); 79 StyleSheetContents* contents = StyleSheetContents::create(CSSParserConte xt(HTMLStandardMode, nullptr));
82 CSSStyleSheet* sheet = CSSStyleSheet::create(contents, document()); 80 CSSStyleSheet* sheet = CSSStyleSheet::create(contents, document());
83 EXPECT_TRUE(sheet); 81 EXPECT_TRUE(sheet);
84 CSSCrossfadeValue* crossfade = CSSCrossfadeValue::create( 82 CSSCrossfadeValue* crossfade = CSSCrossfadeValue::create(
85 CSSImageValue::create(String("image"), imageURL), 83 CSSImageValue::create(String("image"), imageURL),
86 CSSImageValue::create(String("image"), imageURL), 84 CSSImageValue::create(String("image"), imageURL),
87 CSSPrimitiveValue::create(1.0, CSSPrimitiveValue::UnitType::Number)) ; 85 CSSPrimitiveValue::create(1.0, CSSPrimitiveValue::UnitType::Number)) ;
88 Vector<std::unique_ptr<CSSParserSelector>> selectors; 86 Vector<OwnPtr<CSSParserSelector>> selectors;
89 selectors.append(wrapUnique(new CSSParserSelector())); 87 selectors.append(adoptPtr(new CSSParserSelector()));
90 selectors[0]->setMatch(CSSSelector::Id); 88 selectors[0]->setMatch(CSSSelector::Id);
91 selectors[0]->setValue("foo"); 89 selectors[0]->setValue("foo");
92 CSSProperty property(CSSPropertyBackground, *crossfade); 90 CSSProperty property(CSSPropertyBackground, *crossfade);
93 contents->parserAppendRule( 91 contents->parserAppendRule(
94 StyleRule::create(CSSSelectorList::adoptSelectorVector(selectors), I mmutableStylePropertySet::create(&property, 1, HTMLStandardMode))); 92 StyleRule::create(CSSSelectorList::adoptSelectorVector(selectors), I mmutableStylePropertySet::create(&property, 1, HTMLStandardMode)));
95 93
96 crossfade->loadSubimages(document()); 94 crossfade->loadSubimages(document());
97 Resource* imageResource = memoryCache()->resourceForURL(imageURL, Memory Cache::defaultCacheIdentifier()); 95 Resource* imageResource = memoryCache()->resourceForURL(imageURL, Memory Cache::defaultCacheIdentifier());
98 ASSERT_TRUE(imageResource); 96 ASSERT_TRUE(imageResource);
99 ResourceResponse imageResponse; 97 ResourceResponse imageResponse;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // The underlying |contents| for the stylesheet resource must have a 147 // The underlying |contents| for the stylesheet resource must have a
150 // matching reference status. 148 // matching reference status.
151 EXPECT_TRUE(memoryCache()->contains(imageResource)); 149 EXPECT_TRUE(memoryCache()->contains(imageResource));
152 EXPECT_FALSE(memoryCache()->contains(cssResource)); 150 EXPECT_FALSE(memoryCache()->contains(cssResource));
153 EXPECT_FALSE(contents->isReferencedFromResource()); 151 EXPECT_FALSE(contents->isReferencedFromResource());
154 EXPECT_FALSE(cssResource->restoreParsedStyleSheet(parserContext)); 152 EXPECT_FALSE(cssResource->restoreParsedStyleSheet(parserContext));
155 } 153 }
156 154
157 } // namespace 155 } // namespace
158 } // namespace blink 156 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSSelectorList.cpp ('k') | third_party/WebKit/Source/core/css/DragUpdateTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698