Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=541530 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 411103</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=541530">Mozilla Bug 541530</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"></div> |
michael@0 | 15 | |
michael@0 | 16 | <pre id="test"> |
michael@0 | 17 | <script class="testbody" type="text/javascript"> |
michael@0 | 18 | |
michael@0 | 19 | var orig = window; |
michael@0 | 20 | window = {}; |
michael@0 | 21 | |
michael@0 | 22 | var origLocation = location; |
michael@0 | 23 | |
michael@0 | 24 | ok(window === orig, "can't override window"); |
michael@0 | 25 | ok(window.location === location, "properties are properly aliased"); |
michael@0 | 26 | ok(document.location === location, "properties are properly aliased"); |
michael@0 | 27 | |
michael@0 | 28 | var canDefine = false; |
michael@0 | 29 | try { |
michael@0 | 30 | var foo; |
michael@0 | 31 | this.__defineGetter__.call(foo, 'bar', function() {}); |
michael@0 | 32 | this.__defineSetter__.call(foo, 'bar', function() {}); |
michael@0 | 33 | canDefine = true; |
michael@0 | 34 | } catch (e) {} |
michael@0 | 35 | ok(canDefine, "Should have access to __defineGetter__ and __defineSetter__"); |
michael@0 | 36 | |
michael@0 | 37 | try { |
michael@0 | 38 | this.__defineGetter__('window', function() {}); |
michael@0 | 39 | ok(false, "should not be able to defineGetter(window)"); |
michael@0 | 40 | } catch (e) { |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | try { |
michael@0 | 44 | this.__defineGetter__.call(window, 'location', function(){}); |
michael@0 | 45 | ok(false, "should not be able to defineGetter(window.location)"); |
michael@0 | 46 | } catch (e) { |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | try { |
michael@0 | 50 | this.__defineGetter__.call(window.location, 'href', function(){}); |
michael@0 | 51 | ok(false, "shouldn't be able to override location.href"); |
michael@0 | 52 | } catch (e) { |
michael@0 | 53 | ok(/shadow/.exec(e.message), "Should be caught by the anti-shadow mechanism."); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | // Try deleting the property. |
michael@0 | 57 | delete window.location.href; |
michael@0 | 58 | ok(typeof window.location.href !== 'undefined', |
michael@0 | 59 | "shouldn't be able to delete the inherited property"); |
michael@0 | 60 | delete Object.getPrototypeOf(window.location).href; |
michael@0 | 61 | ok(typeof window.location.href !== 'undefined', |
michael@0 | 62 | "shouldn't be able to delete the property off of the prototype"); |
michael@0 | 63 | |
michael@0 | 64 | try { |
michael@0 | 65 | this.__defineGetter__.call(Object.getPrototypeOf(window.location), 'href', function(){}); |
michael@0 | 66 | ok(false, "shouldn't be able to use the prototype"); |
michael@0 | 67 | } catch (e) { |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | try { |
michael@0 | 71 | this.__defineSetter__.call(window.location, 'href', function(){}); |
michael@0 | 72 | ok(false, "overrode a setter for location.href?"); |
michael@0 | 73 | } catch (e) { |
michael@0 | 74 | ok(/shadow/.exec(e.message), "Should be caught by the anti-shadow mechanism."); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | try { |
michael@0 | 78 | this.__defineGetter__.call(document, 'location', function(){}); |
michael@0 | 79 | ok(false, "shouldn't be able to override document.location"); |
michael@0 | 80 | } catch (e) { |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | ok(window === orig, "can't override window"); |
michael@0 | 84 | ok(window.location === origLocation, "properties are properly aliased"); |
michael@0 | 85 | ok(document.location === origLocation, "properties are properly aliased"); |
michael@0 | 86 | |
michael@0 | 87 | location.href = 'javascript:ok(true, "was able to set location.href through a watchpoint")'; |
michael@0 | 88 | |
michael@0 | 89 | </script> |
michael@0 | 90 | </pre> |
michael@0 | 91 | </body> |
michael@0 | 92 | </html> |