tony@chromium.org | d57a78d | 2010-05-27 04:18:07 +0000 | [diff] [blame] | 1 | <head> |
| 2 | <style type="text/css"> |
| 3 | .ahem { font: 20px Ahem; } |
| 4 | </style> |
| 5 | <script> |
| 6 | |
rniwa@webkit.org | 14f6b5b | 2012-06-13 08:51:53 +0000 | [diff] [blame] | 7 | if (window.testRunner) |
| 8 | testRunner.dumpAsText(); |
tony@chromium.org | d57a78d | 2010-05-27 04:18:07 +0000 | [diff] [blame] | 9 | |
| 10 | var onMacPlatform = navigator.userAgent.search(/\bMac OS X\b/) != -1; |
| 11 | |
| 12 | function runTest() { |
| 13 | runFrameScrollTest(); |
| 14 | runDivScrollTest(); |
| 15 | } |
| 16 | |
| 17 | function generateContent() { |
| 18 | var content = ""; |
| 19 | for (var i = 0; i < 10; ++i) |
| 20 | content += "<p>line " + i + "</p>\n"; |
| 21 | return content; |
| 22 | } |
| 23 | |
| 24 | function runFrameScrollTest() { |
| 25 | var frame = frames[0]; |
| 26 | var doc = frame.document; |
| 27 | var body = doc.body; |
| 28 | body.innerHTML = generateContent(); |
| 29 | frame.focus(); |
| 30 | frame.getSelection().setPosition(body.firstChild, 0); |
| 31 | if (onMacPlatform) |
| 32 | offsets = [ 55, 175 ]; |
| 33 | else |
| 34 | offsets = [ 120, 240 ]; |
| 35 | runScrollingTest("iframe", frame, offsets, function() { return frame.pageYOffset; }); |
| 36 | } |
| 37 | |
| 38 | function runDivScrollTest() { |
| 39 | var editable = document.getElementById('editable'); |
| 40 | editable.innerHTML = generateContent(); |
| 41 | editable.focus(); |
| 42 | window.getSelection().setPosition(editable, 0); |
| 43 | if (onMacPlatform) |
| 44 | offsets = [ 75, 195 ]; |
| 45 | else |
| 46 | offsets = [ 140, 260 ]; |
| 47 | runScrollingTest("div", editable, offsets, function() { return editable.scrollTop; }); |
| 48 | } |
| 49 | |
| 50 | function runScrollingTest(testName, frame, offsets, scrollFunction) { |
| 51 | var tolerance = 0; |
| 52 | var modifiers = onMacPlatform ? ["altKey"] : []; |
| 53 | |
| 54 | if (!window.eventSender) |
| 55 | return; |
| 56 | |
| 57 | eventSender.keyDown("pageDown", modifiers); |
| 58 | if (Math.abs(scrollFunction() - offsets[0]) > tolerance) { |
| 59 | throw "Frame viewport should be around " + offsets[0] + |
| 60 | "px , not at " + scrollFunction(); |
| 61 | } |
| 62 | |
| 63 | eventSender.keyDown("pageDown", modifiers); |
| 64 | if (Math.abs(scrollFunction() - offsets[1]) > tolerance) { |
| 65 | throw "Frame viewport should be around " + offsets[1] + |
| 66 | "px , not " + scrollFunction(); |
| 67 | } |
| 68 | |
| 69 | eventSender.keyDown("pageUp", modifiers); |
| 70 | if (Math.abs(scrollFunction() - offsets[0]) > tolerance) { |
| 71 | throw "Frame viewport should be around " + offsets[0] + |
| 72 | "px , not at " + scrollFunction(); |
| 73 | } |
| 74 | |
| 75 | document.getElementById("results").innerHTML += testName + " PASS<br/>"; |
| 76 | } |
| 77 | </script> |
| 78 | </head> |
commit-queue@webkit.org | 0b512b6 | 2011-03-07 08:19:58 +0000 | [diff] [blame] | 79 | <body onload="runTest()"> |
tony@chromium.org | d57a78d | 2010-05-27 04:18:07 +0000 | [diff] [blame] | 80 | <div>Page up/down (option+page up/down on Mac) should move the move cursor and scroll the content |
| 81 | in contenteditable elements. This sample covers scroll position test of a) iframe element containing |
| 82 | contenteditable body and b) content editable div element. Even though the cursor will move exactly to |
| 83 | the same location on all platforms (covered by test option-page-up-down.html), please note that Mac will |
| 84 | scroll the visible area by placing the cursor position in the middle. All other platforms will scroll by |
| 85 | keeping the cursor aligned with the top edge of the visible area. </div> |
commit-queue@webkit.org | 0b512b6 | 2011-03-07 08:19:58 +0000 | [diff] [blame] | 86 | <iframe src="../resources/contenteditable-iframe-fixed-size-src.html" style="height:150px; padding: 0px;"></iframe> |
tony@chromium.org | d57a78d | 2010-05-27 04:18:07 +0000 | [diff] [blame] | 87 | <div id="editable" contenteditable="true" class="ahem" style="height:150px; overflow:auto; padding: 0px; margin: 0px;"></div> |
| 88 | <div id="results"></div> |
commit-queue@webkit.org | 0b512b6 | 2011-03-07 08:19:58 +0000 | [diff] [blame] | 89 | </body> |