summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webstorage/storage_getitem.window.js
blob: 8a5896836d2aeb5d01b3a0465bb08e0065b8b8cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
["localStorage", "sessionStorage"].forEach(function(name) {
    test(function() {
        var storage = window[name];
        storage.clear();
        storage.setItem("name", "x");
        storage.setItem("undefined", "foo");
        storage.setItem("null", "bar");
        storage.setItem("", "baz");

        test(function() {
            assert_equals(storage.length, 4);
        }, "All items should be added to " + name + ".");

        test(function() {
            assert_equals(storage["unknown"], undefined, "storage['unknown']")
            assert_equals(storage["name"], "x", "storage['name']")
            assert_equals(storage["undefined"], "foo", "storage['undefined']")
            assert_equals(storage["null"], "bar", "storage['null']")
            assert_equals(storage[undefined], "foo", "storage[undefined]")
            assert_equals(storage[null], "bar", "storage[null]")
            assert_equals(storage[""], "baz", "storage['']")
        }, "Named access to " + name + " should be correct");

        test(function() {
            assert_equals(storage.getItem("unknown"), null, "storage.getItem('unknown')")
            assert_equals(storage.getItem("name"), "x", "storage.getItem('name')")
            assert_equals(storage.getItem("undefined"), "foo", "storage.getItem('undefined')")
            assert_equals(storage.getItem("null"), "bar", "storage.getItem('null')")
            assert_equals(storage.getItem(undefined), "foo", "storage.getItem(undefined)")
            assert_equals(storage.getItem(null), "bar", "storage.getItem(null)")
            assert_equals(storage.getItem(""), "baz", "storage.getItem('')")
        }, name + ".getItem should be correct")
    }, "Get value by getIten(key) and named access in " + name + ".");
});