summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/test_propertyAndMethod.html
blob: 6e638e419162a57428448475cf1c1eaaa6b6bd19 (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
<html>
  <head>
    <title>NPObject with property and method with the same name</title>

    <script type="text/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"/>
  </head>

  <body onload="run()">

    <script class="testbody" type="application/javascript">
      if (typeof Object.getPrototypeOf !== "function") {
        if (typeof "test".__proto__ === "object") {
          Object.getPrototypeOf = function(object) {
            return object.__proto__;
          };
        } else {
          Object.getPrototypeOf = function(object) {
            // May break if the constructor has been tampered with
            return object.constructor.prototype;
          };
        }
      }

      SimpleTest.waitForExplicitFinish();
      setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);

      function run() {
        var plugin = document.getElementById("plugin");
        var pluginProto = Object.getPrototypeOf(plugin);

        delete pluginProto.propertyAndMethod;
        ok(isNaN(plugin.propertyAndMethod + 0), "Shouldn't be set yet!");

        plugin.propertyAndMethod = 5;
        is(+plugin.propertyAndMethod, 5, "Should be set to 5!");

        delete pluginProto.propertyAndMethod;
        ok(isNaN(plugin.propertyAndMethod + 0), "Shouldn't be set any more!");

        var res = plugin.propertyAndMethod();
        is(res, 5, "Method invocation should return 5!");

        SimpleTest.finish();
      }
    </script>

    <embed id="plugin" type="application/x-test" wmode="window"></embed>
  </body>
</html>