File: patch-range.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (137 lines) | stat: -rw-r--r-- 7,190 bytes parent folder | download | duplicates (5)
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
<!DOCTYPE HTML>
<meta charset="utf-8" />
<title>HTML partial updates - patch range</title>
<link rel=help href="https://github.com/WICG/declarative-partial-updates">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="placeholder">
    <span id="first"></span>
    <span id="last"></span>
</div>
<style id="style"></style>
<p id="target"></p>
<script>

promise_test(async t => {
    const placeholder = document.querySelector("#placeholder");
    const before = placeholder.innerHTML;
    t.add_cleanup(() => { placeholder.innerHTML = before });
    const first = document.querySelector("#first");
    const last = document.querySelector("#last");
    const writable = placeholder.patchBetween(first, last);
    const response = new Response("<span id=middle>Content</span>", {headers: {"Content-Type": "text/html"}});
    response.body.pipeTo(writable);
    assert_true(placeholder.currentPatch instanceof Patch, "currentPatch should be a Patch right after connecting a stream");
    await placeholder.currentPatch.finished;
    assert_equals(placeholder.currentPatch, null);
    const middle = placeholder.querySelector("#middle");
    assert_true(middle instanceof HTMLSpanElement);
    assert_equals(middle.textContent, "Content");
    assert_equals(middle.previousElementSibling, first);
    assert_equals(middle.nextElementSibling, last);
}, "using patchBetween() to insert an element betwen two other elements");

promise_test(async t => {
    const placeholder = document.querySelector("#placeholder");
    const before = placeholder.innerHTML;
    t.add_cleanup(() => { placeholder.innerHTML = before });
    const first = document.querySelector("#first");
    const last = document.querySelector("#last");
    const writable = placeholder.patchAfter(first);
    const response = new Response("<span id=middle>Content</span>", {headers: {"Content-Type": "text/html"}});
    response.body.pipeTo(writable);
    assert_true(placeholder.currentPatch instanceof Patch, "currentPatch should be a Patch right after connecting a stream");
    await placeholder.currentPatch.finished;
    assert_equals(placeholder.currentPatch, null);
    const middle = placeholder.querySelector("#middle");
    assert_true(middle instanceof HTMLSpanElement);
    assert_equals(middle.textContent, "Content");
    assert_equals(middle.previousElementSibling, first);
    assert_equals(middle.nextElementSibling, null);
}, "using patchAfter() to insert an element after another element");

promise_test(async t => {
    const placeholder = document.querySelector("#placeholder");
    const before = placeholder.innerHTML;
    t.add_cleanup(() => { placeholder.innerHTML = before });
    const first = document.querySelector("#first");
    const last = document.querySelector("#last");
    const writable = placeholder.patchBefore(last);
    const response = new Response("<span id=middle>Content</span>", {headers: {"Content-Type": "text/html"}});
    response.body.pipeTo(writable);
    assert_true(placeholder.currentPatch instanceof Patch, "currentPatch should be a Patch right after connecting a stream");
    await placeholder.currentPatch.finished;
    assert_equals(placeholder.currentPatch, null);
    const middle = placeholder.querySelector("#middle");
    assert_true(middle instanceof HTMLSpanElement);
    assert_equals(middle.textContent, "Content");
    assert_equals(middle.previousElementSibling, null);
    assert_equals(middle.nextElementSibling, last);
}, "using patchBefore() to insert an element before another element");

promise_test(async t => {
    const placeholder = document.querySelector("#placeholder");
    const before = placeholder.innerHTML;
    t.add_cleanup(() => { placeholder.innerHTML = before });
    const first = document.querySelector("#first");
    const last = document.querySelector("#last");
    const writable = placeholder.patchAfter(last);
    const response = new Response("<span id=middle>Content</span>", {headers: {"Content-Type": "text/html"}});
    response.body.pipeTo(writable);
    assert_true(placeholder.currentPatch instanceof Patch, "currentPatch should be a Patch right after connecting a stream");
    await placeholder.currentPatch.finished;
    assert_equals(placeholder.currentPatch, null);
    const middle = placeholder.querySelector("#middle");
    assert_true(middle instanceof HTMLSpanElement);
    assert_equals(middle.textContent, "Content");
    assert_equals(middle.previousElementSibling, last);
    assert_equals(middle.nextElementSibling, null);
}, "using patchAfter() to insert an element after the last element");

promise_test(async t => {
    const placeholder = document.querySelector("#placeholder");
    const before = placeholder.innerHTML;
    t.add_cleanup(() => { placeholder.innerHTML = before });
    const first = document.querySelector("#first");
    const last = document.querySelector("#last");
    const writable = placeholder.patchBefore(first);
    const response = new Response("<span id=middle>Content</span>", {headers: {"Content-Type": "text/html"}});
    response.body.pipeTo(writable);
    assert_true(placeholder.currentPatch instanceof Patch, "currentPatch should be a Patch right after connecting a stream");
    await placeholder.currentPatch.finished;
    assert_equals(placeholder.currentPatch, null);
    const middle = placeholder.querySelector("#middle");
    assert_true(middle instanceof HTMLSpanElement);
    assert_equals(middle.textContent, "Content");
    assert_equals(middle.previousElementSibling, null);
    assert_equals(middle.nextElementSibling, first);
}, "using patchBefore() to insert an element before the first element");

promise_test(async t => {
    const placeholder = document.querySelector("#placeholder");
    const before = placeholder.innerHTML;
    t.add_cleanup(() => { placeholder.innerHTML = before });
    const first = document.querySelector("#first");
    const writable = placeholder.patchBefore(first);
    const response = new Response("<span id=middle>Content</span>", {headers: {"Content-Type": "text/html"}});
    first.remove();
    const {finished} = placeholder.currentPatch;
    await promise_rejects_dom(t, "NotFoundError", response.body.pipeTo(writable));
    await promise_rejects_dom(t, "NotFoundError", finished);
}, "using patchBefore() should fail if the reference node is removed while patching");

promise_test(async t => {
    const placeholder = document.querySelector("#placeholder");
    const before = placeholder.innerHTML;
    t.add_cleanup(() => { placeholder.innerHTML = before });
    const first = document.querySelector("#first");
    const last = document.querySelector("#last");
    const writable = placeholder.patchBetween(first, last);
    const response = new Response("<span id=middle>Content</span>", {headers: {"Content-Type": "text/html"}});
    last.remove();
    const {finished} = placeholder.currentPatch;
    await promise_rejects_dom(t, "NotFoundError", response.body.pipeTo(writable));
    await promise_rejects_dom(t, "NotFoundError", finished);
}, "using patchBetween() should fail if the 'before' node is removed while patching");

</script>