blob: b0208f80fadf4768b28aa0bfec8f88d3e18096a2 [file] [log] [blame]
tony@chromium.orgd57a78d2010-05-27 04:18:07 +00001<head>
2<style type="text/css">
3 .ahem { font: 20px Ahem; }
4</style>
5<script>
6
rniwa@webkit.org14f6b5b2012-06-13 08:51:53 +00007if (window.testRunner)
8 testRunner.dumpAsText();
tony@chromium.orgd57a78d2010-05-27 04:18:07 +00009
10var onMacPlatform = navigator.userAgent.search(/\bMac OS X\b/) != -1;
11
12function runTest() {
13 runFrameScrollTest();
14 runDivScrollTest();
15}
16
17function generateContent() {
18 var content = "";
19 for (var i = 0; i < 10; ++i)
20 content += "<p>line " + i + "</p>\n";
21 return content;
22}
23
24function 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
38function 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
50function 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.org0b512b62011-03-07 08:19:58 +000079<body onload="runTest()">
tony@chromium.orgd57a78d2010-05-27 04:18:07 +000080<div>Page up/down (option+page up/down on Mac) should move the move cursor and scroll the content
81in contenteditable elements. This sample covers scroll position test of a) iframe element containing
82contenteditable body and b) content editable div element. Even though the cursor will move exactly to
83the same location on all platforms (covered by test option-page-up-down.html), please note that Mac will
84scroll the visible area by placing the cursor position in the middle. All other platforms will scroll by
85keeping the cursor aligned with the top edge of the visible area. </div>
commit-queue@webkit.org0b512b62011-03-07 08:19:58 +000086<iframe src="../resources/contenteditable-iframe-fixed-size-src.html" style="height:150px; padding: 0px;"></iframe>
tony@chromium.orgd57a78d2010-05-27 04:18:07 +000087<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.org0b512b62011-03-07 08:19:58 +000089</body>