1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/base/tests/chrome/test_scroll_selection_into_view.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for scrolling selection into view</title> 1.8 + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.10 +</head> 1.11 +<body> 1.12 + 1.13 +<pre id="test"> 1.14 +<script class="testbody" type="text/javascript"> 1.15 + 1.16 +var ANCHOR = 0; 1.17 +var FOCUS = 1; 1.18 +var win; 1.19 + 1.20 +function testCollapsed(id, vPercent, startAt, expected) { 1.21 + var selection = win.getSelection().QueryInterface(SpecialPowers.Ci.nsISelectionPrivate); 1.22 + 1.23 + var c = win.document.getElementById("c" + id); 1.24 + var target = win.document.getElementById("target" + id); 1.25 + if (target.contentDocument) { 1.26 + selection = target.contentWindow.getSelection().QueryInterface(SpecialPowers.Ci.nsISelectionPrivate); 1.27 + target = target.contentDocument.getElementById("target" + id); 1.28 + } 1.29 + selection.collapse(target.parentNode, 0); 1.30 + c.scrollTop = startAt; 1.31 + selection.scrollIntoView(FOCUS, true, vPercent, 0); 1.32 + is(c.scrollTop, expected, "Scrolling " + target.id + 1.33 + " into view with vPercent " + vPercent + ", starting at " + startAt); 1.34 +} 1.35 + 1.36 +function doTest() { 1.37 + // Test scrolling an element smaller than the scrollport 1.38 + testCollapsed("1", 0, 0, 400); 1.39 + testCollapsed("1", 100, 0, 220); 1.40 + testCollapsed("1", -1, 0, 220); 1.41 + testCollapsed("1", 0, 500, 400); 1.42 + testCollapsed("1", 100, 500, 220); 1.43 + testCollapsed("1", -1, 500, 400); 1.44 + 1.45 + // overflow:hidden elements should not be scrolled by selection 1.46 + // scrolling-into-view 1.47 + testCollapsed("2", 0, 0, 0); 1.48 + testCollapsed("2", 100, 0, 0); 1.49 + testCollapsed("2", -1, 0, 0); 1.50 + testCollapsed("2", 0, 500, 500); 1.51 + testCollapsed("2", 100, 500, 500); 1.52 + testCollapsed("2", -1, 500, 500); 1.53 + 1.54 + // Test scrolling an element larger than the scrollport 1.55 + testCollapsed("3", 0, 0, 400); 1.56 + testCollapsed("3", 100, 0, 500); 1.57 + testCollapsed("3", -1, 0, 400); 1.58 + testCollapsed("3", 0, 1000, 400); 1.59 + testCollapsed("3", 100, 1000, 500); 1.60 + // If the element can't be completely visible, we make the top edge 1.61 + // visible. 1.62 + testCollapsed("3", -1, 1000, 400); 1.63 + 1.64 + // Test scrolling an element larger than the scrollport 1.65 + testCollapsed("4", 0, 0, 400); 1.66 + testCollapsed("4", 100, 0, 500); 1.67 + testCollapsed("4", -1, 0, 400); 1.68 + testCollapsed("4", 0, 1000, 400); 1.69 + testCollapsed("4", 100, 1000, 500); 1.70 + // If the element can't be completely visible, we make the top edge 1.71 + // visible. 1.72 + testCollapsed("4", -1, 1000, 400); 1.73 + 1.74 + // Test that scrolling a translated element into view takes 1.75 + // account of the transform. 1.76 + testCollapsed("5", 0, 0, 400); 1.77 + 1.78 + // Test that scrolling a scaled element into view takes 1.79 + // account of the transform. 1.80 + testCollapsed("6", 0, 0, 150); 1.81 + 1.82 + // Test that scrolling an element with a translated, scrolling container 1.83 + // into view takes account of the transform. 1.84 + testCollapsed("7", 0, 0, 400); 1.85 + 1.86 + win.close(); 1.87 + SimpleTest.finish(); 1.88 +} 1.89 + 1.90 +function openWindow() { 1.91 + win = open("scroll_selection_into_view_window.html", "_blank", "width=500,height=350"); 1.92 +} 1.93 + 1.94 +SimpleTest.waitForExplicitFinish(); 1.95 +addLoadEvent(openWindow); 1.96 +</script> 1.97 +</pre> 1.98 +</body> 1.99 + 1.100 +</html>