Bug 738396 - Test. r=bsmedberg
authorJohn Schoenick <jschoenick@mozilla.com>
Thu, 25 Apr 2013 13:22:22 -0700
changeset 170903 19a4abd04dceab5eba3cf936dca901e63823808e
parent 170902 12b636c82b24eefd24876981c39829523acc550b
child 170904 277862f099a4ce08bf4273274d0c9b4b5a781d7e
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbsmedberg
bugs738396
milestone30.0a1
Bug 738396 - Test. r=bsmedberg
dom/plugins/test/mochitest/file_bug738396.html
dom/plugins/test/mochitest/mochitest.ini
dom/plugins/test/mochitest/test_bug738396.html
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/mochitest/file_bug738396.html
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Helper for test_bug738396.html</title>
+  <meta charset="utf-8">
+</head>
+<body>
+  <!-- Test that the plugin sees "good" in each of these cases -->
+  <div id="codebasevis">
+    <applet codebase="good" codebase="bad" ></applet>
+
+    <applet codebase="bad">
+      <param name="codebase" value="good">
+    </applet>
+
+    <applet codebase="bad">
+      <param name="codebase" value="stillbad">
+      <param name="codebase" value="good">
+    </applet>
+
+    <applet>
+      <param name="codebase" value="good">
+    </applet>
+
+    <object type="application/x-java-test" codebase="good" codebase="bad"></object>
+
+    <object type="application/x-java-test" codebase="bad">
+      <param name="codebase" value="good">
+    </object>
+
+    <object type="application/x-java-test" codebase="bad">
+      <param name="codebase" value="stillbad">
+      <param name="codebase" value="good">
+    </object>
+
+    <object type="application/x-java-test">
+      <param name="codebase" value="good">
+    </object>
+
+    <embed type="application/x-java-test" codebase="good" codebase="bad">
+  </div>
+  <div id="blockedcodebase">
+    <!-- Test that none of these are allowed to load -->
+    <applet codebase="file:///" codebase="notused"></applet>
+
+    <applet codebase="notused">
+      <param name="codebase" value="file:///">
+    </applet>
+
+    <applet codebase="notused">
+      <param name="codebase" value="notused">
+      <param name="codebase" value="file:///">
+    </applet>
+
+    <applet>
+      <param name="codebase" value="file:///">
+    </applet>
+
+    <object type="application/x-java-test" codebase="file:///" codebase="notused"></object>
+
+    <object type="application/x-java-test" codebase="notused">
+      <param name="codebase" value="file:///">
+    </object>
+
+    <object type="application/x-java-test" codebase="notused">
+      <param name="codebase" value="notused">
+      <param name="codebase" value="file:///">
+    </object>
+
+    <object type="application/x-java-test">
+      <param name="codebase" value="file:///">
+    </object>
+
+    <embed type="application/x-java-test" codebase="file:///" codebase="notused">
+  </div>
+  <div id="nocodebase">
+    <applet></applet>
+    <object type="application/x-java-test"></object>
+    <embed type="application/x-java-test">
+  </div>
+  <div id="emptycodebase">
+    <applet codebase=""></applet>
+    <object type="application/x-java-test" codebase=""></object>
+    <embed type="application/x-java-test" codebase="">
+  </div>
+</body>
+</html>
--- a/dom/plugins/test/mochitest/mochitest.ini
+++ b/dom/plugins/test/mochitest/mochitest.ini
@@ -1,12 +1,13 @@
 [DEFAULT]
 support-files =
   307-xo-redirect.sjs
   crashing_subpage.html
+  file_bug738396.html
   file_bug771202.html
   file_bug863792.html
   large-pic.jpg
   loremipsum.txt
   loremipsum.xtest
   loremipsum.xtest^headers^
   loremipsum_file.txt
   loremipsum_nocache.txt
@@ -21,16 +22,17 @@ support-files =
   utils.js
 
 [test_GCrace.html]
 [test_NPNVdocumentOrigin.html]
 [test_NPPVpluginWantsAllNetworkStreams.html]
 [test_bug532208.html]
 [test_bug539565-1.html]
 [test_bug539565-2.html]
+[test_bug738396.html]
 [test_bug771202.html]
 [test_bug777098.html]
 [test_bug784131.html]
 [test_bug813906.html]
 [test_bug854082.html]
 [test_bug863792.html]
 [test_bug967694.html]
 [test_cocoa_focus.html]
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/mochitest/test_bug738396.html
@@ -0,0 +1,88 @@
+<!doctype html>
+<html>
+<head>
+  <title>Test for Bug 738396</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="utils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+
+  <meta http-equiv="content-type" content="text/html; charset=utf-8">
+</head>
+<body>
+  <script type="text/javascript">
+    setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED,
+                              "Java Test Plug-in");
+
+    SpecialPowers.pushPrefEnv({ "set": [
+                                ['plugin.java.mime', 'application/x-java-test']
+                              ] }, loadFrame);
+    SimpleTest.waitForExplicitFinish();
+
+    function loadFrame() {
+      var iframe = document.createElement("iframe");
+      iframe.src = "./file_bug738396.html";
+      iframe.addEventListener("load", function() {
+        runTest(iframe.contentDocument);
+      });
+      document.body.appendChild(iframe);
+    }
+
+    function runTest(doc) {
+      // Check that the canonicalized version of the codebase 'good' was passed
+      // to the plugin in all cases
+      var a = doc.createElement('a');
+      a.href = "good";
+      var goodCodebase = a.href;
+      var codebasevis = doc.getElementById("codebasevis")
+        .querySelectorAll("applet, object, embed");
+      for (var elem of codebasevis) {
+        var codebase = null;
+        try {
+          codebase = elem.getJavaCodebase();
+        } catch (e) {}
+        is(codebase, goodCodebase,
+           "Check that the test plugin sees the proper codebase");
+      }
+      // Check that none of the applets in blockedcodebase were allowed to spawn
+      var blockedcodebase = doc.getElementById("blockedcodebase")
+        .querySelectorAll("applet, object, embed");
+      for (var elem of blockedcodebase) {
+        var spawned = false;
+        try {
+          elem.getObjectValue();
+          spawned = true;
+        } catch (e) {}
+        ok(!spawned, "Plugin should not be allowed to spawn");
+      }
+
+      // With no codebase, the codebase should resolve to "."
+      a.href = ".";
+      goodCodebase = a.href;
+      var nocodebase = doc.getElementById("nocodebase")
+        .querySelectorAll("applet, object, embed");
+      for (var elem of nocodebase) {
+        var codebase = null;
+        try {
+          codebase = elem.getJavaCodebase();
+        } catch (e) {}
+        is(codebase, goodCodebase, "Codebase should resolve to '.'");
+      }
+
+      // With empty codebase, the codebase should resolve to "/"
+      a.href = "/";
+      goodCodebase = a.href;
+      var nocodebase = doc.getElementById("emptycodebase")
+        .querySelectorAll("applet, object, embed");
+      for (var elem of nocodebase) {
+        var codebase = null;
+        try {
+          codebase = elem.getJavaCodebase();
+        } catch (e) {}
+        is(codebase, goodCodebase, "Codebase should resolve to '/'");
+      }
+
+      SimpleTest.finish();
+    }
+</script>
+</body>
+</html>