File: dynamic-getter.html

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (88 lines) | stat: -rw-r--r-- 2,908 bytes parent folder | download | duplicates (23)
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
<!DOCTYPE html>
<title>innerText/outerText getter test with dynamic style changes</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="container"></div>
<script>
let container = document.querySelector('#container');

function testText(html, expectedPlain, msg, mutate) {
  test(function() {
    container.innerHTML = html;

    // Cause a flush of style and layout
    document.body.offsetTop;

    mutate();

    var e = document.getElementById('target');
    if (!e) {
      e = container.firstChild;
    }
    assert_equals(e.innerText, expectedPlain, "innerText");
    assert_equals(e.outerText, expectedPlain, "outerText");
    container.textContext = '';
  }, msg + ' (' + format_value(html) + ')');
}

function setStyle(id, attr, value) {
  let el = document.getElementById(id);
  if (el) {
    el.style[attr] = value;
  }
}

testText("<div id='target'><div id='child'>abc", "ABC",
         "text-transform applied to child element", function() {
           setStyle("child", "text-transform", "uppercase");
         });
testText("<div id='parent'><div id='target'>abc", "ABC",
         "text-transform applied to parent element", function() {
           setStyle("parent", "text-transform", "uppercase");
         });

testText("<div id='target'>abc<div id='child'>def", "abc",
         "display: none applied to child element", function() {
           setStyle("child", "display", "none");
         });
testText("<div id='parent'>invisible<div id='target'>abc", "abc",
         "display: none applied to parent element", function() {
           setStyle("parent", "display", "none");
         });

testText("<div id='target'>abc", "abc\ndef",
         "insert node into sub-tree", function() {
           let el = document.getElementById("target");
           if (el) {
             let c = document.createTextNode("def");
             let d = document.createElement("div");
             d.appendChild(c);
             el.appendChild(d);
           }
         });

testText("<div id='target'>abc<div id='remove'>def", "abc",
         "remove node from sub-tree", function() {
           let el = document.getElementById("target");
           let victim = document.getElementById("remove");
           if (el && victim) {
             el.removeChild(victim);
           }
         });

testText("<div id='target'>", "abcdef",
         "insert whole sub-tree", function() {
           var el = document.getElementById("target");
           if (el) {
             var def = document.createTextNode("def");
             var s = document.createElement("span");
             s.appendChild(def);

             var abc = document.createTextNode("abc");
             var d = document.createElement("div");
             d.appendChild(abc);
             d.appendChild(s);
             el.appendChild(d);
           }
         });
</script>