1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/test/mochitest/xulbrowser_plugin_visibility.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,139 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> 1.6 + 1.7 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.8 + orient="vertical"> 1.9 + 1.10 + <tabbox id="tabbox" flex="1"> 1.11 + <tabs> 1.12 + <tab id="tab1" label="Tab 1" /> 1.13 + <tab id="tab2" label="Tab 2" /> 1.14 + </tabs> 1.15 + <tabpanels flex="1"> 1.16 + <browser id="browser1" type="content-primary" flex="1" src="about:blank"/> 1.17 + <browser id="browser2" type="content-primary" flex="1" src="about:blank"/> 1.18 + </tabpanels> 1.19 + </tabbox> 1.20 + <script type="application/javascript" src="utils.js"/> 1.21 + <script type="application/javascript"><![CDATA[ 1.22 + const ok = window.opener.wrappedJSObject.ok; 1.23 + const is = window.opener.wrappedJSObject.is; 1.24 + const done = window.opener.wrappedJSObject.done; 1.25 + const SimpleTest = window.opener.wrappedJSObject.SimpleTest; 1.26 + 1.27 + const nsIWebProgress = Components.interfaces.nsIWebProgress; 1.28 + const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener; 1.29 + 1.30 + const kURI = 'http://mochi.test:8888/chrome/dom/plugins/test/mochitest/plugin_visibility_loader.html'; 1.31 + 1.32 + function ProgressListener() { 1.33 + } 1.34 + ProgressListener.prototype.onStateChange = 1.35 + function(progress, req, flags, status) { 1.36 + if ((flags & nsIWebProgressListener.STATE_IS_WINDOW) && 1.37 + (flags & nsIWebProgressListener.STATE_STOP)) 1.38 + browserLoaded(); 1.39 + }; 1.40 + ProgressListener.prototype.QueryInterface = function(iid) { 1.41 + if (iid.equals(nsIWebProgressListener) || 1.42 + iid.equals(Components.interfaces.nsISupportsWeakReference)) 1.43 + return this; 1.44 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.45 + }; 1.46 + 1.47 + var loadCount = 0; 1.48 + function browserLoaded() { 1.49 + ++loadCount; 1.50 + if (2 == loadCount) 1.51 + startTest(); 1.52 + } 1.53 + 1.54 + var tabbox = document.getElementById('tabbox'); 1.55 + var browser1 = document.getElementById('browser1'); 1.56 + var browser2 = document.getElementById('browser2'); 1.57 + 1.58 + var progressListener1, progressListener2; 1.59 + 1.60 + function setup() { 1.61 + progressListener1 = new ProgressListener(); 1.62 + browser1.addProgressListener(progressListener1, nsIWebProgress.NOTIFY_STATE_WINDOW); 1.63 + browser1.loadURI(kURI, null, null); 1.64 + progressListener2 = new ProgressListener(); 1.65 + browser2.addProgressListener(progressListener2, nsIWebProgress.NOTIFY_STATE_WINDOW); 1.66 + browser2.loadURI(kURI, null, null); 1.67 + } 1.68 + 1.69 + window.addEventListener("load", setup, false); 1.70 + 1.71 + var plugin1, plugin2; 1.72 + 1.73 + const kTimeout = 5000; // 5 seconds 1.74 + var paintGiveUp; 1.75 + var paintInterval; 1.76 + 1.77 + function startTest() { 1.78 + plugin1 = browser1.contentDocument.getElementById('p').wrappedJSObject; 1.79 + plugin2 = browser2.contentDocument.getElementById('p').wrappedJSObject; 1.80 + 1.81 + paintGiveUp = Date.now() + kTimeout; 1.82 + paintInterval = setInterval(waitForPaint, 100); 1.83 + } 1.84 + 1.85 + function waitForPaint() { 1.86 + if (!plugin1.isVisible()) { 1.87 + if (Date.now() < paintGiveUp) 1.88 + return; 1.89 + 1.90 + ok(false, "Plugin in tab 1 never became visible."); 1.91 + done(); 1.92 + return; 1.93 + } 1.94 + 1.95 + clearInterval(paintInterval); 1.96 + 1.97 + ok(true, "Plugin in tab 1 should be visible."); 1.98 + paintCountIs(plugin1, 1, "Plugin in tab 1 should have painted once."); 1.99 + 1.100 + ok(!plugin2.isVisible(), "Plugin in tab 2 should not be visible."); 1.101 + paintCountIs(plugin2, 0, "Plugin in tab 2 should not have painted."); 1.102 + 1.103 + tabbox.selectedIndex = 1; 1.104 + paintGiveUp = Date.now() + kTimeout; 1.105 + paintInterval = setInterval(part2, 100); 1.106 + } 1.107 + 1.108 + function part2() { 1.109 + if (!plugin2.isVisible()) { 1.110 + if (Date.now() < paintGiveUp) 1.111 + return; 1.112 + 1.113 + ok(false, "Plugin in tab 2 never became visible."); 1.114 + done(); 1.115 + return; 1.116 + } 1.117 + 1.118 + clearInterval(paintInterval); 1.119 + 1.120 + ok(true, "Plugin in tab 2 became visible."); 1.121 + paintCountIs(plugin2, 1, "Plugin in tab 2 should have painted once."); 1.122 + 1.123 + ok(!plugin1.isVisible(), "Plugin in tab 1 should have become invisible."); 1.124 + paintCountIs(plugin1, 1, "Plugin in tab 1 should have painted once."); 1.125 + 1.126 + // Setcolor invalidates 1.127 + plugin1.setColor('FF00FF00'); 1.128 + plugin2.setColor('FF00FF00'); 1.129 + 1.130 + setTimeout(part3, 500); 1.131 + } 1.132 + 1.133 + function part3() { 1.134 + paintCountIs(plugin1, 1, 1.135 + "Plugin in tab 1 should not have repainted after invalidate."); 1.136 + paintCountIs(plugin2, 2, 1.137 + "Plugin in tab 2 should have repainted after invalidate."); 1.138 + done(); 1.139 + } 1.140 + ]]></script> 1.141 + 1.142 +</window>