js/xpconnect/tests/mochitest/test_bug802557.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=802557
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Test for Bug 802557</title>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 <script type="application/javascript">
michael@0 12
michael@0 13 /** Test for Bug 802557 **/
michael@0 14 SimpleTest.waitForExplicitFinish();
michael@0 15
michael@0 16 function checkThrows(fun, desc) {
michael@0 17 try {
michael@0 18 fun();
michael@0 19 ok(false, "Didn't throw when " + desc);
michael@0 20 } catch(e) {
michael@0 21 ok(true, "Threw when " + desc + " " + e);
michael@0 22 ok(/denied|insecure/.exec(e), "Should be security exception");
michael@0 23 }
michael@0 24 }
michael@0 25
michael@0 26 var loadCount = 0;
michael@0 27 function go() {
michael@0 28 ++loadCount;
michael@0 29 window.ifr = document.getElementById('ifr');
michael@0 30 window.iWin = ifr.contentWindow;
michael@0 31
michael@0 32 if (loadCount == 1) {
michael@0 33 gLoc = iWin.location;
michael@0 34 // Note that accessors pulled off Xrays are currently bound. This is bug 658909.
michael@0 35 // [getter, description, locationObj, bound]
michael@0 36 gGetters = [[ location.toString, 'toString from LW' ],
michael@0 37 [ gLoc.toString, 'toString from XLW' ],
michael@0 38 [ Location.prototype.toString, 'toString from Location.prototype' ],
michael@0 39 [ iWin.Location.prototype.toString, 'toString from iWin.Location.prototype' ],
michael@0 40 [ Object.__lookupGetter__.call(location, 'href'), 'href getter from LW' ],
michael@0 41 [ Object.__lookupGetter__.call(gLoc, 'href'), 'href getter from XLW' ],
michael@0 42 [ Object.getOwnPropertyDescriptor(Location.prototype, 'href').get, 'href getter from Location.prototype' ],
michael@0 43 [ Object.getOwnPropertyDescriptor(iWin.Location.prototype, 'href').get, 'href getter from iWin.Location.prototype' ],
michael@0 44 [ function() { return this + ''; }, 'implicit conversion via [[DefaultValue]]', /* doMessageCheck = */ true ]];
michael@0 45 gGetters.forEach(function(item) {
michael@0 46 try {
michael@0 47 is(item[0].call(location), location.toString(), 'Same-origin LW: ' + item[1]);
michael@0 48 is(item[0].call(gLoc), gLoc.toString(), 'Same-origin XLW: ' + item[1]);
michael@0 49 } catch (e) {
michael@0 50 ok(false, "Threw while applying " + item[1] + " to same-origin location object: " + e);
michael@0 51 }
michael@0 52 });
michael@0 53 ifr.src = "http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
michael@0 54 }
michael@0 55 else if (loadCount == 2) {
michael@0 56 gGetters.forEach(function(item) {
michael@0 57 checkThrows(function() { item[0].call(gLoc); },
michael@0 58 'call()ing ' + item[1] + ' after navigation cross-origin');
michael@0 59 });
michael@0 60 ifr.src = 'http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug802557.html';
michael@0 61 }
michael@0 62 else if (loadCount == 3) {
michael@0 63 gTestFunctions = ifr.contentWindow.getAllTests();
michael@0 64 var win = ifr.contentWindow;
michael@0 65 for (fun in gTestFunctions)
michael@0 66 is(gTestFunctions[fun](), win.location.toString(), "allowed via " + fun);
michael@0 67 win.location = 'http://example.org/tests/js/xpconnect/tests/mochitest/file_bug802557.html';
michael@0 68 }
michael@0 69 else if (loadCount == 4) {
michael@0 70 for (fun in gTestFunctions) {
michael@0 71 var f = gTestFunctions[fun];
michael@0 72 checkThrows(f, "calling " + fun);
michael@0 73 }
michael@0 74 SimpleTest.finish();
michael@0 75 }
michael@0 76 }
michael@0 77
michael@0 78
michael@0 79
michael@0 80 </script>
michael@0 81 </head>
michael@0 82 <body>
michael@0 83 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=802557">Mozilla Bug 802557</a>
michael@0 84 <p id="display"></p>
michael@0 85 <div id="content" style="display: none">
michael@0 86
michael@0 87 </div>
michael@0 88 <iframe id="ifr" onload="go();" src="file_empty.html"></iframe>
michael@0 89 <pre id="test">
michael@0 90 </pre>
michael@0 91 </body>
michael@0 92 </html>

mercurial