OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <script src="../../resources/testharness.js"></script> | 2 <script src="../../resources/testharness.js"></script> |
3 <script src="../../resources/testharnessreport.js"></script> | 3 <script src="../../resources/testharnessreport.js"></script> |
4 <script src="../assert_selection.js"></script> | 4 <script src="../assert_selection.js"></script> |
5 <script> | 5 <script> |
6 function swapMarks(string) { | 6 function swapMarks(string) { |
7 return string.replace('^', '$').replace('|', '^').replace('$', '|'); | 7 return string.replace('^', '$').replace('|', '^').replace('$', '|'); |
8 } | 8 } |
9 | 9 |
10 function test_selection(sample, closure, expected, description) { | 10 function test_selection(sample, closure, expected, description) { |
11 test(() => assert_selection(sample, closure, expected), | 11 test(() => assert_selection(sample, closure, expected), |
12 description + '; anchor is first'); | 12 description + '; anchor is first'); |
13 test(() => assert_selection(swapMarks(sample), closure, swapMarks(expected))
, | 13 test(() => assert_selection(swapMarks(sample), closure, swapMarks(expected))
, |
14 description + '; focus is first'); | 14 description + '; focus is first'); |
15 } | 15 } |
16 | 16 |
17 test_selection( | 17 test_selection( |
18 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 18 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
19 selection => selection.document.querySelector('span').remove(), | 19 selection => selection.document.querySelector('span').remove(), |
20 '<div contenteditable>^ wo|rld</div>', | 20 '<div contenteditable> ^wo|rld</div>', |
21 'Remove the parent of startContainer'); | 21 'Remove the parent of startContainer'); |
22 | 22 |
23 // set nodeValue | 23 // set nodeValue |
24 test_selection( | 24 test_selection( |
25 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 25 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
26 selection => selection.document.querySelector('span').firstChild.nodeValue =
'a', | 26 selection => selection.document.querySelector('span').firstChild.nodeValue =
'a', |
27 '<div contenteditable><span>^a</span> wo|rld</div>', | 27 '<div contenteditable><span>^a</span> wo|rld</div>', |
28 'Replace nodeValue of startContainer'); | 28 'Replace nodeValue of startContainer'); |
29 | 29 |
30 test_selection( | 30 test_selection( |
31 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 31 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
32 selection => selection.document.querySelector('div').lastChild.nodeValue = '
a', | 32 selection => selection.document.querySelector('div').lastChild.nodeValue = '
a', |
33 '<div contenteditable><span>he^llo</span>|a</div>', | 33 '<div contenteditable><span>he^llo|</span>a</div>', |
34 'Replace nodeValue of endContainer'); | 34 'Replace nodeValue of endContainer'); |
35 | 35 |
36 // appendData | 36 // appendData |
37 test_selection( | 37 test_selection( |
38 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 38 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
39 selection => selection.document.querySelector('span').firstChild.appendData(
' xyz'), | 39 selection => selection.document.querySelector('span').firstChild.appendData(
' xyz'), |
40 '<div contenteditable><span>he^llo xyz</span> wo|rld</div>', | 40 '<div contenteditable><span>he^llo xyz</span> wo|rld</div>', |
41 'Appending " xyz" to startContainer'); | 41 'Appending " xyz" to startContainer'); |
42 | 42 |
43 test_selection( | 43 test_selection( |
(...skipping 24 matching lines...) Expand all Loading... |
68 test_selection( | 68 test_selection( |
69 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 69 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
70 selection => selection.document.querySelector('div').lastChild.insertData(3,
' xyz'), | 70 selection => selection.document.querySelector('div').lastChild.insertData(3,
' xyz'), |
71 '<div contenteditable><span>he^llo</span> wo| xyzrld</div>', | 71 '<div contenteditable><span>he^llo</span> wo| xyzrld</div>', |
72 'Inserting " xyz" to endContainer before the after point'); | 72 'Inserting " xyz" to endContainer before the after point'); |
73 | 73 |
74 // deleteData | 74 // deleteData |
75 test_selection( | 75 test_selection( |
76 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 76 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
77 selection => selection.document.querySelector('span').firstChild.deleteData(
1, 4), | 77 selection => selection.document.querySelector('span').firstChild.deleteData(
1, 4), |
78 '<div contenteditable><span>h^</span> wo|rld</div>', | 78 '<div contenteditable><span>h</span>^ wo|rld</div>', |
79 'deleteData(1, 4) in startContainer'); | 79 'deleteData(1, 4) in startContainer'); |
80 | 80 |
81 test_selection( | 81 test_selection( |
82 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 82 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
83 selection => selection.document.querySelector('div').lastChild.deleteData(1,
4), | 83 selection => selection.document.querySelector('div').lastChild.deleteData(1,
4), |
84 '<div contenteditable><span>he^llo</span> |d</div>', | 84 '<div contenteditable><span>he^llo</span> |d</div>', |
85 'deleteData(1, 4) in endContainer'); | 85 'deleteData(1, 4) in endContainer'); |
86 | 86 |
87 test_selection( | 87 test_selection( |
88 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 88 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
89 selection => selection.document.querySelector('span').firstChild.deleteData(
0, 3), | 89 selection => selection.document.querySelector('span').firstChild.deleteData(
0, 3), |
90 '<div contenteditable><span>^lo</span> wo|rld</div>', | 90 '<div contenteditable><span>^lo</span> wo|rld</div>', |
91 'deleteData(0, 3) in startContainer'); | 91 'deleteData(0, 3) in startContainer'); |
92 | 92 |
93 test_selection( | 93 test_selection( |
94 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 94 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
95 selection => selection.document.querySelector('div').lastChild.deleteData(0,
3), | 95 selection => selection.document.querySelector('div').lastChild.deleteData(0,
3), |
96 '<div contenteditable><span>he^llo</span>|rld</div>', | 96 '<div contenteditable><span>he^llo|</span>rld</div>', |
97 'deleteData(0, 3) in endContainer'); | 97 'deleteData(0, 3) in endContainer'); |
98 | 98 |
99 test_selection( | 99 test_selection( |
100 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 100 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
101 selection => selection.document.querySelector('span').firstChild.deleteData(
0, 2), | 101 selection => selection.document.querySelector('span').firstChild.deleteData(
0, 2), |
102 '<div contenteditable><span>^llo</span> wo|rld</div>', | 102 '<div contenteditable><span>^llo</span> wo|rld</div>', |
103 'deleteData(0, 2) in startContainer'); | 103 'deleteData(0, 2) in startContainer'); |
104 | 104 |
105 test_selection( | 105 test_selection( |
106 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 106 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 '<div contenteditable><span>he^l12</span> wo|rld</div>', | 170 '<div contenteditable><span>he^l12</span> wo|rld</div>', |
171 'replaceData(3, 2, "12") in startContainer'); | 171 'replaceData(3, 2, "12") in startContainer'); |
172 | 172 |
173 test_selection( | 173 test_selection( |
174 '<div contenteditable><span>he^llo</span> wo|rld</div>', | 174 '<div contenteditable><span>he^llo</span> wo|rld</div>', |
175 selection => selection.document.querySelector('div').lastChild | 175 selection => selection.document.querySelector('div').lastChild |
176 .replaceData(3, 2, '12'), | 176 .replaceData(3, 2, '12'), |
177 '<div contenteditable><span>he^llo</span> wo|12d</div>', | 177 '<div contenteditable><span>he^llo</span> wo|12d</div>', |
178 'replaceData(3, 2, "12") in endContainer'); | 178 'replaceData(3, 2, "12") in endContainer'); |
179 </script> | 179 </script> |
OLD | NEW |