dom/plugins/test/mochitest/xulbrowser_plugin_visibility.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
     4 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     5 	orient="vertical">
     7   <tabbox id="tabbox" flex="1">
     8     <tabs>
     9       <tab id="tab1" label="Tab 1" />
    10       <tab id="tab2" label="Tab 2" />
    11     </tabs>
    12     <tabpanels flex="1">
    13       <browser id="browser1" type="content-primary" flex="1" src="about:blank"/>
    14       <browser id="browser2" type="content-primary" flex="1" src="about:blank"/>
    15     </tabpanels>
    16   </tabbox>
    17   <script type="application/javascript" src="utils.js"/>
    18   <script type="application/javascript"><![CDATA[
    19     const ok = window.opener.wrappedJSObject.ok;
    20     const is = window.opener.wrappedJSObject.is;
    21     const done = window.opener.wrappedJSObject.done;
    22     const SimpleTest = window.opener.wrappedJSObject.SimpleTest;
    24     const nsIWebProgress = Components.interfaces.nsIWebProgress;
    25     const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
    27     const kURI = 'http://mochi.test:8888/chrome/dom/plugins/test/mochitest/plugin_visibility_loader.html';
    29     function ProgressListener() {
    30     }
    31     ProgressListener.prototype.onStateChange =
    32       function(progress, req, flags, status) {
    33         if ((flags & nsIWebProgressListener.STATE_IS_WINDOW) &&
    34             (flags & nsIWebProgressListener.STATE_STOP))
    35           browserLoaded();
    36       };
    37     ProgressListener.prototype.QueryInterface = function(iid) {
    38       if (iid.equals(nsIWebProgressListener) ||
    39           iid.equals(Components.interfaces.nsISupportsWeakReference))
    40         return this;
    41       throw Components.results.NS_ERROR_NO_INTERFACE;
    42     };
    44     var loadCount = 0;
    45     function browserLoaded() {
    46       ++loadCount;
    47       if (2 == loadCount)
    48         startTest();
    49     }
    51     var tabbox = document.getElementById('tabbox');
    52     var browser1 = document.getElementById('browser1');
    53     var browser2 = document.getElementById('browser2');
    55     var progressListener1, progressListener2;
    57     function setup() {
    58       progressListener1 = new ProgressListener();
    59       browser1.addProgressListener(progressListener1, nsIWebProgress.NOTIFY_STATE_WINDOW);
    60       browser1.loadURI(kURI, null, null);
    61       progressListener2 = new ProgressListener();
    62       browser2.addProgressListener(progressListener2, nsIWebProgress.NOTIFY_STATE_WINDOW);
    63       browser2.loadURI(kURI, null, null);
    64     }
    66     window.addEventListener("load", setup, false);
    68     var plugin1, plugin2;
    70     const kTimeout = 5000; // 5 seconds
    71     var paintGiveUp;
    72     var paintInterval;
    74     function startTest() {
    75       plugin1 = browser1.contentDocument.getElementById('p').wrappedJSObject;
    76       plugin2 = browser2.contentDocument.getElementById('p').wrappedJSObject;
    78       paintGiveUp = Date.now() + kTimeout;
    79       paintInterval = setInterval(waitForPaint, 100);
    80     }
    82     function waitForPaint() {
    83       if (!plugin1.isVisible()) {
    84         if (Date.now() < paintGiveUp)
    85           return;
    87         ok(false, "Plugin in tab 1 never became visible.");
    88         done();
    89         return;
    90       }
    92       clearInterval(paintInterval);
    94       ok(true, "Plugin in tab 1 should be visible.");
    95       paintCountIs(plugin1, 1, "Plugin in tab 1 should have painted once.");
    97       ok(!plugin2.isVisible(), "Plugin in tab 2 should not be visible.");
    98       paintCountIs(plugin2, 0, "Plugin in tab 2 should not have painted.");
   100       tabbox.selectedIndex = 1;
   101       paintGiveUp = Date.now() + kTimeout;
   102       paintInterval = setInterval(part2, 100);
   103     }
   105     function part2() {
   106       if (!plugin2.isVisible()) {
   107         if (Date.now() < paintGiveUp)
   108           return;
   110         ok(false, "Plugin in tab 2 never became visible.");
   111         done();
   112         return;
   113       }
   115       clearInterval(paintInterval);
   117       ok(true, "Plugin in tab 2 became visible.");
   118       paintCountIs(plugin2, 1, "Plugin in tab 2 should have painted once.");
   120       ok(!plugin1.isVisible(), "Plugin in tab 1 should have become invisible.");
   121       paintCountIs(plugin1, 1, "Plugin in tab 1 should have painted once.");
   123       // Setcolor invalidates
   124       plugin1.setColor('FF00FF00');
   125       plugin2.setColor('FF00FF00');
   127       setTimeout(part3, 500);
   128     }
   130     function part3() {
   131       paintCountIs(plugin1, 1,
   132                    "Plugin in tab 1 should not have repainted after invalidate.");
   133       paintCountIs(plugin2, 2,
   134                    "Plugin in tab 2 should have repainted after invalidate.");
   135       done();
   136     }
   137   ]]></script>
   139 </window>

mercurial