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