OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <meta charset=utf-8> |
| 3 <title>DOM IDL tests</title> |
| 4 <script src=../../../resources/testharness.js></script> |
| 5 <script src=../../../resources/testharnessreport.js></script> |
| 6 <script src=../../../resources/WebIDLParser.js></script> |
| 7 <script src=../../../resources/idlharness.js></script> |
| 8 |
| 9 <h1>DOM IDL tests</h1> |
| 10 <div id=log></div> |
| 11 |
| 12 <script type=text/plain> |
| 13 [Constructor(DOMString type, optional EventInit eventInitDict)/*, |
| 14 Exposed=(Window,Worker)*/] |
| 15 interface Event { |
| 16 readonly attribute DOMString type; |
| 17 readonly attribute EventTarget? target; |
| 18 readonly attribute EventTarget? currentTarget; |
| 19 |
| 20 const unsigned short NONE = 0; |
| 21 const unsigned short CAPTURING_PHASE = 1; |
| 22 const unsigned short AT_TARGET = 2; |
| 23 const unsigned short BUBBLING_PHASE = 3; |
| 24 readonly attribute unsigned short eventPhase; |
| 25 |
| 26 void stopPropagation(); |
| 27 void stopImmediatePropagation(); |
| 28 |
| 29 readonly attribute boolean bubbles; |
| 30 readonly attribute boolean cancelable; |
| 31 void preventDefault(); |
| 32 readonly attribute boolean defaultPrevented; |
| 33 |
| 34 [Unforgeable] readonly attribute boolean isTrusted; |
| 35 readonly attribute DOMTimeStamp timeStamp; |
| 36 |
| 37 void initEvent(DOMString type, boolean bubbles, boolean cancelable); |
| 38 }; |
| 39 |
| 40 dictionary EventInit { |
| 41 boolean bubbles = false; |
| 42 boolean cancelable = false; |
| 43 }; |
| 44 |
| 45 [Constructor(DOMString type, optional CustomEventInit eventInitDict)/*, |
| 46 Exposed=(Window,Worker)*/] |
| 47 interface CustomEvent : Event { |
| 48 readonly attribute any detail; |
| 49 |
| 50 void initCustomEvent(DOMString type, boolean bubbles, boolean cancelable, any
detail); |
| 51 }; |
| 52 |
| 53 dictionary CustomEventInit : EventInit { |
| 54 any detail = null; |
| 55 }; |
| 56 |
| 57 //[Exposed=(Window,Worker)] |
| 58 interface EventTarget { |
| 59 void addEventListener(DOMString type, EventListener? callback, optional boolea
n capture = false); |
| 60 void removeEventListener(DOMString type, EventListener? callback, optional boo
lean capture = false); |
| 61 boolean dispatchEvent(Event event); |
| 62 }; |
| 63 |
| 64 callback interface EventListener { |
| 65 void handleEvent(Event event); |
| 66 }; |
| 67 |
| 68 [NoInterfaceObject] |
| 69 interface NonElementParentNode { |
| 70 Element? getElementById(DOMString elementId); |
| 71 }; |
| 72 Document implements NonElementParentNode; |
| 73 DocumentFragment implements NonElementParentNode; |
| 74 |
| 75 [NoInterfaceObject] |
| 76 interface ParentNode { |
| 77 [SameObject] readonly attribute HTMLCollection children; |
| 78 readonly attribute Element? firstElementChild; |
| 79 readonly attribute Element? lastElementChild; |
| 80 readonly attribute unsigned long childElementCount; |
| 81 |
| 82 [Unscopeable] void prepend((Node or DOMString)... nodes); |
| 83 [Unscopeable] void append((Node or DOMString)... nodes); |
| 84 |
| 85 [Unscopeable] Element? query(DOMString relativeSelectors); |
| 86 [NewObject, Unscopeable] Elements queryAll(DOMString relativeSelectors); |
| 87 Element? querySelector(DOMString selectors); |
| 88 [NewObject] NodeList querySelectorAll(DOMString selectors); |
| 89 }; |
| 90 Document implements ParentNode; |
| 91 DocumentFragment implements ParentNode; |
| 92 Element implements ParentNode; |
| 93 |
| 94 [NoInterfaceObject] |
| 95 interface NonDocumentTypeChildNode { |
| 96 readonly attribute Element? previousElementSibling; |
| 97 readonly attribute Element? nextElementSibling; |
| 98 }; |
| 99 Element implements NonDocumentTypeChildNode; |
| 100 CharacterData implements NonDocumentTypeChildNode; |
| 101 |
| 102 [NoInterfaceObject] |
| 103 interface ChildNode { |
| 104 [Unscopeable] void before((Node or DOMString)... nodes); |
| 105 [Unscopeable] void after((Node or DOMString)... nodes); |
| 106 [Unscopeable] void replaceWith((Node or DOMString)... nodes); |
| 107 [Unscopeable] void remove(); |
| 108 }; |
| 109 DocumentType implements ChildNode; |
| 110 Element implements ChildNode; |
| 111 CharacterData implements ChildNode; |
| 112 |
| 113 // XXX unrecognized tokens "class", "extends" |
| 114 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=20020 |
| 115 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=23225 |
| 116 //class Elements extends Array { |
| 117 // Element? query(DOMString relativeSelectors); |
| 118 // Elements queryAll(DOMString relativeSelectors); |
| 119 //}; |
| 120 |
| 121 interface NodeList { |
| 122 getter Node? item(unsigned long index); |
| 123 readonly attribute unsigned long length; |
| 124 // iterable<Node>; |
| 125 }; |
| 126 |
| 127 interface HTMLCollection { |
| 128 readonly attribute unsigned long length; |
| 129 getter Element? item(unsigned long index); |
| 130 getter Element? namedItem(DOMString name); |
| 131 }; |
| 132 |
| 133 [Constructor(MutationCallback callback)] |
| 134 interface MutationObserver { |
| 135 void observe(Node target, MutationObserverInit options); |
| 136 void disconnect(); |
| 137 sequence<MutationRecord> takeRecords(); |
| 138 }; |
| 139 |
| 140 callback MutationCallback = void (sequence<MutationRecord> mutations, MutationOb
server observer); |
| 141 |
| 142 dictionary MutationObserverInit { |
| 143 boolean childList = false; |
| 144 boolean attributes; |
| 145 boolean characterData; |
| 146 boolean subtree = false; |
| 147 boolean attributeOldValue; |
| 148 boolean characterDataOldValue; |
| 149 sequence<DOMString> attributeFilter; |
| 150 }; |
| 151 |
| 152 interface MutationRecord { |
| 153 readonly attribute DOMString type; |
| 154 readonly attribute Node target; |
| 155 [SameObject] readonly attribute NodeList addedNodes; |
| 156 [SameObject] readonly attribute NodeList removedNodes; |
| 157 readonly attribute Node? previousSibling; |
| 158 readonly attribute Node? nextSibling; |
| 159 readonly attribute DOMString? attributeName; |
| 160 readonly attribute DOMString? attributeNamespace; |
| 161 readonly attribute DOMString? oldValue; |
| 162 }; |
| 163 |
| 164 interface Node : EventTarget { |
| 165 const unsigned short ELEMENT_NODE = 1; |
| 166 const unsigned short ATTRIBUTE_NODE = 2; // historical |
| 167 const unsigned short TEXT_NODE = 3; |
| 168 const unsigned short CDATA_SECTION_NODE = 4; // historical |
| 169 const unsigned short ENTITY_REFERENCE_NODE = 5; // historical |
| 170 const unsigned short ENTITY_NODE = 6; // historical |
| 171 const unsigned short PROCESSING_INSTRUCTION_NODE = 7; |
| 172 const unsigned short COMMENT_NODE = 8; |
| 173 const unsigned short DOCUMENT_NODE = 9; |
| 174 const unsigned short DOCUMENT_TYPE_NODE = 10; |
| 175 const unsigned short DOCUMENT_FRAGMENT_NODE = 11; |
| 176 const unsigned short NOTATION_NODE = 12; // historical |
| 177 readonly attribute unsigned short nodeType; |
| 178 readonly attribute DOMString nodeName; |
| 179 |
| 180 readonly attribute DOMString? baseURI; |
| 181 |
| 182 readonly attribute Document? ownerDocument; |
| 183 readonly attribute Node? parentNode; |
| 184 readonly attribute Element? parentElement; |
| 185 boolean hasChildNodes(); |
| 186 [SameObject] readonly attribute NodeList childNodes; |
| 187 readonly attribute Node? firstChild; |
| 188 readonly attribute Node? lastChild; |
| 189 readonly attribute Node? previousSibling; |
| 190 readonly attribute Node? nextSibling; |
| 191 |
| 192 attribute DOMString? nodeValue; |
| 193 attribute DOMString? textContent; |
| 194 void normalize(); |
| 195 |
| 196 [NewObject] Node cloneNode(optional boolean deep = false); |
| 197 boolean isEqualNode(Node? node); |
| 198 |
| 199 const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01; |
| 200 const unsigned short DOCUMENT_POSITION_PRECEDING = 0x02; |
| 201 const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04; |
| 202 const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08; |
| 203 const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10; |
| 204 const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; |
| 205 unsigned short compareDocumentPosition(Node other); |
| 206 boolean contains(Node? other); |
| 207 |
| 208 DOMString? lookupPrefix(DOMString? namespace); |
| 209 DOMString? lookupNamespaceURI(DOMString? prefix); |
| 210 boolean isDefaultNamespace(DOMString? namespace); |
| 211 |
| 212 Node insertBefore(Node node, Node? child); |
| 213 Node appendChild(Node node); |
| 214 Node replaceChild(Node node, Node child); |
| 215 Node removeChild(Node child); |
| 216 }; |
| 217 |
| 218 [Constructor] |
| 219 interface Document : Node { |
| 220 [SameObject] readonly attribute DOMImplementation implementation; |
| 221 readonly attribute DOMString URL; |
| 222 readonly attribute DOMString documentURI; |
| 223 readonly attribute DOMString origin; |
| 224 readonly attribute DOMString compatMode; |
| 225 readonly attribute DOMString characterSet; |
| 226 readonly attribute DOMString charset; // legacy alias of .characterSet |
| 227 readonly attribute DOMString inputEncoding; // legacy alias of .characterSet |
| 228 readonly attribute DOMString contentType; |
| 229 |
| 230 readonly attribute DocumentType? doctype; |
| 231 readonly attribute Element? documentElement; |
| 232 HTMLCollection getElementsByTagName(DOMString localName); |
| 233 HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localNam
e); |
| 234 HTMLCollection getElementsByClassName(DOMString classNames); |
| 235 |
| 236 [NewObject] Element createElement(DOMString localName); |
| 237 [NewObject] Element createElementNS(DOMString? namespace, DOMString qualifiedN
ame); |
| 238 [NewObject] DocumentFragment createDocumentFragment(); |
| 239 [NewObject] Text createTextNode(DOMString data); |
| 240 [NewObject] Comment createComment(DOMString data); |
| 241 [NewObject] ProcessingInstruction createProcessingInstruction(DOMString target
, DOMString data); |
| 242 |
| 243 [NewObject] Node importNode(Node node, optional boolean deep = false); |
| 244 Node adoptNode(Node node); |
| 245 |
| 246 [NewObject] Attr createAttribute(DOMString localName); |
| 247 [NewObject] Attr createAttributeNS(DOMString? namespace, DOMString name); |
| 248 |
| 249 [NewObject] Event createEvent(DOMString interface); |
| 250 |
| 251 [NewObject] Range createRange(); |
| 252 |
| 253 // NodeFilter.SHOW_ALL = 0xFFFFFFFF |
| 254 [NewObject] NodeIterator createNodeIterator(Node root, optional unsigned long
whatToShow = 0xFFFFFFFF, optional NodeFilter? filter = null); |
| 255 [NewObject] TreeWalker createTreeWalker(Node root, optional unsigned long what
ToShow = 0xFFFFFFFF, optional NodeFilter? filter = null); |
| 256 }; |
| 257 |
| 258 interface XMLDocument : Document {}; |
| 259 |
| 260 interface DOMImplementation { |
| 261 [NewObject] DocumentType createDocumentType(DOMString qualifiedName, DOMString
publicId, DOMString systemId); |
| 262 [NewObject] XMLDocument createDocument(DOMString? namespace, [TreatNullAs=Empt
yString] DOMString qualifiedName, optional DocumentType? doctype = null); |
| 263 [NewObject] Document createHTMLDocument(optional DOMString title); |
| 264 |
| 265 boolean hasFeature(); // useless; always returns true |
| 266 }; |
| 267 |
| 268 [Constructor] |
| 269 interface DocumentFragment : Node { |
| 270 }; |
| 271 |
| 272 interface DocumentType : Node { |
| 273 readonly attribute DOMString name; |
| 274 readonly attribute DOMString publicId; |
| 275 readonly attribute DOMString systemId; |
| 276 }; |
| 277 |
| 278 interface Element : Node { |
| 279 readonly attribute DOMString? namespaceURI; |
| 280 readonly attribute DOMString? prefix; |
| 281 readonly attribute DOMString localName; |
| 282 readonly attribute DOMString tagName; |
| 283 |
| 284 attribute DOMString id; |
| 285 attribute DOMString className; |
| 286 [SameObject] readonly attribute DOMTokenList classList; |
| 287 |
| 288 boolean hasAttributes(); |
| 289 [SameObject] readonly attribute NamedNodeMap attributes; |
| 290 DOMString? getAttribute(DOMString name); |
| 291 DOMString? getAttributeNS(DOMString? namespace, DOMString localName); |
| 292 void setAttribute(DOMString name, DOMString value); |
| 293 void setAttributeNS(DOMString? namespace, DOMString name, DOMString value); |
| 294 void removeAttribute(DOMString name); |
| 295 void removeAttributeNS(DOMString? namespace, DOMString localName); |
| 296 boolean hasAttribute(DOMString name); |
| 297 boolean hasAttributeNS(DOMString? namespace, DOMString localName); |
| 298 |
| 299 Attr? getAttributeNode(DOMString name); |
| 300 Attr? getAttributeNodeNS(DOMString? namespace, DOMString localName); |
| 301 Attr? setAttributeNode(Attr attr); |
| 302 Attr? setAttributeNodeNS(Attr attr); |
| 303 Attr removeAttributeNode(Attr attr); |
| 304 |
| 305 Element? closest(DOMString selectors); |
| 306 boolean matches(DOMString selectors); |
| 307 |
| 308 HTMLCollection getElementsByTagName(DOMString localName); |
| 309 HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localNam
e); |
| 310 HTMLCollection getElementsByClassName(DOMString classNames); |
| 311 }; |
| 312 |
| 313 interface NamedNodeMap { |
| 314 readonly attribute unsigned long length; |
| 315 getter Attr? item(unsigned long index); |
| 316 getter Attr? getNamedItem(DOMString name); |
| 317 Attr? getNamedItemNS(DOMString? namespace, DOMString localName); |
| 318 Attr? setNamedItem(Attr attr); |
| 319 Attr? setNamedItemNS(Attr attr); |
| 320 Attr removeNamedItem(DOMString name); |
| 321 Attr removeNamedItemNS(DOMString? namespace, DOMString localName); |
| 322 }; |
| 323 |
| 324 interface Attr { |
| 325 readonly attribute DOMString? namespaceURI; |
| 326 readonly attribute DOMString? prefix; |
| 327 readonly attribute DOMString localName; |
| 328 readonly attribute DOMString name; |
| 329 attribute DOMString value; |
| 330 attribute DOMString nodeValue; // legacy alias of .value |
| 331 attribute DOMString textContent; // legacy alias of .value |
| 332 |
| 333 readonly attribute Element? ownerElement; |
| 334 |
| 335 readonly attribute boolean specified; // useless; always returns true |
| 336 }; |
| 337 |
| 338 interface CharacterData : Node { |
| 339 [TreatNullAs=EmptyString] attribute DOMString data; |
| 340 readonly attribute unsigned long length; |
| 341 DOMString substringData(unsigned long offset, unsigned long count); |
| 342 void appendData(DOMString data); |
| 343 void insertData(unsigned long offset, DOMString data); |
| 344 void deleteData(unsigned long offset, unsigned long count); |
| 345 void replaceData(unsigned long offset, unsigned long count, DOMString data); |
| 346 }; |
| 347 |
| 348 [Constructor(optional DOMString data = "")] |
| 349 interface Text : CharacterData { |
| 350 [NewObject] Text splitText(unsigned long offset); |
| 351 readonly attribute DOMString wholeText; |
| 352 }; |
| 353 |
| 354 interface ProcessingInstruction : CharacterData { |
| 355 readonly attribute DOMString target; |
| 356 }; |
| 357 |
| 358 [Constructor(optional DOMString data = "")] |
| 359 interface Comment : CharacterData { |
| 360 }; |
| 361 |
| 362 [Constructor] |
| 363 interface Range { |
| 364 readonly attribute Node startContainer; |
| 365 readonly attribute unsigned long startOffset; |
| 366 readonly attribute Node endContainer; |
| 367 readonly attribute unsigned long endOffset; |
| 368 readonly attribute boolean collapsed; |
| 369 readonly attribute Node commonAncestorContainer; |
| 370 |
| 371 void setStart(Node node, unsigned long offset); |
| 372 void setEnd(Node node, unsigned long offset); |
| 373 void setStartBefore(Node node); |
| 374 void setStartAfter(Node node); |
| 375 void setEndBefore(Node node); |
| 376 void setEndAfter(Node node); |
| 377 void collapse(optional boolean toStart = false); |
| 378 void selectNode(Node node); |
| 379 void selectNodeContents(Node node); |
| 380 |
| 381 const unsigned short START_TO_START = 0; |
| 382 const unsigned short START_TO_END = 1; |
| 383 const unsigned short END_TO_END = 2; |
| 384 const unsigned short END_TO_START = 3; |
| 385 short compareBoundaryPoints(unsigned short how, Range sourceRange); |
| 386 |
| 387 void deleteContents(); |
| 388 [NewObject] DocumentFragment extractContents(); |
| 389 [NewObject] DocumentFragment cloneContents(); |
| 390 void insertNode(Node node); |
| 391 void surroundContents(Node newParent); |
| 392 |
| 393 [NewObject] Range cloneRange(); |
| 394 void detach(); |
| 395 |
| 396 boolean isPointInRange(Node node, unsigned long offset); |
| 397 short comparePoint(Node node, unsigned long offset); |
| 398 |
| 399 boolean intersectsNode(Node node); |
| 400 |
| 401 stringifier; |
| 402 }; |
| 403 |
| 404 interface NodeIterator { |
| 405 [SameObject] readonly attribute Node root; |
| 406 readonly attribute Node referenceNode; |
| 407 readonly attribute boolean pointerBeforeReferenceNode; |
| 408 readonly attribute unsigned long whatToShow; |
| 409 readonly attribute NodeFilter? filter; |
| 410 |
| 411 Node? nextNode(); |
| 412 Node? previousNode(); |
| 413 |
| 414 void detach(); |
| 415 }; |
| 416 |
| 417 interface TreeWalker { |
| 418 [SameObject] readonly attribute Node root; |
| 419 readonly attribute unsigned long whatToShow; |
| 420 readonly attribute NodeFilter? filter; |
| 421 attribute Node currentNode; |
| 422 |
| 423 Node? parentNode(); |
| 424 Node? firstChild(); |
| 425 Node? lastChild(); |
| 426 Node? previousSibling(); |
| 427 Node? nextSibling(); |
| 428 Node? previousNode(); |
| 429 Node? nextNode(); |
| 430 }; |
| 431 |
| 432 callback interface NodeFilter { |
| 433 // Constants for acceptNode() |
| 434 const unsigned short FILTER_ACCEPT = 1; |
| 435 const unsigned short FILTER_REJECT = 2; |
| 436 const unsigned short FILTER_SKIP = 3; |
| 437 |
| 438 // Constants for whatToShow |
| 439 const unsigned long SHOW_ALL = 0xFFFFFFFF; |
| 440 const unsigned long SHOW_ELEMENT = 0x1; |
| 441 const unsigned long SHOW_ATTRIBUTE = 0x2; // historical |
| 442 const unsigned long SHOW_TEXT = 0x4; |
| 443 const unsigned long SHOW_CDATA_SECTION = 0x8; // historical |
| 444 const unsigned long SHOW_ENTITY_REFERENCE = 0x10; // historical |
| 445 const unsigned long SHOW_ENTITY = 0x20; // historical |
| 446 const unsigned long SHOW_PROCESSING_INSTRUCTION = 0x40; |
| 447 const unsigned long SHOW_COMMENT = 0x80; |
| 448 const unsigned long SHOW_DOCUMENT = 0x100; |
| 449 const unsigned long SHOW_DOCUMENT_TYPE = 0x200; |
| 450 const unsigned long SHOW_DOCUMENT_FRAGMENT = 0x400; |
| 451 const unsigned long SHOW_NOTATION = 0x800; // historical |
| 452 |
| 453 unsigned short acceptNode(Node node); |
| 454 }; |
| 455 |
| 456 interface DOMTokenList { |
| 457 readonly attribute unsigned long length; |
| 458 getter DOMString? item(unsigned long index); |
| 459 boolean contains(DOMString token); |
| 460 void add(DOMString... tokens); |
| 461 void remove(DOMString... tokens); |
| 462 boolean toggle(DOMString token, optional boolean force); |
| 463 stringifier; |
| 464 // iterable<DOMString>; |
| 465 }; |
| 466 |
| 467 interface DOMSettableTokenList : DOMTokenList { |
| 468 attribute DOMString value; |
| 469 }; |
| 470 </script> |
| 471 <script> |
| 472 "use strict"; |
| 473 var xmlDoc, detachedRange, element; |
| 474 var idlArray; |
| 475 setup(function() { |
| 476 xmlDoc = document.implementation.createDocument(null, "", null); |
| 477 detachedRange = document.createRange(); |
| 478 detachedRange.detach(); |
| 479 element = xmlDoc.createElementNS(null, "test"); |
| 480 element.setAttribute("bar", "baz"); |
| 481 |
| 482 idlArray = new IdlArray(); |
| 483 idlArray.add_idls(document.querySelector("script[type=text\\/plain]").textCont
ent); |
| 484 idlArray.add_objects({ |
| 485 Event: ['document.createEvent("Event")', 'new Event("foo")'], |
| 486 CustomEvent: ['new CustomEvent("foo")'], |
| 487 XMLDocument: ['xmlDoc'], |
| 488 DOMImplementation: ['document.implementation'], |
| 489 DocumentFragment: ['document.createDocumentFragment()'], |
| 490 DocumentType: ['document.doctype'], |
| 491 Element: ['element'], |
| 492 Attr: ['document.querySelector("[id]").attributes[0]'], |
| 493 Text: ['document.createTextNode("abc")'], |
| 494 ProcessingInstruction: ['xmlDoc.createProcessingInstruction("abc", "def")'], |
| 495 Comment: ['document.createComment("abc")'], |
| 496 Range: ['document.createRange()', 'detachedRange'], |
| 497 NodeIterator: ['document.createNodeIterator(document.body, NodeFilter.SHOW_A
LL, null, false)'], |
| 498 TreeWalker: ['document.createTreeWalker(document.body, NodeFilter.SHOW_ALL,
null, false)'], |
| 499 NodeList: ['document.querySelectorAll("script")'], |
| 500 HTMLCollection: ['document.body.children'], |
| 501 DOMTokenList: ['document.body.classList'], |
| 502 }); |
| 503 }); |
| 504 idlArray.test(); |
| 505 </script> |
OLD | NEW |