Home | History | Annotate | Download | only in script-tests
      1 description("Test the DOM Storage quota code.");
      2 
      3 function testQuota(storageString)
      4 {
      5     storage = eval(storageString);
      6     if (!storage) {
      7         testFailed(storageString + " DOES NOT exist");
      8         return;
      9     }
     10 
     11     debug("Testing " + storageString);
     12 
     13     evalAndLog("storage.clear()");
     14     shouldBe("storage.length", "0");
     15 
     16     debug("Creating 'data' which contains 64K of data");
     17     data = "X";
     18     for (var i=0; i<16; i++)
     19         data += data;
     20     shouldBe("data.length", "65536");
     21 
     22     debug("Putting 'data' into 39 " + storageString + " buckets.");
     23     for (var i=0; i<39; i++)
     24         storage[i] = data;
     25 
     26     debug("Putting 'data' into another bucket.h");
     27     try {
     28         storage[39] = data;
     29         testFailed("Did not hit quota error.");
     30     } catch (e) {
     31         testPassed("Hit exception as expected");
     32     }
     33 
     34     debug("Verify that data was never inserted.");
     35     shouldBeNull("storage.getItem(39)");
     36 
     37     debug("Removing bucket 38.");
     38     storage.removeItem('38');
     39 
     40     debug("Adding 'Hello!' into a new bucket.");
     41     try {
     42         storage['foo'] = "Hello!";
     43         testPassed("Insertion worked.");
     44     } catch (e) {
     45         testFailed("Exception: " + e);
     46     }
     47 }
     48 
     49 function testNoQuota(storageString)
     50 {
     51     storage = eval(storageString);
     52     if (!storage) {
     53         testFailed(storageString + " DOES NOT exist");
     54         return;
     55     }
     56 
     57     debug("Testing " + storageString);
     58 
     59     evalAndLog("storage.clear()");
     60     shouldBe("storage.length", "0");
     61 
     62     debug("Creating 'data' which contains 64K of data");
     63     data = "X";
     64     for (var i=0; i<16; i++)
     65         data += data;
     66     shouldBe("data.length", "65536");
     67 
     68     debug("Putting 'data' into 39 " + storageString + " buckets.");
     69     for (var i=0; i<39; i++)
     70         storage[i] = data;
     71 
     72     debug("Putting 'data' into another bucket.h");
     73     try {
     74         storage[39] = data;
     75         testPassed("Insertion worked.");
     76     } catch (e) {
     77         testFailed("Exception: " + e);
     78     }
     79 }
     80 
     81 testNoQuota("sessionStorage");
     82 debug("");
     83 debug("");
     84 testQuota("localStorage");
     85 
     86 window.successfullyParsed = true;
     87 isSuccessfullyParsed();
     88