dom/tests/mochitest/localstorage/frameQuota.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

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

mercurial