widget/tests/test_plugin_scroll_invalidation.html

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test for plugin child widgets not being invalidated by scrolling</title>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     7 </head>
     8 <body onload="initialize()">
     9 <script type="application/javascript">
    10 var pluginHost = SpecialPowers.Cc["@mozilla.org/plugin/host;1"]
    11                         .getService(SpecialPowers.Ci.nsIPluginHost);
    12 var pluginTags = pluginHost.getPluginTags();
    13 for (var tag of pluginTags) {
    14   if (tag.name == "Test Plug-in") {
    15     tag.enabledState = SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED;;
    16   }
    17 }
    18 </script>
    20 <p id="display">
    21   <iframe id="i" src="plugin_scroll_invalidation.html"
    22    width="50" height="50" scrolling="no"></iframe>
    23 </p>
    24 <div id="content" style="display: none">
    26 </div>
    27 <pre id="test">
    28 </pre>
    30 <script type="application/javascript">
    31 SimpleTest.waitForExplicitFinish();
    33 var scrolling;
    34 var scrolling_plugins = [];
    35 var paint_waiter;
    36 var last_paint_counts;
    38 function initialize() {
    39   scrolling = document.getElementById("i").contentWindow;
    40   scrolling_plugins = scrolling.document.querySelectorAll("embed.scrolling");
    41   paint_waiter = scrolling.document.getElementById("paint-waiter");
    43   scrolling.scrollTo(50, 45);
    45   is(paint_waiter.getPaintCount(), 0, "zero-sized plugin not painted");
    47   waitForPaint(scrollAround);
    48 }
    50 function scrollAround() {
    51   var paints = getPaintCounts();
    53   for (var i = 0; i < paints.length; ++i) {
    54     isnot(paints[i], 0, "embed " + scrolling_plugins[i].id + " is painted"); 
    55   }
    57   last_paint_counts = paints;
    59   scrolling.scrollBy(-5, 5);
    60   scrolling.scrollBy(5, 5);
    61   scrolling.scrollBy(5, -5);
    62   scrolling.scrollBy(-5, -5);
    64   scrolling.scrollTo(45, 45);
    65   scrolling.scrollBy(10, 0);
    66   scrolling.scrollBy(0, 10);
    67   scrolling.scrollBy(-10, 0);
    68   scrolling.scrollBy(0, -10);
    70   waitForPaint(done);
    71 }
    73 function done() {
    74   var paints = getPaintCounts();
    75   for (var i = 0; i < paints.length; ++i) {
    76     is(paints[i], last_paint_counts[i], "embed " + scrolling_plugins[i].id + " is not painted on scroll");
    77   }
    78   SimpleTest.finish();  
    79 }
    81 // Waits for the paint_waiter plugin to be repainted and then
    82 // calls 'func' to continue.
    83 function waitForPaint(func) {
    84   paint_waiter.last_paint_count = paint_waiter.getPaintCount();
    86   paint_waiter.style.left = scrolling.scrollX + "px";
    87   paint_waiter.style.top = scrolling.scrollY + "px";
    89   // Fiddle with the style in a way that should force some repainting
    90   paint_waiter.style.width =
    91     (paint_waiter.getBoundingClientRect().width + 1) + "px"; 
    92   paint_waiter.style.height = "1px";
    94   function waitForPaintHelper() {
    95     if (paint_waiter.getPaintCount() != paint_waiter.last_paint_count) {
    96       setTimeout(func, 0);
    97       return;
    98     }
    99     setTimeout(waitForPaintHelper, 0);
   100   }
   101   waitForPaintHelper();
   102 }
   104 function getPaintCounts() {
   105   var result = [];
   106   for (var i = 0; i < scrolling_plugins.length; ++i) {
   107     result[i] = scrolling_plugins[i].getPaintCount();
   108   }
   109   return result;
   110 }
   112 </script>
   113 </body>
   114 </html>

mercurial