summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/test_bug738396.html
blob: ead7f5c1aba5319b91df930d155b49236ea0cd01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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="plugin-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>