3 var expectedClicks
= [];
10 function makePluginElement()
12 var f
= document
.createElement('embed');
13 f
.setAttribute('id', 'swf_embed_' + items
);
14 f
.setAttribute('width', width
+ '');
15 f
.setAttribute('height', height
+ '');
16 f
.setAttribute('wmode', 'window');
17 f
.setAttribute('loop', 'false');
18 f
.setAttribute('src', 'resources/simple_blank.swf');
19 f
.setAttribute('type', 'application/x-shockwave-flash');
23 function makePluginElementWithHigherZIndex()
25 var f
= makePluginElement();
26 f
.style
.zIndex
= 1000;
27 f
.style
.position
= 'relative';
31 function makeIframeDiv()
33 var i
= document
.createElement('iframe');
34 i
.style
.position
= 'absolute';
36 i
.style
.left
= '30px';
37 i
.style
.width
= '80px';
38 i
.style
.height
= '80px';
39 i
.setAttribute('frameborder', '0');
40 i
.setAttribute('src', 'javascript:void(0);');
44 function makeOverlayDiv(color
, caseId
)
46 var o
= document
.createElement('div');
47 o
.style
.position
= 'absolute';
49 o
.style
.left
= '30px';
50 o
.style
.width
= '80px';
51 o
.style
.height
= '80px';
52 o
.style
.backgroundColor
= color
;
53 o
.style
.overflow
= 'hidden';
54 o
.innerHTML
= '<input type="button" id="button' + caseId
+ '" ' +
55 'onclick="doClick(' + caseId
+
56 ');" value="clickme" style="position: absolute; top: 10; left: 10; width: 60px; height: 60px;"/>';
60 function appendOverlay(overlayDivZIframe
, overlayDivZOverlay
, overlayInsideDiv
, expectClickable
, caseId
)
62 var id
= makeIframeDiv();
63 var root
= document
.getElementById(caseId
);
64 if (overlayDivZIframe
)
65 id
.style
.zIndex
= overlayDivZIframe
;
67 var od
= makeOverlayDiv(expectClickable
? 'green' : 'red', caseId
);
68 od
.style
.position
= 'absolute';
69 if (overlayDivZOverlay
)
70 od
.style
.zIndex
= overlayDivZOverlay
;
72 if (overlayInsideDiv
) {
73 var parentdiv
= document
.createElement('div');
74 if (overlayDivZOverlay
)
75 parentdiv
.style
.zIndex
= overlayDivZOverlay
;
77 parentdiv
.style
.position
= 'absolute';
78 parentdiv
.style
.top
= '0px';
79 parentdiv
.style
.left
= '0px';
80 parentdiv
.appendChild(id
);
81 parentdiv
.appendChild(od
);
82 root
.appendChild(parentdiv
);
89 function addCase(x
, y
, tags
)
94 var expectClickable
= tags
.expect
&& tags
.expect
.indexOf('UNDER') == -1;
95 expectedClicks
[caseId
] = expectClickable
;
97 var container
= document
.getElementById('container');
98 var root
= document
.createElement('div');
99 root
.style
.position
= 'absolute';
100 root
.style
.left
= x
* (width
+ 40) + 'px';
101 root
.style
.top
= y
* (height
+ 20) + 'px';
103 container
.appendChild(root
);
106 var overlayDivZIframe
;
107 var overlayDivZOverlay
;
108 if (tags
.pluginLowerz
) {
110 overlayDivZIframe
= 200;
111 overlayDivZOverlay
= 201;
112 } else if (tags
.pluginHigherz
) {
114 overlayDivZIframe
= 100;
115 overlayDivZOverlay
= 101;
116 } else if (tags
.pluginEqualz
) {
118 overlayDivZIframe
= 100;
119 overlayDivZOverlay
= 100;
120 } else if (tags
.pluginExplicitHigherZIndex
) {
121 // For this test case we set the z-index for the iframe and the overlay
122 // to be lower than the plugin.
123 overlayDivZIframe
= 100;
124 overlayDivZOverlay
= 0;
127 var appendPlugin = function()
130 if (tags
.pluginExplicitHigherZIndex
) {
131 pd
= makePluginElementWithHigherZIndex();
133 pd
= makePluginElement();
136 if (tags
.pluginInsideDiv
|| pluginDivZ
) {
137 var parentdiv
= document
.createElement('div');
138 parentdiv
.appendChild(pd
)
139 if (!tags
.pluginNorelative
)
140 parentdiv
.style
.position
= 'relative';
143 parentdiv
.style
.zIndex
= pluginDivZ
;
145 root
.appendChild(parentdiv
);
147 if (!tags
.pluginNorelative
)
148 pd
.style
.position
= 'relative';
149 root
.appendChild(pd
);
153 if (tags
.overlayEarlier
) {
154 appendOverlay(overlayDivZIframe
, overlayDivZOverlay
, tags
.overlayInsideDiv
, expectClickable
, caseId
);
158 if (tags
.overlayOnTimeout
) {
159 setTimeout('appendOverlay('+overlayDivZIframe
+', '+overlayDivZOverlay
+', ' + tags
.overlayInsideDiv
+ ', ' + expectClickable
+ ', ' + caseId
+ ')', 0);
161 appendOverlay(overlayDivZIframe
, overlayDivZOverlay
, tags
.overlayInsideDiv
, expectClickable
, caseId
);
170 // Check success/failure.
171 var output
= document
.getElementById("output");
172 var waitingForMoreClicks
= false;
174 for (k
in expectedClicks
) {
175 if (expectedClicks
[k
] && !clicks
[k
])
176 waitingForMoreClicks
= true;
177 else if (!expectedClicks
[k
] && clicks
[k
]) {
178 output
.innerHTML
= 'FAILURE';
183 if (!waitingForMoreClicks
) {
184 output
.innerHTML
= 'SUCCESS';
190 addCase(0, 0, {expect
:'overlay OVER'});
191 addCase(1, 0, {'overlayEarlier':1, 'overlayInsideDiv': 1, 'pluginInsideDiv':1, expect
:'overlay UNDER'});
192 addCase(2, 0, {'pluginLowerz':1, expect
:'overlay OVER'});
193 addCase(3, 0, {'pluginHigherz':1, expect
:'overlay UNDER'});
194 addCase(0, 1, {'overlayInsideDiv':1, expect
:'overlay OVER'});
195 addCase(1, 1, {'pluginLowerz':1, 'overlayInsideDiv':1, expect
:'overlay OVER'});
196 addCase(2, 1, {'pluginHigherz':1, 'overlayInsideDiv':1, expect
:'overlay UNDER'});
197 addCase(0, 2, {'pluginEqualz':1, 'overlayInsideDiv':1, expect
:'overlay OVER'});
198 addCase(1, 2, {'pluginEqualz':1, 'overlayInsideDiv':1, 'overlayEarlier':1, expect
:'overlay UNDER'});
199 addCase(2, 2, {'overlayEarlier':1, expect
:'overlay UNDER'});
200 addCase(3, 2, {'overlayEarlier':1, 'pluginNorelative':1, expect
:'overlay OVER'});
201 addCase(0, 3, {'pluginNorelative':1, expect
:'overlay OVER'});
202 addCase(1, 3, {'overlayEarlier':1, 'pluginNorelative':1, 'pluginInsideDiv':1, expect
:'overlay OVER'});
203 addCase(2, 3, {'pluginNorelative':1, 'pluginInsideDiv':1, expect
:'overlay OVER'});
204 addCase(3, 3, {'pluginLowerz':1, 'overlayOnTimeout':1, expect
:'overlay OVER'});
205 addCase(4, 0, {'pluginExplicitHigherZIndex': 1, 'pluginNorelative': 1, 'pluginInsideDiv': 1, 'overlayInsideDiv': 1, expect
: 'overlay UNDER' });
209 // Automation: try to click on each button.
210 var nextIdToClick
= 0;
213 if (window
.testRunner
&& window
.eventSender
) {
214 testRunner
.waitUntilDone();
215 testRunner
.dumpAsText();
216 setTimeout(doNextClick
, 0);
220 function moveMouseOver(elemName
) {
221 var elem
= document
.getElementById(elemName
);
222 var x
= elem
.offsetLeft
+ elem
.scrollWidth
/ 2;
223 var y
= elem
.offsetTop
+ elem
.scrollHeight
/ 2;
224 var offsetParent
= elem
.offsetParent
;
225 while (offsetParent
) {
226 x
+= offsetParent
.offsetLeft
;
227 y
+= offsetParent
.offsetTop
;
228 offsetParent
= offsetParent
.offsetParent
;
230 eventSender
.mouseMoveTo(x
, y
);
233 function doNextClick() {
234 eventSender
.mouseUp();
235 if (nextIdToClick
< expectedClicks
.length
) {
236 moveMouseOver('button' + nextIdToClick
);
237 eventSender
.mouseDown();
239 setTimeout(doNextClick
, 0);
241 setTimeout(function() {
242 testRunner
.notifyDone();
249 <body onload=
"init()">
251 <p>Test that iframe shims can be used to overlay HTML above a
252 windowed plugin. The red squares should be hidden by the blue
253 flash plugins, and the green squares should appear over the
254 plugins. To test interactively, click over the buttons on the
255 squares. You should not be able to reach the red squares'
258 <p>Prints
"SUCCESS" on success,
"FAILURE" on failure.
</p>
259 <div id=output
>NONE
</div>
260 <div id=
"container" style=
"position: relative;"></div>