File: select-parsing.tentative.html

package info (click to toggle)
firefox-esr 140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,539,276 kB
  • sloc: cpp: 7,381,286; javascript: 6,388,710; ansic: 3,710,139; python: 1,393,780; xml: 628,165; asm: 426,918; java: 184,004; sh: 65,742; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (174 lines) | stat: -rw-r--r-- 5,170 bytes parent folder | download | duplicates (8)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=help href="https://github.com/whatwg/html/issues/9799">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>

<select class=test
    data-description='<div>s, <button>s, and <datalist>s should be allowed in <select>'
    data-expect='
      <div>div 1</div>
      <button>button</button>
      <div>div 2</div>
      <datalist>
        <option>option</option>
      </datalist>
      <div>div 3</div>
      '>
  <div>div 1</div>
  <button>button</button>
  <div>div 2</div>
  <datalist>
    <option>option</option>
  </datalist>
  <div>div 3</div>
</select>

<select class=test
    data-description='</select> should close <button>'
    data-expect='<button>button</button>'>
  <button>button
</select>

<select class=test
    data-description='</select> should close <datalist>'
    data-expect='<datalist>datalist</datalist>'>
  <datalist>datalist
</select>

<select id=nested1 class=test
    data-description='<select> in <button> in <select> should remove inner <select>'
    data-expect='<button></button>'>
  <button>
    <select id=expectafter1></select>
    <div id=expectafter1b></div>
  </button>
</select>

<select id=nested2 class=test
    data-description='<select> in <select><button><div> should remove inner <select>'
    data-expect='<button><div></div></button>'>
  <button>
    <div>
      <select id=expectafter2>
</select>

<select
  id=nested3
  class=test
  data-description='JS added nested <select> should be ignored'
  data-expect='<option>The Initial Option</option>'
>
  <option>The Initial Option</option>
</select>

<select
  id=nested4
  class=test
  data-description='JS added nested <select>s should be ignored'
  data-expect='<option>The Initial Option</option>'
>
  <option>The Initial Option</option>
</select>

<select class=test
    data-description='Divs and imgs should be allowed as direct children of select and within options without a datalist'
    data-expect='
    <div>
      <option><img>option</option>
    </div>'>
  <div>
    <option><img>option</option>
  </div>
</select>

<select class=test
    data-description='Input tags should not parse inside select instead of closing the select'
    data-expect=''>
    <input>
</select>

<select class=test
    data-description='textarea tags should parse inside select instead of closing the select'
    data-expect='<textarea></textarea>'>
    <textarea></textarea>
</select>

<select class=test
    data-description='Input tags should parse inside select if nested in another tag'
    data-expect='<div><input></div>'>
  <div>
    <input>
  </div>
</select>

<select class=test
        data-description='Input tags should close select when directly inside an <option>'
        data-expect='<option></option>'>
  <option>
    <input>
  </option>
</select>

<div id=afterlast>
  keep this div after the last test case
</div>

<script>
function removeWhitespace(t) {
  return t.replace(/\s/g,'');
}
document.querySelectorAll('select.test').forEach(s => {
  assert_true(!!s.dataset.description.length);
  test(() => {
    // The document.body check here and in the other tests is to make sure that a
    // previous test case didn't leave the HTML parser open on another element.
    assert_equals(s.parentNode, document.body);
    assert_equals(removeWhitespace(s.innerHTML),removeWhitespace(s.dataset.expect));
  },s.dataset.description)
});

test(() => {
  assert_equals(document.getElementById('afterlast').parentNode, document.body);
}, 'The last test should not leave any tags open after parsing');

test(() => {
  const outerSelect = document.getElementById('nested1');
  const innerSelect = document.getElementById('expectafter1');
  const nextDiv = document.getElementById('expectafter1b');
  assert_true(!!outerSelect);
  assert_equals(innerSelect, null,'Nested select should be removed');
  assert_equals(outerSelect.nextElementSibling, nextDiv,'Subsequent content is there too');
}, 'Nested selects should be retained 1');

test(() => {
  const outerSelect = document.getElementById('nested2');
  const innerSelect = document.getElementById('expectafter2');
  assert_true(!!outerSelect);
  assert_equals(innerSelect, null,'Nested select should be pushed out as the next sibling');
}, 'Nested selects should be retained 2');

test(() => {
  assert_true(!!nested3);
  nested3.innerHTML = '<select id="ignored"><option>The New Option</option></select>';

  const ignored = document.getElementById('ignored');
  assert_equals(ignored, null);

  assert_equals(nested3.innerHTML, '<option>The New Option</option>');
}, 'JS added nested select should be ignored');

test(() => {
  assert_true(!!nested4);
  nested4.innerHTML = '<select id="ignore1"><select id="ignore2"><option>The New Option</option></select></select>';

  const ignored1 = document.getElementById('ignored1');
  assert_equals(ignored1, null);
  const ignored2 = document.getElementById('ignored2');
  assert_equals(ignored2, null);

  assert_equals(nested4.innerHTML, '<option>The New Option</option>');
}, 'JS added nested selects should be ignored');
</script>