Chromium Code Reviews| Index: third_party/WebKit/Source/web/tests/HTMLDocumentParserLoadingTest.cpp |
| diff --git a/third_party/WebKit/Source/web/tests/HTMLDocumentParserLoadingTest.cpp b/third_party/WebKit/Source/web/tests/HTMLDocumentParserLoadingTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..66d6eeda5538a344eff55e9be041c7f31af2f233 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/web/tests/HTMLDocumentParserLoadingTest.cpp |
| @@ -0,0 +1,727 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/html/parser/HTMLDocumentParser.h" |
| + |
| +#include "core/dom/Document.h" |
| +#include "platform/testing/UnitTestHelpers.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "web/tests/sim/SimRequest.h" |
| +#include "web/tests/sim/SimTest.h" |
| + |
| +namespace blink { |
| + |
| +using namespace HTMLNames; |
| + |
| +class HTMLDocumentParserLoadingTest : public SimTest {}; |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldNotPauseParsingForExternalStylesheetsInHead) { |
| + Document::setThreadedParsingEnabledForTesting(false); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"bodyDiv\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("bodyDiv")); |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("bodyDiv")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldNotPauseParsingForExternalStylesheetsInHeadThreaded) { |
| + Document::setThreadedParsingEnabledForTesting(true); |
|
kouhei (in TOK)
2017/01/20 10:56:47
Please dedupe test cases.
testing::TestWithParam m
Pat Meenan
2017/01/20 13:21:10
Done.
|
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"bodyDiv\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("bodyDiv")); |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("bodyDiv")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldNotPauseParsingForExternalStylesheetsImportedInHead) { |
| + Document::setThreadedParsingEnabledForTesting(false); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<style>" |
| + "@import 'testHead.css'" |
| + "</style>" |
| + "</head><body>" |
| + "<div id=\"bodyDiv\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("bodyDiv")); |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("bodyDiv")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldNotPauseParsingForExternalStylesheetsImportedInHeadThreaded) { |
| + Document::setThreadedParsingEnabledForTesting(true); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<style>" |
| + "@import 'testHead.css'" |
| + "</style>" |
| + "</head><body>" |
| + "<div id=\"bodyDiv\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("bodyDiv")); |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("bodyDiv")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldPauseParsingForExternalStylesheetsInBody) { |
| + Document::setThreadedParsingEnabledForTesting(false); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<link rel=stylesheet href=testBody.css>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the head css shouldn't change anything |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the body resource and pumping the tasks should continue parsing |
| + // and create the "after" div. |
| + cssBodyResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldPauseParsingForExternalStylesheetsInBodyThreaded) { |
| + Document::setThreadedParsingEnabledForTesting(true); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<link rel=stylesheet href=testBody.css>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the head css shouldn't change anything |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the body resource and pumping the tasks should continue parsing |
| + // and create the "after" div. |
| + cssBodyResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldPauseParsingForExternalStylesheetsInBodyIncremental) { |
| + Document::setThreadedParsingEnabledForTesting(false); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + SimRequest cssBodyResource1("https://example.com/testBody1.css", "text/css"); |
| + SimRequest cssBodyResource2("https://example.com/testBody2.css", "text/css"); |
| + SimRequest cssBodyResource3("https://example.com/testBody3.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.start(); |
| + mainResource.write( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<link rel=stylesheet href=testBody1.css>" |
| + "<div id=\"after1\"></div>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after1")); |
| + EXPECT_FALSE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + mainResource.write( |
| + "<link rel=stylesheet href=testBody2.css>" |
| + "<div id=\"after2\"></div>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after1")); |
| + EXPECT_FALSE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + mainResource.complete( |
| + "<link rel=stylesheet href=testBody3.css>" |
| + "<div id=\"after3\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after1")); |
| + EXPECT_FALSE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + // Completing the head css shouldn't change anything |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after1")); |
| + EXPECT_FALSE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + // Completing the second css shouldn't change anything |
| + cssBodyResource2.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after1")); |
| + EXPECT_FALSE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + // Completing the first css should allow the parser to continue past it and |
| + // the second css which was already completed and then pause again before the |
| + // third css. |
| + cssBodyResource1.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after1")); |
| + EXPECT_TRUE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + // Completing the third css should let it continue to the end. |
| + cssBodyResource3.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after1")); |
| + EXPECT_TRUE(document().getElementById("after2")); |
| + EXPECT_TRUE(document().getElementById("after3")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldPauseParsingForExternalStylesheetsInBodyIncrementalThreaded) { |
| + Document::setThreadedParsingEnabledForTesting(true); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + SimRequest cssBodyResource1("https://example.com/testBody1.css", "text/css"); |
| + SimRequest cssBodyResource2("https://example.com/testBody2.css", "text/css"); |
| + SimRequest cssBodyResource3("https://example.com/testBody3.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.start(); |
| + mainResource.write( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<link rel=stylesheet href=testBody1.css>" |
| + "<div id=\"after1\"></div>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after1")); |
| + EXPECT_FALSE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + mainResource.write( |
| + "<link rel=stylesheet href=testBody2.css>" |
| + "<div id=\"after2\"></div>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after1")); |
| + EXPECT_FALSE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + mainResource.complete( |
| + "<link rel=stylesheet href=testBody3.css>" |
| + "<div id=\"after3\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after1")); |
| + EXPECT_FALSE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + // Completing the head css shouldn't change anything |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after1")); |
| + EXPECT_FALSE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + // Completing the second css shouldn't change anything |
| + cssBodyResource2.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after1")); |
| + EXPECT_FALSE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + // Completing the first css should allow the parser to continue past it and |
| + // the second css which was already completed and then pause again before the |
| + // third css. |
| + cssBodyResource1.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after1")); |
| + EXPECT_TRUE(document().getElementById("after2")); |
| + EXPECT_FALSE(document().getElementById("after3")); |
| + |
| + // Completing the third css should let it continue to the end. |
| + cssBodyResource3.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after1")); |
| + EXPECT_TRUE(document().getElementById("after2")); |
| + EXPECT_TRUE(document().getElementById("after3")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldNotPauseParsingForExternalNonMatchingStylesheetsInBody) { |
| + Document::setThreadedParsingEnabledForTesting(false); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<link rel=stylesheet href=testBody.css type='print'>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| + |
| + // Completing the head css shouldn't change anything |
| + cssHeadResource.complete(""); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldNotPauseParsingForExternalNonMatchingStylesheetsInBodyThreaded) { |
| + Document::setThreadedParsingEnabledForTesting(true); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<link rel=stylesheet href=testBody.css type='print'>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| + |
| + // Completing the head css shouldn't change anything |
| + cssHeadResource.complete(""); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldPauseParsingForExternalStylesheetsImportedInBody) { |
| + Document::setThreadedParsingEnabledForTesting(false); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<style>" |
| + "@import 'testBody.css'" |
| + "</style>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the head css shouldn't change anything |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the body resource and pumping the tasks should continue parsing |
| + // and create the "after" div. |
| + cssBodyResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldPauseParsingForExternalStylesheetsImportedInBodyThreaded) { |
| + Document::setThreadedParsingEnabledForTesting(true); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<style>" |
| + "@import 'testBody.css'" |
| + "</style>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the head css shouldn't change anything |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the body resource and pumping the tasks should continue parsing |
| + // and create the "after" div. |
| + cssBodyResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldPauseParsingForExternalStylesheetsWrittenInBody) { |
| + Document::setThreadedParsingEnabledForTesting(false); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<script>" |
| + "document.write('<link rel=stylesheet href=testBody.css>');" |
| + "</script>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the head css shouldn't change anything |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the body resource and pumping the tasks should continue parsing |
| + // and create the "after" div. |
| + cssBodyResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldPauseParsingForExternalStylesheetsWrittenInBodyThreaded) { |
| + Document::setThreadedParsingEnabledForTesting(true); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + SimRequest cssBodyResource("https://example.com/testBody.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<script>" |
| + "document.write('<link rel=stylesheet href=testBody.css>');" |
| + "</script>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the head css shouldn't change anything |
| + cssHeadResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_FALSE(document().getElementById("after")); |
| + |
| + // Completing the body resource and pumping the tasks should continue parsing |
| + // and create the "after" div. |
| + cssBodyResource.complete(""); |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + PendingHeadStylesheetShouldNotBlockParserForBodyInlineStyle) { |
| + Document::setThreadedParsingEnabledForTesting(false); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<style>" |
| + "</style>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| + cssHeadResource.complete(""); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + PendingHeadStylesheetShouldNotBlockParserForBodyInlineStyleThreaded) { |
| + Document::setThreadedParsingEnabledForTesting(true); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<style>" |
| + "</style>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| + cssHeadResource.complete(""); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + PendingHeadStylesheetShouldNotBlockParserForBodyShadowDom) { |
| + Document::setThreadedParsingEnabledForTesting(false); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + // The marquee tag has a shadow DOM that synchronously applies a stylesheet. |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<marquee>Marquee</marquee>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| + cssHeadResource.complete(""); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + PendingHeadStylesheetShouldNotBlockParserForBodyShadowDomThreaded) { |
| + Document::setThreadedParsingEnabledForTesting(true); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssHeadResource("https://example.com/testHead.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + // The marquee tag has a shadow DOM that synchronously applies a stylesheet. |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "<link rel=stylesheet href=testHead.css>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<marquee>Marquee</marquee>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| + cssHeadResource.complete(""); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldNotPauseParsingForExternalStylesheetsAttachedInBody) { |
| + Document::setThreadedParsingEnabledForTesting(false); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssAsyncResource("https://example.com/testAsync.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<script>" |
| + "var attach = document.getElementsByTagName('script')[0];" |
| + "var link = document.createElement('link');" |
| + "link.rel = 'stylesheet';" |
| + "link.type = 'text/css';" |
| + "link.href = 'testAsync.css';" |
| + "link.media = 'all';" |
| + "attach.appendChild(link);" |
| + "</script>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| + |
| + cssAsyncResource.complete(""); |
| +} |
| + |
| +TEST_F(HTMLDocumentParserLoadingTest, |
| + ShouldNotPauseParsingForExternalStylesheetsAttachedInBodyThreaded) { |
| + Document::setThreadedParsingEnabledForTesting(true); |
| + SimRequest mainResource("https://example.com/test.html", "text/html"); |
| + SimRequest cssAsyncResource("https://example.com/testAsync.css", "text/css"); |
| + |
| + loadURL("https://example.com/test.html"); |
| + |
| + mainResource.complete( |
| + "<!DOCTYPE html>" |
| + "<html><head>" |
| + "</head><body>" |
| + "<div id=\"before\"></div>" |
| + "<script>" |
| + "var attach = document.getElementsByTagName('script')[0];" |
| + "var link = document.createElement('link');" |
| + "link.rel = 'stylesheet';" |
| + "link.type = 'text/css';" |
| + "link.href = 'testAsync.css';" |
| + "link.media = 'all';" |
| + "attach.appendChild(link);" |
| + "</script>" |
| + "<div id=\"after\"></div>" |
| + "</body></html>"); |
| + |
| + testing::runPendingTasks(); |
| + EXPECT_TRUE(document().getElementById("before")); |
| + EXPECT_TRUE(document().getElementById("after")); |
| + |
| + cssAsyncResource.complete(""); |
| +} |
| + |
| +} // namespace blink |