1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/mochitest/test_bug802557.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,92 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=802557 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Bug 802557</title> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 + <script type="application/javascript"> 1.15 + 1.16 + /** Test for Bug 802557 **/ 1.17 + SimpleTest.waitForExplicitFinish(); 1.18 + 1.19 + function checkThrows(fun, desc) { 1.20 + try { 1.21 + fun(); 1.22 + ok(false, "Didn't throw when " + desc); 1.23 + } catch(e) { 1.24 + ok(true, "Threw when " + desc + " " + e); 1.25 + ok(/denied|insecure/.exec(e), "Should be security exception"); 1.26 + } 1.27 + } 1.28 + 1.29 + var loadCount = 0; 1.30 + function go() { 1.31 + ++loadCount; 1.32 + window.ifr = document.getElementById('ifr'); 1.33 + window.iWin = ifr.contentWindow; 1.34 + 1.35 + if (loadCount == 1) { 1.36 + gLoc = iWin.location; 1.37 + // Note that accessors pulled off Xrays are currently bound. This is bug 658909. 1.38 + // [getter, description, locationObj, bound] 1.39 + gGetters = [[ location.toString, 'toString from LW' ], 1.40 + [ gLoc.toString, 'toString from XLW' ], 1.41 + [ Location.prototype.toString, 'toString from Location.prototype' ], 1.42 + [ iWin.Location.prototype.toString, 'toString from iWin.Location.prototype' ], 1.43 + [ Object.__lookupGetter__.call(location, 'href'), 'href getter from LW' ], 1.44 + [ Object.__lookupGetter__.call(gLoc, 'href'), 'href getter from XLW' ], 1.45 + [ Object.getOwnPropertyDescriptor(Location.prototype, 'href').get, 'href getter from Location.prototype' ], 1.46 + [ Object.getOwnPropertyDescriptor(iWin.Location.prototype, 'href').get, 'href getter from iWin.Location.prototype' ], 1.47 + [ function() { return this + ''; }, 'implicit conversion via [[DefaultValue]]', /* doMessageCheck = */ true ]]; 1.48 + gGetters.forEach(function(item) { 1.49 + try { 1.50 + is(item[0].call(location), location.toString(), 'Same-origin LW: ' + item[1]); 1.51 + is(item[0].call(gLoc), gLoc.toString(), 'Same-origin XLW: ' + item[1]); 1.52 + } catch (e) { 1.53 + ok(false, "Threw while applying " + item[1] + " to same-origin location object: " + e); 1.54 + } 1.55 + }); 1.56 + ifr.src = "http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"; 1.57 + } 1.58 + else if (loadCount == 2) { 1.59 + gGetters.forEach(function(item) { 1.60 + checkThrows(function() { item[0].call(gLoc); }, 1.61 + 'call()ing ' + item[1] + ' after navigation cross-origin'); 1.62 + }); 1.63 + ifr.src = 'http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug802557.html'; 1.64 + } 1.65 + else if (loadCount == 3) { 1.66 + gTestFunctions = ifr.contentWindow.getAllTests(); 1.67 + var win = ifr.contentWindow; 1.68 + for (fun in gTestFunctions) 1.69 + is(gTestFunctions[fun](), win.location.toString(), "allowed via " + fun); 1.70 + win.location = 'http://example.org/tests/js/xpconnect/tests/mochitest/file_bug802557.html'; 1.71 + } 1.72 + else if (loadCount == 4) { 1.73 + for (fun in gTestFunctions) { 1.74 + var f = gTestFunctions[fun]; 1.75 + checkThrows(f, "calling " + fun); 1.76 + } 1.77 + SimpleTest.finish(); 1.78 + } 1.79 + } 1.80 + 1.81 + 1.82 + 1.83 +</script> 1.84 +</head> 1.85 +<body> 1.86 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=802557">Mozilla Bug 802557</a> 1.87 +<p id="display"></p> 1.88 +<div id="content" style="display: none"> 1.89 + 1.90 +</div> 1.91 +<iframe id="ifr" onload="go();" src="file_empty.html"></iframe> 1.92 +<pre id="test"> 1.93 +</pre> 1.94 +</body> 1.95 +</html>