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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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;
    15   var exceptionThrown = false;
    16   var p = null;
    17   var d1 = null;
    18   var d2 = null;
    20   var destroyed = false;
    22   function begin() {
    23     runTests(function() {
    24       // Callback when finished - set plugin to windowed and repeat the tests
    26       info("Repeating tests with wmode=window");
    27       p.setAttribute("wmode", "window");
    28       d1.appendChild(p);
    30       // Forces the plugin to be respawned
    31       p.src = p.src;
    33       destroyed = false;
    34       exceptionThrown = false;
    35       runTests(function () {
    36         SimpleTest.finish();
    37       });
    38     });
    39   }
    41   function runTests(callback) {
    42     p = document.getElementById('plugin1');
    43     d1 = document.getElementById('div1');
    44     d2 = document.getElementById('div2');
    46     // First tests involve moving the instance from one div to another.
    47     p.startWatchingInstanceCount();
    48     p.callOnDestroy(function() {
    49       destroyed = true;
    50     });
    52     try {
    53       d1.removeChild(p);
    54     } catch (e) {
    55       exceptionThrown = true;
    56     }
    57     is(exceptionThrown, false, "Testing for exception after removeChild.");
    59     try {
    60       d2.appendChild(p);
    61     } catch (e) {
    62       exceptionThrown = true;
    63     }
    64     is(exceptionThrown, false, "Testing for exception after appendChild.");
    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.");
    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.");
    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.");
    86           p.stopWatchingInstanceCount();
    87           callback.apply(null);
    88         });
    89       });
    90     });
    91   }
    92   </script>
    94   <p id="display"></p>
    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>

mercurial