Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / text-iterator / range-to-from-location-and-length.html
blob5fb73db2a119dd32a48730be95dc18d6e86f5144
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <div id="test" contenteditable>
8 <p> hello<br>
9 world.</p>
10 <blockquote><div>|<br></div></blockquote>
11 <em>webkit</em>
12 </div>
13 <div id="console"></div>
14 <script>
16 if (!window.internals)
17 testFailed('This test requires internals object');
18 else {
19 var container = document.getElementById('test');
21 function range(startContainer, startOffset, endContainer, endOffset) {
22 var range = document.createRange();
23 range.setStart(startContainer, startOffset);
24 range.setEnd(endContainer, endOffset);
25 return range;
28 function locationAndLengthFromRange(range) {
29 var location = internals.locationFromRange(container, range);
30 var length = internals.lengthFromRange(container, range);
31 return [location, length];
34 Range.prototype.toArray = function () {
35 return [this.startContainer, this.startOffset, this.endContainer, this.endOffset];
38 var p = document.querySelector('#test p');
39 var div = document.querySelector('#test div');
40 var r = internals.rangeFromLocationAndLength(container, 0, 1);
41 shouldBe('locationAndLengthFromRange(range(p.firstChild, 0, p.firstChild, 3))', '[0, 1]');
42 shouldBe('locationAndLengthFromRange(range(p.firstChild, 1, p.firstChild, 4))', '[0, 2]');
43 shouldBe('locationAndLengthFromRange(range(p.firstChild, 2, p.firstChild, 3))', '[0, 1]');
44 shouldBe('internals.rangeFromLocationAndLength(container, 0, 1).toArray()', '[p.firstChild, 2, p.firstChild, 3]');
46 shouldBe('locationAndLengthFromRange(range(p.firstChild, 2, p.firstChild, 7))', '[0, 5]');
47 shouldBe('locationAndLengthFromRange(range(p.firstChild, 2, p, 1))', '[0, 5]');
48 shouldBe('locationAndLengthFromRange(range(p.firstChild, 2, p, 2))', '[0, 6]');
49 shouldBe('locationAndLengthFromRange(range(p.firstChild, 2, p.childNodes[2], 1))', '[0, 6]');
50 shouldBe('internals.rangeFromLocationAndLength(container, 1, 4).toArray()', '[p.firstChild, 3, p.firstChild, 7]');
51 shouldBe('internals.rangeFromLocationAndLength(container, 0, 6).toArray()', '[p.firstChild, 2, p.childNodes[2], 1]');
53 shouldBe('locationAndLengthFromRange(range(p.childNodes[2], 6, p, 3))', '[11, 1]');
54 shouldBe('internals.rangeFromLocationAndLength(container, 11, 2).toArray()', '[p.childNodes[2], 6, div, 0]');
56 container.style.display = 'none';
60 </script>
61 </body>
62 </html>