Home | History | Annotate | Download | only in script-tests
      1 description("This is a test to make sure DOM Storage mutations fire StorageEvents that are caught by the event listener set via window.onstorage.");
      2 
      3 function test(storageString, callback)
      4 {
      5     window.completionCallback = callback;
      6     window.storage = eval(storageString);
      7     if (!storage) {
      8         testFailed(storageString + " DOES NOT exist");
      9         return;
     10     }
     11 
     12     debug("Testing " + storageString);
     13 
     14     evalAndLog("storage.clear()");
     15     shouldBe("storage.length", "0");
     16 
     17     runAfterStorageEvents(step1);
     18 }
     19 
     20 function step1()
     21 {
     22     debug("Reset storage event list");
     23     evalAndLog("storageEventList = new Array()");
     24     evalAndLog("storage.setItem('FOO', 'BAR')");
     25 
     26     runAfterStorageEvents(step2);
     27 }
     28 
     29 function step2()
     30 {
     31     shouldBe("storageEventList.length", "1");
     32     shouldBeEqualToString("storageEventList[0].key", "FOO");
     33     shouldBeNull("storageEventList[0].oldValue");
     34     shouldBeEqualToString("storageEventList[0].newValue", "BAR");
     35     evalAndLog("storage.setItem('FU', 'BAR')");
     36     evalAndLog("storage.setItem('a', '1')");
     37     evalAndLog("storage.setItem('b', '2')");
     38     evalAndLog("storage.setItem('b', '3')");
     39 
     40     runAfterStorageEvents(step3);
     41 }
     42 
     43 function step3()
     44 {
     45     shouldBe("storageEventList.length", "5");
     46     shouldBeEqualToString("storageEventList[1].key", "FU");
     47     shouldBeNull("storageEventList[1].oldValue");
     48     shouldBeEqualToString("storageEventList[1].newValue", "BAR");
     49     shouldBeEqualToString("storageEventList[2].key", "a");
     50     shouldBeNull("storageEventList[2].oldValue");
     51     shouldBeEqualToString("storageEventList[2].newValue", "1");
     52     shouldBeEqualToString("storageEventList[3].key", "b");
     53     shouldBeNull("storageEventList[3].oldValue");
     54     shouldBeEqualToString("storageEventList[3].newValue", "2");
     55     shouldBeEqualToString("storageEventList[4].key", "b");
     56     shouldBeEqualToString("storageEventList[4].oldValue", "2");
     57     shouldBeEqualToString("storageEventList[4].newValue", "3");
     58     evalAndLog("storage.removeItem('FOO')");
     59 
     60     runAfterStorageEvents(step4);
     61 }
     62 
     63 function step4()
     64 {
     65     shouldBe("storageEventList.length", "6");
     66     shouldBeEqualToString("storageEventList[5].key", "FOO");
     67     shouldBeEqualToString("storageEventList[5].oldValue", "BAR");
     68     shouldBeNull("storageEventList[5].newValue");
     69     evalAndLog("storage.removeItem('FU')");
     70 
     71     runAfterStorageEvents(step5);
     72 }
     73 
     74 function step5()
     75 {
     76     shouldBe("storageEventList.length", "7");
     77     shouldBeEqualToString("storageEventList[6].key", "FU");
     78     shouldBeEqualToString("storageEventList[6].oldValue", "BAR");
     79     shouldBeNull("storageEventList[6].newValue");
     80     evalAndLog("storage.clear()");
     81  
     82     runAfterStorageEvents(step6);
     83 }
     84 
     85 function step6()
     86 {
     87     shouldBe("storageEventList.length", "8");
     88     shouldBeNull("storageEventList[7].key");
     89     shouldBeNull("storageEventList[7].oldValue");
     90     shouldBeNull("storageEventList[7].newValue");
     91  
     92     completionCallback();
     93 }
     94 
     95 testStorages(test);
     96 
     97 var successfullyParsed = true;
     98