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