js/xpconnect/tests/mochitest/test_bug484107.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=484107
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 484107</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=484107">Mozilla Bug 484107</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 <script type="application/javascript">
michael@0 19
michael@0 20 /** Test for Bug 484107 **/
michael@0 21
michael@0 22 var text = "first group",
michael@0 23 xpcWin = new XPCSafeJSObjectWrapper(window);
michael@0 24 function get$1() { return RegExp.$1 };
michael@0 25
michael@0 26 function reset() {
michael@0 27 var match = /(.*)/.exec(text);
michael@0 28 if (!reset.skipStupidTests) {
michael@0 29 reset.skipStupidTests = true;
michael@0 30 ok(match, "No match?");
michael@0 31 is(match[1], text, "Bad match?");
michael@0 32 is(text, RegExp.$1, "RegExp.$1 missing?");
michael@0 33 is(text, get$1(), "RegExp.$1 inaccessible?");
michael@0 34 }
michael@0 35 }
michael@0 36
michael@0 37 function test_XPC_SJOW_Call() {
michael@0 38 isnot(text, xpcWin.get$1(), "Able to see RegExp.$1 from wrapped method.");
michael@0 39 is("", xpcWin.get$1(), "Saw something other than an empty string for " +
michael@0 40 "RegExp.$1 from wrapped method.");
michael@0 41 is(text, window.get$1(), "Unable to see RegExp.$1 from non-wrapped method.");
michael@0 42 }
michael@0 43
michael@0 44 function test_XPC_SJOW_Call_foreign_obj() {
michael@0 45 var obj = {
michael@0 46 xpcGet: xpcWin.get$1,
michael@0 47 rawGet: window.get$1
michael@0 48 };
michael@0 49 isnot(text, obj.xpcGet(), "obj.xpcGet() returned matched text.");
michael@0 50 is("", obj.xpcGet(), "obj.xpcGet() returned something other than the empty string.");
michael@0 51 is(text, obj.rawGet(), "obj.rawGet() did not return matched text.");
michael@0 52 }
michael@0 53
michael@0 54 function test_XPC_SJOW_toString() {
michael@0 55 var str = new XPCSafeJSObjectWrapper({
michael@0 56 toString: function() { return RegExp.$1 }
michael@0 57 }) + "";
michael@0 58 isnot(text, str, "toString() returned the matched text.");
michael@0 59 is("", str, "toString() returned something other than the empty string.");
michael@0 60 }
michael@0 61
michael@0 62 function test_XPC_SJOW_GetOrSetProperty() {
michael@0 63 window.__defineGetter__("firstMatch", function() { return RegExp.$1 });
michael@0 64 isnot(text, xpcWin.firstMatch, "Getter xpcWin.firstMatch returned matched text.");
michael@0 65 is("", xpcWin.firstMatch,
michael@0 66 "Getter xpcWin.firstMatch returned something other than the empty string.");
michael@0 67 is(text, window.firstMatch, "Getter window.firstMatch did not return matched text.");
michael@0 68 }
michael@0 69
michael@0 70 function test_XPC_SJOW_Create() {
michael@0 71 function ctor() {
michael@0 72 this.match = RegExp.$1;
michael@0 73 return this; // XXX Why is this necessary?
michael@0 74 }
michael@0 75 ctor.prototype.getMatch = function() { return this.match };
michael@0 76 var xpcCtor = new XPCSafeJSObjectWrapper(ctor),
michael@0 77 match = (new xpcCtor).getMatch();
michael@0 78 isnot(text, match, "(new xpcCtor).getMatch() was the matched text.");
michael@0 79 is("", match, "(new xpcCtor).getMatch() was not the empty string.");
michael@0 80 }
michael@0 81
michael@0 82 var tests = [
michael@0 83 test_XPC_SJOW_Call,
michael@0 84 test_XPC_SJOW_Call_foreign_obj,
michael@0 85 test_XPC_SJOW_toString,
michael@0 86 test_XPC_SJOW_GetOrSetProperty,
michael@0 87 test_XPC_SJOW_Create
michael@0 88 ];
michael@0 89
michael@0 90 for (var i = 0; i < tests.length; i++) {
michael@0 91 reset();
michael@0 92 tests[i]();
michael@0 93 is(text, RegExp.$1, "RegExp.$1 was clobbered.");
michael@0 94 }
michael@0 95
michael@0 96 </script>
michael@0 97 </pre>
michael@0 98 </body>
michael@0 99 </html>

mercurial