dom/tests/mochitest/bugs/test_bug541530.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/bugs/test_bug541530.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=541530
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 411103</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=541530">Mozilla Bug 541530</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none"></div>
    1.18 +
    1.19 +<pre id="test">
    1.20 +<script class="testbody" type="text/javascript">
    1.21 +
    1.22 +var orig = window;
    1.23 +window = {};
    1.24 +
    1.25 +var origLocation = location;
    1.26 +
    1.27 +ok(window === orig, "can't override window");
    1.28 +ok(window.location === location, "properties are properly aliased");
    1.29 +ok(document.location === location, "properties are properly aliased");
    1.30 +
    1.31 +var canDefine = false;
    1.32 +try {
    1.33 +    var foo;
    1.34 +    this.__defineGetter__.call(foo, 'bar', function() {});
    1.35 +    this.__defineSetter__.call(foo, 'bar', function() {});
    1.36 +    canDefine = true;
    1.37 +} catch (e) {}
    1.38 +ok(canDefine, "Should have access to __defineGetter__ and __defineSetter__");
    1.39 +
    1.40 +try {
    1.41 +    this.__defineGetter__('window', function() {});
    1.42 +    ok(false, "should not be able to defineGetter(window)");
    1.43 +} catch (e) {
    1.44 +}
    1.45 +
    1.46 +try {
    1.47 +    this.__defineGetter__.call(window, 'location', function(){});
    1.48 +    ok(false, "should not be able to defineGetter(window.location)");
    1.49 +} catch (e) {
    1.50 +}
    1.51 +
    1.52 +try {
    1.53 +    this.__defineGetter__.call(window.location, 'href', function(){});
    1.54 +    ok(false, "shouldn't be able to override location.href");
    1.55 +} catch (e) {
    1.56 +    ok(/shadow/.exec(e.message), "Should be caught by the anti-shadow mechanism.");
    1.57 +}
    1.58 +
    1.59 +// Try deleting the property.
    1.60 +delete window.location.href;
    1.61 +ok(typeof window.location.href !== 'undefined',
    1.62 +   "shouldn't be able to delete the inherited property");
    1.63 +delete Object.getPrototypeOf(window.location).href;
    1.64 +ok(typeof window.location.href !== 'undefined',
    1.65 +   "shouldn't be able to delete the property off of the prototype");
    1.66 +
    1.67 +try {
    1.68 +    this.__defineGetter__.call(Object.getPrototypeOf(window.location), 'href', function(){});
    1.69 +    ok(false, "shouldn't be able to use the prototype");
    1.70 +} catch (e) {
    1.71 +}
    1.72 +
    1.73 +try {
    1.74 +    this.__defineSetter__.call(window.location, 'href', function(){});
    1.75 +    ok(false, "overrode a setter for location.href?");
    1.76 +} catch (e) {
    1.77 +    ok(/shadow/.exec(e.message), "Should be caught by the anti-shadow mechanism.");
    1.78 +}
    1.79 +
    1.80 +try {
    1.81 +    this.__defineGetter__.call(document, 'location', function(){});
    1.82 +    ok(false, "shouldn't be able to override document.location");
    1.83 +} catch (e) {
    1.84 +}
    1.85 +
    1.86 +ok(window === orig, "can't override window");
    1.87 +ok(window.location === origLocation, "properties are properly aliased");
    1.88 +ok(document.location === origLocation, "properties are properly aliased");
    1.89 +
    1.90 +location.href = 'javascript:ok(true, "was able to set location.href through a watchpoint")';
    1.91 +
    1.92 +</script>
    1.93 +</pre>
    1.94 +</body>
    1.95 +</html>

mercurial