mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
Merge pull request #88 from Browsercore/domdoc-implementation
add document.implementation
This commit is contained in:
@@ -14,6 +14,7 @@ const Element = @import("element.zig").Element;
|
||||
const ElementUnion = @import("element.zig").Union;
|
||||
|
||||
const DocumentType = @import("document_type.zig").DocumentType;
|
||||
const DOMImplementation = @import("implementation.zig").DOMImplementation;
|
||||
|
||||
// WEB IDL https://dom.spec.whatwg.org/#document
|
||||
pub const Document = struct {
|
||||
@@ -21,14 +22,17 @@ pub const Document = struct {
|
||||
pub const prototype = *Node;
|
||||
pub const mem_guarantied = true;
|
||||
|
||||
// pub fn constructor() *parser.Document {
|
||||
// // TODO
|
||||
// return .{};
|
||||
// }
|
||||
pub fn constructor() *parser.Document {
|
||||
return parser.domImplementationCreateHTMLDocument(null);
|
||||
}
|
||||
|
||||
// JS funcs
|
||||
// --------
|
||||
//
|
||||
|
||||
pub fn get_implementation(_: *parser.Document) DOMImplementation {
|
||||
return DOMImplementation{};
|
||||
}
|
||||
|
||||
pub fn get_documentElement(self: *parser.Document) ElementUnion {
|
||||
const e = parser.documentGetDocumentElement(self);
|
||||
return Element.toInterface(e);
|
||||
@@ -198,6 +202,21 @@ pub fn testExecFn(
|
||||
};
|
||||
try checkCases(js_env, &getDocumentURI);
|
||||
|
||||
var getImplementation = [_]Case{
|
||||
.{ .src = "let impl = document.implementation", .ex = "undefined" },
|
||||
};
|
||||
try checkCases(js_env, &getImplementation);
|
||||
|
||||
var new = [_]Case{
|
||||
.{ .src = "let d = new Document()", .ex = "undefined" },
|
||||
.{ .src = "d.characterSet", .ex = "UTF-8" },
|
||||
.{ .src = "d.URL", .ex = "about:blank" },
|
||||
.{ .src = "d.documentURI", .ex = "about:blank" },
|
||||
.{ .src = "d.compatMode", .ex = "CSS1Compat" },
|
||||
.{ .src = "d.contentType", .ex = "text/html" },
|
||||
};
|
||||
try checkCases(js_env, &new);
|
||||
|
||||
const tags = comptime parser.Tag.all();
|
||||
comptime var createElements: [(tags.len) * 2]Case = undefined;
|
||||
inline for (tags, 0..) |tag, i| {
|
||||
|
||||
@@ -2,11 +2,13 @@ const generate = @import("../generate.zig");
|
||||
|
||||
const DOMException = @import("exceptions.zig").DOMException;
|
||||
const EventTarget = @import("event_target.zig").EventTarget;
|
||||
const DOMImplementation = @import("implementation.zig").DOMImplementation;
|
||||
const Nod = @import("node.zig");
|
||||
|
||||
pub const Interfaces = generate.Tuple(.{
|
||||
DOMException,
|
||||
EventTarget,
|
||||
DOMImplementation,
|
||||
Nod.Node,
|
||||
Nod.Interfaces,
|
||||
});
|
||||
|
||||
84
src/dom/implementation.zig
Normal file
84
src/dom/implementation.zig
Normal file
@@ -0,0 +1,84 @@
|
||||
const std = @import("std");
|
||||
|
||||
const parser = @import("../netsurf.zig");
|
||||
|
||||
const jsruntime = @import("jsruntime");
|
||||
const Case = jsruntime.test_utils.Case;
|
||||
const checkCases = jsruntime.test_utils.checkCases;
|
||||
|
||||
const Document = @import("document.zig").Document;
|
||||
const DocumentType = @import("document_type.zig").DocumentType;
|
||||
|
||||
// WEB IDL https://dom.spec.whatwg.org/#domimplementation
|
||||
pub const DOMImplementation = struct {
|
||||
pub const mem_guarantied = true;
|
||||
|
||||
pub fn _createDocumentType(
|
||||
_: *DOMImplementation,
|
||||
alloc: std.mem.Allocator,
|
||||
qname: []const u8,
|
||||
publicId: []const u8,
|
||||
systemId: []const u8,
|
||||
) !*parser.DocumentType {
|
||||
const cqname = try alloc.dupeZ(u8, qname);
|
||||
defer alloc.free(cqname);
|
||||
|
||||
const cpublicId = try alloc.dupeZ(u8, publicId);
|
||||
defer alloc.free(cpublicId);
|
||||
|
||||
const csystemId = try alloc.dupeZ(u8, systemId);
|
||||
defer alloc.free(csystemId);
|
||||
|
||||
return parser.domImplementationCreateDocumentType(cqname, cpublicId, csystemId);
|
||||
}
|
||||
|
||||
pub fn _createDocument(
|
||||
_: *DOMImplementation,
|
||||
alloc: std.mem.Allocator,
|
||||
namespace: ?[]const u8,
|
||||
qname: ?[]const u8,
|
||||
doctype: ?*parser.DocumentType,
|
||||
) !*parser.Document {
|
||||
var cnamespace: ?[:0]const u8 = null;
|
||||
if (namespace) |ns| {
|
||||
cnamespace = try alloc.dupeZ(u8, ns);
|
||||
defer alloc.free(cnamespace.?);
|
||||
}
|
||||
|
||||
var cqname: ?[:0]const u8 = null;
|
||||
if (qname) |qn| {
|
||||
cqname = try alloc.dupeZ(u8, qn);
|
||||
defer alloc.free(cqname.?);
|
||||
}
|
||||
|
||||
return parser.domImplementationCreateDocument(cnamespace, cqname, doctype);
|
||||
}
|
||||
|
||||
pub fn _createHTMLDocument(_: *DOMImplementation, title: ?[]const u8) *parser.Document {
|
||||
return parser.domImplementationCreateHTMLDocument(title);
|
||||
}
|
||||
|
||||
pub fn _hasFeature(_: *DOMImplementation) bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn deinit(_: *DOMImplementation, _: std.mem.Allocator) void {}
|
||||
};
|
||||
|
||||
// Tests
|
||||
// -----
|
||||
|
||||
pub fn testExecFn(
|
||||
_: std.mem.Allocator,
|
||||
js_env: *jsruntime.Env,
|
||||
comptime _: []jsruntime.API,
|
||||
) !void {
|
||||
var getImplementation = [_]Case{
|
||||
.{ .src = "let impl = document.implementation", .ex = "undefined" },
|
||||
.{ .src = "impl.createHTMLDocument();", .ex = "[object Document]" },
|
||||
.{ .src = "impl.createDocument(null, 'foo');", .ex = "[object Document]" },
|
||||
.{ .src = "impl.createDocumentType('foo', 'bar', 'baz')", .ex = "[object DocumentType]" },
|
||||
.{ .src = "impl.hasFeature()", .ex = "true" },
|
||||
};
|
||||
try checkCases(js_env, &getImplementation);
|
||||
}
|
||||
@@ -826,6 +826,54 @@ pub inline fn documentTypeGetSystemId(dt: *DocumentType) []const u8 {
|
||||
return stringToData(s.?);
|
||||
}
|
||||
|
||||
// DOMImplementation
|
||||
pub inline fn domImplementationCreateDocument(namespace: ?[:0]const u8, qname: ?[:0]const u8, doctype: ?*DocumentType) *Document {
|
||||
var doc: ?*Document = undefined;
|
||||
|
||||
var ptrnamespace: [*c]const u8 = null;
|
||||
if (namespace) |ns| {
|
||||
ptrnamespace = ns.ptr;
|
||||
}
|
||||
|
||||
var ptrqname: [*c]const u8 = null;
|
||||
if (qname) |qn| {
|
||||
ptrqname = qn.ptr;
|
||||
}
|
||||
|
||||
_ = c.dom_implementation_create_document(
|
||||
c.DOM_IMPLEMENTATION_XML,
|
||||
ptrnamespace,
|
||||
ptrqname,
|
||||
doctype,
|
||||
null,
|
||||
null,
|
||||
&doc,
|
||||
);
|
||||
return doc.?;
|
||||
}
|
||||
|
||||
pub inline fn domImplementationCreateDocumentType(qname: [:0]const u8, publicId: [:0]const u8, systemId: [:0]const u8) *DocumentType {
|
||||
var dt: ?*DocumentType = undefined;
|
||||
_ = c.dom_implementation_create_document_type(qname.ptr, publicId.ptr, systemId.ptr, &dt);
|
||||
return dt.?;
|
||||
}
|
||||
|
||||
pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) *Document {
|
||||
var doc: ?*Document = undefined;
|
||||
_ = c.dom_implementation_create_document(
|
||||
c.DOM_IMPLEMENTATION_HTML,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
&doc,
|
||||
);
|
||||
// TODO set title
|
||||
_ = title;
|
||||
return doc.?;
|
||||
}
|
||||
|
||||
// Document
|
||||
pub const Document = c.dom_document;
|
||||
|
||||
@@ -915,7 +963,7 @@ pub fn documentHTMLParseFromFile(filename: [:0]const u8) !*DocumentHTML {
|
||||
// The allocator is required to create a null terminated string.
|
||||
// The c string allocated is freed by the function.
|
||||
// The caller is responsible for closing the document.
|
||||
pub fn documentHTMLParseFromStrAlloc(allocator: std.mem.Allocator, str: [:0]const u8) !*DocumentHTML {
|
||||
pub fn documentHTMLParseFromStrAlloc(allocator: std.mem.Allocator, str: []const u8) !*DocumentHTML {
|
||||
// create a null terminated c string.
|
||||
const cstr = try allocator.dupeZ(u8, str);
|
||||
defer allocator.free(cstr);
|
||||
|
||||
@@ -13,6 +13,7 @@ const characterDataTestExecFn = @import("dom/character_data.zig").testExecFn;
|
||||
const textTestExecFn = @import("dom/text.zig").testExecFn;
|
||||
const HTMLCollectionTestExecFn = @import("dom/html_collection.zig").testExecFn;
|
||||
const DOMExceptionTestExecFn = @import("dom/exceptions.zig").testExecFn;
|
||||
const DOMImplementationExecFn = @import("dom/implementation.zig").testExecFn;
|
||||
|
||||
var doc: *parser.DocumentHTML = undefined;
|
||||
|
||||
@@ -55,6 +56,7 @@ fn testsAllExecFn(
|
||||
textTestExecFn,
|
||||
HTMLCollectionTestExecFn,
|
||||
DOMExceptionTestExecFn,
|
||||
DOMImplementationExecFn,
|
||||
};
|
||||
|
||||
inline for (testFns) |testFn| {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>DOMImplementation.createDocument()</title>
|
||||
<link rel="author" title="Nate Chapin" href="mailto:japhet@chromium.org">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createdocument">
|
||||
<link rel="help" href="https://bugs.chromium.org/p/chromium/issues/detail?id=1086801">
|
||||
<meta name="assert" content="Calling on createDocument() on a DOMImplementation from a document with a null browsing context should not crash"/>
|
||||
<iframe id="i"></iframe>
|
||||
<script>
|
||||
var doc = i.contentDocument;
|
||||
i.remove();
|
||||
doc.implementation.createDocument("", "");
|
||||
</script>
|
||||
170
tests/wpt/dom/nodes/DOMImplementation-createDocument.html
Normal file
170
tests/wpt/dom/nodes/DOMImplementation-createDocument.html
Normal file
@@ -0,0 +1,170 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>DOMImplementation.createDocument(namespace, qualifiedName, doctype)</title>
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createdocument">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-createelementns">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-nodetype">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-documentelement">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-doctype">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="Document-createElementNS.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
var htmlNamespace = "http://www.w3.org/1999/xhtml"
|
||||
var svgNamespace = "http://www.w3.org/2000/svg"
|
||||
var mathMLNamespace = "http://www.w3.org/1998/Math/MathML"
|
||||
|
||||
// Make DocumentTypes distinct
|
||||
function my_format_value(val) {
|
||||
if (val instanceof DocumentType) {
|
||||
return "DocumentType node <!DOCTYPE " + val.name
|
||||
+ (val.publicId ? " " + val.publicId : "")
|
||||
+ (val.systemId ? " " + val.systemId : "")
|
||||
+ ">";
|
||||
}
|
||||
return format_value(val);
|
||||
}
|
||||
|
||||
test(function() {
|
||||
var tests = createElementNS_tests.map(function(t) {
|
||||
return [t[0], t[1], null, t[2]]
|
||||
}).concat([
|
||||
/* Arrays with four elements:
|
||||
* the namespace argument
|
||||
* the qualifiedName argument
|
||||
* the doctype argument
|
||||
* the expected exception, or null if none
|
||||
*/
|
||||
[null, null, false, TypeError],
|
||||
[null, "", null, null],
|
||||
[undefined, null, undefined, null],
|
||||
[undefined, undefined, undefined, null],
|
||||
[undefined, "", undefined, null],
|
||||
["http://example.com/", null, null, null],
|
||||
["http://example.com/", "", null, null],
|
||||
["/", null, null, null],
|
||||
["/", "", null, null],
|
||||
["http://www.w3.org/XML/1998/namespace", null, null, null],
|
||||
["http://www.w3.org/XML/1998/namespace", "", null, null],
|
||||
["http://www.w3.org/2000/xmlns/", null, null, null],
|
||||
["http://www.w3.org/2000/xmlns/", "", null, null],
|
||||
["foo:", null, null, null],
|
||||
["foo:", "", null, null],
|
||||
[null, null, document.implementation.createDocumentType("foo", "", ""), null],
|
||||
[null, null, document.doctype, null], // This causes a horrible WebKit bug (now fixed in trunk).
|
||||
[null, null, function() {
|
||||
var foo = document.implementation.createDocumentType("bar", "", "");
|
||||
document.implementation.createDocument(null, null, foo);
|
||||
return foo;
|
||||
}(), null], // DOCTYPE already associated with a document.
|
||||
[null, null, function() {
|
||||
var bar = document.implementation.createDocument(null, null, null);
|
||||
return bar.implementation.createDocumentType("baz", "", "");
|
||||
}(), null], // DOCTYPE created by a different implementation.
|
||||
[null, null, function() {
|
||||
var bar = document.implementation.createDocument(null, null, null);
|
||||
var magic = bar.implementation.createDocumentType("quz", "", "");
|
||||
bar.implementation.createDocument(null, null, magic);
|
||||
return magic;
|
||||
}(), null], // DOCTYPE created by a different implementation and already associated with a document.
|
||||
[null, "foo", document.implementation.createDocumentType("foo", "", ""), null],
|
||||
["foo", null, document.implementation.createDocumentType("foo", "", ""), null],
|
||||
["foo", "bar", document.implementation.createDocumentType("foo", "", ""), null],
|
||||
[htmlNamespace, "", null, null],
|
||||
[svgNamespace, "", null, null],
|
||||
[mathMLNamespace, "", null, null],
|
||||
[null, "html", null, null],
|
||||
[null, "svg", null, null],
|
||||
[null, "math", null, null],
|
||||
[null, "", document.implementation.createDocumentType("html",
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN",
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")],
|
||||
[null, "", document.implementation.createDocumentType("svg",
|
||||
"-//W3C//DTD SVG 1.1//EN",
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd")],
|
||||
[null, "", document.implementation.createDocumentType("math",
|
||||
"-//W3C//DTD MathML 2.0//EN",
|
||||
"http://www.w3.org/Math/DTD/mathml2/mathml2.dtd")],
|
||||
])
|
||||
|
||||
tests.forEach(function(t, i) {
|
||||
var namespace = t[0], qualifiedName = t[1], doctype = t[2], expected = t[3]
|
||||
test(function() {
|
||||
if (expected != null) {
|
||||
if (typeof expected == "string") {
|
||||
assert_throws_dom(expected, function() { document.implementation.createDocument(namespace, qualifiedName, doctype) });
|
||||
} else {
|
||||
assert_throws_js(expected, function() { document.implementation.createDocument(namespace, qualifiedName, doctype) });
|
||||
}
|
||||
} else {
|
||||
var doc = document.implementation.createDocument(namespace, qualifiedName, doctype)
|
||||
assert_equals(doc.nodeType, Node.DOCUMENT_NODE)
|
||||
assert_equals(doc.nodeType, doc.DOCUMENT_NODE)
|
||||
assert_equals(doc.nodeName, "#document")
|
||||
assert_equals(doc.nodeValue, null)
|
||||
assert_equals(Object.getPrototypeOf(doc), XMLDocument.prototype)
|
||||
var omitRootElement = qualifiedName === null || String(qualifiedName) === ""
|
||||
if (omitRootElement) {
|
||||
assert_equals(doc.documentElement, null)
|
||||
} else {
|
||||
var element = doc.documentElement
|
||||
assert_not_equals(element, null)
|
||||
assert_equals(element.nodeType, Node.ELEMENT_NODE)
|
||||
assert_equals(element.ownerDocument, doc)
|
||||
var qualified = String(qualifiedName), names = []
|
||||
if (qualified.indexOf(":") >= 0) {
|
||||
names = qualified.split(":", 2)
|
||||
} else {
|
||||
names = [null, qualified]
|
||||
}
|
||||
assert_equals(element.prefix, names[0])
|
||||
assert_equals(element.localName, names[1])
|
||||
assert_equals(element.namespaceURI, namespace === undefined ? null : namespace)
|
||||
}
|
||||
if (!doctype) {
|
||||
assert_equals(doc.doctype, null)
|
||||
} else {
|
||||
assert_equals(doc.doctype, doctype)
|
||||
assert_equals(doc.doctype.ownerDocument, doc)
|
||||
}
|
||||
assert_equals(doc.childNodes.length, !omitRootElement + !!doctype)
|
||||
}
|
||||
}, "createDocument test: " + t.map(my_format_value))
|
||||
|
||||
if (expected === null) {
|
||||
test(function() {
|
||||
var doc = document.implementation.createDocument(namespace, qualifiedName, doctype)
|
||||
assert_equals(doc.location, null)
|
||||
assert_equals(doc.compatMode, "CSS1Compat")
|
||||
assert_equals(doc.characterSet, "UTF-8")
|
||||
assert_equals(doc.contentType, namespace == htmlNamespace ? "application/xhtml+xml"
|
||||
: namespace == svgNamespace ? "image/svg+xml"
|
||||
: "application/xml")
|
||||
assert_equals(doc.URL, "about:blank")
|
||||
assert_equals(doc.documentURI, "about:blank")
|
||||
assert_equals(doc.createElement("DIV").localName, "DIV");
|
||||
}, "createDocument test: metadata for " +
|
||||
[namespace, qualifiedName, doctype].map(my_format_value))
|
||||
|
||||
test(function() {
|
||||
var doc = document.implementation.createDocument(namespace, qualifiedName, doctype)
|
||||
assert_equals(doc.characterSet, "UTF-8", "characterSet");
|
||||
assert_equals(doc.charset, "UTF-8", "charset");
|
||||
assert_equals(doc.inputEncoding, "UTF-8", "inputEncoding");
|
||||
}, "createDocument test: characterSet aliases for " +
|
||||
[namespace, qualifiedName, doctype].map(my_format_value))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test(function() {
|
||||
assert_throws_js(TypeError, function() {
|
||||
document.implementation.createDocument()
|
||||
}, "createDocument() should throw")
|
||||
|
||||
assert_throws_js(TypeError, function() {
|
||||
document.implementation.createDocument('')
|
||||
}, "createDocument('') should throw")
|
||||
}, "createDocument with missing arguments");
|
||||
</script>
|
||||
123
tests/wpt/dom/nodes/DOMImplementation-createDocumentType.html
Normal file
123
tests/wpt/dom/nodes/DOMImplementation-createDocumentType.html
Normal file
@@ -0,0 +1,123 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>DOMImplementation.createDocumentType(qualifiedName, publicId, systemId)</title>
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-name">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-publicid">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-systemid">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-node-ownerdocument">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
var tests = [
|
||||
["", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["test:root", "1234", "", null],
|
||||
["test:root", "1234", "test", null],
|
||||
["test:root", "test", "", null],
|
||||
["test:root", "test", "test", null],
|
||||
["_:_", "", "", null],
|
||||
["_:h0", "", "", null],
|
||||
["_:test", "", "", null],
|
||||
["_:_.", "", "", null],
|
||||
["_:a-", "", "", null],
|
||||
["l_:_", "", "", null],
|
||||
["ns:_0", "", "", null],
|
||||
["ns:a0", "", "", null],
|
||||
["ns0:test", "", "", null],
|
||||
["ns:EEE.", "", "", null],
|
||||
["ns:_-", "", "", null],
|
||||
["a.b:c", "", "", null],
|
||||
["a-b:c.j", "", "", null],
|
||||
["a-b:c", "", "", null],
|
||||
["foo", "", "", null],
|
||||
["1foo", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["foo1", "", "", null],
|
||||
["f1oo", "", "", null],
|
||||
["@foo", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["foo@", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["f@oo", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:{", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:}", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:~", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:'", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:!", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:@", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:#", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:$", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:%", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:^", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:&", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:*", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:(", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:)", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:+", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:=", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:[", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:]", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:\\", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:/", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:;", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:`", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:<", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:>", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:,", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:a ", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["edi:\"", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["{", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["}", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["'", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["~", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["`", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["@", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["#", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["$", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["%", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["^", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["&", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["*", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["(", "", "", "INVALID_CHARACTER_ERR"],
|
||||
[")", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["f:oo", "", "", null],
|
||||
[":foo", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["foo:", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["prefix::local", "", "", "INVALID_CHARACTER_ERR"],
|
||||
["foo", "foo", "", null],
|
||||
["foo", "", "foo", null],
|
||||
["foo", "f'oo", "", null],
|
||||
["foo", "", "f'oo", null],
|
||||
["foo", 'f"oo', "", null],
|
||||
["foo", "", 'f"oo', null],
|
||||
["foo", "f'o\"o", "", null],
|
||||
["foo", "", "f'o\"o", null],
|
||||
["foo", "foo>", "", null],
|
||||
["foo", "", "foo>", null]
|
||||
]
|
||||
|
||||
var doc = document.implementation.createHTMLDocument("title");
|
||||
var doTest = function(aDocument, aQualifiedName, aPublicId, aSystemId) {
|
||||
var doctype = aDocument.implementation.createDocumentType(aQualifiedName, aPublicId, aSystemId);
|
||||
assert_equals(doctype.name, aQualifiedName, "name")
|
||||
assert_equals(doctype.nodeName, aQualifiedName, "nodeName")
|
||||
assert_equals(doctype.publicId, aPublicId, "publicId")
|
||||
assert_equals(doctype.systemId, aSystemId, "systemId")
|
||||
assert_equals(doctype.ownerDocument, aDocument, "ownerDocument")
|
||||
assert_equals(doctype.nodeValue, null, "nodeValue")
|
||||
}
|
||||
tests.forEach(function(t) {
|
||||
var qualifiedName = t[0], publicId = t[1], systemId = t[2], expected = t[3]
|
||||
test(function() {
|
||||
if (expected) {
|
||||
assert_throws_dom(expected, function() {
|
||||
document.implementation.createDocumentType(qualifiedName, publicId, systemId)
|
||||
})
|
||||
} else {
|
||||
doTest(document, qualifiedName, publicId, systemId);
|
||||
doTest(doc, qualifiedName, publicId, systemId);
|
||||
}
|
||||
}, "createDocumentType(" + format_value(qualifiedName) + ", " + format_value(publicId) + ", " + format_value(systemId) + ") should " +
|
||||
(expected ? "throw " + expected : "work"));
|
||||
});
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>DOMImplementation.createHTMLDocument()</title>
|
||||
<link rel="author" title="Nate Chapin" href="mailto:japhet@chromium.org">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument">
|
||||
<link rel="help" href="https://bugs.chromium.org/p/chromium/issues/detail?id=1086800">
|
||||
<meta name="assert" content="Calling on createHTMLDocument() on a DOMImplementation from a document with a null browsing context should not crash"/>
|
||||
<iframe id="i"></iframe>
|
||||
<script>
|
||||
var doc = i.contentDocument;
|
||||
i.remove();
|
||||
doc.implementation.createHTMLDocument();
|
||||
</script>
|
||||
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<title>DOMImplementation.createHTMLDocument</title>
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
// Test the document location getter is null outside of browser context
|
||||
test(function() {
|
||||
var iframe = document.createElement("iframe");
|
||||
document.body.appendChild(iframe);
|
||||
var implementation = iframe.contentDocument.implementation;
|
||||
iframe.remove();
|
||||
assert_not_equals(implementation.createHTMLDocument(), null);
|
||||
}, "createHTMLDocument(): from a saved and detached implementation does not return null")
|
||||
</script>
|
||||
@@ -0,0 +1,96 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset=windows-1252>
|
||||
<!-- Using windows-1252 to ensure that DOMImplementation.createHTMLDocument()
|
||||
doesn't inherit utf-8 from the parent document. -->
|
||||
<title>DOMImplementation.createHTMLDocument</title>
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-name">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-publicid">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-documenttype-systemid">
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-documentelement">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="DOMImplementation-createHTMLDocument.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
createHTMLDocuments(function(doc, expectedtitle, normalizedtitle) {
|
||||
assert_true(doc instanceof Document, "Should be a Document")
|
||||
assert_true(doc instanceof Node, "Should be a Node")
|
||||
assert_equals(doc.childNodes.length, 2,
|
||||
"Document should have two child nodes")
|
||||
|
||||
var doctype = doc.doctype
|
||||
assert_true(doctype instanceof DocumentType,
|
||||
"Doctype should be a DocumentType")
|
||||
assert_true(doctype instanceof Node, "Doctype should be a Node")
|
||||
assert_equals(doctype.name, "html")
|
||||
assert_equals(doctype.publicId, "")
|
||||
assert_equals(doctype.systemId, "")
|
||||
|
||||
var documentElement = doc.documentElement
|
||||
assert_true(documentElement instanceof HTMLHtmlElement,
|
||||
"Document element should be a HTMLHtmlElement")
|
||||
assert_equals(documentElement.childNodes.length, 2,
|
||||
"Document element should have two child nodes")
|
||||
assert_equals(documentElement.localName, "html")
|
||||
assert_equals(documentElement.tagName, "HTML")
|
||||
|
||||
var head = documentElement.firstChild
|
||||
assert_true(head instanceof HTMLHeadElement,
|
||||
"Head should be a HTMLHeadElement")
|
||||
assert_equals(head.localName, "head")
|
||||
assert_equals(head.tagName, "HEAD")
|
||||
|
||||
if (expectedtitle !== undefined) {
|
||||
assert_equals(head.childNodes.length, 1)
|
||||
|
||||
var title = head.firstChild
|
||||
assert_true(title instanceof HTMLTitleElement,
|
||||
"Title should be a HTMLTitleElement")
|
||||
assert_equals(title.localName, "title")
|
||||
assert_equals(title.tagName, "TITLE")
|
||||
assert_equals(title.childNodes.length, 1)
|
||||
assert_equals(title.firstChild.data, expectedtitle)
|
||||
} else {
|
||||
assert_equals(head.childNodes.length, 0)
|
||||
}
|
||||
|
||||
var body = documentElement.lastChild
|
||||
assert_true(body instanceof HTMLBodyElement,
|
||||
"Body should be a HTMLBodyElement")
|
||||
assert_equals(body.localName, "body")
|
||||
assert_equals(body.tagName, "BODY")
|
||||
assert_equals(body.childNodes.length, 0)
|
||||
})
|
||||
|
||||
test(function() {
|
||||
var doc = document.implementation.createHTMLDocument("test");
|
||||
assert_equals(doc.URL, "about:blank");
|
||||
assert_equals(doc.documentURI, "about:blank");
|
||||
assert_equals(doc.compatMode, "CSS1Compat");
|
||||
assert_equals(doc.characterSet, "UTF-8");
|
||||
assert_equals(doc.contentType, "text/html");
|
||||
assert_equals(doc.createElement("DIV").localName, "div");
|
||||
}, "createHTMLDocument(): metadata")
|
||||
|
||||
test(function() {
|
||||
var doc = document.implementation.createHTMLDocument("test");
|
||||
assert_equals(doc.characterSet, "UTF-8", "characterSet");
|
||||
assert_equals(doc.charset, "UTF-8", "charset");
|
||||
assert_equals(doc.inputEncoding, "UTF-8", "inputEncoding");
|
||||
}, "createHTMLDocument(): characterSet aliases")
|
||||
|
||||
test(function() {
|
||||
var doc = document.implementation.createHTMLDocument("test");
|
||||
var a = doc.createElement("a");
|
||||
// In UTF-8: 0xC3 0xA4
|
||||
a.href = "http://example.org/?\u00E4";
|
||||
assert_equals(a.href, "http://example.org/?%C3%A4");
|
||||
}, "createHTMLDocument(): URL parsing")
|
||||
|
||||
// Test the document location getter is null outside of browser context
|
||||
test(function() {
|
||||
var doc = document.implementation.createHTMLDocument();
|
||||
assert_equals(doc.location, null);
|
||||
}, "createHTMLDocument(): document location getter is null")
|
||||
</script>
|
||||
25
tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument.js
Normal file
25
tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument.js
Normal file
@@ -0,0 +1,25 @@
|
||||
function createHTMLDocuments(checkDoc) {
|
||||
var tests = [
|
||||
["", "", ""],
|
||||
[null, "null", "null"],
|
||||
[undefined, undefined, ""],
|
||||
["foo bar baz", "foo bar baz", "foo bar baz"],
|
||||
["foo\t\tbar baz", "foo\t\tbar baz", "foo bar baz"],
|
||||
["foo\n\nbar baz", "foo\n\nbar baz", "foo bar baz"],
|
||||
["foo\f\fbar baz", "foo\f\fbar baz", "foo bar baz"],
|
||||
["foo\r\rbar baz", "foo\r\rbar baz", "foo bar baz"],
|
||||
]
|
||||
|
||||
tests.forEach(function(t, i) {
|
||||
var title = t[0], expectedtitle = t[1], normalizedtitle = t[2]
|
||||
test(function() {
|
||||
var doc = document.implementation.createHTMLDocument(title);
|
||||
checkDoc(doc, expectedtitle, normalizedtitle)
|
||||
}, "createHTMLDocument test " + i + ": " + t.map(function(el) { return format_value(el) }))
|
||||
})
|
||||
|
||||
test(function() {
|
||||
var doc = document.implementation.createHTMLDocument();
|
||||
checkDoc(doc, undefined, "")
|
||||
}, "Missing title argument");
|
||||
}
|
||||
155
tests/wpt/dom/nodes/DOMImplementation-hasFeature.html
Normal file
155
tests/wpt/dom/nodes/DOMImplementation-hasFeature.html
Normal file
@@ -0,0 +1,155 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>DOMImplementation.hasFeature(feature, version)</title>
|
||||
<link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-hasfeature">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
test(function() {
|
||||
var tests = [
|
||||
[],
|
||||
["Core"],
|
||||
["XML"],
|
||||
["org.w3c.svg"],
|
||||
["org.w3c.dom.svg"],
|
||||
["http://www.w3.org/TR/SVG11/feature#Script"],
|
||||
["Core", "1.0"],
|
||||
["Core", "2.0"],
|
||||
["Core", "3.0"],
|
||||
["Core", "100.0"],
|
||||
["XML", "1.0"],
|
||||
["XML", "2.0"],
|
||||
["XML", "3.0"],
|
||||
["XML", "100.0"],
|
||||
["Core", "1"],
|
||||
["Core", "2"],
|
||||
["Core", "3"],
|
||||
["Core", "100"],
|
||||
["XML", "1"],
|
||||
["XML", "2"],
|
||||
["XML", "3"],
|
||||
["XML", "100"],
|
||||
["Core", "1.1"],
|
||||
["Core", "2.1"],
|
||||
["Core", "3.1"],
|
||||
["Core", "100.1"],
|
||||
["XML", "1.1"],
|
||||
["XML", "2.1"],
|
||||
["XML", "3.1"],
|
||||
["XML", "100.1"],
|
||||
["Core", ""],
|
||||
["XML", ""],
|
||||
["core", ""],
|
||||
["xml", ""],
|
||||
["CoRe", ""],
|
||||
["XmL", ""],
|
||||
[" Core", ""],
|
||||
[" XML", ""],
|
||||
["Core ", ""],
|
||||
["XML ", ""],
|
||||
["Co re", ""],
|
||||
["XM L", ""],
|
||||
["aCore", ""],
|
||||
["aXML", ""],
|
||||
["Corea", ""],
|
||||
["XMLa", ""],
|
||||
["Coare", ""],
|
||||
["XMaL", ""],
|
||||
["Core", " "],
|
||||
["XML", " "],
|
||||
["Core", " 1.0"],
|
||||
["Core", " 2.0"],
|
||||
["Core", " 3.0"],
|
||||
["Core", " 100.0"],
|
||||
["XML", " 1.0"],
|
||||
["XML", " 2.0"],
|
||||
["XML", " 3.0"],
|
||||
["XML", " 100.0"],
|
||||
["Core", "1.0 "],
|
||||
["Core", "2.0 "],
|
||||
["Core", "3.0 "],
|
||||
["Core", "100.0 "],
|
||||
["XML", "1.0 "],
|
||||
["XML", "2.0 "],
|
||||
["XML", "3.0 "],
|
||||
["XML", "100.0 "],
|
||||
["Core", "1. 0"],
|
||||
["Core", "2. 0"],
|
||||
["Core", "3. 0"],
|
||||
["Core", "100. 0"],
|
||||
["XML", "1. 0"],
|
||||
["XML", "2. 0"],
|
||||
["XML", "3. 0"],
|
||||
["XML", "100. 0"],
|
||||
["Core", "a1.0"],
|
||||
["Core", "a2.0"],
|
||||
["Core", "a3.0"],
|
||||
["Core", "a100.0"],
|
||||
["XML", "a1.0"],
|
||||
["XML", "a2.0"],
|
||||
["XML", "a3.0"],
|
||||
["XML", "a100.0"],
|
||||
["Core", "1.0a"],
|
||||
["Core", "2.0a"],
|
||||
["Core", "3.0a"],
|
||||
["Core", "100.0a"],
|
||||
["XML", "1.0a"],
|
||||
["XML", "2.0a"],
|
||||
["XML", "3.0a"],
|
||||
["XML", "100.0a"],
|
||||
["Core", "1.a0"],
|
||||
["Core", "2.a0"],
|
||||
["Core", "3.a0"],
|
||||
["Core", "100.a0"],
|
||||
["XML", "1.a0"],
|
||||
["XML", "2.a0"],
|
||||
["XML", "3.a0"],
|
||||
["XML", "100.a0"],
|
||||
["Core", 1],
|
||||
["Core", 2],
|
||||
["Core", 3],
|
||||
["Core", 100],
|
||||
["XML", 1],
|
||||
["XML", 2],
|
||||
["XML", 3],
|
||||
["XML", 100],
|
||||
["Core", null],
|
||||
["XML", null],
|
||||
["core", null],
|
||||
["xml", null],
|
||||
["CoRe", null],
|
||||
["XmL", null],
|
||||
[" Core", null],
|
||||
[" XML", null],
|
||||
["Core ", null],
|
||||
["XML ", null],
|
||||
["Co re", null],
|
||||
["XM L", null],
|
||||
["aCore", null],
|
||||
["aXML", null],
|
||||
["Corea", null],
|
||||
["XMLa", null],
|
||||
["Coare", null],
|
||||
["XMaL", null],
|
||||
["Core", undefined],
|
||||
["XML", undefined],
|
||||
["This is filler text.", ""],
|
||||
[null, ""],
|
||||
[undefined, ""],
|
||||
["org.w3c.svg", ""],
|
||||
["org.w3c.svg", "1.0"],
|
||||
["org.w3c.svg", "1.1"],
|
||||
["org.w3c.dom.svg", ""],
|
||||
["org.w3c.dom.svg", "1.0"],
|
||||
["org.w3c.dom.svg", "1.1"],
|
||||
["http://www.w3.org/TR/SVG11/feature#Script", "7.5"],
|
||||
];
|
||||
tests.forEach(function(data) {
|
||||
test(function() {
|
||||
assert_equals(document.implementation.hasFeature
|
||||
.apply(document.implementation, data), true)
|
||||
}, "hasFeature(" + data.map(format_value).join(", ") + ")")
|
||||
})
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user