Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test for scrolling selection into view</title> |
michael@0 | 5 | <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | |
michael@0 | 10 | <pre id="test"> |
michael@0 | 11 | <script class="testbody" type="text/javascript"> |
michael@0 | 12 | |
michael@0 | 13 | var ANCHOR = 0; |
michael@0 | 14 | var FOCUS = 1; |
michael@0 | 15 | var win; |
michael@0 | 16 | |
michael@0 | 17 | function testCollapsed(id, vPercent, startAt, expected) { |
michael@0 | 18 | var selection = win.getSelection().QueryInterface(SpecialPowers.Ci.nsISelectionPrivate); |
michael@0 | 19 | |
michael@0 | 20 | var c = win.document.getElementById("c" + id); |
michael@0 | 21 | var target = win.document.getElementById("target" + id); |
michael@0 | 22 | if (target.contentDocument) { |
michael@0 | 23 | selection = target.contentWindow.getSelection().QueryInterface(SpecialPowers.Ci.nsISelectionPrivate); |
michael@0 | 24 | target = target.contentDocument.getElementById("target" + id); |
michael@0 | 25 | } |
michael@0 | 26 | selection.collapse(target.parentNode, 0); |
michael@0 | 27 | c.scrollTop = startAt; |
michael@0 | 28 | selection.scrollIntoView(FOCUS, true, vPercent, 0); |
michael@0 | 29 | is(c.scrollTop, expected, "Scrolling " + target.id + |
michael@0 | 30 | " into view with vPercent " + vPercent + ", starting at " + startAt); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function doTest() { |
michael@0 | 34 | // Test scrolling an element smaller than the scrollport |
michael@0 | 35 | testCollapsed("1", 0, 0, 400); |
michael@0 | 36 | testCollapsed("1", 100, 0, 220); |
michael@0 | 37 | testCollapsed("1", -1, 0, 220); |
michael@0 | 38 | testCollapsed("1", 0, 500, 400); |
michael@0 | 39 | testCollapsed("1", 100, 500, 220); |
michael@0 | 40 | testCollapsed("1", -1, 500, 400); |
michael@0 | 41 | |
michael@0 | 42 | // overflow:hidden elements should not be scrolled by selection |
michael@0 | 43 | // scrolling-into-view |
michael@0 | 44 | testCollapsed("2", 0, 0, 0); |
michael@0 | 45 | testCollapsed("2", 100, 0, 0); |
michael@0 | 46 | testCollapsed("2", -1, 0, 0); |
michael@0 | 47 | testCollapsed("2", 0, 500, 500); |
michael@0 | 48 | testCollapsed("2", 100, 500, 500); |
michael@0 | 49 | testCollapsed("2", -1, 500, 500); |
michael@0 | 50 | |
michael@0 | 51 | // Test scrolling an element larger than the scrollport |
michael@0 | 52 | testCollapsed("3", 0, 0, 400); |
michael@0 | 53 | testCollapsed("3", 100, 0, 500); |
michael@0 | 54 | testCollapsed("3", -1, 0, 400); |
michael@0 | 55 | testCollapsed("3", 0, 1000, 400); |
michael@0 | 56 | testCollapsed("3", 100, 1000, 500); |
michael@0 | 57 | // If the element can't be completely visible, we make the top edge |
michael@0 | 58 | // visible. |
michael@0 | 59 | testCollapsed("3", -1, 1000, 400); |
michael@0 | 60 | |
michael@0 | 61 | // Test scrolling an element larger than the scrollport |
michael@0 | 62 | testCollapsed("4", 0, 0, 400); |
michael@0 | 63 | testCollapsed("4", 100, 0, 500); |
michael@0 | 64 | testCollapsed("4", -1, 0, 400); |
michael@0 | 65 | testCollapsed("4", 0, 1000, 400); |
michael@0 | 66 | testCollapsed("4", 100, 1000, 500); |
michael@0 | 67 | // If the element can't be completely visible, we make the top edge |
michael@0 | 68 | // visible. |
michael@0 | 69 | testCollapsed("4", -1, 1000, 400); |
michael@0 | 70 | |
michael@0 | 71 | // Test that scrolling a translated element into view takes |
michael@0 | 72 | // account of the transform. |
michael@0 | 73 | testCollapsed("5", 0, 0, 400); |
michael@0 | 74 | |
michael@0 | 75 | // Test that scrolling a scaled element into view takes |
michael@0 | 76 | // account of the transform. |
michael@0 | 77 | testCollapsed("6", 0, 0, 150); |
michael@0 | 78 | |
michael@0 | 79 | // Test that scrolling an element with a translated, scrolling container |
michael@0 | 80 | // into view takes account of the transform. |
michael@0 | 81 | testCollapsed("7", 0, 0, 400); |
michael@0 | 82 | |
michael@0 | 83 | win.close(); |
michael@0 | 84 | SimpleTest.finish(); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function openWindow() { |
michael@0 | 88 | win = open("scroll_selection_into_view_window.html", "_blank", "width=500,height=350"); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 92 | addLoadEvent(openWindow); |
michael@0 | 93 | </script> |
michael@0 | 94 | </pre> |
michael@0 | 95 | </body> |
michael@0 | 96 | |
michael@0 | 97 | </html> |