Parcourir la source

LibWeb/Tests: Add a basic set of tests for document.all

Shannon Booth il y a 1 an
Parent
commit
851114e462

+ 33 - 0
Tests/LibWeb/Text/expected/HTML/HTMLAllCollection-basic.txt

@@ -0,0 +1,33 @@
+      HTMLAllCollection
+typeof document.all = undefined
+equal to undefined = true
+equal to null = true
+strictly equal to undefined = false
+strictly equal to null = false
+is an html collection = true
+length = 9
+out of range (9)  = undefined
+out of range (-1) = undefined
+item #0 = [object HTMLHtmlElement], id = '', name = 'undefined'
+item #1 = [object HTMLHeadElement], id = '', name = 'undefined'
+item #2 = [object HTMLBodyElement], id = '', name = 'undefined'
+item #3 = [object HTMLFormElement], id = '', name = ''
+item #4 = [object HTMLInputElement], id = 'formcontrol', name = 'one'
+item #5 = [object HTMLInputElement], id = 'formcontrol', name = 'two'
+item #6 = [object HTMLScriptElement], id = '', name = 'undefined'
+item #7 = [object HTMLScriptElement], id = '', name = 'undefined'
+item #8 = [object HTMLPreElement], id = 'out', name = 'undefined'
+From good string index = [object HTMLInputElement], name = one
+From bad string index = undefined
+[object HTMLInputElement], name one
+[object HTMLInputElement], name two
+undefined
+[object HTMLCollection], length = 2
+first = [object HTMLInputElement]
+second = [object HTMLInputElement]
+namedItem('one') = [object HTMLInputElement]
+namedItem('1') = null
+namedItem('not in list') = null
+item() = null
+item('1') = [object HTMLHeadElement]
+namedItem(2) = [object HTMLBodyElement]

+ 54 - 0
Tests/LibWeb/Text/input/HTML/HTMLAllCollection-basic.html

@@ -0,0 +1,54 @@
+<form>
+  <input name="one" id="formcontrol" type="button" />
+  <input name="two" id="formcontrol" type="text" />
+</form>
+
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        println(document.all.constructor.name);
+        println(`typeof document.all = ${typeof document.all}`);
+        println(`equal to undefined = ${document.all == undefined}`);
+        println(`equal to null = ${document.all == null}`);
+        println(`strictly equal to undefined = ${document.all === undefined}`);
+        println(`strictly equal to null = ${document.all === null}`);
+
+        println(`is an html collection = ${document.all instanceof HTMLAllCollection}`);
+        println(`length = ${document.all.length}`);
+        println(`out of range (9)  = ${document.all[9]}`);
+        println(`out of range (-1) = ${document.all[-1]}`);
+
+        // All items
+        for (let i = 0; i < document.all.length; i++) {
+            const item = document.all[i];
+            println(`item #${i} = ${item}, id = '${item.id}', name = '${item.name}'`);
+        }
+
+        // String-like
+        println(`From good string index = ${document.all["4"]}, name = ${document.all["4"].name}`);
+        println(`From bad string index = ${document.all["50"]}`);
+
+        // Single lookup
+        println(`${document.all.one}, name ${document.all.one.name}`);
+        println(`${document.all.two}, name ${document.all.two.name}`);
+
+        // No match
+        println(document.all.nomatch);
+
+        // Matching multiple
+        const subcollection = document.all.formcontrol;
+        println(`${subcollection}, length = ${subcollection.length}`);
+        println(`first = ${subcollection[0]}`);
+        println(`second = ${subcollection[1]}`);
+
+        // Explicit named item call
+        println(`namedItem('one') = ${document.all.namedItem('one')}`);
+        println(`namedItem('1') = ${document.all.namedItem('1')}`);
+        println(`namedItem('not in list') = ${document.all.namedItem('not in list')}`);
+
+        // Explicit item call
+        println(`item() = ${document.all.item()}`);
+        println(`item('1') = ${document.all.item('1')}`);
+        println(`namedItem(2) = ${document.all.item(2)}`);
+    });
+</script>