dom/plugins/test/mochitest/test_instance_re-parent.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/mochitest/test_instance_re-parent.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test re-parentinging an instance's DOM node</title>
     1.8 +  <script type="text/javascript" src="/MochiKit/packed.js"></script>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +  <script type="text/javascript" src="utils.js"></script>
    1.12 +</head>
    1.13 +<body onload="begin()">
    1.14 +  <script type="application/javascript;version=1.8">
    1.15 +  SimpleTest.waitForExplicitFinish();
    1.16 +  getTestPlugin().enabledState = SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED;
    1.17 +
    1.18 +  var exceptionThrown = false;
    1.19 +  var p = null;
    1.20 +  var d1 = null;
    1.21 +  var d2 = null;
    1.22 +
    1.23 +  var destroyed = false;
    1.24 +
    1.25 +  function begin() {
    1.26 +    runTests(function() {
    1.27 +      // Callback when finished - set plugin to windowed and repeat the tests
    1.28 +
    1.29 +      info("Repeating tests with wmode=window");
    1.30 +      p.setAttribute("wmode", "window");
    1.31 +      d1.appendChild(p);
    1.32 +
    1.33 +      // Forces the plugin to be respawned
    1.34 +      p.src = p.src;
    1.35 +
    1.36 +      destroyed = false;
    1.37 +      exceptionThrown = false;
    1.38 +      runTests(function () {
    1.39 +        SimpleTest.finish();
    1.40 +      });
    1.41 +    });
    1.42 +  }
    1.43 +
    1.44 +  function runTests(callback) {
    1.45 +    p = document.getElementById('plugin1');
    1.46 +    d1 = document.getElementById('div1');
    1.47 +    d2 = document.getElementById('div2');
    1.48 +
    1.49 +    // First tests involve moving the instance from one div to another.
    1.50 +    p.startWatchingInstanceCount();
    1.51 +    p.callOnDestroy(function() {
    1.52 +      destroyed = true;
    1.53 +    });
    1.54 +
    1.55 +    try {
    1.56 +      d1.removeChild(p);
    1.57 +    } catch (e) {
    1.58 +      exceptionThrown = true;
    1.59 +    }
    1.60 +    is(exceptionThrown, false, "Testing for exception after removeChild.");
    1.61 +
    1.62 +    try {
    1.63 +      d2.appendChild(p);
    1.64 +    } catch (e) {
    1.65 +      exceptionThrown = true;
    1.66 +    }
    1.67 +    is(exceptionThrown, false, "Testing for exception after appendChild.");
    1.68 +
    1.69 +    is(destroyed, false, "No instances should have been destroyed at this point.");
    1.70 +    is(p.getInstanceCount(), 0, "No new instances should have been created at this point.");
    1.71 +
    1.72 +    // Wait for the event loop to spin and ensure the plugin still wasn't touched
    1.73 +    SimpleTest.executeSoon(function() {
    1.74 +      is(destroyed, false, "No instances should have been destroyed at this point.");
    1.75 +      is(p.getInstanceCount(), 0, "No new instances should have been created at this point.");
    1.76 +
    1.77 +      // Removing the instance for a full event loop *should* respawn
    1.78 +      d2.removeChild(p);
    1.79 +      SimpleTest.executeSoon(function() {
    1.80 +        d2.appendChild(p);
    1.81 +        SimpleTest.executeSoon(function() {
    1.82 +          try {
    1.83 +            is(p.getInstanceCount(), 1, "One new instance should have been created at this point.");
    1.84 +          } catch (e) {
    1.85 +            exceptionThrown = true;
    1.86 +          }
    1.87 +          is(exceptionThrown, false, "Testing for exception getting instance count from plugin.");
    1.88 +
    1.89 +          p.stopWatchingInstanceCount();
    1.90 +          callback.apply(null);
    1.91 +        });
    1.92 +      });
    1.93 +    });
    1.94 +  }
    1.95 +  </script>
    1.96 +
    1.97 +  <p id="display"></p>
    1.98 +
    1.99 +  <div id="div1">
   1.100 +    <!-- This embed has to have a "src" attribute. Part of this test involves seeing if we
   1.101 +         properly restart plugins that have been added back to a document without a change
   1.102 +         in URL. Not re-loading an object when the URL hasn't changed is a shortcut used for
   1.103 +         some object types. Without a URL, this won't be tested. -->
   1.104 +    <embed id="plugin1" src="loremipsum.txt" type="application/x-test" width="200" height="200"></embed>
   1.105 +  </div>
   1.106 +  <div id="div2">
   1.107 +  </div>
   1.108 +</body>
   1.109 +</html>

mercurial