Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rcdom/data/test/wpt-commit.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
31d1feb70e2d02f25ae26254caba19c8de0b56e0
8746bafe086e036b5e5be028ac200e4a595ef3d0
112 changes: 112 additions & 0 deletions rcdom/wpt-tree-construction-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Tree Construction Tests
=======================

Each file containing tree construction tests consists of any number of
tests separated by two newlines (LF) and a single newline before the end
of the file. For instance:

[TEST]LF
LF
[TEST]LF
LF
[TEST]LF

Where [TEST] is the following format:

Each test \*may\* begin with a string "\#description" followed by a
newline (LF). All subsequent lines until a line that says "\#data" are
the test description and \*should\* be passed to the test harness to
supplement the test's name.

Each test must either begin with "\#description" (see above) or begin
with a string "\#data" followed by a newline (LF). All subsequent lines
until a line that says "\#errors" are the test data and must be passed
to the system being tested unchanged, except with the final newline
(on the last line) removed.

Then there must be a line that says "\#errors". It must be followed by
one line per parse error that a conformant checker would return. It
doesn't matter what those lines are, although they can't be
"\#new-errors", "\#document-fragment", "\#document", "\#script-off",
"\#script-on", or empty, the only thing that matters is that there be
the right number of parse errors.

Then there \*may\* be a line that says "\#new-errors", which works like
the "\#errors" section adding more errors to the expected number of
errors.

Then there \*may\* be a line that says "\#document-fragment", which must
be followed by a newline (LF), followed by a string of characters that
indicates the context element, followed by a newline (LF). If the string
of characters starts with "svg ", the context element is in the SVG
namespace and the substring after "svg " is the local name. If the
string of characters starts with "math ", the context element is in the
MathML namespace and the substring after "math " is the local name.
Otherwise, the context element is in the HTML namespace and the string
is the local name. If this line is present the "\#data" must be parsed
using the HTML fragment parsing algorithm with the context element as
context.

Then there \*may\* be a line that says "\#script-off" or
"\#script-on". If a line that says "\#script-off" is present, the
parser must set the scripting flag to disabled. If a line that says
"\#script-on" is present, it must set it to enabled. Otherwise, the
test should be run in both modes.

Then there must be a line that says "\#document", which must be followed
by a dump of the tree of the parsed DOM. Each node must be represented
by a single line. Each line must start with "| ", followed by two spaces
per parent node that the node has before the root document node.

