summaryrefslogtreecommitdiff
path: root/dom/base/test/test_viewport_scroll.html
blob: 7db02b78154f98ab1cca8c47a8dfe038195bb07d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for mapping of scrollTop/scrollLeft to viewport</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body onload="doTest()">
<p id="display"></p>

<iframe id="quirks"></iframe>
<iframe id="standards"></iframe>
<iframe id="xml"></iframe>

<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();

var quirks = document.getElementById("quirks");
var standards = document.getElementById("standards");
var xml = document.getElementById("xml");

quirks.src = "data:text/html,<html><body style='height:2000px; width:2000px;'>";
standards.src = "data:text/html,<!DOCTYPE HTML><html><body style='height:2000px; width:2000px;'>";
xml.src = "data:text/xml,<?xml-stylesheet href='data:text/css,html { display:block; height:2000px; width:2000px; }'?><foo><html></html></foo>";

function subtest(winProp, elemProp, win, correctElement, elemToSet, otherElem1, otherElem2) {
  win.scrollTo(50, 50);
  elemToSet[elemProp] = 100;
  if (elemToSet == correctElement) {
    is(Math.round(win[winProp]), 100, "Setting " + elemToSet.name + "." + elemProp + " should scroll");
    is(elemToSet[elemProp], 100, "Reading back " + elemToSet.name + "." + elemProp + " after scrolling");
  } else {
    is(Math.round(win[winProp]), 50, "Setting " + elemToSet.name + "." + elemProp + " should not scroll");
    is(elemToSet[elemProp], 0, "Reading back " + elemToSet.name + "." + elemProp + " after not scrolling");
  }
  if (otherElem1 == correctElement) {
    is(otherElem1[elemProp], 50, "Reading back " + otherElem1.name + "." + elemProp + " (correct element) after not scrolling");
  } else {
    is(otherElem1[elemProp], 0, "Reading back " + otherElem1.name + "." + elemProp + " (irrelevant element)");
  }
  if (otherElem2 == correctElement) {
    is(otherElem2[elemProp], 50, "Reading back " + otherElem2.name + "." + elemProp + " (correct element) after not scrolling");
  } else {
    is(otherElem2[elemProp], 0, "Reading back " + otherElem2.name + "." + elemProp + " (irrelevant element)");
  }
}

function testScroll(winProp, elemProp, win, elemToSet, otherElem1, otherElem2) {
  subtest(winProp, elemProp, win, elemToSet, elemToSet, otherElem1, otherElem2);
  subtest(winProp, elemProp, win, elemToSet, otherElem1, elemToSet, otherElem2);
  subtest(winProp, elemProp, win, elemToSet, otherElem2, elemToSet, otherElem1);
}

function doTest() {
  var quirksRoot = quirks.contentDocument.documentElement;
  quirksRoot.name = "quirks HTML";
  var quirksBody = quirks.contentDocument.body;
  quirksBody.name = "quirks BODY";
  var quirksBody2 = quirks.contentDocument.createElement("body");
  quirksBody2.name = "quirks other BODY";
  quirksRoot.appendChild(quirksBody2);
  testScroll("scrollX", "scrollLeft", quirks.contentWindow, quirksBody, quirksRoot, quirksBody2);
  testScroll("scrollY", "scrollTop", quirks.contentWindow, quirksBody, quirksRoot, quirksBody2);

  var standardsRoot = standards.contentDocument.documentElement;
  standardsRoot.name = "standards HTML";
  var standardsBody = standards.contentDocument.body;
  standardsBody.name = "standards BODY";
  var standardsBody2 = standards.contentDocument.createElement("body");
  standardsBody2.name = "standards other BODY";
  standardsRoot.appendChild(standardsBody2);
  testScroll("scrollX", "scrollLeft", standards.contentWindow, standardsRoot, standardsBody, standardsBody2);
  testScroll("scrollY", "scrollTop", standards.contentWindow, standardsRoot, standardsBody, standardsBody2);

  var xmlRoot = xml.contentDocument.documentElement;
  xmlRoot.name = "XML root";
  var xmlOther = xmlRoot.firstChild;
  xmlOther.name = "XML other";
  testScroll("scrollX", "scrollLeft", xml.contentWindow, xmlRoot, xmlOther, xmlOther);
  testScroll("scrollY", "scrollTop", xml.contentWindow, xmlRoot, xmlOther, xmlOther);

  SimpleTest.finish();
}
</script>

</pre>
</body>
</html>