|
1 <!DOCTYPE html> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test re-parentinging an instance's DOM node</title> |
|
5 <script type="text/javascript" src="/MochiKit/packed.js"></script> |
|
6 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
8 <script type="text/javascript" src="utils.js"></script> |
|
9 </head> |
|
10 <body onload="begin()"> |
|
11 <script type="application/javascript;version=1.8"> |
|
12 SimpleTest.waitForExplicitFinish(); |
|
13 getTestPlugin().enabledState = SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED; |
|
14 |
|
15 var exceptionThrown = false; |
|
16 var p = null; |
|
17 var d1 = null; |
|
18 var d2 = null; |
|
19 |
|
20 var destroyed = false; |
|
21 |
|
22 function begin() { |
|
23 runTests(function() { |
|
24 // Callback when finished - set plugin to windowed and repeat the tests |
|
25 |
|
26 info("Repeating tests with wmode=window"); |
|
27 p.setAttribute("wmode", "window"); |
|
28 d1.appendChild(p); |
|
29 |
|
30 // Forces the plugin to be respawned |
|
31 p.src = p.src; |
|
32 |
|
33 destroyed = false; |
|
34 exceptionThrown = false; |
|
35 runTests(function () { |
|
36 SimpleTest.finish(); |
|
37 }); |
|
38 }); |
|
39 } |
|
40 |
|
41 function runTests(callback) { |
|
42 p = document.getElementById('plugin1'); |
|
43 d1 = document.getElementById('div1'); |
|
44 d2 = document.getElementById('div2'); |
|
45 |
|
46 // First tests involve moving the instance from one div to another. |
|
47 p.startWatchingInstanceCount(); |
|
48 p.callOnDestroy(function() { |
|
49 destroyed = true; |
|
50 }); |
|
51 |
|
52 try { |
|
53 d1.removeChild(p); |
|
54 } catch (e) { |
|
55 exceptionThrown = true; |
|
56 } |
|
57 is(exceptionThrown, false, "Testing for exception after removeChild."); |
|
58 |
|
59 try { |
|
60 d2.appendChild(p); |
|
61 } catch (e) { |
|
62 exceptionThrown = true; |
|
63 } |
|
64 is(exceptionThrown, false, "Testing for exception after appendChild."); |
|
65 |
|
66 is(destroyed, false, "No instances should have been destroyed at this point."); |
|
67 is(p.getInstanceCount(), 0, "No new instances should have been created at this point."); |
|
68 |
|
69 // Wait for the event loop to spin and ensure the plugin still wasn't touched |
|
70 SimpleTest.executeSoon(function() { |
|
71 is(destroyed, false, "No instances should have been destroyed at this point."); |
|
72 is(p.getInstanceCount(), 0, "No new instances should have been created at this point."); |
|
73 |
|
74 // Removing the instance for a full event loop *should* respawn |
|
75 d2.removeChild(p); |
|
76 SimpleTest.executeSoon(function() { |
|
77 d2.appendChild(p); |
|
78 SimpleTest.executeSoon(function() { |
|
79 try { |
|
80 is(p.getInstanceCount(), 1, "One new instance should have been created at this point."); |
|
81 } catch (e) { |
|
82 exceptionThrown = true; |
|
83 } |
|
84 is(exceptionThrown, false, "Testing for exception getting instance count from plugin."); |
|
85 |
|
86 p.stopWatchingInstanceCount(); |
|
87 callback.apply(null); |
|
88 }); |
|
89 }); |
|
90 }); |
|
91 } |
|
92 </script> |
|
93 |
|
94 <p id="display"></p> |
|
95 |
|
96 <div id="div1"> |
|
97 <!-- This embed has to have a "src" attribute. Part of this test involves seeing if we |
|
98 properly restart plugins that have been added back to a document without a change |
|
99 in URL. Not re-loading an object when the URL hasn't changed is a shortcut used for |
|
100 some object types. Without a URL, this won't be tested. --> |
|
101 <embed id="plugin1" src="loremipsum.txt" type="application/x-test" width="200" height="200"></embed> |
|
102 </div> |
|
103 <div id="div2"> |
|
104 </div> |
|
105 </body> |
|
106 </html> |