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

Unified Diff: third_party/WebKit/Source/web/tests/HTMLDocumentParserLoadingTest.cpp

Issue 2674533009: Add SimTests for HTML parser rewinding (Closed)
Patch Set: add <title> test 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 4f084d6f3fd5fbcd67a6dbb6a9a6e1b5a0f4cd10..28e6769a5cae694fa7fe5fd8ceee97f08630e7da 100644
--- a/third_party/WebKit/Source/web/tests/HTMLDocumentParserLoadingTest.cpp
+++ b/third_party/WebKit/Source/web/tests/HTMLDocumentParserLoadingTest.cpp
@@ -5,6 +5,7 @@
#include "core/html/parser/HTMLDocumentParser.h"
#include "core/dom/Document.h"
+#include "platform/testing/HistogramTester.h"
#include "platform/testing/UnitTestHelpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "web/tests/sim/SimRequest.h"
@@ -14,8 +15,16 @@ namespace blink {
using namespace HTMLNames;
+class HTMLDocumentParserSimTest : public SimTest {
+ protected:
+ HTMLDocumentParserSimTest() {
+ Document::setThreadedParsingEnabledForTesting(true);
+ }
+ HistogramTester m_histogram;
+};
+
class HTMLDocumentParserLoadingTest
- : public SimTest,
+ : public HTMLDocumentParserSimTest,
public ::testing::WithParamInterface<bool> {
protected:
HTMLDocumentParserLoadingTest() {
@@ -374,4 +383,92 @@ TEST_P(HTMLDocumentParserLoadingTest,
cssAsyncResource.complete("");
}
+TEST_F(HTMLDocumentParserSimTest, NoRewindNoDocWrite) {
+ SimRequest mainResource("https://example.com/test.html", "text/html");
+ loadURL("https://example.com/test.html");
+
+ mainResource.complete(
+ "<!DOCTYPE html>"
+ "<html><body>no doc write"
+ "</body></html>");
+
+ testing::runPendingTasks();
+ m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 0);
+}
+
+TEST_F(HTMLDocumentParserSimTest, RewindBrokenToken) {
+ SimRequest mainResource("https://example.com/test.html", "text/html");
+ loadURL("https://example.com/test.html");
+
+ mainResource.complete(
+ "<!DOCTYPE html>"
+ "<script>"
+ "document.write('<a');"
+ "</script>");
+
+ testing::runPendingTasks();
+ m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 1);
+}
+
+TEST_F(HTMLDocumentParserSimTest, RewindDifferentNamespace) {
+ SimRequest mainResource("https://example.com/test.html", "text/html");
+ loadURL("https://example.com/test.html");
+
+ mainResource.complete(
+ "<!DOCTYPE html>"
+ "<script>"
+ "document.write('<svg>');"
+ "</script>");
+
+ testing::runPendingTasks();
+ m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 1);
+}
+
+TEST_F(HTMLDocumentParserSimTest, NoRewindSaneDocWrite1) {
+ SimRequest mainResource("https://example.com/test.html", "text/html");
+ loadURL("https://example.com/test.html");
+
+ mainResource.complete(
+ "<!DOCTYPE html>"
+ "<script>"
+ "document.write('<script>console.log(\'hello world\');<\\/script>');"
+ "</script>");
+
+ testing::runPendingTasks();
+ m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 0);
+}
+
+TEST_F(HTMLDocumentParserSimTest, NoRewindSaneDocWrite2) {
+ SimRequest mainResource("https://example.com/test.html", "text/html");
+ loadURL("https://example.com/test.html");
+
+ mainResource.complete(
+ "<!DOCTYPE html>"
+ "<script>"
+ "document.write('<p>hello world<\\/p><a>yo');"
+ "</script>");
+
+ testing::runPendingTasks();
+ m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 0);
+}
+
+TEST_F(HTMLDocumentParserSimTest, NoRewindSaneDocWriteWithTitle) {
+ SimRequest mainResource("https://example.com/test.html", "text/html");
+ loadURL("https://example.com/test.html");
+
+ mainResource.complete(
+ "<!DOCTYPE html>"
+ "<html>"
+ "<head>"
+ "<title></title>"
+ "<script>document.write('<p>testing');</script>"
+ "</head>"
+ "<body>"
+ "</body>"
+ "</html>");
+
+ testing::runPendingTasks();
+ m_histogram.expectTotalCount("Parser.DiscardedTokenCount", 0);
+}
+
} // namespace blink
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698