mirror of
				https://github.com/lightpanda-io/browser.git
				synced 2025-10-29 15:13:28 +00:00 
			
		
		
		
	Merge pull request #1031 from lightpanda-io/migrate_some_tests_8
migrate more tests to htmlRunner
This commit is contained in:
		| @@ -631,262 +631,7 @@ pub const Node = struct { | ||||
| }; | ||||
|  | ||||
| const testing = @import("../../testing.zig"); | ||||
| test "Browser.DOM.node" { | ||||
|     var runner = try testing.jsRunner(testing.tracking_allocator, .{}); | ||||
|     defer runner.deinit(); | ||||
|  | ||||
|     { | ||||
|         var err_out: ?[]const u8 = null; | ||||
|         try runner.exec( | ||||
|             \\ function trimAndReplace(str) { | ||||
|             \\   str = str.replace(/(\r\n|\n|\r)/gm,''); | ||||
|             \\   str = str.replace(/\s+/g, ' '); | ||||
|             \\   str = str.trim(); | ||||
|             \\   return str; | ||||
|             \\ } | ||||
|         , "trimAndReplace", &err_out); | ||||
|     } | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "document.body.compareDocumentPosition(document.firstChild); ", "10" }, | ||||
|         .{ "document.getElementById(\"para-empty\").compareDocumentPosition(document.getElementById(\"content\"));", "10" }, | ||||
|         .{ "document.getElementById(\"content\").compareDocumentPosition(document.getElementById(\"para-empty\"));", "20" }, | ||||
|         .{ "document.getElementById(\"link\").compareDocumentPosition(document.getElementById(\"link\"));", "0" }, | ||||
|         .{ "document.getElementById(\"para-empty\").compareDocumentPosition(document.getElementById(\"link\"));", "2" }, | ||||
|         .{ "document.getElementById(\"link\").compareDocumentPosition(document.getElementById(\"para-empty\"));", "4" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "document.getElementById('content').getRootNode().__proto__.constructor.name", "HTMLDocument" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         // for next test cases | ||||
|         .{ "let content = document.getElementById('content')", "undefined" }, | ||||
|         .{ "let link = document.getElementById('link')", "undefined" }, | ||||
|         .{ "let first_child = content.firstChild.nextSibling", "undefined" }, // nextSibling because of line return \n | ||||
|  | ||||
|         .{ "let body_first_child = document.body.firstChild", "undefined" }, | ||||
|         .{ "body_first_child.localName", "div" }, | ||||
|         .{ "body_first_child.__proto__.constructor.name", "HTMLDivElement" }, | ||||
|         .{ "document.getElementById('para-empty').firstChild.firstChild", "null" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "let last_child = content.lastChild.previousSibling", "undefined" }, // previousSibling because of line return \n | ||||
|         .{ "last_child.__proto__.constructor.name", "Comment" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "let next_sibling = link.nextSibling.nextSibling", "undefined" }, | ||||
|         .{ "next_sibling.localName", "p" }, | ||||
|         .{ "next_sibling.__proto__.constructor.name", "HTMLParagraphElement" }, | ||||
|         .{ "content.nextSibling.nextSibling", "null" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "let prev_sibling = document.getElementById('para-empty').previousSibling.previousSibling", "undefined" }, | ||||
|         .{ "prev_sibling.localName", "a" }, | ||||
|         .{ "prev_sibling.__proto__.constructor.name", "HTMLAnchorElement" }, | ||||
|         .{ "content.previousSibling", "null" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "let parent = document.getElementById('para').parentElement", "undefined" }, | ||||
|         .{ "parent.localName", "div" }, | ||||
|         .{ "parent.__proto__.constructor.name", "HTMLDivElement" }, | ||||
|         .{ "let h = content.parentElement.parentElement", "undefined" }, | ||||
|         .{ "h.parentElement", "null" }, | ||||
|         .{ "h.parentNode.__proto__.constructor.name", "HTMLDocument" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "first_child.nodeName === 'A'", "true" }, | ||||
|         .{ "link.firstChild.nodeName === '#text'", "true" }, | ||||
|         .{ "last_child.nodeName === '#comment'", "true" }, | ||||
|         .{ "document.nodeName === '#document'", "true" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "first_child.nodeType === 1", "true" }, | ||||
|         .{ "link.firstChild.nodeType === 3", "true" }, | ||||
|         .{ "last_child.nodeType === 8", "true" }, | ||||
|         .{ "document.nodeType === 9", "true" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "let owner = content.ownerDocument", "undefined" }, | ||||
|         .{ "owner.__proto__.constructor.name", "HTMLDocument" }, | ||||
|         .{ "document.ownerDocument", "null" }, | ||||
|         .{ "let owner2 = document.createElement('div').ownerDocument", "undefined" }, | ||||
|         .{ "owner2.__proto__.constructor.name", "HTMLDocument" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "content.isConnected", "true" }, | ||||
|         .{ "document.isConnected", "true" }, | ||||
|         .{ "const connDiv = document.createElement('div')", null }, | ||||
|         .{ "connDiv.isConnected", "false" }, | ||||
|         .{ "const connParentDiv = document.createElement('div')", null }, | ||||
|         .{ "connParentDiv.appendChild(connDiv)", null }, | ||||
|         .{ "connDiv.isConnected", "false" }, | ||||
|         .{ "content.appendChild(connParentDiv)", null }, | ||||
|         .{ "connDiv.isConnected", "true" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "last_child.nodeValue === 'comment'", "true" }, | ||||
|         .{ "link.nodeValue === null", "true" }, | ||||
|         .{ "let text = link.firstChild", "undefined" }, | ||||
|         .{ "text.nodeValue === 'OK'", "true" }, | ||||
|         .{ "text.nodeValue = 'OK modified'", "OK modified" }, | ||||
|         .{ "text.nodeValue === 'OK modified'", "true" }, | ||||
|         .{ "link.nodeValue = 'nothing'", "nothing" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "text.textContent === 'OK modified'", "true" }, | ||||
|         .{ "trimAndReplace(content.textContent) === 'OK modified And'", "true" }, | ||||
|         .{ "text.textContent = 'OK'", "OK" }, | ||||
|         .{ "text.textContent", "OK" }, | ||||
|         .{ "trimAndReplace(document.getElementById('para-empty').textContent)", "" }, | ||||
|         .{ "document.getElementById('para-empty').textContent = 'OK'", "OK" }, | ||||
|         .{ "document.getElementById('para-empty').firstChild.nodeName === '#text'", "true" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "let append = document.createElement('h1')", "undefined" }, | ||||
|         .{ "content.appendChild(append).toString()", "[object HTMLHeadingElement]" }, | ||||
|         .{ "content.lastChild.__proto__.constructor.name", "HTMLHeadingElement" }, | ||||
|         .{ "content.appendChild(link).toString()", "[object HTMLAnchorElement]" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "let clone = link.cloneNode()", "undefined" }, | ||||
|         .{ "clone.toString()", "[object HTMLAnchorElement]" }, | ||||
|         .{ "clone.parentNode === null", "true" }, | ||||
|         .{ "clone.firstChild === null", "true" }, | ||||
|         .{ "let clone_deep = link.cloneNode(true)", "undefined" }, | ||||
|         .{ "clone_deep.firstChild.nodeName === '#text'", "true" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "link.contains(text)", "true" }, | ||||
|         .{ "text.contains(link)", "false" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "link.hasChildNodes()", "true" }, | ||||
|         .{ "text.hasChildNodes()", "false" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "link.childNodes.length", "1" }, | ||||
|         .{ "text.childNodes.length", "0" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "let insertBefore = document.createElement('a')", "undefined" }, | ||||
|         .{ "link.insertBefore(insertBefore, text) !== undefined", "true" }, | ||||
|         .{ "link.firstChild.localName === 'a'", "true" }, | ||||
|  | ||||
|         .{ "let insertBefore2 = document.createElement('b')", null }, | ||||
|         .{ "link.insertBefore(insertBefore2, null).localName", "b" }, | ||||
|         .{ "link.childNodes[link.childNodes.length - 1].localName", "b" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         // TODO: does not seems to work | ||||
|         // .{ "link.isDefaultNamespace('')", "true" }, | ||||
|         .{ "link.isDefaultNamespace('false')", "false" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "let equal1 = document.createElement('a')", "undefined" }, | ||||
|         .{ "let equal2 = document.createElement('a')", "undefined" }, | ||||
|         .{ "equal1.textContent = 'is equal'", "is equal" }, | ||||
|         .{ "equal2.textContent = 'is equal'", "is equal" }, | ||||
|         // TODO: does not seems to work | ||||
|         // .{ "equal1.isEqualNode(equal2)", "true" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "document.body.isSameNode(document.body)", "true" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         // TODO: no test | ||||
|         .{ "link.normalize()", "undefined" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "link.baseURI", "https://lightpanda.io/opensource-browser/" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "content.removeChild(append) !== undefined", "true" }, | ||||
|         .{ "last_child.__proto__.constructor.name !== 'HTMLHeadingElement'", "true" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "let replace = document.createElement('div')", "undefined" }, | ||||
|         .{ "link.replaceChild(replace, insertBefore) !== undefined", "true" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "Node.ELEMENT_NODE", "1" }, | ||||
|         .{ "Node.ATTRIBUTE_NODE", "2" }, | ||||
|         .{ "Node.TEXT_NODE", "3" }, | ||||
|         .{ "Node.CDATA_SECTION_NODE", "4" }, | ||||
|         .{ "Node.PROCESSING_INSTRUCTION_NODE", "7" }, | ||||
|         .{ "Node.COMMENT_NODE", "8" }, | ||||
|         .{ "Node.DOCUMENT_NODE", "9" }, | ||||
|         .{ "Node.DOCUMENT_TYPE_NODE", "10" }, | ||||
|         .{ "Node.DOCUMENT_FRAGMENT_NODE", "11" }, | ||||
|         .{ "Node.ENTITY_REFERENCE_NODE", "5" }, | ||||
|         .{ "Node.ENTITY_NODE", "6" }, | ||||
|         .{ "Node.NOTATION_NODE", "12" }, | ||||
|     }, .{}); | ||||
| } | ||||
|  | ||||
| test "Browser.DOM.node.owner" { | ||||
|     var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html =  | ||||
|         \\  <div id="target-container"> | ||||
|         \\     <p id="reference-node"> | ||||
|         \\         I am the original reference node. | ||||
|         \\     </p> | ||||
|         \\  </div>" | ||||
|     }); | ||||
|  | ||||
|     defer runner.deinit(); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ | ||||
|             \\ const parser = new DOMParser(); | ||||
|             \\ const newDoc = parser.parseFromString('<div id="new-node"><p>Hey</p><span>Marked</span></div>', 'text/html'); | ||||
|             \\ const newNode = newDoc.getElementById('new-node'); | ||||
|             \\ const parent = document.getElementById('target-container'); | ||||
|             \\ const referenceNode = document.getElementById('reference-node'); | ||||
|             \\ parent.insertBefore(newNode, referenceNode); | ||||
|             \\ const k = document.getElementById('new-node'); | ||||
|             \\ const ptag = k.querySelector('p'); | ||||
|             \\ const spanTag = k.querySelector('span'); | ||||
|             \\ const anotherDoc = parser.parseFromString('<div id="another-new-node"></div>', 'text/html'); | ||||
|             \\ const anotherNewNode = anotherDoc.getElementById('another-new-node'); | ||||
|             \\ | ||||
|             \\ parent.appendChild(anotherNewNode) | ||||
|             , | ||||
|             "[object HTMLDivElement]", | ||||
|         }, | ||||
|  | ||||
|         .{ "parent.ownerDocument === newNode.ownerDocument", "true" }, | ||||
|         .{ "parent.ownerDocument === anotherNewNode.ownerDocument", "true" }, | ||||
|         .{ "newNode.firstChild.nodeName", "P" }, | ||||
|         .{ "ptag.ownerDocument === parent.ownerDocument", "true" }, | ||||
|         .{ "spanTag.ownerDocument === parent.ownerDocument", "true" }, | ||||
|         .{ "parent.contains(newNode)", "true" }, | ||||
|         .{ "parent.contains(anotherNewNode)", "true" }, | ||||
|         .{ "anotherDoc.contains(anotherNewNode)", "false" }, | ||||
|         .{ "newDoc.contains(newNode)", "false" }, | ||||
|     }, .{}); | ||||
| test "Browser: DOM.Node" { | ||||
|     try testing.htmlRunner("dom/node.html"); | ||||
|     try testing.htmlRunner("dom/node_owner.html"); | ||||
| } | ||||
|   | ||||
| @@ -75,15 +75,6 @@ pub fn verify(what_to_show: u32, filter: ?Env.Function, node: *parser.Node) !Ver | ||||
| } | ||||
|  | ||||
| const testing = @import("../../testing.zig"); | ||||
| test "Browser.DOM.NodeFilter" { | ||||
|     var runner = try testing.jsRunner(testing.tracking_allocator, .{}); | ||||
|     defer runner.deinit(); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "NodeFilter.FILTER_ACCEPT", "1" }, | ||||
|         .{ "NodeFilter.FILTER_REJECT", "2" }, | ||||
|         .{ "NodeFilter.FILTER_SKIP", "3" }, | ||||
|         .{ "NodeFilter.SHOW_ALL", "4294967295" }, | ||||
|         .{ "NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT", "129" }, | ||||
|     }, .{}); | ||||
| test "Browser: DOM.NodeFilter" { | ||||
|     try testing.htmlRunner("dom/node_filter.html"); | ||||
| } | ||||
|   | ||||
| @@ -268,71 +268,6 @@ pub const NodeIterator = struct { | ||||
| }; | ||||
|  | ||||
| const testing = @import("../../testing.zig"); | ||||
| test "Browser.DOM.NodeFilter" { | ||||
|     var runner = try testing.jsRunner(testing.tracking_allocator, .{}); | ||||
|     defer runner.deinit(); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ | ||||
|             \\ const nodeIterator = document.createNodeIterator( | ||||
|             \\   document.body, | ||||
|             \\   NodeFilter.SHOW_ELEMENT, | ||||
|             \\   { | ||||
|             \\     acceptNode(node) { | ||||
|             \\       return NodeFilter.FILTER_ACCEPT; | ||||
|             \\     }, | ||||
|             \\   }, | ||||
|             \\ ); | ||||
|             \\ nodeIterator.nextNode().nodeName; | ||||
|             , | ||||
|             "BODY", | ||||
|         }, | ||||
|         .{ "nodeIterator.nextNode().nodeName", "DIV" }, | ||||
|         .{ "nodeIterator.nextNode().nodeName", "A" }, | ||||
|         .{ "nodeIterator.previousNode().nodeName", "A" }, // pointer_before_current flips | ||||
|         .{ "nodeIterator.nextNode().nodeName", "A" }, // pointer_before_current flips | ||||
|         .{ "nodeIterator.previousNode().nodeName", "A" }, // pointer_before_current flips | ||||
|         .{ "nodeIterator.previousNode().nodeName", "DIV" }, | ||||
|         .{ "nodeIterator.previousNode().nodeName", "BODY" }, | ||||
|         .{ "nodeIterator.previousNode()", "null" }, // Not HEAD since body is root | ||||
|         .{ "nodeIterator.previousNode()", "null" }, // Keeps returning null | ||||
|         .{ "nodeIterator.nextNode().nodeName", "BODY" }, | ||||
|  | ||||
|         .{ "nodeIterator.nextNode().nodeName", null }, | ||||
|         .{ "nodeIterator.nextNode().nodeName", null }, | ||||
|         .{ "nodeIterator.nextNode().nodeName", null }, | ||||
|         .{ "nodeIterator.nextNode().nodeName", "SPAN" }, | ||||
|         .{ "nodeIterator.nextNode().nodeName", "P" }, | ||||
|         .{ "nodeIterator.nextNode()", "null" }, // Just the last one | ||||
|         .{ "nodeIterator.nextNode()", "null" }, // Keeps returning null | ||||
|         .{ "nodeIterator.previousNode().nodeName", "P" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ | ||||
|             \\ const notationIterator = document.createNodeIterator( | ||||
|             \\   document.body, | ||||
|             \\   NodeFilter.SHOW_NOTATION, | ||||
|             \\ ); | ||||
|             \\ notationIterator.nextNode(); | ||||
|             , | ||||
|             "null", | ||||
|         }, | ||||
|         .{ "notationIterator.previousNode()", "null" }, | ||||
|     }, .{}); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "nodeIterator.filter.acceptNode(document.body)", "1" }, | ||||
|         .{ "notationIterator.filter", "null" }, | ||||
|         .{ | ||||
|             \\ const rejectIterator = document.createNodeIterator( | ||||
|             \\   document.body, | ||||
|             \\   NodeFilter.SHOW_ALL, | ||||
|             \\   (e => { return NodeFilter.FILTER_REJECT}), | ||||
|             \\ ); | ||||
|             \\ rejectIterator.filter(document.body); | ||||
|             , | ||||
|             "2", | ||||
|         }, | ||||
|     }, .{}); | ||||
| test "Browser: DOM.NodeIterator" { | ||||
|     try testing.htmlRunner("dom/node_iterator.html"); | ||||
| } | ||||
|   | ||||
| @@ -177,22 +177,6 @@ pub const NodeList = struct { | ||||
| }; | ||||
|  | ||||
| const testing = @import("../../testing.zig"); | ||||
| test "Browser.DOM.NodeList" { | ||||
|     var runner = try testing.jsRunner(testing.tracking_allocator, .{}); | ||||
|     defer runner.deinit(); | ||||
|  | ||||
|     try runner.testCases(&.{ | ||||
|         .{ "let list = document.getElementById('content').childNodes", "undefined" }, | ||||
|         .{ "list.length", "9" }, | ||||
|         .{ "list[0].__proto__.constructor.name", "Text" }, | ||||
|         .{ | ||||
|             \\  let i = 0; | ||||
|             \\  list.forEach(function (n, idx) { | ||||
|             \\    i += idx; | ||||
|             \\  }); | ||||
|             \\  i; | ||||
|             , | ||||
|             "36", | ||||
|         }, | ||||
|     }, .{}); | ||||
| test "Browser: DOM.NodeList" { | ||||
|     try testing.htmlRunner("dom/node_list.html"); | ||||
| } | ||||
|   | ||||
| @@ -1055,7 +1055,7 @@ pub const HTMLSlotElement = struct { | ||||
|  | ||||
|     fn findAssignedSlotNodes(self: *parser.Slot, opts: AssignedNodesOpts, page: *Page) !?[]NodeUnion { | ||||
|         if (opts.flatten) { | ||||
|             log.warn(.web_api, "not implemented", .{ .feature = "HTMLSlotElement flatten assignedNodes" }); | ||||
|             log.debug(.web_api, "not implemented", .{ .feature = "HTMLSlotElement flatten assignedNodes" }); | ||||
|         } | ||||
|  | ||||
|         const slot_name = try parser.elementGetAttribute(@ptrCast(@alignCast(self)), "name"); | ||||
|   | ||||
							
								
								
									
										225
									
								
								src/tests/dom/node.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										225
									
								
								src/tests/dom/node.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,225 @@ | ||||
| <body><div id="content"> | ||||
|     <a id="link" href="foo" class="ok">OK</a> | ||||
|     <p id="para-empty" class="ok empty"> | ||||
|       <span id="para-empty-child"></span> | ||||
|     </p> | ||||
|     <p id="para"> And</p> | ||||
|     <!--comment--> | ||||
|   </div> | ||||
| </body> | ||||
|  | ||||
| <script src="../testing.js"></script> | ||||
| <script> | ||||
| function trimAndReplace(str) { | ||||
|   str = str.replace(/(\r\n|\n|\r)/gm,''); | ||||
|   str = str.replace(/\s+/g, ' '); | ||||
|   str = str.trim(); | ||||
|   return str; | ||||
| } | ||||
|  | ||||
| let content = $('#content'); | ||||
| let link = $('#link'); | ||||
| let first_child = content.firstChild.nextSibling; // nextSibling because of line return \n | ||||
| </script> | ||||
|  | ||||
| <script id=compareDocumentPosition> | ||||
|   testing.expectEqual(10, document.body.compareDocumentPosition(document.firstChild)); | ||||
|   testing.expectEqual(10, $('#para-empty').compareDocumentPosition(content)); | ||||
|   testing.expectEqual(20, content.compareDocumentPosition($('#para-empty'))); | ||||
|   testing.expectEqual(0, link.compareDocumentPosition(link)); | ||||
|   testing.expectEqual(2, $('#para-empty').compareDocumentPosition(link)); | ||||
|   testing.expectEqual(4, link.compareDocumentPosition($('#para-empty'))); | ||||
| </script> | ||||
|  | ||||
| <script id=proto> | ||||
|   testing.expectEqual('HTMLDocument', content.getRootNode().__proto__.constructor.name); | ||||
| </script> | ||||
|  | ||||
| <script id=firstChild> | ||||
|   let body_first_child = document.body.firstChild; | ||||
|   testing.expectEqual('div', body_first_child.localName); | ||||
|   testing.expectEqual('HTMLDivElement', body_first_child.__proto__.constructor.name); | ||||
|   testing.expectEqual(null, $('#para-empty').firstChild.firstChild); | ||||
| </script> | ||||
|  | ||||
| <script id=lastChild> | ||||
|   let last_child = content.lastChild.previousSibling; // previousSibling because of line return \n | ||||
|   testing.expectEqual('Comment', last_child.__proto__.constructor.name); | ||||
| </script> | ||||
|  | ||||
| <script id=nextSibling> | ||||
|   let next_sibling = link.nextSibling.nextSibling; | ||||
|   testing.expectEqual('p', next_sibling.localName); | ||||
|   testing.expectEqual('HTMLParagraphElement', next_sibling.__proto__.constructor.name); | ||||
|   testing.expectEqual(null, $('#para-empty-child').nextSibling.nextSibling); | ||||
| </script> | ||||
|  | ||||
| <script id=previousSibling> | ||||
|   let prev_sibling = $('#para-empty').previousSibling.previousSibling; | ||||
|   testing.expectEqual('a', prev_sibling.localName); | ||||
|   testing.expectEqual('HTMLAnchorElement', prev_sibling.__proto__.constructor.name); | ||||
|   testing.expectEqual(null, content.previousSibling); | ||||
| </script> | ||||
|  | ||||
| <script id=parentElement> | ||||
|   let parent = $('#para').parentElement; | ||||
|   testing.expectEqual('div', parent.localName); | ||||
|   testing.expectEqual('HTMLDivElement', parent.__proto__.constructor.name) | ||||
|  | ||||
|   let h = content.parentElement.parentElement; | ||||
|   testing.expectEqual(null, h.parentElement); | ||||
|   testing.expectEqual('HTMLDocument', h.parentNode.__proto__.constructor.name); | ||||
| </script> | ||||
|  | ||||
| <script id=nodeName> | ||||
|   testing.expectEqual('A', first_child.nodeName); | ||||
|   testing.expectEqual('#text', link.firstChild.nodeName); | ||||
|   testing.expectEqual('#comment', last_child.nodeName); | ||||
|   testing.expectEqual('#document', document.nodeName); | ||||
| </script> | ||||
|  | ||||
| <script id=nodeType> | ||||
|   testing.expectEqual(1, first_child.nodeType) | ||||
|   testing.expectEqual(3, link.firstChild.nodeType) | ||||
|   testing.expectEqual(8, last_child.nodeType) | ||||
|   testing.expectEqual(9, document.nodeType) | ||||
| </script> | ||||
|  | ||||
| <script id=ownerDocument> | ||||
|   let owner = content.ownerDocument; | ||||
|   testing.expectEqual('HTMLDocument', owner.__proto__.constructor.name); | ||||
|   testing.expectEqual(null, document.ownerDocument) | ||||
|  | ||||
|   let owner2 = document.createElement('div').ownerDocument; | ||||
|   testing.expectEqual('HTMLDocument', owner2.__proto__.constructor.name); | ||||
| </script> | ||||
|  | ||||
| <script id=isConnected> | ||||
|   testing.expectEqual(true, content.isConnected); | ||||
|   testing.expectEqual(true, document.isConnected); | ||||
|  | ||||
|   const connDiv = document.createElement('div'); | ||||
|   testing.expectEqual(false, connDiv.isConnected); | ||||
|  | ||||
|   const connParentDiv = document.createElement('div'); | ||||
|   connParentDiv.appendChild(connDiv); | ||||
|   testing.expectEqual(false, connDiv.isConnected); | ||||
|  | ||||
|   content.appendChild(connParentDiv); | ||||
|   testing.expectEqual(true, connDiv.isConnected); | ||||
| </script> | ||||
|  | ||||
| <script id=nodeValue> | ||||
|   testing.expectEqual('comment', last_child.nodeValue); | ||||
|   testing.expectEqual(null, link.nodeValue); | ||||
|  | ||||
|   let text = link.firstChild; | ||||
|   testing.expectEqual('OK', text.nodeValue); | ||||
|  | ||||
|   text.nodeValue = 'OK modified'; | ||||
|   testing.expectEqual('OK modified', text.nodeValue); | ||||
| </script> | ||||
|  | ||||
| <script id=textContent> | ||||
|   testing.expectEqual('OK modified', text.textContent); | ||||
|   testing.expectEqual('OK modified And', trimAndReplace(content.textContent)); | ||||
|   text.textContent = 'OK'; | ||||
|   testing.expectEqual('OK', text.textContent); | ||||
|  | ||||
|   testing.expectEqual('', trimAndReplace($('#para-empty').textContent)); | ||||
|  | ||||
|   $('#para-empty').textContent = 'OK'; | ||||
|   testing.expectEqual('#text', $('#para-empty').firstChild.nodeName); | ||||
| </script> | ||||
|  | ||||
| <script id=appendChild> | ||||
|   let append = document.createElement('h1'); | ||||
|   testing.expectEqual('[object HTMLHeadingElement]', content.appendChild(append).toString()); | ||||
|   testing.expectEqual('HTMLHeadingElement', content.lastChild.__proto__.constructor.name); | ||||
|   testing.expectEqual('[object HTMLAnchorElement]', content.appendChild(link).toString()); | ||||
| </script> | ||||
|  | ||||
| <script id=cloneNode> | ||||
|   let clone = link.cloneNode(); | ||||
|   testing.expectEqual('[object HTMLAnchorElement]', clone.toString()); | ||||
|   testing.expectEqual(null, clone.parentNode); | ||||
|   testing.expectEqual(null, clone.firstChild); | ||||
|  | ||||
|   let clone_deep = link.cloneNode(true); | ||||
|   testing.expectEqual('#text', clone_deep.firstChild.nodeName); | ||||
| </script> | ||||
|  | ||||
| <script id=contains> | ||||
|   testing.expectEqual(true, link.contains(text)); | ||||
|   testing.expectEqual(false, text.contains(link)); | ||||
| </script> | ||||
|  | ||||
| <script id=hasChildNodes> | ||||
|   testing.expectEqual(true, link.hasChildNodes()); | ||||
|   testing.expectEqual(false, text.hasChildNodes()); | ||||
| </script> | ||||
|  | ||||
| <script id=childNodesLength> | ||||
|   testing.expectEqual(1, link.childNodes.length); | ||||
|   testing.expectEqual(0, text.childNodes.length); | ||||
| </script> | ||||
|  | ||||
| <script id=insertBefore> | ||||
|   let insertBefore = document.createElement('a'); | ||||
|   testing.expectEqual(true, link.insertBefore(insertBefore, text) !== undefined); | ||||
|   testing.expectEqual('a', link.firstChild.localName); | ||||
|  | ||||
|   let insertBefore2 = document.createElement('b'); | ||||
|   testing.expectEqual('b', link.insertBefore(insertBefore2, null).localName); | ||||
|   testing.expectEqual('b', link.childNodes[link.childNodes.length - 1].localName); | ||||
| </script> | ||||
|  | ||||
| <script id=isDefaultNamespace> | ||||
|   // TODO: does not seems to work | ||||
|   //   link.isDefaultNamespace('')", "true" }, | ||||
|   testing.expectEqual(false, link.isDefaultNamespace('false')); | ||||
| </script> | ||||
|  | ||||
| <script id=isEqualNode> | ||||
|   let equal1 = document.createElement('a'); | ||||
|   let equal2 = document.createElement('a'); | ||||
|   equal1.textContent = 'is equal'; | ||||
|   equal2.textContent = 'is equal'; | ||||
|   // TODO: does not seems to work | ||||
|   // testing.expectEqual(true, equal1.isEqualNode(equal2)); | ||||
|   testing.skip(); | ||||
| </script> | ||||
|  | ||||
| <script id=isSameNode> | ||||
|   testing.expectEqual(true, document.body.isSameNode(document.body)); | ||||
|   testing.expectEqual(false, document.body.isSameNode(content)); | ||||
| </script> | ||||
|  | ||||
| <script id=baseURI> | ||||
|   testing.expectEqual('http://localhost:9582/src/tests/dom/node.html', link.baseURI); | ||||
| </script> | ||||
|  | ||||
| <script id=removeChild> | ||||
|   testing.expectEqual(true, content.removeChild(append) !== undefined); | ||||
|   testing.expectEqual(true, last_child.__proto__.constructor.name !== 'HTMLHeadingElement'); | ||||
| </script> | ||||
|  | ||||
| <script id=replaceChild> | ||||
|   let replace = document.createElement('div'); | ||||
|   testing.expectEqual(true, link.replaceChild(replace, insertBefore) !== undefined); | ||||
| </script> | ||||
|  | ||||
| <script id=NODE_TYPE> | ||||
|   testing.expectEqual(1, Node.ELEMENT_NODE); | ||||
|   testing.expectEqual(2, Node.ATTRIBUTE_NODE); | ||||
|   testing.expectEqual(3, Node.TEXT_NODE); | ||||
|   testing.expectEqual(4, Node.CDATA_SECTION_NODE); | ||||
|   testing.expectEqual(7, Node.PROCESSING_INSTRUCTION_NODE); | ||||
|   testing.expectEqual(8, Node.COMMENT_NODE); | ||||
|   testing.expectEqual(9, Node.DOCUMENT_NODE); | ||||
|   testing.expectEqual(10, Node.DOCUMENT_TYPE_NODE); | ||||
|   testing.expectEqual(11, Node.DOCUMENT_FRAGMENT_NODE); | ||||
|   testing.expectEqual(5, Node.ENTITY_REFERENCE_NODE); | ||||
|   testing.expectEqual(6, Node.ENTITY_NODE); | ||||
|   testing.expectEqual(12, Node.NOTATION_NODE); | ||||
| </script> | ||||
							
								
								
									
										8
									
								
								src/tests/dom/node_filter.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/tests/dom/node_filter.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| <script src="../testing.js"></script> | ||||
| <script id=nodeFilter> | ||||
|   testing.expectEqual(1, NodeFilter.FILTER_ACCEPT); | ||||
|   testing.expectEqual(2, NodeFilter.FILTER_REJECT); | ||||
|   testing.expectEqual(3, NodeFilter.FILTER_SKIP); | ||||
|   testing.expectEqual(4294967295, NodeFilter.SHOW_ALL); | ||||
|   testing.expectEqual(129, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT); | ||||
| </script> | ||||
							
								
								
									
										61
									
								
								src/tests/dom/node_iterator.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								src/tests/dom/node_iterator.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| <script src="../testing.js"></script> | ||||
| <script id=nodeIterator> | ||||
|   const nodeIterator = document.createNodeIterator( | ||||
|     document.body, | ||||
|     NodeFilter.SHOW_ELEMENT, | ||||
|     { | ||||
|       acceptNode(node) { | ||||
|         return NodeFilter.FILTER_ACCEPT; | ||||
|       }, | ||||
|     }, | ||||
|   ); | ||||
|   testing.expectEqual('BODY', nodeIterator.nextNode().nodeName); | ||||
|  | ||||
|   testing.expectEqual('DIV', nodeIterator.nextNode().nodeName); | ||||
|   testing.expectEqual('A', nodeIterator.nextNode().nodeName); | ||||
|   testing.expectEqual('A', nodeIterator.previousNode().nodeName); // pointer_before_current flips | ||||
|   testing.expectEqual('A', nodeIterator.nextNode().nodeName); // pointer_before_current flips | ||||
|   testing.expectEqual('A', nodeIterator.previousNode().nodeName); // pointer_before_current flips | ||||
|   testing.expectEqual('DIV', nodeIterator.previousNode().nodeName); | ||||
|   testing.expectEqual('BODY', nodeIterator.previousNode().nodeName); | ||||
|   testing.expectEqual(null, nodeIterator.previousNode()); // Not HEAD since body is root | ||||
|   testing.expectEqual(null, nodeIterator.previousNode()); // Keeps returning null | ||||
|   testing.expectEqual('BODY', nodeIterator.nextNode().nodeName); | ||||
|  | ||||
|   nodeIterator.nextNode(); | ||||
|   nodeIterator.nextNode(); | ||||
|   nodeIterator.nextNode(); | ||||
|   testing.expectEqual('SPAN', nodeIterator.nextNode().nodeName); | ||||
|   testing.expectEqual('P', nodeIterator.nextNode().nodeName); | ||||
|   testing.expectEqual(null, nodeIterator.nextNode()); // Just the last one | ||||
|   testing.expectEqual(null ,nodeIterator.nextNode()); // Keeps returning null | ||||
|   testing.expectEqual('P', nodeIterator.previousNode().nodeName); | ||||
|  | ||||
|   const notationIterator = document.createNodeIterator( | ||||
|     document.body, | ||||
|     NodeFilter.SHOW_NOTATION, | ||||
|   ); | ||||
|   testing.expectEqual(null, notationIterator.nextNode()); | ||||
|   testing.expectEqual(null, notationIterator.previousNode()); | ||||
|  | ||||
|   testing.expectEqual(1, nodeIterator.filter.acceptNode(document.body)); | ||||
|   testing.expectEqual(null, notationIterator.filter); | ||||
|  | ||||
|   const rejectIterator = document.createNodeIterator( | ||||
|     document.body, | ||||
|     NodeFilter.SHOW_ALL, | ||||
|     (e => { return NodeFilter.FILTER_REJECT}), | ||||
|   ); | ||||
|   testing.expectEqual(2, rejectIterator.filter(document.body)); | ||||
| </script> | ||||
|  | ||||
| <body> | ||||
|     <div id="content"> | ||||
|     <a id="link" href="foo" class="ok">OK</a> | ||||
|     <p id="para-empty" class="ok empty"> | ||||
|       <span id="para-empty-child"></span> | ||||
|     </p> | ||||
|     <p id="para"> And</p> | ||||
|     <!--comment--> | ||||
|   </div> | ||||
| </body> | ||||
							
								
								
									
										18
									
								
								src/tests/dom/node_list.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/tests/dom/node_list.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| <div id="content"> | ||||
|   <a id="link" href="foo" class="ok">OK</a> | ||||
|   <p id="para-empty" class="ok empty"> | ||||
|     <span id="para-empty-child"></span> | ||||
|   </p> | ||||
|   <p id="para"> And</p> | ||||
|   <!--comment--> | ||||
| </div> | ||||
|  | ||||
| <script src="../testing.js"></script> | ||||
| <script id=nodeList> | ||||
|   let list = document.getElementById('content').childNodes; | ||||
|   testing.expectEqual(9, list.length); | ||||
|   testing.expectEqual('Text', list[0].__proto__.constructor.name); | ||||
|   let i = 0; | ||||
|   list.forEach(function (n, idx) { i += idx; }); | ||||
|   testing.expectEqual(36, i); | ||||
| </script> | ||||
							
								
								
									
										33
									
								
								src/tests/dom/node_owner.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/tests/dom/node_owner.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| <div id="target-container"> | ||||
|   <p id="reference-node"> | ||||
|   I am the original reference node. | ||||
|   </p> | ||||
| </div> | ||||
|  | ||||
| <script src="../testing.js"></script> | ||||
| <script id=nodeOwner> | ||||
|   const parser = new DOMParser(); | ||||
|   const newDoc = parser.parseFromString('<div id="new-node"><p>Hey</p><span>Marked</span></div>', 'text/html'); | ||||
|   const newNode = newDoc.getElementById('new-node'); | ||||
|   const parent = $('#target-container'); | ||||
|   const referenceNode = $('#reference-node'); | ||||
|  | ||||
|   parent.insertBefore(newNode, referenceNode); | ||||
|   const k = $('#new-node'); | ||||
|   const ptag = k.querySelector('p'); | ||||
|   const spanTag = k.querySelector('span'); | ||||
|   const anotherDoc = parser.parseFromString('<div id="another-new-node"></div>', 'text/html'); | ||||
|   const anotherNewNode = anotherDoc.getElementById('another-new-node'); | ||||
|   testing.expectEqual('[object HTMLDivElement]', parent.appendChild(anotherNewNode).toString()); | ||||
|  | ||||
|  | ||||
|   testing.expectEqual(newNode.ownerDocument, parent.ownerDocument); | ||||
|   testing.expectEqual(anotherNewNode.ownerDocument, parent.ownerDocument); | ||||
|   testing.expectEqual('P', newNode.firstChild.nodeName); | ||||
|   testing.expectEqual(parent.ownerDocument, ptag.ownerDocument); | ||||
|   testing.expectEqual(parent.ownerDocument, spanTag.ownerDocument); | ||||
|   testing.expectEqual(true, parent.contains(newNode)); | ||||
|   testing.expectEqual(true, parent.contains(anotherNewNode)); | ||||
|   testing.expectEqual(false, anotherDoc.contains(anotherNewNode)); | ||||
|   testing.expectEqual(false, newDoc.contains(newNode)); | ||||
| </script> | ||||
		Reference in New Issue
	
	Block a user
	 Karl Seguin
					Karl Seguin