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

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

Issue 2381193004: Use sheetText() instead of decodedText() in the CSS preload scanner (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/parser/CSSPreloadScannerTest.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/CSSPreloadScannerTest.cpp b/third_party/WebKit/Source/core/html/parser/CSSPreloadScannerTest.cpp
index f951ec7f6d49fd1572188bc7c4267456dae0fcc2..790dbcddd98c96448455fb41e1b8e0c54cf761d9 100644
--- a/third_party/WebKit/Source/core/html/parser/CSSPreloadScannerTest.cpp
+++ b/third_party/WebKit/Source/core/html/parser/CSSPreloadScannerTest.cpp
@@ -11,6 +11,7 @@
#include "core/html/parser/HTMLResourcePreloader.h"
#include "core/testing/DummyPageHolder.h"
#include "platform/heap/Heap.h"
+#include "platform/network/ResourceError.h"
#include "platform/network/ResourceRequest.h"
#include "platform/weborigin/KURL.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -87,4 +88,58 @@ TEST_F(CSSPreloadScannerTest, DestroyClientBeforeDataSent) {
resource->appendData(data, strlen(data));
}
+// Regression test for crbug.com/646869 where the client's data is cleared
+// before didAppendFirstData is called.
+TEST_F(CSSPreloadScannerTest, DontReadFromClearedData) {
+ std::unique_ptr<DummyPageHolder> dummyPageHolder =
+ DummyPageHolder::create(IntSize(500, 500));
+ dummyPageHolder->document().settings()->setCSSExternalScannerNoPreload(true);
+
+ HTMLResourcePreloader* preloader =
+ HTMLResourcePreloader::create(dummyPageHolder->document());
+
+ KURL url(ParsedURLString, "http://127.0.0.1/foo.css");
+ CSSStyleSheetResource* resource =
+ CSSStyleSheetResource::createForTest(ResourceRequest(url), "utf-8");
+
+ const char* data = "@import url('http://127.0.0.1/preload.css');";
+ resource->appendData(data, strlen(data));
+ ResourceError error(errorDomainBlinkInternal, 0, url.getString(), "");
+ resource->error(error);
+
+ // Should not crash.
+ PreloadSuppressingCSSPreloaderResourceClient* resourceClient =
+ new PreloadSuppressingCSSPreloaderResourceClient(resource, preloader);
+
+ EXPECT_EQ(0u, resourceClient->m_preloads.size());
+}
+
+// Regression test for crbug.com/645331, where a resource client gets callbacks
+// after the document is shutdown and we have no frame.
+TEST_F(CSSPreloadScannerTest, DoNotExpectValidDocument) {
+ std::unique_ptr<DummyPageHolder> dummyPageHolder =
+ DummyPageHolder::create(IntSize(500, 500));
+ dummyPageHolder->document().settings()->setCSSExternalScannerNoPreload(true);
+
+ HTMLResourcePreloader* preloader =
+ HTMLResourcePreloader::create(dummyPageHolder->document());
+
+ KURL url(ParsedURLString, "http://127.0.0.1/foo.css");
+ CSSStyleSheetResource* resource =
+ CSSStyleSheetResource::createForTest(ResourceRequest(url), "utf-8");
+ resource->setStatus(Resource::Pending);
+
+ PreloadSuppressingCSSPreloaderResourceClient* resourceClient =
+ new PreloadSuppressingCSSPreloaderResourceClient(resource, preloader);
+
+ dummyPageHolder->document().shutdown();
+
+ const char* data = "@import url('http://127.0.0.1/preload.css');";
+ resource->appendData(data, strlen(data));
+
+ EXPECT_EQ(1u, resourceClient->m_preloads.size());
+ EXPECT_EQ("http://127.0.0.1/preload.css",
+ resourceClient->m_preloads.first()->resourceURL());
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698