dom/plugins/test/mochitest/test_bug406541.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.

michael@0 1 <!doctype html>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test for Bug 406541</title>
michael@0 5 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="utils.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 8
michael@0 9 <meta http-equiv="content-type" content="text/html; charset=utf-8">
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <script type="application/x-child-payload" id="child-payload">
michael@0 13 // This is injected into the file:/// origin iframe, see below.
michael@0 14
michael@0 15 // appletA should spawn, appletB, with a codebase outside the temp directory,
michael@0 16 // should not.
michael@0 17 var appletA = document.createElement("applet");
michael@0 18 var appletB = document.createElement("applet");
michael@0 19 var appletC = document.createElement("applet");
michael@0 20 appletA.type = appletB.type = appletC.type = "application/x-java-test";
michael@0 21 appletB.setAttribute("codebase", "file:///");
michael@0 22 appletC.setAttribute("codebase", "./subdir_bug406541/");
michael@0 23 document.body.appendChild(appletA);
michael@0 24 document.body.appendChild(appletB);
michael@0 25 document.body.appendChild(appletC);
michael@0 26 function isSpawned(plugin) {
michael@0 27 try {
michael@0 28 var x = plugin.getJavaCodebase();
michael@0 29 return true;
michael@0 30 } catch (e) {}
michael@0 31 return false;
michael@0 32 }
michael@0 33 window.parent.postMessage({ "A": isSpawned(appletA),
michael@0 34 "B": isSpawned(appletB),
michael@0 35 "C": isSpawned(appletC) }, "*");
michael@0 36 </script>
michael@0 37 <script type="application/javascript">
michael@0 38 SimpleTest.waitForExplicitFinish();
michael@0 39 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED,
michael@0 40 "Java Test Plug-in");
michael@0 41 SpecialPowers.pushPrefEnv({ "set": [
michael@0 42 ['plugin.java.mime', 'application/x-java-test']
michael@0 43 ] }, runTest);
michael@0 44
michael@0 45 function runTest() {
michael@0 46 // Create a empty file and point an iframe at it
michael@0 47 var Cc = SpecialPowers.Cc;
michael@0 48 var Ci = SpecialPowers.Ci;
michael@0 49 var file = Cc["@mozilla.org/file/directory_service;1"]
michael@0 50 .getService(Ci.nsIProperties)
michael@0 51 .get("TmpD", Ci.nsIFile);
michael@0 52 var subdir = Cc["@mozilla.org/file/directory_service;1"]
michael@0 53 .getService(Ci.nsIProperties)
michael@0 54 .get("TmpD", Ci.nsIFile);
michael@0 55 file.append("test_bug406541.html");
michael@0 56 file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
michael@0 57 subdir.append("subdir_bug406541");
michael@0 58 subdir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600);
michael@0 59
michael@0 60 var i = document.createElement("iframe");
michael@0 61 var loaded = false;
michael@0 62 i.addEventListener("load", function initialLoad() {
michael@0 63 if (!loaded) {
michael@0 64 // Once loaded, use special powers to point it at the file
michael@0 65 SpecialPowers.wrap(i.contentWindow).location.href = "file://" + file.path;
michael@0 66 loaded = true;
michael@0 67 } else {
michael@0 68 // Inject the child-payload script to the file:/// origin. Let it test
michael@0 69 // applet spawning and send the results in a postMessage. (Because I
michael@0 70 // couldn't get SpecialPowers to let me touch applets cross-origin, then
michael@0 71 // gave up.)
michael@0 72 var innerdoc = SpecialPowers.wrap(i.contentWindow).document;
michael@0 73 var s = innerdoc.createElement("script");
michael@0 74 s.type = "text/javascript";
michael@0 75 s.textContent = document.getElementById("child-payload").textContent;
michael@0 76 var finished = false;
michael@0 77 window.onmessage = function(message) {
michael@0 78 ok(message.data.A, "Plugin A should spawn");
michael@0 79 ok(!message.data.B, "Plugin B should NOT spawn");
michael@0 80 ok(message.data.C, "Plugin C should spawn");
michael@0 81 file.remove(false);
michael@0 82 subdir.remove(false);
michael@0 83 finished = true;
michael@0 84 SimpleTest.finish();
michael@0 85 };
michael@0 86 innerdoc.body.appendChild(s);
michael@0 87
michael@0 88 SimpleTest.executeSoon(function() {
michael@0 89 if (!finished) {
michael@0 90 ok(finished, "Should have received callback by now");
michael@0 91 SimpleTest.finish();
michael@0 92 }
michael@0 93 });
michael@0 94 }
michael@0 95 }, false);
michael@0 96 document.body.appendChild(i);
michael@0 97 }
michael@0 98 </script>
michael@0 99 </body>
michael@0 100 </html>

mercurial