dom/tests/mochitest/dom-level0/test_location.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 <head>
michael@0 4 <title>Test for location object behaviors</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 7 </head>
michael@0 8 <body>
michael@0 9 <p id="display"></p>
michael@0 10 <div id="content" style="display: none">
michael@0 11
michael@0 12 </div>
michael@0 13 <pre id="test">
michael@0 14 <script class="testbody" type="text/javascript">
michael@0 15
michael@0 16 SimpleTest.waitForExplicitFinish();
michael@0 17
michael@0 18 var count = 0;
michael@0 19 var firstlocation;
michael@0 20 var lastlocation;
michael@0 21
michael@0 22 function runTest() {
michael@0 23 ++count;
michael@0 24 if (count == 1) {
michael@0 25 firstlocation = $('ifr').contentWindow.location;
michael@0 26 firstlocation.existingprop = 'fail';
michael@0 27 firstlocation.href = 'file_location.html';
michael@0 28 return;
michael@0 29 }
michael@0 30
michael@0 31 if (count == 2) {
michael@0 32 lastlocation = $('ifr').contentWindow.location;
michael@0 33 is(lastlocation.iframeprop, 42, 'can read the new prop');
michael@0 34 ok(firstlocation !== lastlocation, 'got a new location object');
michael@0 35 // firstlocation should still work.
michael@0 36 ok(firstlocation.href.indexOf('file_location.html'), 'can read location.href');
michael@0 37 firstlocation.href = 'http://example.com/tests/dom/tests/mochitest/dom-level0/file_location.html';
michael@0 38 return;
michael@0 39 }
michael@0 40
michael@0 41 if (count == 3) {
michael@0 42 var permissionDenied = false;
michael@0 43 try {
michael@0 44 var foo = $('ifr').contentWindow.location.href == '';
michael@0 45 } catch (e) {
michael@0 46 permissionDenied = /Permission denied/.test(e.message);
michael@0 47 }
michael@0 48 ok(permissionDenied, 'correctly threw a permission denied security error when reading location.href');
michael@0 49
michael@0 50 permissionDenied = false;
michael@0 51 try {
michael@0 52 var foo = $('ifr').contentWindow.location.iframeprop == 42;
michael@0 53 } catch (e) {
michael@0 54 permissionDenied = /Permission denied/.test(e.message);
michael@0 55 }
michael@0 56 ok(permissionDenied, 'correctly threw a permission denied security error an expando on location');
michael@0 57
michael@0 58 firstlocation.href = 'http://mochi.test:8888/tests/dom/tests/mochitest/dom-level0/file_location.html';
michael@0 59 return;
michael@0 60 }
michael@0 61
michael@0 62 is(lastlocation.iframeprop, 42, 'can still read old values of the location object');
michael@0 63 ok(lastlocation !== $('ifr').contentWindow.location, 'location objects are distinct');
michael@0 64 ok(firstlocation.href.indexOf('file_location.html'), 'can read location.href');
michael@0 65
michael@0 66 SimpleTest.finish();
michael@0 67 }
michael@0 68
michael@0 69 </script>
michael@0 70 </pre>
michael@0 71 <iframe id="ifr" onload="runTest()"></iframe>
michael@0 72 </body>
michael@0 73 </html>

mercurial