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
|
"use strict";
var { LabelUtils } = ChromeUtils.importESModule(
"resource://gre/modules/shared/LabelUtils.sys.mjs"
);
const TESTCASES = [
{
description: "A label element contains one input element.",
document: `<label id="typeA"> label type A
<!-- This comment should not be extracted. -->
<input type="text">
<script>FOO</script>
<noscript>FOO</noscript>
<option>FOO</option>
<style>FOO</style>
</label>`,
inputId: "typeA",
expectedStrings: ["label type A"],
},
{
description: "A label element with inner div contains one input element.",
document: `<label id="typeB"> label type B
<!-- This comment should not be extracted. -->
<script>FOO</script>
<noscript>FOO</noscript>
<option>FOO</option>
<style>FOO</style>
<div> inner div
<input type="text">
</div>
</label>`,
inputId: "typeB",
expectedStrings: ["label type B", "inner div"],
},
{
description:
"A label element with inner prefix/postfix strings contains span elements.",
document: `<label id="typeC"> label type C
<!-- This comment should not be extracted. -->
<script>FOO</script>
<noscript>FOO</noscript>
<option>FOO</option>
<style>FOO</style>
<div> inner div prefix
<span>test C-1 </span>
<span> test C-2</span>
inner div postfix
</div>
</label>`,
inputId: "typeC",
expectedStrings: [
"label type C",
"inner div prefix",
"test C-1",
"test C-2",
"inner div postfix",
],
},
];
TESTCASES.forEach(testcase => {
add_task(async function () {
info("Starting testcase: " + testcase.description);
LabelUtils._labelStrings = new WeakMap();
let doc = MockDocument.createTestDocument(
"http://localhost:8080/test/",
testcase.document
);
let element = doc.getElementById(testcase.inputId);
let strings = LabelUtils.extractLabelStrings(element);
Assert.deepEqual(strings, testcase.expectedStrings);
});
});
|