4 <script src=
"../../../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div id=
"console"></div>
11 description("This tests the constructor for the StorageEvent DOM class.");
13 // No initializer is passed.
14 shouldBe("new StorageEvent('eventType').bubbles", "false");
15 shouldBe("new StorageEvent('eventType').cancelable", "false");
16 // Note: key is nullable.
17 shouldBeNull("new StorageEvent('eventType').key");
18 // Note: oldValue is nullable.
19 shouldBeNull("new StorageEvent('eventType').oldValue");
20 // Note: newValue is nullable.
21 shouldBeNull("new StorageEvent('eventType').newValue");
22 shouldBeEqualToString("new StorageEvent('eventType').url", "");
23 shouldBeNull("new StorageEvent('eventType').storageArea");
26 shouldBe("new StorageEvent('eventType', { bubbles: false }).bubbles", "false");
27 shouldBe("new StorageEvent('eventType', { bubbles: true }).bubbles", "true");
29 // cancelable is passed.
30 shouldBe("new StorageEvent('eventType', { cancelable: false }).cancelable", "false");
31 shouldBe("new StorageEvent('eventType', { cancelable: true }).cancelable", "true");
33 // key, oldValue, newValue and url is passed.
34 ["key", "oldValue", "newValue", "url"].forEach(function(attr
) {
36 shouldBeEqualToString("new StorageEvent('eventType', { " + attr
+ ": 'abcde' })." + attr
, "abcde");
37 shouldBeEqualToString("new StorageEvent('eventType', { " + attr
+ ": '' })." + attr
, "");
40 shouldBeEqualToString("new StorageEvent('eventType', { " + attr
+ ": false })." + attr
, "false");
41 shouldBeEqualToString("new StorageEvent('eventType', { " + attr
+ ": true })." + attr
, "true");
42 shouldBeEqualToString("new StorageEvent('eventType', { " + attr
+ ": 12345 })." + attr
, "12345");
43 shouldBeEqualToString("new StorageEvent('eventType', { " + attr
+ ": 18446744073709551615 })." + attr
, "18446744073709552000");
44 shouldBeEqualToString("new StorageEvent('eventType', { " + attr
+ ": NaN })." + attr
, "NaN");
45 shouldBeEqualToString("new StorageEvent('eventType', { " + attr
+ ": [] })." + attr
, "");
46 shouldBeEqualToString("new StorageEvent('eventType', { " + attr
+ ": [1, 2, 3] })." + attr
, "1,2,3");
47 shouldBeEqualToString("new StorageEvent('eventType', { " + attr
+ ": {abcde: 12345} })." + attr
, "[object Object]");
48 shouldBeEqualToString("new StorageEvent('eventType', { " + attr
+ ": {valueOf: function () { return 'abcde'; } } })." + attr
, "[object Object]");
51 // key, oldValue and newValue are nullable strings.
52 ["key", "oldValue", "newValue"].forEach(function(attr
) {
53 shouldBeNull("new StorageEvent('eventType', { " + attr
+ ": undefined })." + attr
);
54 shouldBeNull("new StorageEvent('eventType', { " + attr
+ ": null })." + attr
);
57 // url is non-nullable string.
58 shouldBeEqualToString("new StorageEvent('eventType', { url: undefined }).url", "");
59 shouldBeEqualToString("new StorageEvent('eventType', { url: null }).url", "null");
61 // storageArea is passed.
63 shouldBe("new StorageEvent('eventType', { storageArea: localStorage }).storageArea", "localStorage");
64 shouldBe("new StorageEvent('eventType', { storageArea: sessionStorage }).storageArea", "sessionStorage");
66 // Non-Storage objects.
67 var test_object
= {abc
: 123};
68 shouldThrow("new StorageEvent('eventType', { storageArea: test_object }).storageArea");
69 shouldThrow("new StorageEvent('eventType', { storageArea: window }).storageArea");
70 shouldThrow("new StorageEvent('eventType', { storageArea: document }).storageArea");
71 shouldBe("new StorageEvent('eventType', { storageArea: undefined }).storageArea", "null");
72 shouldBe("new StorageEvent('eventType', { storageArea: null }).storageArea", "null");
73 shouldThrow("new StorageEvent('eventType', { storageArea: false }).storageArea");
74 shouldThrow("new StorageEvent('eventType', { storageArea: true }).storageArea");
75 shouldThrow("new StorageEvent('eventType', { storageArea: '' }).storageArea");
76 shouldThrow("new StorageEvent('eventType', { storageArea: 'chocolate' }).storageArea");
77 shouldThrow("new StorageEvent('eventType', { storageArea: 12345 }).storageArea");
78 shouldThrow("new StorageEvent('eventType', { storageArea: 18446744073709551615 }).storageArea");
79 shouldThrow("new StorageEvent('eventType', { storageArea: NaN }).storageArea");
80 // Note that valueOf() is not called, when the left hand side is evaluated.
81 shouldThrow("new StorageEvent('eventType', { storageArea: {valueOf: function () { return window; } } }).storageArea == window");
82 shouldBe("new StorageEvent('eventType', { get storageArea() { return localStorage; } }).storageArea", "localStorage");
83 shouldThrow("new StorageEvent('eventType', { get storageArea() { return 123; } }).storageArea");
84 shouldThrow("new StorageEvent('eventType', { get storageArea() { throw 'StorageEvent Error'; } })");
86 // All initializers are passed.
87 shouldBe("new StorageEvent('eventType', { bubbles: true, cancelable: false, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).bubbles", "true");
88 shouldBe("new StorageEvent('eventType', { bubbles: false, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).cancelable", "true");
89 shouldBeEqualToString("new StorageEvent('eventType', { bubbles: true, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).key", "abc");
90 shouldBeEqualToString("new StorageEvent('eventType', { bubbles: true, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).oldValue", "def");
91 shouldBeEqualToString("new StorageEvent('eventType', { bubbles: true, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).newValue", "ghi");
92 shouldBeEqualToString("new StorageEvent('eventType', { bubbles: true, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).url", "jkl");
93 shouldBe("new StorageEvent('eventType', { bubbles: true, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).storageArea", "localStorage");