1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/dom-level0/test_location.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for location object behaviors</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.10 +</head> 1.11 +<body> 1.12 +<p id="display"></p> 1.13 +<div id="content" style="display: none"> 1.14 + 1.15 +</div> 1.16 +<pre id="test"> 1.17 +<script class="testbody" type="text/javascript"> 1.18 + 1.19 +SimpleTest.waitForExplicitFinish(); 1.20 + 1.21 +var count = 0; 1.22 +var firstlocation; 1.23 +var lastlocation; 1.24 + 1.25 +function runTest() { 1.26 + ++count; 1.27 + if (count == 1) { 1.28 + firstlocation = $('ifr').contentWindow.location; 1.29 + firstlocation.existingprop = 'fail'; 1.30 + firstlocation.href = 'file_location.html'; 1.31 + return; 1.32 + } 1.33 + 1.34 + if (count == 2) { 1.35 + lastlocation = $('ifr').contentWindow.location; 1.36 + is(lastlocation.iframeprop, 42, 'can read the new prop'); 1.37 + ok(firstlocation !== lastlocation, 'got a new location object'); 1.38 + // firstlocation should still work. 1.39 + ok(firstlocation.href.indexOf('file_location.html'), 'can read location.href'); 1.40 + firstlocation.href = 'http://example.com/tests/dom/tests/mochitest/dom-level0/file_location.html'; 1.41 + return; 1.42 + } 1.43 + 1.44 + if (count == 3) { 1.45 + var permissionDenied = false; 1.46 + try { 1.47 + var foo = $('ifr').contentWindow.location.href == ''; 1.48 + } catch (e) { 1.49 + permissionDenied = /Permission denied/.test(e.message); 1.50 + } 1.51 + ok(permissionDenied, 'correctly threw a permission denied security error when reading location.href'); 1.52 + 1.53 + permissionDenied = false; 1.54 + try { 1.55 + var foo = $('ifr').contentWindow.location.iframeprop == 42; 1.56 + } catch (e) { 1.57 + permissionDenied = /Permission denied/.test(e.message); 1.58 + } 1.59 + ok(permissionDenied, 'correctly threw a permission denied security error an expando on location'); 1.60 + 1.61 + firstlocation.href = 'http://mochi.test:8888/tests/dom/tests/mochitest/dom-level0/file_location.html'; 1.62 + return; 1.63 + } 1.64 + 1.65 + is(lastlocation.iframeprop, 42, 'can still read old values of the location object'); 1.66 + ok(lastlocation !== $('ifr').contentWindow.location, 'location objects are distinct'); 1.67 + ok(firstlocation.href.indexOf('file_location.html'), 'can read location.href'); 1.68 + 1.69 + SimpleTest.finish(); 1.70 +} 1.71 + 1.72 +</script> 1.73 +</pre> 1.74 +<iframe id="ifr" onload="runTest()"></iframe> 1.75 +</body> 1.76 +</html>