js/xpconnect/tests/mochitest/test_bug484107.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/mochitest/test_bug484107.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=484107
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 484107</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=484107">Mozilla Bug 484107</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 484107 **/
    1.24 +
    1.25 +  var text = "first group",
    1.26 +      xpcWin = new XPCSafeJSObjectWrapper(window);
    1.27 +  function get$1() { return RegExp.$1 };
    1.28 +
    1.29 +  function reset() {
    1.30 +    var match = /(.*)/.exec(text);
    1.31 +    if (!reset.skipStupidTests) {
    1.32 +      reset.skipStupidTests = true;
    1.33 +      ok(match, "No match?");
    1.34 +      is(match[1], text, "Bad match?");
    1.35 +      is(text, RegExp.$1, "RegExp.$1 missing?");
    1.36 +      is(text, get$1(), "RegExp.$1 inaccessible?");
    1.37 +    }
    1.38 +  }
    1.39 +
    1.40 +  function test_XPC_SJOW_Call() {
    1.41 +    isnot(text, xpcWin.get$1(), "Able to see RegExp.$1 from wrapped method.");
    1.42 +    is("", xpcWin.get$1(), "Saw something other than an empty string for " +
    1.43 +                           "RegExp.$1 from wrapped method.");
    1.44 +    is(text, window.get$1(), "Unable to see RegExp.$1 from non-wrapped method.");
    1.45 +  }
    1.46 +
    1.47 +  function test_XPC_SJOW_Call_foreign_obj() {
    1.48 +    var obj = {
    1.49 +      xpcGet: xpcWin.get$1,
    1.50 +      rawGet: window.get$1
    1.51 +    };
    1.52 +    isnot(text, obj.xpcGet(), "obj.xpcGet() returned matched text.");
    1.53 +    is("", obj.xpcGet(), "obj.xpcGet() returned something other than the empty string.");
    1.54 +    is(text, obj.rawGet(), "obj.rawGet() did not return matched text.");
    1.55 +  }
    1.56 +
    1.57 +  function test_XPC_SJOW_toString() {
    1.58 +    var str = new XPCSafeJSObjectWrapper({
    1.59 +      toString: function() { return RegExp.$1 }
    1.60 +    }) + "";
    1.61 +    isnot(text, str, "toString() returned the matched text.");
    1.62 +    is("", str, "toString() returned something other than the empty string.");
    1.63 +  }
    1.64 +
    1.65 +  function test_XPC_SJOW_GetOrSetProperty() {
    1.66 +    window.__defineGetter__("firstMatch", function() { return RegExp.$1 });
    1.67 +    isnot(text, xpcWin.firstMatch, "Getter xpcWin.firstMatch returned matched text.");
    1.68 +    is("", xpcWin.firstMatch,
    1.69 +       "Getter xpcWin.firstMatch returned something other than the empty string.");
    1.70 +    is(text, window.firstMatch, "Getter window.firstMatch did not return matched text.");
    1.71 +  }
    1.72 +
    1.73 +  function test_XPC_SJOW_Create() {
    1.74 +    function ctor() {
    1.75 +      this.match = RegExp.$1;
    1.76 +      return this; // XXX Why is this necessary?
    1.77 +    }
    1.78 +    ctor.prototype.getMatch = function() { return this.match };
    1.79 +    var xpcCtor = new XPCSafeJSObjectWrapper(ctor),
    1.80 +        match = (new xpcCtor).getMatch();
    1.81 +    isnot(text, match, "(new xpcCtor).getMatch() was the matched text.");
    1.82 +    is("", match, "(new xpcCtor).getMatch() was not the empty string.");
    1.83 +  }
    1.84 +
    1.85 +  var tests = [
    1.86 +    test_XPC_SJOW_Call,
    1.87 +    test_XPC_SJOW_Call_foreign_obj,
    1.88 +    test_XPC_SJOW_toString,
    1.89 +    test_XPC_SJOW_GetOrSetProperty,
    1.90 +    test_XPC_SJOW_Create
    1.91 +  ];
    1.92 +
    1.93 +  for (var i = 0; i < tests.length; i++) {
    1.94 +    reset();
    1.95 +    tests[i]();
    1.96 +    is(text, RegExp.$1, "RegExp.$1 was clobbered.");
    1.97 +  }
    1.98 +
    1.99 +</script>
   1.100 +</pre>
   1.101 +</body>
   1.102 +</html>

mercurial