4 https://bugzilla.mozilla.org/show_bug.cgi?id=802557
8 <title>Test for Bug
802557</title>
9 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
11 <script type=
"application/javascript">
13 /** Test for Bug
802557 **/
14 SimpleTest.waitForExplicitFinish();
16 function checkThrows(fun, desc) {
19 ok(false,
"Didn't throw when " + desc);
21 ok(true,
"Threw when " + desc +
" " + e);
22 ok(/denied|insecure/.exec(e),
"Should be security exception");
29 window.ifr = document.getElementById('ifr');
30 window.iWin = ifr.contentWindow;
34 // Note that accessors pulled off Xrays are currently bound. This is bug
658909.
35 // [getter, description, locationObj, bound]
36 gGetters = [[ location.toString, 'toString from LW' ],
37 [ gLoc.toString, 'toString from XLW' ],
38 [ Object.__lookupGetter__.call(location, 'href'), 'href getter from LW' ],
39 [ Object.__lookupGetter__.call(gLoc, 'href'), 'href getter from XLW' ],
40 [ Object.getOwnPropertyDescriptor(location, 'href').get, 'href getter from location' ],
41 [ Object.getOwnPropertyDescriptor(gLoc, 'href').get, 'href getter from iWin.location' ],
42 [ function() { return this + ''; }, 'implicit conversion via [[DefaultValue]]', /* doMessageCheck = */ true ]];
43 gGetters.forEach(function(item) {
45 is(item[
0].call(location), location.toString(), 'Same-origin LW: ' + item[
1]);
46 is(item[
0].call(gLoc), gLoc.toString(), 'Same-origin XLW: ' + item[
1]);
48 ok(false,
"Threw while applying " + item[
1] +
" to same-origin location object: " + e);
51 ifr.src =
"http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
53 else if (loadCount ==
2) {
54 gGetters.forEach(function(item) {
55 checkThrows(function() { item[
0].call(gLoc); },
56 'call()ing ' + item[
1] + ' after navigation cross-origin');
58 ifr.src = 'http://mochi.test:
8888/tests/js/xpconnect/tests/mochitest/file_bug802557.html';
60 else if (loadCount ==
3) {
61 gTestFunctions = ifr.contentWindow.getAllTests();
62 var win = ifr.contentWindow;
63 for (fun in gTestFunctions)
64 is(gTestFunctions[fun](), win.location.toString(),
"allowed via " + fun);
65 win.location = 'http://example.org/tests/js/xpconnect/tests/mochitest/file_bug802557.html';
67 else if (loadCount ==
4) {
68 for (fun in gTestFunctions) {
69 var f = gTestFunctions[fun];
70 checkThrows(f,
"calling " + fun);
73 // Verify that URL.prototype.toString can't be applied to Location
76 URL.prototype.toString.call(location);
81 "Should not be able to use URL.prototype.toString on a Location instance");
83 // Verify that URL.prototype.href getter can't be applied to Location
85 var reachedTest = false;
87 var get = Object.getOwnPropertyDescriptor(URL.prototype,
"href").get;
88 is(typeof(get),
"function",
"Should have an href getter on URL.prototype");
89 var reachedTest = true;
95 "Should not be able to find URL.prototype.href getter");
97 "Should not be able to use URL.prototype.href getter on a Location instance");
107 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=802557">Mozilla Bug
802557</a>
109 <div id=
"content" style=
"display: none">
112 <iframe id=
"ifr" onload=
"go();" src=
"file_empty.html"></iframe>