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

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

Issue 2479703003: Stop preloading scripts that have invalid type/language attributes (Closed)
Patch Set: Created 4 years, 1 month 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
Index: third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp b/third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp
index 677677633cdb5d659994c18bb3b34f1efa9c1f3a..41d01177a7c4f190e29ace77cfec24e712ad7d70 100644
--- a/third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp
+++ b/third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.cpp
@@ -740,4 +740,52 @@ TEST_F(HTMLPreloadScannerTest, testNoDataUrls) {
test(testCase);
}
+// The preload scanner should follow the same policy that the ScriptLoader does
+// with regard to the type and language attribute.
+TEST_F(HTMLPreloadScannerTest, testScriptTypeAndLanguage) {
+ TestCase testCases[] = {
+ // Allow empty src and language attributes.
+ {"http://example.test", "<script src='test.js'></script>", "test.js",
+ "http://example.test/", Resource::Script, 0},
+ {"http://example.test",
+ "<script type='' language='' src='test.js'></script>", "test.js",
+ "http://example.test/", Resource::Script, 0},
+ // Allow standard language and type attributes.
+ {"http://example.test",
+ "<script type='text/javascript' src='test.js'></script>", "test.js",
+ "http://example.test/", Resource::Script, 0},
+ {"http://example.test",
+ "<script type='text/javascript' language='javascript' "
+ "src='test.js'></script>",
+ "test.js", "http://example.test/", Resource::Script, 0},
+ // Allow legacy languages in the "language" attribute with an empty
+ // type.
+ {"http://example.test",
+ "<script language='javascript1.1' src='test.js'></script>", "test.js",
+ "http://example.test/", Resource::Script, 0},
+ // Allow legacy languages in the "type" attribute.
+ {"http://example.test",
+ "<script type='javascript' src='test.js'></script>", "test.js",
+ "http://example.test/", Resource::Script, 0},
+ {"http://example.test",
+ "<script type='javascript1.7' src='test.js'></script>", "test.js",
+ "http://example.test/", Resource::Script, 0},
+ // Do not allow invalid types in the "type" attribute.
+ {"http://example.test", "<script type='invalid' src='test.js'></script>",
+ nullptr, "http://example.test/", Resource::Script, 0},
+ {"http://example.test", "<script type='asdf' src='test.js'></script>",
+ nullptr, "http://example.test/", Resource::Script, 0},
+ // Do not allow invalid languages.
+ {"http://example.test",
+ "<script language='french' src='test.js'></script>", nullptr,
+ "http://example.test/", Resource::Script, 0},
+ {"http://example.test",
+ "<script language='python' src='test.js'></script>", nullptr,
+ "http://example.test/", Resource::Script, 0},
+ };
+
+ for (const auto& testCase : testCases)
+ test(testCase);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698