Home | History | Annotate | Download | only in script-tests
      1 description("Test some corner case DOM Storage values.");
      2 
      3 function testKeyValue(key, value)
      4 {
      5     keyString = "storage['" + key + "']";
      6     shouldBeEqualToString("typeof " + keyString, "string");
      7     shouldBeEqualToString(keyString, value);
      8 
      9     keyString = "storage." + key;
     10     shouldBeEqualToString("typeof " + keyString, "string");
     11     shouldBeEqualToString(keyString, value);
     12 
     13     keyString = "storage.getItem('" + key + "')";
     14     shouldBeEqualToString("typeof " + keyString, "string");
     15     shouldBeEqualToString(keyString, value);
     16 }
     17 
     18 function test(storageString)
     19 {
     20     storage = eval(storageString);
     21     if (!storage) {
     22         testFailed(storageString + " DOES NOT exist");
     23         return;
     24     }
     25 
     26     debug("Testing " + storageString);
     27 
     28     evalAndLog("storage.clear()");
     29     shouldBe("storage.length", "0");
     30 
     31     debug("");
     32     shouldBeEqualToString("typeof storage['foo']", "undefined");
     33     shouldBeUndefined("storage['foo']");
     34     shouldBeEqualToString("typeof storage.foo", "undefined");
     35     shouldBeUndefined("storage.foo");
     36     shouldBeEqualToString("typeof storage.getItem('foo')", "object");
     37     shouldBeNull("storage.getItem('foo')");
     38 
     39     debug("");
     40     evalAndLog("storage.foo1 = null");
     41     testKeyValue("foo1", "null");
     42     evalAndLog("storage['foo2'] = null");
     43     testKeyValue("foo2", "null");
     44     evalAndLog("storage.setItem('foo3', null)");
     45     testKeyValue("foo3", "null");
     46 
     47     debug("");
     48     evalAndLog("storage.foo4 = undefined");
     49     testKeyValue("foo4", "undefined");
     50     evalAndLog("storage['foo5'] = undefined");
     51     testKeyValue("foo5", "undefined");
     52     evalAndLog("storage.setItem('foo6', undefined)");
     53     testKeyValue("foo6", "undefined");
     54 
     55     debug("");
     56     evalAndLog("storage.foo7 = 2");
     57     testKeyValue("foo7", "2");
     58     evalAndLog("storage['foo8'] = 2");
     59     testKeyValue("foo8", "2");
     60     evalAndLog("storage.setItem('foo9', 2)");
     61     testKeyValue("foo9", "2");
     62 
     63     debug("");
     64     k = String.fromCharCode(255425) + String.fromCharCode(255) + String.fromCharCode(2554252321) + String.fromCharCode(0) + 'hello';
     65     evalAndLog("storage.foo10 = k");
     66     testKeyValue("foo10", k);
     67     evalAndLog("storage['foo11'] = k");
     68     testKeyValue("foo11", k);
     69     evalAndLog("storage.setItem('foo12', k)");
     70     testKeyValue("foo12", k);
     71 }
     72 
     73 test("sessionStorage");
     74 debug("");
     75 debug("");
     76 test("localStorage");
     77 
     78 window.successfullyParsed = true;
     79 isSuccessfullyParsed();
     80