summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/test_bug967694.html
blob: 8a7602134dfbaa4b38fd4a881661c801626d6767 (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
<!doctype html>
<html>
<head>
  <title>Test for Bug 967694</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/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="application/javascript">

// Touching a plugin from chrome scope should not spawn it, bug should
// synchronously spawn it from content scope

setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);

var plugin;
var spPlugin;

function recreatePlugin() {
  if (plugin) {
    document.body.removeChild(plugin);
  }
  plugin = document.createElement("embed");
  plugin.type = "application/x-test";

  document.body.appendChild(plugin);
  // Plugin should now be queued for async spawning.
  spPlugin = SpecialPowers.wrap(plugin);

  is(spPlugin.displayedType, spPlugin.TYPE_PLUGIN, "Should be configured as plugin");
  ok(!spPlugin.hasRunningPlugin, "Should not be spawned yet");
}

recreatePlugin();

// Try various JS operations with chrome context
var thrown = false;
// Get and set non-existent Property
var hi = spPlugin._testShouldntExist;
spPlugin._testShouldntExist = 5;
// Call some test-plugin function
try {
  var val = spPlugin.getObjectValue();
} catch (e) {
  thrown = true;
}

ok(thrown, "Function call should have thrown");
ok(!spPlugin.hasRunningPlugin, "Plugin should not have spawned");

// Try property access from content
var hi = plugin._testShouldntExistContent;
ok(spPlugin.hasRunningPlugin, "Should've caused plugin to spawn");

// Property set
recreatePlugin();
plugin._testShouldntExistContent = 5;
ok(spPlugin.hasRunningPlugin, "Should've caused plugin to spawn");

// Call test plugin function. Should succeed.
recreatePlugin();
thrown = false;
try {
  var value = plugin.getObjectValue();
} catch (e) {
  thrown = true;
}

ok(!thrown, "Call should have succeeded");
ok(spPlugin.hasRunningPlugin, "Call should have synchronously spawned plugin");
ok(plugin.checkObjectValue(value), "Plugin should recognize self");

</script>
</body>
</html>