<script>
  function noop(x) {
  }

  function doGC() {
    if (window.gc) {
      // GC twice to make sure everything is cleaned up.
      for (var i = 0; i < 4; i++) {
        window.gc();
      }
    }
  }

  function runtest() {
    if (window.testRunner)
      testRunner.dumpAsText();

    doGC();

    var plug1 = document.getElementById("plug1");
    var plug2 = document.getElementById("plug2");
    var output = document.getElementById("output");
    output.innerHTML = "";

    var testObj1 = plug1.testObject;
    var testObj2 = plug2.testObject;

    var successCount = 0;

    // Verify we can access each object.
    if (testObj1.foo == "foo") {
      successCount++;
      output.innerHTML += "Got testObj1 property<br>";
    }
    if (testObj2.foo == "foo") {
      successCount++;
      output.innerHTML += "Got testObj2 property<br>";
    }

    // Now remove the first plugin
    plug1.parentNode.removeChild(plug1);

    try {
      if (testObj1.foo == "foo") {
        output.innerHTML = "Accessed nuked object!<br>";
      }
    } catch (e) {
        if (e instanceof ReferenceError)
            successCount++;
    }

    try {
      if (testObj2.foo == "foo") {
        successCount++;
        output.innerHTML += "Got testObj2 property<br>";
      }
    } catch(e) {
      output.inerHTML += "Reference error accessing live object: " + e;
    }

    // Now remove the second plugin
    plug2.parentNode.removeChild(plug2);

    try {
      if (testObj2.foo == "foo") {
        output.innerHTML = "Accessed nuked object!<br>";
      }
    } catch (e) {
        if (e instanceof ReferenceError)
            successCount++;
    }

    var success = (successCount == 5);
    output.innerHTML += (success ? "SUCCESS" : "FAILURE");
  }
</script>

<body onload="runtest()">

Test that we can create two plugins, and independently clean each.

Prints "SUCCESS" on success, "FAILURE" on failure.

<embed id="plug1" type="application/x-webkit-test-netscape">
<embed id="plug2" type="application/x-webkit-test-netscape">

<div id=output>FAILURE</div>

</body>

