File: common-HTMLOptionsCollection-add.html

package info (click to toggle)
thunderbird 1%3A60.9.0-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,339,492 kB
  • sloc: cpp: 5,457,040; ansic: 2,360,385; python: 596,167; asm: 340,963; java: 326,296; xml: 258,830; sh: 84,445; makefile: 23,705; perl: 17,317; objc: 3,768; yacc: 1,766; ada: 1,681; lex: 1,364; pascal: 1,264; cs: 879; exp: 527; php: 436; lisp: 258; ruby: 153; awk: 152; sed: 53; csh: 27
file content (89 lines) | stat: -rw-r--r-- 2,626 bytes parent folder | download | duplicates (30)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title id='title'>HTMLOptionsCollection</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<select id="selly">
  <option id="id1" name="name1">1</option>
  <option id="id2" name="name2">2</option>
  <option id="id3" name="name3">3</option>
  <option id="id4" name="name4">4</option>
  <optgroup id="og1">
    <option name="nameonly">n1</option>
    <option id="id5">5</option>
  </optgroup>
  <optgroup id="og2">
    <option name="nameonly">n2</option>
    <option id="id6">6</option>
  </optgroup>

</select>

<script>
var selly;
setup(function() {
    selly = document.getElementById('selly');
});

test(function () {
    var option = document.getElementById('id1');
    var optgroup = document.getElementById('og1');
    selly.options.add(option, option);
    selly.options.add(optgroup, optgroup);
    assert_equals(selly.children.length, 6);
    assert_equals(selly.length, 8);
}, "if before and node are the same element nothing should be done");

test(function () {
    var o1 = document.createElement("option");
    o1.value = "a";
    var o2 = document.createElement("option");
    o2.value = "b";
    var o3 = document.createElement("option");
    o3.value = "c";
    var optgroup = document.getElementById('og1');
    selly.options.add(o1, null);
    selly.options.add(o2, optgroup);
    selly.options.add(o3, 0);

    var elarray = [];
    for (var i = 0; i < selly.length; i++) {
        elarray.push(selly[i].value);
    }
    assert_array_equals(elarray, ["c", "1", "2", "3", "4", "b", "n1", "5", "n2", "6", "a"]);
}, "add method should add option elements correctly");

test(function () {
    var og1 = document.createElement("optgroup");
    var o1 = document.createElement("option");
    o1.value = "a";
    o1.appendChild(og1);
    var og2 = document.createElement("optgroup");
    var o2 = document.createElement("option");
    o2.value = "b";
    o2.appendChild(og2);
    var og3 = document.createElement("optgroup");
    var o3 = document.createElement("option");
    o3.value = "c";
    o3.appendChild(og3);

    var optgroup = document.getElementById('og1');
    selly.options.add(og1, null);
    selly.options.add(og2, optgroup);
    selly.options.add(og3, 0);

    var elarray = [];
    for (var i = 0; i < selly.length; i++) {
        elarray.push(selly[i].value);
    }
    assert_array_equals(elarray, ["c", "1", "2", "3", "4", "b", "n1", "5", "n2", "6", "a"]);
}, "add method should add option groups correctly");

</script>
</body>
</html>