diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/webstorage/event_basic.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webstorage/event_basic.js')
-rw-r--r-- | testing/web-platform/tests/webstorage/event_basic.js | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webstorage/event_basic.js b/testing/web-platform/tests/webstorage/event_basic.js new file mode 100644 index 0000000000..09f5f1bfb9 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_basic.js @@ -0,0 +1,128 @@ +testStorages(function(storageString) { + async_test(function(t) { + assert_true(storageString in window, storageString + " exist"); + var storage = window[storageString]; + t.add_cleanup(function() { storage.clear() }); + + clearStorage(storageString, t.step_func(loadiframe)); + assert_equals(storage.length, 0, "storage.length"); + + function loadiframe(msg) + { + iframe.onload = t.step_func(step1); + iframe.src = "resources/event_basic.html"; + } + + function step1(msg) + { + storage.setItem('FOO', 'BAR'); + + runAfterNStorageEvents(t.step_func(step2), 1); + } + + function step2(msg) + { + if(msg != undefined) { + assert_unreached(msg); + } + assert_equals(storageEventList.length, 1); + assert_equals(storageEventList[0].storageAreaString, storageString, + "Storage event came from wrong storage type."); + assert_equals(storageEventList[0].key, "FOO"); + assert_equals(storageEventList[0].oldValue, null); + assert_equals(storageEventList[0].newValue, "BAR"); + + storage.setItem('FU', 'BAR'); + storage.setItem('a', '1'); + storage.setItem('b', '2'); + storage.setItem('b', '3'); + + runAfterNStorageEvents(t.step_func(step3), 5); + } + + function step3(msg) + { + if(msg != undefined) { + assert_unreached(msg); + } + assert_equals(storageEventList.length, 5); + assert_equals(storageEventList[1].storageAreaString, storageString, + "Storage event came from wrong storage type."); + assert_equals(storageEventList[1].key, "FU"); + assert_equals(storageEventList[1].oldValue, null); + assert_equals(storageEventList[1].newValue, "BAR"); + + assert_equals(storageEventList[2].storageAreaString, storageString, + "Storage event came from wrong storage type."); + assert_equals(storageEventList[2].key, "a"); + assert_equals(storageEventList[2].oldValue, null); + assert_equals(storageEventList[2].newValue, "1"); + + assert_equals(storageEventList[3].storageAreaString, storageString, + "Storage event came from wrong storage type."); + assert_equals(storageEventList[3].key, "b"); + assert_equals(storageEventList[3].oldValue, null); + assert_equals(storageEventList[3].newValue, "2"); + + assert_equals(storageEventList[4].storageAreaString, storageString, + "Storage event came from wrong storage type."); + assert_equals(storageEventList[4].key, "b"); + assert_equals(storageEventList[4].oldValue, "2"); + assert_equals(storageEventList[4].newValue, "3"); + + storage.removeItem('FOO'); + + runAfterNStorageEvents(t.step_func(step4), 6); + } + + function step4(msg) + { + if(msg != undefined) { + assert_unreached(msg); + } + assert_equals(storageEventList.length, 6); + assert_equals(storageEventList[5].storageAreaString, storageString, + "Storage event came from wrong storage type."); + assert_equals(storageEventList[5].key, "FOO"); + assert_equals(storageEventList[5].oldValue, "BAR"); + assert_equals(storageEventList[5].newValue, null); + + storage.removeItem('FU'); + + runAfterNStorageEvents(t.step_func(step5), 7); + } + + function step5(msg) + { + if(msg != undefined) { + assert_unreached(msg); + } + assert_equals(storageEventList.length, 7); + assert_equals(storageEventList[6].storageAreaString, storageString, + "Storage event came from wrong storage type."); + assert_equals(storageEventList[6].key, "FU"); + assert_equals(storageEventList[6].oldValue, "BAR"); + assert_equals(storageEventList[6].newValue, null); + + storage.clear(); + + runAfterNStorageEvents(t.step_func(step6), 8); + } + + function step6(msg) + { + if(msg != undefined) { + assert_unreached(msg); + } + assert_equals(storageEventList.length, 8); + assert_equals(storageEventList[7].storageAreaString, storageString, + "Storage event came from wrong storage type."); + assert_equals(storageEventList[7].key, null); + assert_equals(storageEventList[7].oldValue, null); + assert_equals(storageEventList[7].newValue, null); + + t.done(); + } + + }, storageString + " mutations fire StorageEvents that are caught by the event listener set via window.onstorage."); +}); |