|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> |
|
3 |
|
4 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
5 orient="vertical"> |
|
6 |
|
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; |
|
23 |
|
24 const nsIWebProgress = Components.interfaces.nsIWebProgress; |
|
25 const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener; |
|
26 |
|
27 const kURI = 'http://mochi.test:8888/chrome/dom/plugins/test/mochitest/plugin_visibility_loader.html'; |
|
28 |
|
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 }; |
|
43 |
|
44 var loadCount = 0; |
|
45 function browserLoaded() { |
|
46 ++loadCount; |
|
47 if (2 == loadCount) |
|
48 startTest(); |
|
49 } |
|
50 |
|
51 var tabbox = document.getElementById('tabbox'); |
|
52 var browser1 = document.getElementById('browser1'); |
|
53 var browser2 = document.getElementById('browser2'); |
|
54 |
|
55 var progressListener1, progressListener2; |
|
56 |
|
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 } |
|
65 |
|
66 window.addEventListener("load", setup, false); |
|
67 |
|
68 var plugin1, plugin2; |
|
69 |
|
70 const kTimeout = 5000; // 5 seconds |
|
71 var paintGiveUp; |
|
72 var paintInterval; |
|
73 |
|
74 function startTest() { |
|
75 plugin1 = browser1.contentDocument.getElementById('p').wrappedJSObject; |
|
76 plugin2 = browser2.contentDocument.getElementById('p').wrappedJSObject; |
|
77 |
|
78 paintGiveUp = Date.now() + kTimeout; |
|
79 paintInterval = setInterval(waitForPaint, 100); |
|
80 } |
|
81 |
|
82 function waitForPaint() { |
|
83 if (!plugin1.isVisible()) { |
|
84 if (Date.now() < paintGiveUp) |
|
85 return; |
|
86 |
|
87 ok(false, "Plugin in tab 1 never became visible."); |
|
88 done(); |
|
89 return; |
|
90 } |
|
91 |
|
92 clearInterval(paintInterval); |
|
93 |
|
94 ok(true, "Plugin in tab 1 should be visible."); |
|
95 paintCountIs(plugin1, 1, "Plugin in tab 1 should have painted once."); |
|
96 |
|
97 ok(!plugin2.isVisible(), "Plugin in tab 2 should not be visible."); |
|
98 paintCountIs(plugin2, 0, "Plugin in tab 2 should not have painted."); |
|
99 |
|
100 tabbox.selectedIndex = 1; |
|
101 paintGiveUp = Date.now() + kTimeout; |
|
102 paintInterval = setInterval(part2, 100); |
|
103 } |
|
104 |
|
105 function part2() { |
|
106 if (!plugin2.isVisible()) { |
|
107 if (Date.now() < paintGiveUp) |
|
108 return; |
|
109 |
|
110 ok(false, "Plugin in tab 2 never became visible."); |
|
111 done(); |
|
112 return; |
|
113 } |
|
114 |
|
115 clearInterval(paintInterval); |
|
116 |
|
117 ok(true, "Plugin in tab 2 became visible."); |
|
118 paintCountIs(plugin2, 1, "Plugin in tab 2 should have painted once."); |
|
119 |
|
120 ok(!plugin1.isVisible(), "Plugin in tab 1 should have become invisible."); |
|
121 paintCountIs(plugin1, 1, "Plugin in tab 1 should have painted once."); |
|
122 |
|
123 // Setcolor invalidates |
|
124 plugin1.setColor('FF00FF00'); |
|
125 plugin2.setColor('FF00FF00'); |
|
126 |
|
127 setTimeout(part3, 500); |
|
128 } |
|
129 |
|
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> |
|
138 |
|
139 </window> |