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 | <html xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 2 | <head> |
michael@0 | 3 | <title>slave for sessionStorage test</title> |
michael@0 | 4 | |
michael@0 | 5 | <script type="text/javascript" src="interOriginFrame.js"></script> |
michael@0 | 6 | <script type="text/javascript"> |
michael@0 | 7 | |
michael@0 | 8 | const DOM_QUOTA_REACHED = 2152924150; |
michael@0 | 9 | |
michael@0 | 10 | function checkException(func, exc) |
michael@0 | 11 | { |
michael@0 | 12 | var exceptionThrew = false; |
michael@0 | 13 | try { |
michael@0 | 14 | func(); |
michael@0 | 15 | } |
michael@0 | 16 | catch (ex) { |
michael@0 | 17 | exceptionThrew = true; |
michael@0 | 18 | is(ex.result, exc, "Expected "+exc+" exception"); |
michael@0 | 19 | } |
michael@0 | 20 | ok(exceptionThrew, "Exception "+exc+" threw at "+location); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function doStep() |
michael@0 | 24 | { |
michael@0 | 25 | var query = location.search.substring(1); |
michael@0 | 26 | var queries = query.split("&"); |
michael@0 | 27 | |
michael@0 | 28 | var operation = queries[0]; |
michael@0 | 29 | var keyName = queries[1]; |
michael@0 | 30 | var result = queries[2]; |
michael@0 | 31 | |
michael@0 | 32 | switch (result) |
michael@0 | 33 | { |
michael@0 | 34 | case "success": |
michael@0 | 35 | switch (operation) |
michael@0 | 36 | { |
michael@0 | 37 | case "add": |
michael@0 | 38 | // Store 500 bytes long string must succeed |
michael@0 | 39 | localStorage.setItem(keyName, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); |
michael@0 | 40 | is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "500 bytes key "+keyName+" stored"); |
michael@0 | 41 | break; |
michael@0 | 42 | |
michael@0 | 43 | case "remove": |
michael@0 | 44 | localStorage.removeItem(keyName); |
michael@0 | 45 | is(localStorage.getItem(keyName), null, "Key "+keyName+" removed"); |
michael@0 | 46 | break; |
michael@0 | 47 | |
michael@0 | 48 | case "checkclean": |
michael@0 | 49 | is(localStorage.getItem(keyName), null, "Key "+keyName+" not present"); |
michael@0 | 50 | break; |
michael@0 | 51 | |
michael@0 | 52 | case "checknotclean": |
michael@0 | 53 | is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "Key "+keyName+" is present"); |
michael@0 | 54 | break; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | break; |
michael@0 | 58 | |
michael@0 | 59 | case "failure": |
michael@0 | 60 | switch (operation) |
michael@0 | 61 | { |
michael@0 | 62 | case "add": |
michael@0 | 63 | // Attempt to store 500 bytes long string that doens't |
michael@0 | 64 | // fit the quota, have to throw DOM_QUOTA_REACHED exception |
michael@0 | 65 | checkException(function() { |
michael@0 | 66 | localStorage.setItem(keyName, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); |
michael@0 | 67 | }, DOM_QUOTA_REACHED); |
michael@0 | 68 | is(localStorage.getItem(keyName), null, "500 bytes key "+keyName+" is NOT stored"); |
michael@0 | 69 | break; |
michael@0 | 70 | |
michael@0 | 71 | case "add2": |
michael@0 | 72 | // Attempt to change a key value to reach the DOM quota and |
michael@0 | 73 | // check it fails and the old key value is still present. |
michael@0 | 74 | checkException(function() { |
michael@0 | 75 | localStorage.setItem(keyName, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); |
michael@0 | 76 | }, DOM_QUOTA_REACHED); |
michael@0 | 77 | is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "Key "+keyName+" left unchanged"); |
michael@0 | 78 | break; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | break; |
michael@0 | 82 | |
michael@0 | 83 | default: |
michael@0 | 84 | switch (operation) |
michael@0 | 85 | { |
michael@0 | 86 | case "clear": |
michael@0 | 87 | localStorage.clear(); |
michael@0 | 88 | break; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | break; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | // Just inform the master we are finished now |
michael@0 | 95 | postMsg("done"); |
michael@0 | 96 | return false; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | </script> |
michael@0 | 100 | |
michael@0 | 101 | </head> |
michael@0 | 102 | |
michael@0 | 103 | <body onload="postMsg('frame loaded');"> |
michael@0 | 104 | </body> |
michael@0 | 105 | </html> |