From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- testing/web-platform/tests/webstorage/META.yml | 6 + testing/web-platform/tests/webstorage/README.md | 4 + .../tests/webstorage/defineProperty.window.js | 57 ++++++ .../tests/webstorage/document-domain.html | 20 ++ .../tests/webstorage/eventTestHarness.js | 54 ++++++ .../web-platform/tests/webstorage/event_basic.html | 15 ++ .../web-platform/tests/webstorage/event_basic.js | 128 ++++++++++++ .../tests/webstorage/event_body_attribute.html | 15 ++ .../tests/webstorage/event_body_attribute.js | 116 +++++++++++ .../tests/webstorage/event_case_sensitive.html | 15 ++ .../tests/webstorage/event_case_sensitive.js | 52 +++++ .../tests/webstorage/event_constructor.window.js | 69 +++++++ .../webstorage/event_initstorageevent.window.js | 60 ++++++ .../tests/webstorage/event_local_key.html | 38 ++++ .../tests/webstorage/event_local_newvalue.html | 38 ++++ .../tests/webstorage/event_local_oldvalue.html | 38 ++++ .../tests/webstorage/event_local_removeitem.html | 45 +++++ .../tests/webstorage/event_local_storagearea.html | 39 ++++ .../tests/webstorage/event_local_url.html | 43 +++++ .../tests/webstorage/event_no_duplicates.html | 111 +++++++++++ .../tests/webstorage/event_session_key.html | 38 ++++ .../tests/webstorage/event_session_newvalue.html | 40 ++++ .../tests/webstorage/event_session_oldvalue.html | 38 ++++ .../tests/webstorage/event_session_removeitem.html | 44 +++++ .../webstorage/event_session_storagearea.html | 40 ++++ .../tests/webstorage/event_session_url.html | 43 +++++ .../tests/webstorage/event_setattribute.html | 15 ++ .../tests/webstorage/event_setattribute.js | 115 +++++++++++ ...rame-opens-3P-window.partitioned.tentative.html | 75 +++++++ ...calstorage-basic-partitioned.tentative.sub.html | 61 ++++++ ...e-cross-origin-iframe.tentative.https.window.js | 27 +++ .../tests/webstorage/missing_arguments.window.js | 17 ++ .../tests/webstorage/resources/event_basic.html | 16 ++ .../webstorage/resources/event_body_handler.html | 14 ++ .../resources/event_setattribute_handler.html | 15 ++ .../resources/local_change_item_iframe.html | 18 ++ .../resources/local_set_item_clear_iframe.html | 17 ++ .../resources/local_set_item_iframe.html | 16 ++ .../resources/local_set_item_remove_iframe.html | 11 ++ ...ocalstorage-about-blank-partitioned-iframe.html | 41 ++++ ...alstorage-about-blank-partitioned-win-open.html | 37 ++++ .../webstorage/resources/partitioning-utils.js | 20 ++ ...sionStorage-about-blank-partitioned-iframe.html | 44 +++++ .../resources/session_change_item_iframe.html | 18 ++ .../resources/session_set_item_clear_iframe.html | 17 ++ .../resources/session_set_item_iframe.html | 16 ++ .../resources/session_set_item_remove_iframe.html | 11 ++ .../storage_local_window_open_second.html | 36 ++++ .../storage_session_window_noopener_second.html | 34 ++++ .../storage_session_window_open_second.html | 41 ++++ ...ionStorage-basic-partitioned.tentative.sub.html | 73 +++++++ .../web-platform/tests/webstorage/set.window.js | 102 ++++++++++ .../tests/webstorage/storage_builtins.window.js | 16 ++ .../tests/webstorage/storage_clear.window.js | 16 ++ .../tests/webstorage/storage_enumerate.window.js | 55 ++++++ .../storage_functions_not_overwritten.window.js | 37 ++++ .../tests/webstorage/storage_getitem.window.js | 34 ++++ .../tests/webstorage/storage_in.window.js | 22 +++ .../tests/webstorage/storage_indexing.window.js | 28 +++ .../tests/webstorage/storage_key.window.js | 51 +++++ .../webstorage/storage_key_empty_string.window.js | 10 + .../tests/webstorage/storage_length.window.js | 23 +++ .../tests/webstorage/storage_local-manual.html | 40 ++++ ...torage_local_setitem_quotaexceedederr.window.js | 16 ++ .../webstorage/storage_local_window_open.window.js | 16 ++ .../tests/webstorage/storage_removeitem.window.js | 44 +++++ .../tests/webstorage/storage_session-manual.html | 39 ++++ ...rage_session_setitem_quotaexceedederr.window.js | 16 ++ .../storage_session_window_noopener.window.js | 21 ++ .../storage_session_window_open.window.js | 17 ++ .../storage_session_window_reopen.window.js | 26 +++ .../storage_set_value_enumerate.window.js | 21 ++ .../tests/webstorage/storage_setitem.window.js | 215 +++++++++++++++++++++ .../webstorage/storage_string_conversion.window.js | 32 +++ .../storage_supported_property_names.window.js | 15 ++ .../tests/webstorage/symbol-props.window.js | 81 ++++++++ 76 files changed, 3004 insertions(+) create mode 100644 testing/web-platform/tests/webstorage/META.yml create mode 100644 testing/web-platform/tests/webstorage/README.md create mode 100644 testing/web-platform/tests/webstorage/defineProperty.window.js create mode 100644 testing/web-platform/tests/webstorage/document-domain.html create mode 100644 testing/web-platform/tests/webstorage/eventTestHarness.js create mode 100644 testing/web-platform/tests/webstorage/event_basic.html create mode 100644 testing/web-platform/tests/webstorage/event_basic.js create mode 100644 testing/web-platform/tests/webstorage/event_body_attribute.html create mode 100644 testing/web-platform/tests/webstorage/event_body_attribute.js create mode 100644 testing/web-platform/tests/webstorage/event_case_sensitive.html create mode 100644 testing/web-platform/tests/webstorage/event_case_sensitive.js create mode 100644 testing/web-platform/tests/webstorage/event_constructor.window.js create mode 100644 testing/web-platform/tests/webstorage/event_initstorageevent.window.js create mode 100644 testing/web-platform/tests/webstorage/event_local_key.html create mode 100644 testing/web-platform/tests/webstorage/event_local_newvalue.html create mode 100644 testing/web-platform/tests/webstorage/event_local_oldvalue.html create mode 100644 testing/web-platform/tests/webstorage/event_local_removeitem.html create mode 100644 testing/web-platform/tests/webstorage/event_local_storagearea.html create mode 100644 testing/web-platform/tests/webstorage/event_local_url.html create mode 100644 testing/web-platform/tests/webstorage/event_no_duplicates.html create mode 100644 testing/web-platform/tests/webstorage/event_session_key.html create mode 100644 testing/web-platform/tests/webstorage/event_session_newvalue.html create mode 100644 testing/web-platform/tests/webstorage/event_session_oldvalue.html create mode 100644 testing/web-platform/tests/webstorage/event_session_removeitem.html create mode 100644 testing/web-platform/tests/webstorage/event_session_storagearea.html create mode 100644 testing/web-platform/tests/webstorage/event_session_url.html create mode 100644 testing/web-platform/tests/webstorage/event_setattribute.html create mode 100644 testing/web-platform/tests/webstorage/event_setattribute.js create mode 100644 testing/web-platform/tests/webstorage/localstorage-about-blank-3P-iframe-opens-3P-window.partitioned.tentative.html create mode 100644 testing/web-platform/tests/webstorage/localstorage-basic-partitioned.tentative.sub.html create mode 100644 testing/web-platform/tests/webstorage/localstorage-cross-origin-iframe.tentative.https.window.js create mode 100644 testing/web-platform/tests/webstorage/missing_arguments.window.js create mode 100644 testing/web-platform/tests/webstorage/resources/event_basic.html create mode 100644 testing/web-platform/tests/webstorage/resources/event_body_handler.html create mode 100644 testing/web-platform/tests/webstorage/resources/event_setattribute_handler.html create mode 100644 testing/web-platform/tests/webstorage/resources/local_change_item_iframe.html create mode 100644 testing/web-platform/tests/webstorage/resources/local_set_item_clear_iframe.html create mode 100644 testing/web-platform/tests/webstorage/resources/local_set_item_iframe.html create mode 100644 testing/web-platform/tests/webstorage/resources/local_set_item_remove_iframe.html create mode 100644 testing/web-platform/tests/webstorage/resources/localstorage-about-blank-partitioned-iframe.html create mode 100644 testing/web-platform/tests/webstorage/resources/localstorage-about-blank-partitioned-win-open.html create mode 100644 testing/web-platform/tests/webstorage/resources/partitioning-utils.js create mode 100644 testing/web-platform/tests/webstorage/resources/sessionStorage-about-blank-partitioned-iframe.html create mode 100644 testing/web-platform/tests/webstorage/resources/session_change_item_iframe.html create mode 100644 testing/web-platform/tests/webstorage/resources/session_set_item_clear_iframe.html create mode 100644 testing/web-platform/tests/webstorage/resources/session_set_item_iframe.html create mode 100644 testing/web-platform/tests/webstorage/resources/session_set_item_remove_iframe.html create mode 100644 testing/web-platform/tests/webstorage/resources/storage_local_window_open_second.html create mode 100644 testing/web-platform/tests/webstorage/resources/storage_session_window_noopener_second.html create mode 100644 testing/web-platform/tests/webstorage/resources/storage_session_window_open_second.html create mode 100644 testing/web-platform/tests/webstorage/sessionStorage-basic-partitioned.tentative.sub.html create mode 100644 testing/web-platform/tests/webstorage/set.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_builtins.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_clear.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_enumerate.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_functions_not_overwritten.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_getitem.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_in.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_indexing.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_key.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_key_empty_string.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_length.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_local-manual.html create mode 100644 testing/web-platform/tests/webstorage/storage_local_setitem_quotaexceedederr.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_local_window_open.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_removeitem.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_session-manual.html create mode 100644 testing/web-platform/tests/webstorage/storage_session_setitem_quotaexceedederr.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_session_window_noopener.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_session_window_open.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_session_window_reopen.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_set_value_enumerate.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_setitem.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_string_conversion.window.js create mode 100644 testing/web-platform/tests/webstorage/storage_supported_property_names.window.js create mode 100644 testing/web-platform/tests/webstorage/symbol-props.window.js (limited to 'testing/web-platform/tests/webstorage') diff --git a/testing/web-platform/tests/webstorage/META.yml b/testing/web-platform/tests/webstorage/META.yml new file mode 100644 index 0000000000..020075c3f2 --- /dev/null +++ b/testing/web-platform/tests/webstorage/META.yml @@ -0,0 +1,6 @@ +spec: https://html.spec.whatwg.org/multipage/webstorage.html +suggested_reviewers: + - siusin + - inexorabletash + - zqzhang + - jdm diff --git a/testing/web-platform/tests/webstorage/README.md b/testing/web-platform/tests/webstorage/README.md new file mode 100644 index 0000000000..2bbc5fbfb6 --- /dev/null +++ b/testing/web-platform/tests/webstorage/README.md @@ -0,0 +1,4 @@ +These are the storage (`localStorage`, `sessionStorage`) tests for the +[Web storage chapter of the HTML Standard](https://html.spec.whatwg.org/multipage/webstorage.html). + +IDL is covered by `/html/dom/idlharness.https.html`. diff --git a/testing/web-platform/tests/webstorage/defineProperty.window.js b/testing/web-platform/tests/webstorage/defineProperty.window.js new file mode 100644 index 0000000000..d8ab163df6 --- /dev/null +++ b/testing/web-platform/tests/webstorage/defineProperty.window.js @@ -0,0 +1,57 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + [9, "x"].forEach(function(key) { + test(function() { + var desc = { + value: "value", + }; + + var storage = window[name]; + storage.clear(); + + assert_equals(storage[key], undefined); + assert_equals(storage.getItem(key), null); + assert_equals(Object.defineProperty(storage, key, desc), storage); + assert_equals(storage[key], "value"); + assert_equals(storage.getItem(key), "value"); + }, "Defining data property for key " + key + " on " + name); + + test(function() { + var desc1 = { + value: "value", + }; + var desc2 = { + value: "new value", + }; + + var storage = window[name]; + storage.clear(); + + assert_equals(storage[key], undefined); + assert_equals(storage.getItem(key), null); + assert_equals(Object.defineProperty(storage, key, desc1), storage); + assert_equals(storage[key], "value"); + assert_equals(storage.getItem(key), "value"); + + assert_equals(Object.defineProperty(storage, key, desc2), storage); + assert_equals(storage[key], "new value"); + assert_equals(storage.getItem(key), "new value"); + }, "Defining data property for key " + key + " on " + name + " twice"); + + test(function() { + var desc = { + value: { + toString: function() { return "value"; } + }, + }; + + var storage = window[name]; + storage.clear(); + + assert_equals(storage[key], undefined); + assert_equals(storage.getItem(key), null); + assert_equals(Object.defineProperty(storage, key, desc), storage); + assert_equals(storage[key], "value"); + assert_equals(storage.getItem(key), "value"); + }, "Defining data property with toString for key " + key + " on " + name); + }); +}); diff --git a/testing/web-platform/tests/webstorage/document-domain.html b/testing/web-platform/tests/webstorage/document-domain.html new file mode 100644 index 0000000000..3232b0d508 --- /dev/null +++ b/testing/web-platform/tests/webstorage/document-domain.html @@ -0,0 +1,20 @@ + +localStorage and document.domain + + + + +
+ + diff --git a/testing/web-platform/tests/webstorage/eventTestHarness.js b/testing/web-platform/tests/webstorage/eventTestHarness.js new file mode 100644 index 0000000000..0a98546ace --- /dev/null +++ b/testing/web-platform/tests/webstorage/eventTestHarness.js @@ -0,0 +1,54 @@ +storageEventList = []; +iframe = document.createElement("IFRAME"); +document.body.appendChild(iframe); + +function runAfterNStorageEvents(callback, expectedNumEvents) +{ + countStorageEvents(callback, expectedNumEvents, 0) +} + +function countStorageEvents(callback, expectedNumEvents, times) +{ + function onTimeout() + { + var currentCount = storageEventList.length; + if (currentCount == expectedNumEvents) { + callback(); + } else if (currentCount > expectedNumEvents) { + msg = "got at least " + currentCount + ", expected only " + expectedNumEvents + " events"; + callback(msg); + } else if (times > 50) { + msg = "Timeout: only got " + currentCount + ", expected " + expectedNumEvents + " events"; + callback(msg); + } else { + countStorageEvents(callback, expectedNumEvents, times+1); + } + } + setTimeout(onTimeout, 20); +} + +function clearStorage(storageName, callback) +{ + if (window[storageName].length === 0) { + storageEventList = []; + setTimeout(callback, 0); + } else { + window[storageName].clear(); + runAfterNStorageEvents(function() { + storageEventList = []; + callback(); + }, 1); + } +} + +function testStorages(testCallback) +{ + testCallback("sessionStorage"); + var hit = false; + add_result_callback(function() { + if (!hit) { + hit = true; + testCallback("localStorage"); + } + }); +} diff --git a/testing/web-platform/tests/webstorage/event_basic.html b/testing/web-platform/tests/webstorage/event_basic.html new file mode 100644 index 0000000000..407e41c4b1 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_basic.html @@ -0,0 +1,15 @@ + + + + +WebStorage Test: StorageEvent - window.onstorage + + + + +
+ + + + + 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."); +}); diff --git a/testing/web-platform/tests/webstorage/event_body_attribute.html b/testing/web-platform/tests/webstorage/event_body_attribute.html new file mode 100644 index 0000000000..80ec676186 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_body_attribute.html @@ -0,0 +1,15 @@ + + + + +WebStorage Test: StorageEvent - set onstorage as body attribute + + + + +
+ + + + + diff --git a/testing/web-platform/tests/webstorage/event_body_attribute.js b/testing/web-platform/tests/webstorage/event_body_attribute.js new file mode 100644 index 0000000000..a0e596da95 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_body_attribute.js @@ -0,0 +1,116 @@ +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(step0)); + assert_equals(storage.length, 0, "storage.length"); + + function step0(msg) + { + iframe.onload = t.step_func(step1); + // Null out the existing handler eventTestHarness.js set up; + // otherwise this test won't be testing much of anything useful. + iframe.contentWindow.onstorage = null; + iframe.src = "resources/event_body_handler.html"; + } + + function step1(msg) + { + storageEventList = new Array(); + 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].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].key, "FU"); + assert_equals(storageEventList[1].oldValue, null); + assert_equals(storageEventList[1].newValue, "BAR"); + + assert_equals(storageEventList[2].key, "a"); + assert_equals(storageEventList[2].oldValue, null); + assert_equals(storageEventList[2].newValue, "1"); + + assert_equals(storageEventList[3].key, "b"); + assert_equals(storageEventList[3].oldValue, null); + assert_equals(storageEventList[3].newValue, "2"); + + 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].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].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].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 specified as an attribute on the body."); +}); diff --git a/testing/web-platform/tests/webstorage/event_case_sensitive.html b/testing/web-platform/tests/webstorage/event_case_sensitive.html new file mode 100644 index 0000000000..916b230412 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_case_sensitive.html @@ -0,0 +1,15 @@ + + + + +WebStorage Test: StorageEvent - the case of value changed + + + + +
+ + + + + diff --git a/testing/web-platform/tests/webstorage/event_case_sensitive.js b/testing/web-platform/tests/webstorage/event_case_sensitive.js new file mode 100644 index 0000000000..9c9397fd5a --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_case_sensitive.js @@ -0,0 +1,52 @@ +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(step0); + iframe.src = "resources/event_basic.html"; + } + + function step0(msg) + { + storage.foo = "test"; + runAfterNStorageEvents(t.step_func(step1), 1); + } + + function step1(msg) + { + storageEventList = new Array(); + storage.foo = "test"; + + runAfterNStorageEvents(t.step_func(step2), 0); + } + + function step2(msg) + { + if(msg != undefined) { + assert_unreached(msg); + } + assert_equals(storageEventList.length, 0); + + storage.foo = "TEST"; + + runAfterNStorageEvents(t.step_func(step3), 1); + } + + function step3(msg) + { + if(msg != undefined) { + assert_unreached(msg); + } + assert_equals(storageEventList.length, 1); + + t.done(); + } + }, storageString + " storage events fire even when only the case of the value changes."); +}); diff --git a/testing/web-platform/tests/webstorage/event_constructor.window.js b/testing/web-platform/tests/webstorage/event_constructor.window.js new file mode 100644 index 0000000000..ba7dd91965 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_constructor.window.js @@ -0,0 +1,69 @@ +test(function() { + assert_throws_js(TypeError, () => new StorageEvent()); + // should be redundant, but .length can be wrong with custom bindings + assert_equals(StorageEvent.length, 1, 'StorageEvent.length'); +}, 'constructor with no arguments'); + +test(function() { + var event = new StorageEvent('type'); + assert_equals(event.type, 'type', 'type'); + assert_equals(event.key, null, 'key'); + assert_equals(event.oldValue, null, 'oldValue'); + assert_equals(event.newValue, null, 'newValue'); + assert_equals(event.url, '', 'url'); + assert_equals(event.storageArea, null, 'storageArea'); +}, 'constructor with just type argument'); + +test(function() { + assert_not_equals(localStorage, null, 'localStorage'); // precondition + + var event = new StorageEvent('storage', { + bubbles: true, + cancelable: true, + key: 'key', + oldValue: 'oldValue', + newValue: 'newValue', + url: 'url', // not an absolute URL to ensure it isn't resolved + storageArea: localStorage + }); + assert_equals(event.type, 'storage', 'type'); + assert_equals(event.bubbles, true, 'bubbles'); + assert_equals(event.cancelable, true, 'cancelable'); + assert_equals(event.key, 'key', 'key'); + assert_equals(event.oldValue, 'oldValue', 'oldValue'); + assert_equals(event.newValue, 'newValue', 'newValue'); + assert_equals(event.url, 'url', 'url'); + assert_equals(event.storageArea, localStorage, 'storageArea'); +}, 'constructor with sensible type argument and members'); + +test(function() { + var event = new StorageEvent(null, { + key: null, + oldValue: null, + newValue: null, + url: null, + storageArea: null + }); + assert_equals(event.type, 'null', 'type'); + assert_equals(event.key, null, 'key'); + assert_equals(event.oldValue, null, 'oldValue'); + assert_equals(event.newValue, null, 'newValue'); + assert_equals(event.url, 'null', 'url'); + assert_equals(event.storageArea, null, 'storageArea'); +}, 'constructor with null type argument and members'); + +test(function() { + var event = new StorageEvent(undefined, { + key: undefined, + oldValue: undefined, + newValue: undefined, + url: undefined, + storageArea: undefined + }); + assert_equals(event.type, 'undefined', 'type'); + assert_equals(event.key, null, 'key'); + assert_equals(event.oldValue, null, 'oldValue'); + assert_equals(event.newValue, null, 'newValue'); + assert_equals(event.url, '', 'url'); // not 'undefined'! + assert_equals(event.storageArea, null, 'storageArea'); +}, 'constructor with undefined type argument and members'); diff --git a/testing/web-platform/tests/webstorage/event_initstorageevent.window.js b/testing/web-platform/tests/webstorage/event_initstorageevent.window.js new file mode 100644 index 0000000000..ac0a757021 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_initstorageevent.window.js @@ -0,0 +1,60 @@ +test(() => { + const event = new StorageEvent('storage'); + assert_throws_js(TypeError, () => event.initStorageEvent()); + // should be redundant, but .length can be wrong with custom bindings + assert_equals(event.initStorageEvent.length, 1, 'event.initStorageEvent.length'); +}, 'initStorageEvent with 0 arguments'); + +test(() => { + const event = new StorageEvent('storage'); + event.initStorageEvent('type'); + assert_equals(event.type, 'type', 'event.type'); + assert_equals(event.bubbles, false, 'event.bubbles'); + assert_equals(event.cancelable, false, 'event.cancelable'); + assert_equals(event.key, null, 'event.key'); + assert_equals(event.oldValue, null, 'event.oldValue'); + assert_equals(event.newValue, null, 'event.newValue'); + assert_equals(event.url, '', 'event.url'); + assert_equals(event.storageArea, null, 'event.storageArea'); +}, 'initStorageEvent with 1 argument'); + +test(() => { + assert_not_equals(localStorage, null, 'localStorage'); // precondition + + const event = new StorageEvent('storage'); + event.initStorageEvent('type', true, true, 'key', 'oldValue', 'newValue', 'url', localStorage); + assert_equals(event.type, 'type', 'event.type'); + assert_equals(event.bubbles, true, 'event.bubbles'); + assert_equals(event.cancelable, true, 'event.cancelable'); + assert_equals(event.key, 'key', 'event.key'); + assert_equals(event.oldValue, 'oldValue', 'event.oldValue'); + assert_equals(event.newValue, 'newValue', 'event.newValue'); + assert_equals(event.url, 'url', 'event.url'); + assert_equals(event.storageArea, localStorage, 'event.storageArea'); +}, 'initStorageEvent with 8 sensible arguments'); + +test(() => { + const event = new StorageEvent('storage'); + event.initStorageEvent(null, null, null, null, null, null, null, null); + assert_equals(event.type, 'null', 'event.type'); + assert_equals(event.bubbles, false, 'event.bubbles'); + assert_equals(event.cancelable, false, 'event.cancelable'); + assert_equals(event.key, null, 'event.key'); + assert_equals(event.oldValue, null, 'event.oldValue'); + assert_equals(event.newValue, null, 'event.newValue'); + assert_equals(event.url, 'null', 'event.url'); + assert_equals(event.storageArea, null, 'event.storageArea'); +}, 'initStorageEvent with 8 null arguments'); + +test(() => { + const event = new StorageEvent('storage'); + event.initStorageEvent(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined); + assert_equals(event.type, 'undefined', 'event.type'); + assert_equals(event.bubbles, false, 'event.bubbles'); + assert_equals(event.cancelable, false, 'event.cancelable'); + assert_equals(event.key, null, 'event.key'); + assert_equals(event.oldValue, null, 'event.oldValue'); + assert_equals(event.newValue, null, 'event.newValue'); + assert_equals(event.url, '', 'event.url'); + assert_equals(event.storageArea, null, 'event.storageArea'); +}, 'initStorageEvent with 8 undefined arguments'); diff --git a/testing/web-platform/tests/webstorage/event_local_key.html b/testing/web-platform/tests/webstorage/event_local_key.html new file mode 100644 index 0000000000..84512da2d2 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_local_key.html @@ -0,0 +1,38 @@ + + + + WebStorage Test: localStorage event - key + + + + +

event_local_key

+
+ + + diff --git a/testing/web-platform/tests/webstorage/event_local_newvalue.html b/testing/web-platform/tests/webstorage/event_local_newvalue.html new file mode 100644 index 0000000000..2b743c37bf --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_local_newvalue.html @@ -0,0 +1,38 @@ + + + + WebStorage Test: localStorage event - newValue + + + + +

event_local_newValue

+
+ + + diff --git a/testing/web-platform/tests/webstorage/event_local_oldvalue.html b/testing/web-platform/tests/webstorage/event_local_oldvalue.html new file mode 100644 index 0000000000..87c79aa07d --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_local_oldvalue.html @@ -0,0 +1,38 @@ + + + + WebStorage Test: localStorage event - oldValue + + + + +

event_local_oldValue

+
+ + + diff --git a/testing/web-platform/tests/webstorage/event_local_removeitem.html b/testing/web-platform/tests/webstorage/event_local_removeitem.html new file mode 100644 index 0000000000..7b81ea2bac --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_local_removeitem.html @@ -0,0 +1,45 @@ + + +Web Storage Test: event - localStorage removeItem + + + + +
+ + diff --git a/testing/web-platform/tests/webstorage/event_local_storagearea.html b/testing/web-platform/tests/webstorage/event_local_storagearea.html new file mode 100644 index 0000000000..db4b114a95 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_local_storagearea.html @@ -0,0 +1,39 @@ + + + + WebStorage Test: localStorage event - storageArea + + + + +

event_local_storageArea

+
+ + + diff --git a/testing/web-platform/tests/webstorage/event_local_url.html b/testing/web-platform/tests/webstorage/event_local_url.html new file mode 100644 index 0000000000..7345ce3736 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_local_url.html @@ -0,0 +1,43 @@ + + + + WebStorage Test: localStorage event - url + + + + +

event_local_url

+
+ + + diff --git a/testing/web-platform/tests/webstorage/event_no_duplicates.html b/testing/web-platform/tests/webstorage/event_no_duplicates.html new file mode 100644 index 0000000000..8fbea2bef9 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_no_duplicates.html @@ -0,0 +1,111 @@ + + +WebStorage Test: StorageEvent - only if something changes + + + + + + + diff --git a/testing/web-platform/tests/webstorage/event_session_key.html b/testing/web-platform/tests/webstorage/event_session_key.html new file mode 100644 index 0000000000..62600aa394 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_session_key.html @@ -0,0 +1,38 @@ + + + + WebStorage Test: sessionStorage event - key + + + + +

event_session_key

+
+ + + diff --git a/testing/web-platform/tests/webstorage/event_session_newvalue.html b/testing/web-platform/tests/webstorage/event_session_newvalue.html new file mode 100644 index 0000000000..1f367988e0 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_session_newvalue.html @@ -0,0 +1,40 @@ + + + + WebStorage Test: sessionStorage event - newValue + + + + +

event_session_newValue

+
+ + + diff --git a/testing/web-platform/tests/webstorage/event_session_oldvalue.html b/testing/web-platform/tests/webstorage/event_session_oldvalue.html new file mode 100644 index 0000000000..00400df252 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_session_oldvalue.html @@ -0,0 +1,38 @@ + + + + WebStorage Test: sessionStorage event - oldValue + + + + +

event_session_oldValue

+
+ + + diff --git a/testing/web-platform/tests/webstorage/event_session_removeitem.html b/testing/web-platform/tests/webstorage/event_session_removeitem.html new file mode 100644 index 0000000000..7b3c6446ed --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_session_removeitem.html @@ -0,0 +1,44 @@ + + +Web Storage Test: event - sessionStorage removeItem + + + + +
+ + diff --git a/testing/web-platform/tests/webstorage/event_session_storagearea.html b/testing/web-platform/tests/webstorage/event_session_storagearea.html new file mode 100644 index 0000000000..d2c2ba437e --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_session_storagearea.html @@ -0,0 +1,40 @@ + + + + WebStorage Test: sessionStorage event - storageArea + + + + +

event_session_storageArea

+
+ + + + diff --git a/testing/web-platform/tests/webstorage/event_session_url.html b/testing/web-platform/tests/webstorage/event_session_url.html new file mode 100644 index 0000000000..85250acc2b --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_session_url.html @@ -0,0 +1,43 @@ + + + + WebStorage Test: sessionStorage event - url + + + + +

event_session_url

+
+ + + diff --git a/testing/web-platform/tests/webstorage/event_setattribute.html b/testing/web-platform/tests/webstorage/event_setattribute.html new file mode 100644 index 0000000000..c48a2e0fc3 --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_setattribute.html @@ -0,0 +1,15 @@ + + + + +WebStorage Test: StorageEvent - attached setAttribute + + + + +
+ + + + + diff --git a/testing/web-platform/tests/webstorage/event_setattribute.js b/testing/web-platform/tests/webstorage/event_setattribute.js new file mode 100644 index 0000000000..8070938baf --- /dev/null +++ b/testing/web-platform/tests/webstorage/event_setattribute.js @@ -0,0 +1,115 @@ +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(step0)); + assert_equals(storage.length, 0, "storage.length"); + + function step0(msg) + { + iframe.onload = t.step_func(step1); + // Null out the existing handler eventTestHarness.js set up; + // otherwise this test won't be testing much of anything useful. + iframe.contentWindow.onstorage = null; + iframe.src = "resources/event_setattribute_handler.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].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].key, "FU"); + assert_equals(storageEventList[1].oldValue, null); + assert_equals(storageEventList[1].newValue, "BAR"); + + assert_equals(storageEventList[2].key, "a"); + assert_equals(storageEventList[2].oldValue, null); + assert_equals(storageEventList[2].newValue, "1"); + + assert_equals(storageEventList[3].key, "b"); + assert_equals(storageEventList[3].oldValue, null); + assert_equals(storageEventList[3].newValue, "2"); + + 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].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].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].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 attached via setattribute."); +}); diff --git a/testing/web-platform/tests/webstorage/localstorage-about-blank-3P-iframe-opens-3P-window.partitioned.tentative.html b/testing/web-platform/tests/webstorage/localstorage-about-blank-3P-iframe-opens-3P-window.partitioned.tentative.html new file mode 100644 index 0000000000..de94fb2cf4 --- /dev/null +++ b/testing/web-platform/tests/webstorage/localstorage-about-blank-3P-iframe-opens-3P-window.partitioned.tentative.html @@ -0,0 +1,75 @@ + + +localStorage: about:blank partitioning + + + + + + + + diff --git a/testing/web-platform/tests/webstorage/localstorage-basic-partitioned.tentative.sub.html b/testing/web-platform/tests/webstorage/localstorage-basic-partitioned.tentative.sub.html new file mode 100644 index 0000000000..7ed49b1e9a --- /dev/null +++ b/testing/web-platform/tests/webstorage/localstorage-basic-partitioned.tentative.sub.html @@ -0,0 +1,61 @@ + + +localStorage: partitioned storage test + + + + + + + diff --git a/testing/web-platform/tests/webstorage/localstorage-cross-origin-iframe.tentative.https.window.js b/testing/web-platform/tests/webstorage/localstorage-cross-origin-iframe.tentative.https.window.js new file mode 100644 index 0000000000..39812f27a0 --- /dev/null +++ b/testing/web-platform/tests/webstorage/localstorage-cross-origin-iframe.tentative.https.window.js @@ -0,0 +1,27 @@ +// META: script=/common/get-host-info.sub.js +// META: script=/common/utils.js +// META: script=/common/dispatcher/dispatcher.js +// META: script=/html/cross-origin-embedder-policy/credentialless/resources/common.js +// META: script=/html/anonymous-iframe/resources/common.js + +promise_test(async test => { + const same_origin= get_host_info().HTTPS_ORIGIN; + const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN; + const reply_token = token(); + + for(iframe of [ + newIframe(same_origin), + newIframe(cross_origin), + ]) { + send(iframe, ` + try { + let c = window.localStorage; + send("${reply_token}","OK"); + } catch (exception) { + send("${reply_token}","ERROR"); + } + `); + } + assert_equals(await receive(reply_token), "OK"); + assert_equals(await receive(reply_token), "OK"); + }, "LocalStorage should be accessible on both same_origin and cross_origin iframes"); \ No newline at end of file diff --git a/testing/web-platform/tests/webstorage/missing_arguments.window.js b/testing/web-platform/tests/webstorage/missing_arguments.window.js new file mode 100644 index 0000000000..2e41a22ec7 --- /dev/null +++ b/testing/web-platform/tests/webstorage/missing_arguments.window.js @@ -0,0 +1,17 @@ +var tests = [ + function() { localStorage.key(); }, + function() { localStorage.getItem(); }, + function() { localStorage.setItem(); }, + function() { localStorage.setItem("a"); }, + function() { localStorage.removeItem(); }, + function() { sessionStorage.key(); }, + function() { sessionStorage.getItem(); }, + function() { sessionStorage.setItem(); }, + function() { sessionStorage.setItem("a"); }, + function() { sessionStorage.removeItem(); }, +]; +tests.forEach(function(fun) { + test(function() { + assert_throws_js(TypeError, fun); + }, "Should throw TypeError for " + format_value(fun) + "."); +}); diff --git a/testing/web-platform/tests/webstorage/resources/event_basic.html b/testing/web-platform/tests/webstorage/resources/event_basic.html new file mode 100644 index 0000000000..5933b40eeb --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/event_basic.html @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/event_body_handler.html b/testing/web-platform/tests/webstorage/resources/event_body_handler.html new file mode 100644 index 0000000000..11d8ec9447 --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/event_body_handler.html @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/event_setattribute_handler.html b/testing/web-platform/tests/webstorage/resources/event_setattribute_handler.html new file mode 100644 index 0000000000..b9e2f04021 --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/event_setattribute_handler.html @@ -0,0 +1,15 @@ + + + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/local_change_item_iframe.html b/testing/web-platform/tests/webstorage/resources/local_change_item_iframe.html new file mode 100644 index 0000000000..17be8fb26e --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/local_change_item_iframe.html @@ -0,0 +1,18 @@ + + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/local_set_item_clear_iframe.html b/testing/web-platform/tests/webstorage/resources/local_set_item_clear_iframe.html new file mode 100644 index 0000000000..742b7dad1a --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/local_set_item_clear_iframe.html @@ -0,0 +1,17 @@ + + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/local_set_item_iframe.html b/testing/web-platform/tests/webstorage/resources/local_set_item_iframe.html new file mode 100644 index 0000000000..0693824e5d --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/local_set_item_iframe.html @@ -0,0 +1,16 @@ + + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/local_set_item_remove_iframe.html b/testing/web-platform/tests/webstorage/resources/local_set_item_remove_iframe.html new file mode 100644 index 0000000000..7451594c89 --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/local_set_item_remove_iframe.html @@ -0,0 +1,11 @@ + + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/localstorage-about-blank-partitioned-iframe.html b/testing/web-platform/tests/webstorage/resources/localstorage-about-blank-partitioned-iframe.html new file mode 100644 index 0000000000..5cb2c4f7e2 --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/localstorage-about-blank-partitioned-iframe.html @@ -0,0 +1,41 @@ + + + diff --git a/testing/web-platform/tests/webstorage/resources/localstorage-about-blank-partitioned-win-open.html b/testing/web-platform/tests/webstorage/resources/localstorage-about-blank-partitioned-win-open.html new file mode 100644 index 0000000000..90d3a4309e --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/localstorage-about-blank-partitioned-win-open.html @@ -0,0 +1,37 @@ + + + + diff --git a/testing/web-platform/tests/webstorage/resources/partitioning-utils.js b/testing/web-platform/tests/webstorage/resources/partitioning-utils.js new file mode 100644 index 0000000000..9d9e0b8ac5 --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/partitioning-utils.js @@ -0,0 +1,20 @@ +function getOrCreateID(key) { + if (!localStorage.getItem(key)) { + const newID = +new Date() + "-" + Math.random(); + localStorage.setItem(key, newID); + } + return localStorage.getItem(key); +} + +function addIframePromise(url) { + return new Promise(resolve => { + const iframe = document.createElement("iframe"); + iframe.style.display = "none"; + iframe.src = url; + iframe.addEventListener("load", (e) => { + resolve(iframe); + }, {once: true}); + + document.body.appendChild(iframe); + }); +} diff --git a/testing/web-platform/tests/webstorage/resources/sessionStorage-about-blank-partitioned-iframe.html b/testing/web-platform/tests/webstorage/resources/sessionStorage-about-blank-partitioned-iframe.html new file mode 100644 index 0000000000..dd530a7c22 --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/sessionStorage-about-blank-partitioned-iframe.html @@ -0,0 +1,44 @@ + + + diff --git a/testing/web-platform/tests/webstorage/resources/session_change_item_iframe.html b/testing/web-platform/tests/webstorage/resources/session_change_item_iframe.html new file mode 100644 index 0000000000..1e1867e51e --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/session_change_item_iframe.html @@ -0,0 +1,18 @@ + + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/session_set_item_clear_iframe.html b/testing/web-platform/tests/webstorage/resources/session_set_item_clear_iframe.html new file mode 100644 index 0000000000..7deaa9b17c --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/session_set_item_clear_iframe.html @@ -0,0 +1,17 @@ + + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/session_set_item_iframe.html b/testing/web-platform/tests/webstorage/resources/session_set_item_iframe.html new file mode 100644 index 0000000000..de844cca45 --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/session_set_item_iframe.html @@ -0,0 +1,16 @@ + + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/session_set_item_remove_iframe.html b/testing/web-platform/tests/webstorage/resources/session_set_item_remove_iframe.html new file mode 100644 index 0000000000..60303e70f5 --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/session_set_item_remove_iframe.html @@ -0,0 +1,11 @@ + + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/storage_local_window_open_second.html b/testing/web-platform/tests/webstorage/resources/storage_local_window_open_second.html new file mode 100644 index 0000000000..3c8405adcf --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/storage_local_window_open_second.html @@ -0,0 +1,36 @@ + + + +WebStorage Test: localStorage - second page + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/storage_session_window_noopener_second.html b/testing/web-platform/tests/webstorage/resources/storage_session_window_noopener_second.html new file mode 100644 index 0000000000..7e477375ae --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/storage_session_window_noopener_second.html @@ -0,0 +1,34 @@ + + + +WebStorage Test: sessionStorage - second page + + + + + diff --git a/testing/web-platform/tests/webstorage/resources/storage_session_window_open_second.html b/testing/web-platform/tests/webstorage/resources/storage_session_window_open_second.html new file mode 100644 index 0000000000..2eeff0b865 --- /dev/null +++ b/testing/web-platform/tests/webstorage/resources/storage_session_window_open_second.html @@ -0,0 +1,41 @@ + + + +WebStorage Test: sessionStorage - second page + + + + + diff --git a/testing/web-platform/tests/webstorage/sessionStorage-basic-partitioned.tentative.sub.html b/testing/web-platform/tests/webstorage/sessionStorage-basic-partitioned.tentative.sub.html new file mode 100644 index 0000000000..30575bfaf1 --- /dev/null +++ b/testing/web-platform/tests/webstorage/sessionStorage-basic-partitioned.tentative.sub.html @@ -0,0 +1,73 @@ + + +sessionStorage: partitioned storage test + + + + + + + diff --git a/testing/web-platform/tests/webstorage/set.window.js b/testing/web-platform/tests/webstorage/set.window.js new file mode 100644 index 0000000000..8e671d2ded --- /dev/null +++ b/testing/web-platform/tests/webstorage/set.window.js @@ -0,0 +1,102 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + [9, "x"].forEach(function(key) { + test(function() { + var expected = "value for " + this.name; + var value = expected; + + var storage = window[name]; + storage.clear(); + + assert_equals(storage[key], undefined); + assert_equals(storage.getItem(key), null); + assert_equals(storage[key] = value, value); + assert_equals(storage[key], expected); + assert_equals(storage.getItem(key), expected); + }, "Setting property for key " + key + " on " + name); + + test(function() { + var expected = "value for " + this.name; + var value = { + toString: function() { return expected; } + }; + + var storage = window[name]; + storage.clear(); + + assert_equals(storage[key], undefined); + assert_equals(storage.getItem(key), null); + assert_equals(storage[key] = value, value); + assert_equals(storage[key], expected); + assert_equals(storage.getItem(key), expected); + }, "Setting property with toString for key " + key + " on " + name); + + test(function() { + var proto = "proto for " + this.name; + Storage.prototype[key] = proto; + this.add_cleanup(function() { delete Storage.prototype[key]; }); + + var value = "value for " + this.name; + + var storage = window[name]; + storage.clear(); + + assert_equals(storage[key], proto); + assert_equals(storage.getItem(key), null); + assert_equals(storage[key] = value, value); + // Hidden because no [LegacyOverrideBuiltIns]. + assert_equals(storage[key], proto); + assert_equals(Object.getOwnPropertyDescriptor(storage, key), undefined); + assert_equals(storage.getItem(key), value); + }, "Setting property for key " + key + " on " + name + " with data property on prototype"); + + test(function() { + var proto = "proto for " + this.name; + Storage.prototype[key] = proto; + this.add_cleanup(function() { delete Storage.prototype[key]; }); + + var value = "value for " + this.name; + var existing = "existing for " + this.name; + + var storage = window[name]; + storage.clear(); + + storage.setItem(key, existing); + + // Hidden because no [LegacyOverrideBuiltIns]. + assert_equals(storage[key], proto); + assert_equals(Object.getOwnPropertyDescriptor(storage, key), undefined); + assert_equals(storage.getItem(key), existing); + assert_equals(storage[key] = value, value); + assert_equals(storage[key], proto); + assert_equals(Object.getOwnPropertyDescriptor(storage, key), undefined); + assert_equals(storage.getItem(key), value); + }, "Setting property for key " + key + " on " + name + " with data property on prototype and existing item"); + + test(function() { + var storage = window[name]; + storage.clear(); + + var proto = "proto getter for " + this.name; + Object.defineProperty(Storage.prototype, key, { + "get": function() { return proto; }, + "set": this.unreached_func("Should not call [[Set]] on prototype"), + "configurable": true, + }); + this.add_cleanup(function() { + delete Storage.prototype[key]; + delete storage[key]; + assert_false(key in storage); + }); + + var value = "value for " + this.name; + + assert_equals(storage[key], proto); + assert_equals(storage.getItem(key), null); + assert_equals(storage[key] = value, value); + // Property is hidden because no [LegacyOverrideBuiltIns]. + assert_equals(storage[key], proto); + assert_equals(Object.getOwnPropertyDescriptor(storage, key), undefined); + assert_equals(storage.getItem(key), value); + }, "Setting property for key " + key + " on " + name + " with accessor property on prototype"); + }); +}); diff --git a/testing/web-platform/tests/webstorage/storage_builtins.window.js b/testing/web-platform/tests/webstorage/storage_builtins.window.js new file mode 100644 index 0000000000..72bb90db21 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_builtins.window.js @@ -0,0 +1,16 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + var storage = window[name]; + storage.clear(); + assert_equals(storage.length, 0, "storage.length"); + + var builtins = ["key", "getItem", "setItem", "removeItem", "clear"]; + var origBuiltins = builtins.map(function(b) { return Storage.prototype[b]; }); + assert_array_equals(builtins.map(function(b) { return storage[b]; }), origBuiltins, "a"); + builtins.forEach(function(b) { storage[b] = b; }); + assert_array_equals(builtins.map(function(b) { return storage[b]; }), origBuiltins, "b"); + assert_array_equals(builtins.map(function(b) { return storage.getItem(b); }), builtins, "c"); + + assert_equals(storage.length, builtins.length, "storage.length"); + }, "Builtins in " + name); +}); diff --git a/testing/web-platform/tests/webstorage/storage_clear.window.js b/testing/web-platform/tests/webstorage/storage_clear.window.js new file mode 100644 index 0000000000..6f42bf85f7 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_clear.window.js @@ -0,0 +1,16 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem("name", "user1"); + assert_equals(storage.getItem("name"), "user1"); + assert_equals(storage.name, "user1"); + assert_equals(storage.length, 1); + + storage.clear(); + assert_equals(storage.getItem("name"), null, "storage.getItem('name')"); + assert_equals(storage.name, undefined, "storage.name"); + assert_equals(storage.length, 0, "storage.length"); + }, "Clear in " + name); +}); diff --git a/testing/web-platform/tests/webstorage/storage_enumerate.window.js b/testing/web-platform/tests/webstorage/storage_enumerate.window.js new file mode 100644 index 0000000000..fcc71e1c9e --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_enumerate.window.js @@ -0,0 +1,55 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + assert_true(name in window, name + " exist"); + + var storage = window[name]; + storage.clear(); + + Storage.prototype.prototypeTestKey = "prototypeTestValue"; + storage.foo = "bar"; + storage.fu = "baz"; + storage.batman = "bin suparman"; + storage.bar = "foo"; + storage.alpha = "beta"; + storage.zeta = "gamma"; + + const enumeratedArray = Object.keys(storage); + enumeratedArray.sort(); // Storage order is implementation-defined. + + const expectArray = ["alpha", "bar", "batman", "foo", "fu", "zeta"]; + assert_array_equals(enumeratedArray, expectArray); + + // 'prototypeTestKey' is not an actual storage key, it is just a + // property set on Storage's prototype object. + assert_equals(storage.length, 6); + assert_equals(storage.getItem("prototypeTestKey"), null); + assert_equals(storage.prototypeTestKey, "prototypeTestValue"); + }, name + ": enumerate a Storage object and get only the keys as a result and the built-in properties of the Storage object should be ignored"); + + test(function() { + const storage = window[name]; + storage.clear(); + + storage.setItem("foo", "bar"); + storage.baz = "quux"; + storage.setItem(0, "alpha"); + storage[42] = "beta"; + + for (let prop in storage) { + if (!storage.hasOwnProperty(prop)) + continue; + const desc = Object.getOwnPropertyDescriptor(storage, prop); + assert_true(desc.configurable); + assert_true(desc.enumerable); + assert_true(desc.writable); + } + + const keys = Object.keys(storage); + keys.sort(); // Storage order is implementation-defined. + assert_array_equals(keys, ["0", "42", "baz", "foo"]); + + const values = Object.values(storage); + values.sort(); // Storage order is implementation-defined. + assert_array_equals(values, ["alpha", "bar", "beta", "quux"]); + }, name + ": test enumeration of numeric and non-numeric keys"); +}); diff --git a/testing/web-platform/tests/webstorage/storage_functions_not_overwritten.window.js b/testing/web-platform/tests/webstorage/storage_functions_not_overwritten.window.js new file mode 100644 index 0000000000..693743de90 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_functions_not_overwritten.window.js @@ -0,0 +1,37 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + var storage = window[name]; + storage.clear(); + + runTest(); + function doWedgeThySelf() { + storage.setItem("clear", "almost"); + storage.setItem("key", "too"); + storage.setItem("getItem", "funny"); + storage.setItem("removeItem", "to"); + storage.setItem("length", "be"); + storage.setItem("setItem", "true"); + } + + function runTest() { + doWedgeThySelf(); + + assert_equals(storage.getItem('clear'), "almost"); + assert_equals(storage.getItem('key'), "too"); + assert_equals(storage.getItem('getItem'), "funny"); + assert_equals(storage.getItem('removeItem'), "to"); + assert_equals(storage.getItem('length'), "be"); + assert_equals(storage.getItem('setItem'), "true"); + + // Test to see if an exception is thrown for any of the built in + // functions. + storage.setItem("test", "123"); + storage.key(0); + storage.getItem("test"); + storage.removeItem("test"); + storage.clear(); + assert_equals(storage.length, 0); + } + + }, name + " should be not rendered unusable by setting a key with the same name as a storage function such that the function is hidden"); +}); diff --git a/testing/web-platform/tests/webstorage/storage_getitem.window.js b/testing/web-platform/tests/webstorage/storage_getitem.window.js new file mode 100644 index 0000000000..8a5896836d --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_getitem.window.js @@ -0,0 +1,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 + "."); +}); diff --git a/testing/web-platform/tests/webstorage/storage_in.window.js b/testing/web-platform/tests/webstorage/storage_in.window.js new file mode 100644 index 0000000000..148285a1eb --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_in.window.js @@ -0,0 +1,22 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + var storage = window[name]; + storage.clear(); + + assert_false("name" in storage); + storage["name"] = "user1"; + assert_true("name" in storage); + }, "The in operator in " + name + ": property access"); + + test(function() { + var storage = window[name]; + storage.clear(); + + assert_false("name" in storage); + storage.setItem("name", "user1"); + assert_true("name" in storage); + assert_equals(storage.name, "user1"); + storage.removeItem("name"); + assert_false("name" in storage); + }, "The in operator in " + name + ": method access"); +}); diff --git a/testing/web-platform/tests/webstorage/storage_indexing.window.js b/testing/web-platform/tests/webstorage/storage_indexing.window.js new file mode 100644 index 0000000000..685b6b67fb --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_indexing.window.js @@ -0,0 +1,28 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + var storage = window[name]; + storage.clear(); + storage["name"] = "user1"; + storage["age"] = "42"; + + test(function() { + assert_equals(storage[-1], undefined); + assert_equals(storage[0], undefined); + assert_equals(storage[1], undefined); + assert_equals(storage[2], undefined); + }, "Getting number properties on " + name); + + test(function() { + assert_equals(storage["-1"], undefined); + assert_equals(storage["0"], undefined); + assert_equals(storage["1"], undefined); + assert_equals(storage["2"], undefined); + }, "Getting number-valued string properties on " + name); + + test(function() { + storage.setItem(1, "number"); + assert_equals(storage[1], "number"); + assert_equals(storage["1"], "number"); + }, "Getting existing number-valued properties on " + name); + }, "Indexed getter on " + name); +}); diff --git a/testing/web-platform/tests/webstorage/storage_key.window.js b/testing/web-platform/tests/webstorage/storage_key.window.js new file mode 100644 index 0000000000..723f6563d7 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_key.window.js @@ -0,0 +1,51 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem("name", "user1"); + storage.setItem("age", "20"); + storage.setItem("a", "1"); + storage.setItem("b", "2"); + + var keys = ["name", "age", "a", "b"]; + function doTest(index) { + test(function() { + var key = storage.key(index); + assert_not_equals(key, null); + assert_true(keys.indexOf(key) >= 0, + "Unexpected key " + key + " found."); + }, name + ".key(" + index + ") should return the right thing."); + } + for (var i = 0; i < keys.length; ++i) { + doTest(i); + doTest(i + 0x100000000); + } + + test(function() { + assert_equals(storage.key(-1), null, "storage.key(-1)"); + assert_equals(storage.key(4), null, "storage.key(4)"); + }, name + ".key() should return null for out-of-range arguments."); + }, name + ".key"); + + test(function() { + var get_keys = function(s) { + var keys = []; + for (var i = 0; i < s.length; ++i) { + keys.push(s.key(i)); + } + return keys; + }; + var storage = window[name]; + storage.clear(); + + storage.setItem("name", "user1"); + storage.setItem("age", "20"); + storage.setItem("a", "1"); + storage.setItem("b", "2"); + + var expected_keys = get_keys(storage); + storage.setItem("name", "user2"); + assert_array_equals(get_keys(storage), expected_keys); + }, name + ".key with value changes"); +}); diff --git a/testing/web-platform/tests/webstorage/storage_key_empty_string.window.js b/testing/web-platform/tests/webstorage/storage_key_empty_string.window.js new file mode 100644 index 0000000000..c3d59c42b8 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_key_empty_string.window.js @@ -0,0 +1,10 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function () { + var storage = window[name]; + storage.clear(); + + storage.setItem("", "empty string"); + assert_equals(storage.getItem(""), "empty string"); + + }, name + ".key with empty string"); +}); diff --git a/testing/web-platform/tests/webstorage/storage_length.window.js b/testing/web-platform/tests/webstorage/storage_length.window.js new file mode 100644 index 0000000000..9648e48c8d --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_length.window.js @@ -0,0 +1,23 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + var storage = window[name]; + storage.clear(); + assert_equals(storage.length, 0, "storage.length") + + storage["name"] = "user1"; + storage["age"] = "20"; + + assert_equals(storage.length, 2, "storage.length") + }, name + ".length (method access)"); + + test(function() { + var storage = window[name]; + storage.clear(); + assert_equals(storage.length, 0, "storage.length") + + storage.setItem("name", "user1"); + storage.setItem("age", "20"); + + assert_equals(storage.length, 2, "storage.length") + }, name + ".length (proprty access)"); +}); diff --git a/testing/web-platform/tests/webstorage/storage_local-manual.html b/testing/web-platform/tests/webstorage/storage_local-manual.html new file mode 100644 index 0000000000..d039773b5b --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_local-manual.html @@ -0,0 +1,40 @@ + + +WebStorage Test: local storage + + + +

Description

+

+ This test validates that store data using Local Storage which means that close the page, and re-open it, the data saved before should be loaded again. +

+ +

Preconditions

+
    +
  1. + Click the "Clear" button, refresh the page once and then check if the page shows "You have viewed this page 1 time(s)" +
  2. +
  3. + Close the page, re-open it and then check if the page still shows "You have viewed this page 2 time(s)" +
  4. +
  5. + If the above two steps are all true the test case pass, otherwise it fail +
  6. +
+ +

+

You have viewed this page + an untold number of + time(s).

+ +

+ + diff --git a/testing/web-platform/tests/webstorage/storage_local_setitem_quotaexceedederr.window.js b/testing/web-platform/tests/webstorage/storage_local_setitem_quotaexceedederr.window.js new file mode 100644 index 0000000000..fff7d6444a --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_local_setitem_quotaexceedederr.window.js @@ -0,0 +1,16 @@ +test(function() { + localStorage.clear(); + + var index = 0; + var key = "name"; + var val = "x".repeat(1024); + + assert_throws_dom("QUOTA_EXCEEDED_ERR", function() { + while (true) { + index++; + localStorage.setItem("" + key + index, "" + val + index); + } + }); + + localStorage.clear(); +}, "Throws QuotaExceededError when the quota has been exceeded"); diff --git a/testing/web-platform/tests/webstorage/storage_local_window_open.window.js b/testing/web-platform/tests/webstorage/storage_local_window_open.window.js new file mode 100644 index 0000000000..8c67289400 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_local_window_open.window.js @@ -0,0 +1,16 @@ +async_test(function(t) { + + var storage = window.localStorage; + storage.clear(); + + storage.setItem("FOO", "BAR"); + var win = window.open("resources/storage_local_window_open_second.html"); + window.addEventListener('message', t.step_func(function(e) { + e.data.forEach(t.step_func(function(assertion) { + assert_equals(assertion.actual, assertion.expected, assertion.message); + })); + win.close(); + t.done(); + })); + +}, "A new window to make sure there is a copy of the previous window's localStorage, and that they do not diverge after a change"); diff --git a/testing/web-platform/tests/webstorage/storage_removeitem.window.js b/testing/web-platform/tests/webstorage/storage_removeitem.window.js new file mode 100644 index 0000000000..be3174a89b --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_removeitem.window.js @@ -0,0 +1,44 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem("name", "user1"); + assert_equals(storage.getItem("name"), "user1"); + + storage.removeItem("name"); + storage.removeItem("unknown"); + assert_equals(storage.getItem("name"), null, "storage.getItem('name')") + }, name + ".removeItem()"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem("name", "user1"); + assert_equals(storage.getItem("name"), "user1"); + delete storage["name"]; + delete storage["unknown"]; + assert_equals(storage.getItem("name"), null, "storage.getItem('name')") + }, "delete " + name + "[]"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem("null", "test"); + assert_true("null" in storage); + storage.removeItem(null); + assert_false("null" in storage); + }, name + ".removeItem(null)"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem("undefined", "test"); + assert_true("undefined" in storage); + storage.removeItem(undefined); + assert_false("undefined" in storage); + }, name + ".removeItem(undefined)"); +}); diff --git a/testing/web-platform/tests/webstorage/storage_session-manual.html b/testing/web-platform/tests/webstorage/storage_session-manual.html new file mode 100644 index 0000000000..c2676af14d --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_session-manual.html @@ -0,0 +1,39 @@ + + +WebStorage Test: session storage + + + +

