4 <script src=
"../../resources/js-test.js"></script>
7 <div id=
"test" contenteditable
>
10 <blockquote><div>|
<br></div></blockquote>
13 <div id=
"console"></div>
16 if (!window
.internals
)
17 testFailed('This test requires internals object');
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
);
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';