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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/CSSPreloadScannerTest.cpp

Issue 2642383003: Replace Resource::Status with ResourceStatus (Closed)
Patch Set: Rebase. Created 3 years, 10 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/html/parser/CSSPreloadScanner.h" 5 #include "core/html/parser/CSSPreloadScanner.h"
6 6
7 #include "core/frame/Settings.h" 7 #include "core/frame/Settings.h"
8 #include "core/html/parser/HTMLResourcePreloader.h" 8 #include "core/html/parser/HTMLResourcePreloader.h"
9 #include "core/testing/DummyPageHolder.h" 9 #include "core/testing/DummyPageHolder.h"
10 #include "platform/heap/Heap.h" 10 #include "platform/heap/Heap.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 std::unique_ptr<DummyPageHolder> dummyPageHolder = 56 std::unique_ptr<DummyPageHolder> dummyPageHolder =
57 DummyPageHolder::create(IntSize(500, 500)); 57 DummyPageHolder::create(IntSize(500, 500));
58 dummyPageHolder->document().settings()->setCSSExternalScannerNoPreload(true); 58 dummyPageHolder->document().settings()->setCSSExternalScannerNoPreload(true);
59 59
60 MockHTMLResourcePreloader* preloader = 60 MockHTMLResourcePreloader* preloader =
61 new MockHTMLResourcePreloader(dummyPageHolder->document()); 61 new MockHTMLResourcePreloader(dummyPageHolder->document());
62 62
63 KURL url(ParsedURLString, "http://127.0.0.1/foo.css"); 63 KURL url(ParsedURLString, "http://127.0.0.1/foo.css");
64 CSSStyleSheetResource* resource = 64 CSSStyleSheetResource* resource =
65 CSSStyleSheetResource::createForTest(ResourceRequest(url), "utf-8"); 65 CSSStyleSheetResource::createForTest(ResourceRequest(url), "utf-8");
66 resource->setStatus(Resource::Pending); 66 resource->setStatus(ResourceStatus::Pending);
67 67
68 PreloadRecordingCSSPreloaderResourceClient* resourceClient = 68 PreloadRecordingCSSPreloaderResourceClient* resourceClient =
69 new PreloadRecordingCSSPreloaderResourceClient(resource, preloader); 69 new PreloadRecordingCSSPreloaderResourceClient(resource, preloader);
70 70
71 const char* data = "@import url('http://127.0.0.1/preload.css');"; 71 const char* data = "@import url('http://127.0.0.1/preload.css');";
72 resource->appendData(data, strlen(data)); 72 resource->appendData(data, strlen(data));
73 73
74 EXPECT_EQ(Resource::PreloadNotReferenced, resource->getPreloadResult()); 74 EXPECT_EQ(Resource::PreloadNotReferenced, resource->getPreloadResult());
75 EXPECT_EQ(1u, resourceClient->m_preloadUrls.size()); 75 EXPECT_EQ(1u, resourceClient->m_preloadUrls.size());
76 EXPECT_EQ("http://127.0.0.1/preload.css", 76 EXPECT_EQ("http://127.0.0.1/preload.css",
77 resourceClient->m_preloadUrls.front()); 77 resourceClient->m_preloadUrls.front());
78 } 78 }
79 79
80 // Regression test for crbug.com/608310 where the client is destroyed but was 80 // Regression test for crbug.com/608310 where the client is destroyed but was
81 // not removed from the resource's client list. 81 // not removed from the resource's client list.
82 TEST_F(CSSPreloadScannerTest, DestroyClientBeforeDataSent) { 82 TEST_F(CSSPreloadScannerTest, DestroyClientBeforeDataSent) {
83 std::unique_ptr<DummyPageHolder> dummyPageHolder = 83 std::unique_ptr<DummyPageHolder> dummyPageHolder =
84 DummyPageHolder::create(IntSize(500, 500)); 84 DummyPageHolder::create(IntSize(500, 500));
85 dummyPageHolder->document().settings()->setCSSExternalScannerNoPreload(true); 85 dummyPageHolder->document().settings()->setCSSExternalScannerNoPreload(true);
86 86
87 Persistent<MockHTMLResourcePreloader> preloader = 87 Persistent<MockHTMLResourcePreloader> preloader =
88 new MockHTMLResourcePreloader(dummyPageHolder->document()); 88 new MockHTMLResourcePreloader(dummyPageHolder->document());
89 89
90 KURL url(ParsedURLString, "http://127.0.0.1/foo.css"); 90 KURL url(ParsedURLString, "http://127.0.0.1/foo.css");
91 Persistent<CSSStyleSheetResource> resource = 91 Persistent<CSSStyleSheetResource> resource =
92 CSSStyleSheetResource::createForTest(ResourceRequest(url), "utf-8"); 92 CSSStyleSheetResource::createForTest(ResourceRequest(url), "utf-8");
93 resource->setStatus(Resource::Pending); 93 resource->setStatus(ResourceStatus::Pending);
94 94
95 new PreloadRecordingCSSPreloaderResourceClient(resource, preloader); 95 new PreloadRecordingCSSPreloaderResourceClient(resource, preloader);
96 96
97 // Destroys the resourceClient. 97 // Destroys the resourceClient.
98 ThreadState::current()->collectAllGarbage(); 98 ThreadState::current()->collectAllGarbage();
99 99
100 const char* data = "@import url('http://127.0.0.1/preload.css');"; 100 const char* data = "@import url('http://127.0.0.1/preload.css');";
101 // Should not crash. 101 // Should not crash.
102 resource->appendData(data, strlen(data)); 102 resource->appendData(data, strlen(data));
103 } 103 }
(...skipping 30 matching lines...) Expand all
134 std::unique_ptr<DummyPageHolder> dummyPageHolder = 134 std::unique_ptr<DummyPageHolder> dummyPageHolder =
135 DummyPageHolder::create(IntSize(500, 500)); 135 DummyPageHolder::create(IntSize(500, 500));
136 dummyPageHolder->document().settings()->setCSSExternalScannerNoPreload(true); 136 dummyPageHolder->document().settings()->setCSSExternalScannerNoPreload(true);
137 137
138 MockHTMLResourcePreloader* preloader = 138 MockHTMLResourcePreloader* preloader =
139 new MockHTMLResourcePreloader(dummyPageHolder->document()); 139 new MockHTMLResourcePreloader(dummyPageHolder->document());
140 140
141 KURL url(ParsedURLString, "http://127.0.0.1/foo.css"); 141 KURL url(ParsedURLString, "http://127.0.0.1/foo.css");
142 CSSStyleSheetResource* resource = 142 CSSStyleSheetResource* resource =
143 CSSStyleSheetResource::createForTest(ResourceRequest(url), "utf-8"); 143 CSSStyleSheetResource::createForTest(ResourceRequest(url), "utf-8");
144 resource->setStatus(Resource::Pending); 144 resource->setStatus(ResourceStatus::Pending);
145 145
146 PreloadRecordingCSSPreloaderResourceClient* resourceClient = 146 PreloadRecordingCSSPreloaderResourceClient* resourceClient =
147 new PreloadRecordingCSSPreloaderResourceClient(resource, preloader); 147 new PreloadRecordingCSSPreloaderResourceClient(resource, preloader);
148 148
149 dummyPageHolder->document().shutdown(); 149 dummyPageHolder->document().shutdown();
150 150
151 const char* data = "@import url('http://127.0.0.1/preload.css');"; 151 const char* data = "@import url('http://127.0.0.1/preload.css');";
152 resource->appendData(data, strlen(data)); 152 resource->appendData(data, strlen(data));
153 153
154 // Do not expect to gather any preloads, as the document loader is invalid, 154 // Do not expect to gather any preloads, as the document loader is invalid,
155 // which means we can't notify WebLoadingBehaviorData of the preloads. 155 // which means we can't notify WebLoadingBehaviorData of the preloads.
156 EXPECT_EQ(0u, resourceClient->m_preloadUrls.size()); 156 EXPECT_EQ(0u, resourceClient->m_preloadUrls.size());
157 } 157 }
158 158
159 } // namespace blink 159 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/ImageDocument.cpp ('k') | third_party/WebKit/Source/core/inspector/InspectorPageAgent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698