- Element nodes must be represented by a "`<`" then the *tag name
string* "`>`", and all the attributes must be given, sorted
lexicographically by UTF-16 code unit according to their *attribute
name string*, on subsequent lines, as if they were children of the
element node.
- Attribute nodes must have the *attribute name string*, then an "="
sign, then the attribute value in double quotes (").
- Text nodes must be the string, in double quotes. Newlines aren't
escaped.
- Comments must be "`<`" then "`!-- `" then the data then "` -->`".
- DOCTYPEs must be "`<!DOCTYPE `" then the name then if either of the
system id or public id is non-empty a space, public id in
double-quotes, another space an the system id in double-quotes, and
then in any case "`>`".
- Processing instructions must be "`<?`", then the target, then a
space, then the data and then "`?>`".
- Template contents are represented by the string "content" with the
children below it.

The *tag name string* is the local name prefixed by a namespace
designator. For the HTML namespace, the namespace designator is the
empty string, i.e. there's no prefix. For the SVG namespace, the
namespace designator is "svg ". For the MathML namespace, the namespace
designator is "math ".

The *attribute name string* is the local name prefixed by a namespace
designator. For no namespace, the namespace designator is the empty
string, i.e. there's no prefix. For the XLink namespace, the namespace
designator is "xlink ". For the XML namespace, the namespace designator
is "xml ". For the XMLNS namespace, the namespace designator is "xmlns
". Note the difference between "xlink:href" which is an attribute in no
namespace with the local name "xlink:href" and "xlink href" which is an
attribute in the xlink namespace with the local name "href".

If there is also a "\#document-fragment" the bit following "\#document"
must be a representation of the HTML fragment serialization for the
context element given by "\#document-fragment".

For example:

#data
<p>One<p>Two
#errors
3: Missing document type declaration
#document
| <html>
| <head>
| <body>
| <p>
| "One"
| <p>
| "Two"
32 changes: 32 additions & 0 deletions rcdom/wpt-tree-construction-tests/adoption-agency-reparenting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";

// Shared helpers for the adoption-agency-reparenting tests.

// Compact serializer: element -> <name>[#id][children]; text -> "data".
// <script> contents are elided to keep expectations stable.
function serialize(n) {
if (n.nodeType === Node.TEXT_NODE)
return `"${n.data}"`;
if (n.nodeType !== Node.ELEMENT_NODE)
return "";
const label = `<${n.localName}${n.id ? "#" + n.id : ""}>`;
if (n.localName === "script")
return label;
const kids = tree(n);
return kids ? `${label}[${kids}]` : label;
}

function tree(node) {
return [...node.childNodes].map(serialize).join("");
}

// Parse srcdoc in an iframe (so inline scripts run during parsing) and resolve
// with the iframe once loaded.
function parseInIframe(t, srcdoc) {
const iframe = document.createElement("iframe");
iframe.srcdoc = srcdoc;
return new Promise(resolve => {
iframe.onload = t.step_func(() => resolve(iframe));
document.body.appendChild(iframe);
});
}
33 changes: 33 additions & 0 deletions rcdom/wpt-tree-construction-tests/adoption02.dat
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,36 @@
| <address>
| <a>
| <a>

#data
<nobr><table><marquee></table><nobr>
#errors
(1,6): expected-doctype-but-got-start-tag
(1,22): unexpected-start-tag-implies-table-voodoo
(1,30): end-tag-too-early-named
(1,36): unexpected-start-tag-implies-end-tag
(1,36): expected-closing-tag-but-got-eof
#document
| <html>
| <head>
| <body>
| <nobr>
| <marquee>
| <table>
| <nobr>

#data
<a><table><marquee></table><a>
#errors
(1,3): expected-doctype-but-got-start-tag
(1,19): unexpected-start-tag-implies-table-voodoo
(1,27): end-tag-too-early-named
(1,30): expected-closing-tag-but-got-eof
#document
| <html>
| <head>
| <body>
| <a>
| <marquee>
| <table>
| <a>
32 changes: 32 additions & 0 deletions rcdom/wpt-tree-construction-tests/chunked-response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import time


def main(request, response):
action = request.GET.first(b"action", None)
key = request.GET.first(b"key")

if action == b"continue":
request.server.stash.take(key)
request.server.stash.put(key, "continue")
return (
200,
[(b"Content-Type", b"text/plain"), (b"Cache-Control", b"no-store")],
b"ok",
)

content_type = request.GET.first(b"content_type", b"text/html; charset=utf-8")
chunk1 = request.GET.first(b"chunk1", b"")
chunk2 = request.GET.first(b"chunk2", b"")

response.headers.set(b"Content-Type", content_type)
response.headers.set(b"Cache-Control", b"no-store")
response.headers.set(b"X-Content-Type-Options", b"nosniff")
response.write_status_headers()
response.writer.write_content(chunk1)

for _ in range(250):
if request.server.stash.take(key) == "continue":
break
time.sleep(0.02)

response.writer.write_content(chunk2)
9 changes: 3 additions & 6 deletions rcdom/wpt-tree-construction-tests/comments01.dat
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,9 @@ FOO<!-->BAZ
#data
<?xml version="1.0">Hi
#errors
(1,1): expected-tag-name-but-got-question-mark
(1,22): expected-doctype-but-got-chars
#new-errors
(1:2) unexpected-question-mark-instead-of-tag-name
(1:6) disallowed-processing-instruction-target
#document
| <!-- ?xml version="1.0" -->
| <html>
Expand All @@ -169,10 +168,9 @@ FOO<!-->BAZ
#data
<?xml version="1.0">
#errors
(1,1): expected-tag-name-but-got-question-mark
(1,20): expected-doctype-but-got-eof
#new-errors
(1:2) unexpected-question-mark-instead-of-tag-name
(1:6) disallowed-processing-instruction-target
#document
| <!-- ?xml version="1.0" -->
| <html>
Expand All @@ -182,10 +180,9 @@ FOO<!-->BAZ
#data
<?xml version
#errors
(1,1): expected-tag-name-but-got-question-mark
(1,13): expected-doctype-but-got-eof
#new-errors
(1:2) unexpected-question-mark-instead-of-tag-name
(1:6) disallowed-processing-instruction-target
#document
| <!-- ?xml version -->
| <html>
Expand Down
72 changes: 68 additions & 4 deletions rcdom/wpt-tree-construction-tests/html5test-com.dat
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,9 @@
#data
<?import namespace="foo" implementation="#bar">
#errors
(1,1): expected-tag-name-but-got-question-mark
(1,47): expected-doctype-but-got-eof
#new-errors
(1:2) unexpected-question-mark-instead-of-tag-name
#document
| <!-- ?import namespace="foo" implementation="#bar" -->
| <?import namespace="foo" implementation="#bar"?>
| <html>
| <head>
| <body>
Expand All @@ -149,6 +146,73 @@
| <head>
| <body>

#data
<svg><title><![CDATA[x]]>
#errors
#document
| <html>
| <head>
| <body>
| <svg svg>
| <svg title>
| "x"

#data
<svg><foreignobject><![CDATA[x]]>
#errors
#document
| <html>
| <head>
| <body>
| <svg svg>
| <svg foreignObject>
| "x"

#data
<svg><foreignobject><p><![CDATA[x]]>
#errors
#document
| <html>
| <head>
| <body>
| <svg svg>
| <svg foreignObject>
| <p>
| <!-- [CDATA[x]] -->

#data
<math><![CDATA[x]]>
#errors
#document
| <html>
| <head>
| <body>
| <math math>
| "x"

#data
<math><mtext><![CDATA[x]]>
#errors
#document
| <html>
| <head>
| <body>
| <math math>
| <math mtext>
| "x"

#data
<math><mtext><i><![CDATA[x]]>
#errors
#document
| <html>
| <head>
| <body>
| <math math>
| <math mtext>
| <i>
| <!-- [CDATA[x]] -->

#data
<![CDATA[x]]>
#errors
Expand Down
Binary file modified rcdom/wpt-tree-construction-tests/plain-text-unsafe.dat
Binary file not shown.
Loading
Loading