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