dom/plugins/test/mochitest/test_bug406541.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/mochitest/test_bug406541.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +<!doctype html>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test for Bug 406541</title>
     1.8 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="utils.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.11 +
    1.12 +  <meta http-equiv="content-type" content="text/html; charset=utf-8">
    1.13 +</head>
    1.14 +<body>
    1.15 +<script type="application/x-child-payload" id="child-payload">
    1.16 +  // This is injected into the file:/// origin iframe, see below.
    1.17 +
    1.18 +  // appletA should spawn, appletB, with a codebase outside the temp directory,
    1.19 +  // should not.
    1.20 +  var appletA = document.createElement("applet");
    1.21 +  var appletB = document.createElement("applet");
    1.22 +  var appletC = document.createElement("applet");
    1.23 +  appletA.type = appletB.type = appletC.type = "application/x-java-test";
    1.24 +  appletB.setAttribute("codebase", "file:///");
    1.25 +  appletC.setAttribute("codebase", "./subdir_bug406541/");
    1.26 +  document.body.appendChild(appletA);
    1.27 +  document.body.appendChild(appletB);
    1.28 +  document.body.appendChild(appletC);
    1.29 +  function isSpawned(plugin) {
    1.30 +    try {
    1.31 +      var x = plugin.getJavaCodebase();
    1.32 +      return true;
    1.33 +    } catch (e) {}
    1.34 +    return false;
    1.35 +  }
    1.36 +  window.parent.postMessage({ "A": isSpawned(appletA),
    1.37 +                              "B": isSpawned(appletB),
    1.38 +                              "C": isSpawned(appletC) }, "*");
    1.39 +</script>
    1.40 +<script type="application/javascript">
    1.41 +  SimpleTest.waitForExplicitFinish();
    1.42 +  setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED,
    1.43 +                            "Java Test Plug-in");
    1.44 +  SpecialPowers.pushPrefEnv({ "set": [
    1.45 +                              ['plugin.java.mime', 'application/x-java-test']
    1.46 +                            ] }, runTest);
    1.47 +
    1.48 +  function runTest() {
    1.49 +    // Create a empty file and point an iframe at it
    1.50 +    var Cc = SpecialPowers.Cc;
    1.51 +    var Ci = SpecialPowers.Ci;
    1.52 +    var file = Cc["@mozilla.org/file/directory_service;1"]
    1.53 +      .getService(Ci.nsIProperties)
    1.54 +      .get("TmpD", Ci.nsIFile);
    1.55 +    var subdir = Cc["@mozilla.org/file/directory_service;1"]
    1.56 +      .getService(Ci.nsIProperties)
    1.57 +      .get("TmpD", Ci.nsIFile);
    1.58 +    file.append("test_bug406541.html");
    1.59 +    file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
    1.60 +    subdir.append("subdir_bug406541");
    1.61 +    subdir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600);
    1.62 +
    1.63 +    var i = document.createElement("iframe");
    1.64 +    var loaded = false;
    1.65 +    i.addEventListener("load", function initialLoad() {
    1.66 +      if (!loaded) {
    1.67 +        // Once loaded, use special powers to point it at the file
    1.68 +        SpecialPowers.wrap(i.contentWindow).location.href = "file://" + file.path;
    1.69 +        loaded = true;
    1.70 +      } else {
    1.71 +        // Inject the child-payload script to the file:/// origin. Let it test
    1.72 +        // applet spawning and send the results in a postMessage. (Because I
    1.73 +        // couldn't get SpecialPowers to let me touch applets cross-origin, then
    1.74 +        // gave up.)
    1.75 +        var innerdoc = SpecialPowers.wrap(i.contentWindow).document;
    1.76 +        var s = innerdoc.createElement("script");
    1.77 +        s.type = "text/javascript";
    1.78 +        s.textContent = document.getElementById("child-payload").textContent;
    1.79 +        var finished = false;
    1.80 +        window.onmessage = function(message) {
    1.81 +          ok(message.data.A, "Plugin A should spawn");
    1.82 +          ok(!message.data.B, "Plugin B should NOT spawn");
    1.83 +          ok(message.data.C, "Plugin C should spawn");
    1.84 +          file.remove(false);
    1.85 +          subdir.remove(false);
    1.86 +          finished = true;
    1.87 +          SimpleTest.finish();
    1.88 +        };
    1.89 +        innerdoc.body.appendChild(s);
    1.90 +
    1.91 +        SimpleTest.executeSoon(function() {
    1.92 +          if (!finished) {
    1.93 +            ok(finished, "Should have received callback by now");
    1.94 +            SimpleTest.finish();
    1.95 +          }
    1.96 +        });
    1.97 +      }
    1.98 +    }, false);
    1.99 +    document.body.appendChild(i);
   1.100 +  }
   1.101 +</script>
   1.102 +</body>
   1.103 +</html>

mercurial