layout/base/tests/bug450930.xhtml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/base/tests/bug450930.xhtml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,181 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg">
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=450930
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 450930 (MozAfterPaint)</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body onload="runNext()">
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450930">Mozilla Bug 450930</a>
    1.16 +<div id="display">
    1.17 +  <div id="d" style="width:400px; height:200px;"></div>
    1.18 +  <iframe id="iframe" style="width:400px; height:200px;"
    1.19 +   src="data:text/html,&lt;div id='d'&gt;&lt;span style='margin-left:3px;'&gt;Hello&lt;/span&gt;
    1.20 +        &lt;/div&gt;&lt;div style='margin-top:500px' id='d2'&gt;
    1.21 +        &lt;span style='margin-left:3px;'&gt;Goodbye&lt;/span&gt;&lt;/div>"></iframe>
    1.22 +  <svg:svg style="width:410px; height:210px;" id="svg">
    1.23 +    <svg:foreignObject width="100%" height="100%">
    1.24 +      <iframe id="iframe2" style="width:400px; height:200px;"
    1.25 +       src="data:text/html,&lt;div id='d'&gt;&lt;span style='margin-left:3px;'&gt;Hello&lt;/span&gt;
    1.26 +            &lt;/div&gt;&lt;div style='margin-top:500px' id='d2'&gt;
    1.27 +            &lt;span style='margin-left:3px;'&gt;Goodbye&lt;/span&gt;&lt;/div>"></iframe>
    1.28 +    </svg:foreignObject>
    1.29 +  </svg:svg>
    1.30 +</div>
    1.31 +<div id="content" style="display: none">
    1.32 +</div>
    1.33 +
    1.34 +
    1.35 +<pre id="test">
    1.36 +<script class="testbody" type="text/javascript"><![CDATA[
    1.37 +
    1.38 +function flash(doc, name) {
    1.39 +  var d = doc.getElementById(name);
    1.40 +  d.style.backgroundColor = d.style.backgroundColor == "blue" ? "yellow" : "blue";
    1.41 +  // Now flush out style changes in that document, since our event listeners
    1.42 +  // seem to assume that things will work that way.
    1.43 +  d.getBoundingClientRect();
    1.44 +}
    1.45 +
    1.46 +function le(v1, v2, s) {
    1.47 +  window.opener.ok(v1 <= v2, s + " (" + v1 + "," + v2 + ")");
    1.48 +}
    1.49 +
    1.50 +function checkContains(r1, r2, s) {
    1.51 +  le(Math.round(r1.left), Math.round(r2.left), "Left edges out" + s);
    1.52 +  le(Math.round(r2.right), Math.round(r1.right), "Right edges out" + s);
    1.53 +  le(Math.round(r1.top), Math.round(r2.top), "Top edges out" + s);
    1.54 +  le(Math.round(r2.bottom), Math.round(r1.bottom), "Bottom edges out" + s);
    1.55 +}
    1.56 +
    1.57 +function isRect(r1, r2) {
    1.58 +  return (Math.abs(r1.left - r2.left) <= 1 ||
    1.59 +          Math.abs(r1.right - r2.right) <= 1 ||
    1.60 +          Math.abs(r1.top - r2.top) <= 1 ||
    1.61 +          Math.abs(r1.bottom - r2.bottom) <= 1);
    1.62 +}
    1.63 +
    1.64 +function isRectInList(r, list) {
    1.65 +  for (var i = 0; i < list.length; ++i) {
    1.66 +    if (isRect(r, list[i]))
    1.67 +      return true;
    1.68 +  }
    1.69 +  return false;
    1.70 +}
    1.71 +
    1.72 +function doesRectContain(r1, r2) {
    1.73 +  return Math.floor(r1.left) <= r2.left && r2.right <= Math.ceil(r1.right) &&
    1.74 +         Math.floor(r1.top) <= r2.top && r2.bottom <= Math.ceil(r1.bottom);
    1.75 +}
    1.76 +
    1.77 +function rectToString(r) {
    1.78 +  return "(" + r.left + "," + r.top + "," + r.right + "," + r.bottom + ")";
    1.79 +}
    1.80 +
    1.81 +function doesRectContainListElement(r, list) {
    1.82 +  dump("Incoming rect: " + rectToString(r) + "\n");
    1.83 +  for (var i = 0; i < list.length; ++i) {
    1.84 +    dump("List rect " + i + ": " + rectToString(list[i]));
    1.85 +    if (doesRectContain(r, list[i])) {
    1.86 +      dump(" FOUND\n");
    1.87 +      return true;
    1.88 +    }
    1.89 +    dump("\n");
    1.90 +  }
    1.91 +  dump("NOT FOUND\n");
    1.92 +  return false;
    1.93 +}
    1.94 +
    1.95 +function checkGotSubdoc(list, container) {
    1.96 +  var r = container.getBoundingClientRect();
    1.97 +  return doesRectContainListElement(r, list);
    1.98 +}
    1.99 +
   1.100 +function runTest1() {
   1.101 +  // test basic functionality
   1.102 +  var iterations = 0;
   1.103 +  var foundExactRect = false;
   1.104 +
   1.105 +  function listener(event) {
   1.106 +    var r = SpecialPowers.wrap(event).boundingClientRect;
   1.107 +    var bounds = document.getElementById('d').getBoundingClientRect();
   1.108 +    checkContains(r, bounds, "");
   1.109 +    if (isRectInList(bounds, SpecialPowers.wrap(event).clientRects)) {
   1.110 +      foundExactRect = true;
   1.111 +    }
   1.112 +    window.removeEventListener("MozAfterPaint", listener, false);
   1.113 +    ++iterations;
   1.114 +    if (iterations < 4) {
   1.115 +      setTimeout(triggerPaint, 100);
   1.116 +    } else {
   1.117 +      window.opener.ok(foundExactRect, "Found exact rect");
   1.118 +      runNext();
   1.119 +    }
   1.120 +  }
   1.121 +
   1.122 +  function triggerPaint() {
   1.123 +    window.addEventListener("MozAfterPaint", listener, false);
   1.124 +    flash(document, 'd');
   1.125 +    window.opener.ok(true, "trigger test1 paint");
   1.126 +  }
   1.127 +  triggerPaint();
   1.128 +}
   1.129 +
   1.130 +function runTest2(frameID, containerID) {
   1.131 +  // test reporting of painting in subdocuments
   1.132 +  var fired = 0;
   1.133 +  var gotSubdocPrivileged = false;
   1.134 +  var iframe = document.getElementById(frameID);
   1.135 +  var container = document.getElementById(containerID);
   1.136 +
   1.137 +  function listener(event) {
   1.138 +    if (checkGotSubdoc(SpecialPowers.wrap(event).clientRects, container))
   1.139 +      gotSubdocPrivileged = true;
   1.140 +    if (SpecialPowers.wrap(event).clientRects.length > 0) {
   1.141 +      if (++fired == 1)
   1.142 +        setTimeout(check, 100);
   1.143 +    }
   1.144 +  }
   1.145 +
   1.146 +  function check() {
   1.147 +    window.opener.is(fired, 1, "Wrong event count (" + frameID + ")");
   1.148 +    window.opener.ok(gotSubdocPrivileged, "Didn't get subdoc invalidation while we were privileged (" + frameID + ")");
   1.149 +    window.removeEventListener("MozAfterPaint", listener, false);
   1.150 +    runNext();
   1.151 +  }
   1.152 +
   1.153 +  function triggerPaint() {
   1.154 +    window.addEventListener("MozAfterPaint", listener, false);
   1.155 +    document.body.offsetTop;
   1.156 +    flash(iframe.contentDocument, 'd');
   1.157 +  }
   1.158 +  triggerPaint();
   1.159 +}
   1.160 +
   1.161 +var test = 0;
   1.162 +var tests = [runTest1,
   1.163 +             function() { runTest2("iframe", "iframe") },
   1.164 +             function() { runTest2("iframe2", "svg") }];
   1.165 +function runNext() {
   1.166 +  if (SpecialPowers.DOMWindowUtils.isMozAfterPaintPending) {
   1.167 +    // Wait until there are no pending paints before trying to run tests
   1.168 +    setTimeout(runNext, 100);
   1.169 +    return;
   1.170 +  }
   1.171 +  if (test < tests.length) {
   1.172 +    ++test;
   1.173 +    tests[test - 1]();
   1.174 +  } else {
   1.175 +    window.opener.finishTests();
   1.176 +  }
   1.177 +}
   1.178 +
   1.179 +
   1.180 +]]></script>
   1.181 +</pre>
   1.182 +
   1.183 +</body>
   1.184 +</html>

mercurial