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

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

Issue 2382523002: Revert of Revert r403630 which broke parsing on some sites. (Closed)
Patch Set: Created 4 years, 3 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/HTMLTreeBuilderSimulator.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/HTMLTreeBuilderSimulatorTest.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulatorTest.cpp b/third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulatorTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f5471c62e8e90530891672a07bb92fccacf7315f
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulatorTest.cpp
@@ -0,0 +1,72 @@
+// Copyright 2016 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/HTMLTreeBuilderSimulator.h"
+
+#include "core/html/parser/CompactHTMLToken.h"
+#include "core/html/parser/HTMLParserOptions.h"
+#include "core/html/parser/HTMLToken.h"
+#include "core/html/parser/HTMLTokenizer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "wtf/text/TextPosition.h"
+
+#include <memory>
+
+namespace blink {
+
+namespace {
+
+static void startTag(HTMLToken& token, const char* name)
+{
+ token.clear();
+ token.beginStartTag(name[0]);
+ size_t length = strlen(name);
+ for (size_t i = 1; i < length; ++i)
+ token.appendToName(name[i]);
+}
+
+static void simulate(HTMLTreeBuilderSimulator& simulator, HTMLToken& token, HTMLTokenizer* tokenizer)
+{
+ CompactHTMLToken compactToken(&token, TextPosition::minimumPosition());
+ simulator.simulate(compactToken, tokenizer);
+}
+
+// This is a regression test for crbug.com/542803
+TEST(HTMLTreeBuilderSimulatorTest, ChangeStateInForeignContentAtHTMLIntegrationPoint)
+{
+ HTMLParserOptions options;
+ HTMLTreeBuilderSimulator simulator(options);
+ std::unique_ptr<HTMLTokenizer> tokenizer = HTMLTokenizer::create(options);
+ HTMLToken token;
+
+ startTag(token, "svg");
+ simulate(simulator, token, tokenizer.get()); // open elements: svg
+ EXPECT_EQ(HTMLTokenizer::DataState, tokenizer->getState())
+ << "the svg start tag should have put the simulator into 'in body' "
+ << "state";
+
+ startTag(token, "title");
+ simulate(simulator, token, tokenizer.get()); // svg > title
+ EXPECT_EQ(HTMLTokenizer::DataState, tokenizer->getState())
+ << "the title start tag should not have flipped the simulator into "
+ << "RCDATA state because svg is not a HTML integration point";
+
+ startTag(token, "desc");
+ simulate(simulator, token, tokenizer.get()); // svg > title > desc
+ EXPECT_EQ(HTMLTokenizer::DataState, tokenizer->getState())
+ << "the desc tag should not have flipped the simulator into the "
+ << "any unusual state because desc parsing rules do not change state, "
+ << "despite title being a HTML integration point";
+
+ startTag(token, "title");
+ simulate(simulator, token, tokenizer.get()); // svg > title > desc > title
+ EXPECT_EQ(HTMLTokenizer::RCDATAState, tokenizer->getState())
+ << "the title start tag should have flipped the simulator into the "
+ << "RCDATA state for title, despite being in foreign content mode, "
+ << "because desc is a HTML integration point";
+}
+
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/HTMLTreeBuilderSimulator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698