Description

+

+ This test validates that store the data using Session Storage which means that even if you close the page, and re-open it, the data saved before should be lost. +

+ +
    +
  1. + Click the "Clear" button, refresh the page once and then check if the page shows "You have viewed this page 1 time(s)" +
  2. +
  3. + Close the page, re-open it and then check if the page still shows "You have viewed this page 1 time(s)" +
  4. +
  5. + If the above two steps are all true the test case pass, otherwise it fail.
    +
  6. +
+ +

+

You have viewed this page + an untold number of + time(s).

+ +

+ + diff --git a/testing/web-platform/tests/webstorage/storage_session_setitem_quotaexceedederr.window.js b/testing/web-platform/tests/webstorage/storage_session_setitem_quotaexceedederr.window.js new file mode 100644 index 0000000000..42a895470e --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_session_setitem_quotaexceedederr.window.js @@ -0,0 +1,16 @@ +test(function() { + sessionStorage.clear(); + + var index = 0; + var key = "name"; + var val = "x".repeat(1024); + + assert_throws_dom("QUOTA_EXCEEDED_ERR", function() { + while (true) { + index++; + sessionStorage.setItem("" + key + index, "" + val + index); + } + }); + + sessionStorage.clear(); +}, "Throws QuotaExceededError when the quota has been exceeded"); diff --git a/testing/web-platform/tests/webstorage/storage_session_window_noopener.window.js b/testing/web-platform/tests/webstorage/storage_session_window_noopener.window.js new file mode 100644 index 0000000000..fe131059d8 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_session_window_noopener.window.js @@ -0,0 +1,21 @@ +async_test(function(t) { + + var storage = window.sessionStorage; + storage.clear(); + + storage.setItem("FOO", "BAR"); + + let channel = new BroadcastChannel("storage_session_window_noopener"); + channel.addEventListener("message", t.step_func(function(e) { + e.data.forEach(t.step_func(function(assertion) { + assert_equals(assertion.actual, assertion.expected, assertion.message); + })); + assert_equals(storage.getItem("FOO"), "BAR", "value for FOO in original window"); + t.done(); + })); + + var win = window.open("resources/storage_session_window_noopener_second.html", + "_blank", + "noopener"); + +}, "A new noopener window to make sure there is a not copy of the previous window's sessionStorage"); diff --git a/testing/web-platform/tests/webstorage/storage_session_window_open.window.js b/testing/web-platform/tests/webstorage/storage_session_window_open.window.js new file mode 100644 index 0000000000..83d4447017 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_session_window_open.window.js @@ -0,0 +1,17 @@ +async_test(function(t) { + + var storage = window.sessionStorage; + storage.clear(); + + storage.setItem("FOO", "BAR"); + var win = window.open("resources/storage_session_window_open_second.html"); + storage.setItem("BAZ", "QUX"); + window.addEventListener('message', t.step_func(function(e) { + e.data.forEach(t.step_func(function(assertion) { + assert_equals(assertion.actual, assertion.expected, assertion.message); + })); + win.close(); + t.done(); + })); + +}, "A new window to make sure there is a copy of the previous window's sessionStorage, and that they diverge after a change"); diff --git a/testing/web-platform/tests/webstorage/storage_session_window_reopen.window.js b/testing/web-platform/tests/webstorage/storage_session_window_reopen.window.js new file mode 100644 index 0000000000..1ce17d47f1 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_session_window_reopen.window.js @@ -0,0 +1,26 @@ +test(function() { + var popup = window.open("", "sessionStorageTestWindow"); + + sessionStorage.setItem("FOO", "BAR"); + + var reopened = window.open("", "sessionStorageTestWindow"); + + assert_equals( + popup, + reopened, + "window.open with the same name should re-open the same window" + ); + + assert_equals( + sessionStorage.getItem("FOO"), + "BAR", + "local sessionStorage is correct" + ); + assert_equals( + popup.sessionStorage.getItem("FOO"), + null, + "popup sessionStorage is correct" + ); + + popup.close(); +}, "ensure that re-opening a named window doesn't copy sessionStorage"); diff --git a/testing/web-platform/tests/webstorage/storage_set_value_enumerate.window.js b/testing/web-platform/tests/webstorage/storage_set_value_enumerate.window.js new file mode 100644 index 0000000000..09a55ad454 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_set_value_enumerate.window.js @@ -0,0 +1,21 @@ +var store_list = [ + ["key0", "value0"], + ["key1", "value1"], + ["key2", "value2"] +]; +["localStorage", "sessionStorage"].forEach(function(name) { + test(function () { + var storage = window[name]; + storage.clear(); + + store_list.forEach(function(item) { + storage.setItem(item[0], item[1]); + }); + + for (var i = 0; i < store_list.length; i++) { + var value = storage.getItem("key" + i); + assert_equals(value, "value" + i); + } + }, "enumerate a " + name + " object with the key and get the values"); +}); + diff --git a/testing/web-platform/tests/webstorage/storage_setitem.window.js b/testing/web-platform/tests/webstorage/storage_setitem.window.js new file mode 100644 index 0000000000..97817da1d8 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_setitem.window.js @@ -0,0 +1,215 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + var test_error = { name: "test" }; + var interesting_strs = ["\uD7FF", "\uD800", "\uDBFF", "\uDC00", + "\uDFFF", "\uE000", "\uFFFD", "\uFFFE", "\uFFFF", + "\uD83C\uDF4D", "\uD83Ca", "a\uDF4D", + "\uDBFF\uDFFF"]; + + for (var i = 0; i <= 0xFF; i++) { + interesting_strs.push(String.fromCharCode(i)); + } + + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem("name", "user1"); + assert_equals(storage.length, 1, "localStorage.setItem") + }, name + ".setItem()"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage["name"] = "user1"; + assert_true("name" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("name"), "user1"); + assert_equals(storage["name"], "user1"); + }, name + "[]"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage["name"] = "user1"; + storage["name"] = "user2"; + assert_true("name" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("name"), "user2"); + assert_equals(storage["name"], "user2"); + }, name + "[] update"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem("age", null); + assert_true("age" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("age"), "null"); + assert_equals(storage["age"], "null"); + }, name + ".setItem(_, null)"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage["age"] = null; + assert_true("age" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("age"), "null"); + assert_equals(storage["age"], "null"); + }, name + "[] = null"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem("age", undefined); + assert_true("age" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("age"), "undefined"); + assert_equals(storage["age"], "undefined"); + }, name + ".setItem(_, undefined)"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage["age"] = undefined; + assert_true("age" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("age"), "undefined"); + assert_equals(storage["age"], "undefined"); + }, name + "[] = undefined"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem("age", "10"); + assert_throws_exactly(test_error, function() { + storage.setItem("age", + { toString: function() { throw test_error; } }); + }); + assert_true("age" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("age"), "10"); + assert_equals(storage["age"], "10"); + }, name + ".setItem({ throws })"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem("age", "10"); + assert_throws_exactly(test_error, function() { + storage["age"] = + { toString: function() { throw test_error; } }; + }); + assert_true("age" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("age"), "10"); + assert_equals(storage["age"], "10"); + }, name + "[] = { throws }"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem(undefined, "test"); + assert_true("undefined" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("undefined"), "test"); + assert_equals(storage["undefined"], "test"); + }, name + ".setItem(undefined, _)"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage[undefined] = "test2"; + assert_true("undefined" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("undefined"), "test2"); + assert_equals(storage["undefined"], "test2"); + }, name + "[undefined]"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage.setItem(null, "test"); + assert_true("null" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("null"), "test"); + assert_equals(storage["null"], "test"); + }, name + ".setItem(null, _)"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage[null] = "test2"; + assert_true("null" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("null"), "test2"); + assert_equals(storage["null"], "test2"); + }, name + "[null]"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage["foo\0bar"] = "user1"; + assert_true("foo\0bar" in storage); + assert_false("foo\0" in storage); + assert_false("foo\0baz" in storage); + assert_false("foo" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("foo\0bar"), "user1"); + assert_equals(storage.getItem("foo\0"), null); + assert_equals(storage.getItem("foo\0baz"), null); + assert_equals(storage.getItem("foo"), null); + assert_equals(storage["foo\0bar"], "user1"); + assert_equals(storage["foo\0"], undefined); + assert_equals(storage["foo\0baz"], undefined); + assert_equals(storage["foo"], undefined); + }, name + " key containing null"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage["name"] = "foo\0bar"; + assert_true("name" in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("name"), "foo\0bar"); + assert_equals(storage["name"], "foo\0bar"); + }, name + " value containing null"); + + for (i = 0; i < interesting_strs.length; i++) { + var str = interesting_strs[i]; + test(function() { + var storage = window[name]; + storage.clear(); + + storage[str] = "user1"; + assert_true(str in storage); + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem(str), "user1"); + assert_equals(storage[str], "user1"); + }, name + "[" + format_value(str) + "]"); + + test(function() { + var storage = window[name]; + storage.clear(); + + storage["name"] = str; + assert_equals(storage.length, 1, "storage.length") + assert_equals(storage.getItem("name"), str); + assert_equals(storage["name"], str); + }, name + "[] = " + format_value(str)); + } +}); diff --git a/testing/web-platform/tests/webstorage/storage_string_conversion.window.js b/testing/web-platform/tests/webstorage/storage_string_conversion.window.js new file mode 100644 index 0000000000..51b07a3a38 --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_string_conversion.window.js @@ -0,0 +1,32 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + assert_true(name in window, name + " exist"); + + var storage = window[name]; + storage.clear(); + + assert_equals(storage.length, 0); + + storage.a = null; + assert_equals(storage.a, "null"); + storage.b = 0; + assert_equals(storage.b, "0"); + storage.c = function(){}; + assert_equals(storage.c, "function(){}"); + + storage.setItem('d', null); + assert_equals(storage.d, "null"); + storage.setItem('e', 0); + assert_equals(storage.e, "0"); + storage.setItem('f', function(){}); + assert_equals(storage.f, "function(){}"); + + storage['g'] = null; + assert_equals(storage.g, "null"); + storage['h'] = 0; + assert_equals(storage.h, "0"); + storage['i'] = function(){}; + assert_equals(storage.f, "function(){}"); + + }, name + " only stores strings"); +}); diff --git a/testing/web-platform/tests/webstorage/storage_supported_property_names.window.js b/testing/web-platform/tests/webstorage/storage_supported_property_names.window.js new file mode 100644 index 0000000000..08c5d77afc --- /dev/null +++ b/testing/web-platform/tests/webstorage/storage_supported_property_names.window.js @@ -0,0 +1,15 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + var storage = window[name]; + storage.clear(); + + storage["name"] = "user1"; + assert_array_equals(Object.getOwnPropertyNames(storage), ['name']); + }, "Object.getOwnPropertyNames on " + name + " Storage"); + + test(function() { + var storage = window[name]; + storage.clear(); + assert_array_equals(Object.getOwnPropertyNames(storage), []); + }, "Object.getOwnPropertyNames on " + name + " storage with empty collection"); +}); diff --git a/testing/web-platform/tests/webstorage/symbol-props.window.js b/testing/web-platform/tests/webstorage/symbol-props.window.js new file mode 100644 index 0000000000..61dd8f83dc --- /dev/null +++ b/testing/web-platform/tests/webstorage/symbol-props.window.js @@ -0,0 +1,81 @@ +["localStorage", "sessionStorage"].forEach(function(name) { + test(function() { + var key = Symbol(); + + var storage = window[name]; + storage.clear(); + + storage[key] = "test"; + assert_equals(storage[key], "test"); + }, name + ": plain set + get (loose)"); + + test(function() { + "use strict"; + var key = Symbol(); + + var storage = window[name]; + storage.clear(); + + storage[key] = "test"; + assert_equals(storage[key], "test"); + }, name + ": plain set + get (strict)"); + + test(function() { + var key = Symbol(); + + var storage = window[name]; + storage.clear(); + + Object.defineProperty(storage, key, { "value": "test" }); + assert_equals(storage[key], "test"); + }, name + ": defineProperty + get"); + + test(function() { + var key = Symbol(); + + var storage = window[name]; + storage.clear(); + + Object.defineProperty(storage, key, { "value": "test", "configurable": false }); + assert_equals(storage[key], "test"); + var desc = Object.getOwnPropertyDescriptor(storage, key); + assert_true(desc.configurable, "configurable"); + + assert_true(delete storage[key]); + assert_equals(storage[key], undefined); + }, name + ": defineProperty not configurable"); + + test(function() { + var key = Symbol(); + Storage.prototype[key] = "test"; + this.add_cleanup(function() { delete Storage.prototype[key]; }); + + var storage = window[name]; + storage.clear(); + + assert_equals(storage[key], "test"); + var desc = Object.getOwnPropertyDescriptor(storage, key); + assert_equals(desc, undefined); + }, name + ": get with symbol on prototype"); + + test(function() { + var key = Symbol(); + + var storage = window[name]; + storage.clear(); + + storage[key] = "test"; + assert_true(delete storage[key]); + assert_equals(storage[key], undefined); + }, name + ": delete existing property"); + + test(function() { + var key = Symbol(); + + var storage = window[name]; + storage.clear(); + + assert_true(delete storage[key]); + assert_equals(storage[key], undefined); + }, name + ": delete non-existent property"); +}); -- cgit v1.2.3