Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Document / CaretRangeFromPoint / caretRangeFromPoint-with-before-style.html
blobc1ec206f7b6128baf324a102155c8d8815a74d45
1 <!DOCTTYPE html>
2 <style>
3 body { font-family: monospace; }
4 #margin:before { content: "MARGIN"; color: red; margin-left: -60px; }
5 #margin { margin-left: 60px; }
6 #noMargin:before { content: "BEFORE"; color: red; }
7 </style>
8 <script src="../../../../resources/js-test.js"></script>
9 <script>
10 // Since, CSSOM View introduces document.caretPositionFromPoint to replace
11 // document.caretRangeFromPoint. We make a polyfill to make this script works
12 // with Firefox.
13 if (!document.caretPositionFromPoint) {
14 document.caretPositionFromPoint = function(x, y) {
15 var range = document.caretRangeFromPoint(x, y);
16 if (range === null)
17 return null;
18 return {offset: range.startOffset, offsetNode: range.startContainer};
22 function testIt(id, charIndex) {
23 var sample = document.getElementById(id).firstChild;
24 var charWidth = sample.offsetWidth / sample.textContent.length;
25 var x = sample.offsetLeft + charWidth * charIndex + 1;
26 var y = sample.offsetTop + sample.offsetHeight / 2;
27 var position = document.caretPositionFromPoint(x, y);
28 if (!position)
29 return 'null';
30 if (position.offsetNode.nodeType != Node.TEXT_NODE)
31 return 'not text';
32 return position.offsetNode.textContent[position.offset];
35 onload = function() {
36 description('caretRangeFromPoint() should work with :before style');
38 shouldBeEqualToString('testIt("margin", -2)', 'a');
39 shouldBeEqualToString('testIt("margin", -1)', 'a');
40 shouldBeEqualToString('testIt("margin", 0)', 'a');
41 shouldBeEqualToString('testIt("margin", 1)', 'b');
42 debug('');
43 shouldBeEqualToString('testIt("noMargin", -2)', 'a');
44 shouldBeEqualToString('testIt("noMargin", -1)', 'a');
45 shouldBeEqualToString('testIt("noMargin", 0)', 'a');
46 shouldBeEqualToString('testIt("noMargin", 1)', 'b');
48 if (window.testRunner)
49 document.getElementById('container').textContent = '';
51 </script>
52 <div id="container">
53 <p id="description"></p>
54 <p id="margin"><span>abcde</span></p>
55 <p id="noMargin"><span>abcde</span></p>
56 </div>