diff options
Diffstat (limited to '')
18 files changed, 422 insertions, 0 deletions
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 @@ +<!DOCTYPE HTML> +<html> +<head> +<script> +function handleStorageEvent(e) { + if (window.sessionStorage === e.storageArea) + e.storageAreaString = "sessionStorage"; + else if (window.localStorage === e.storageArea) + e.storageAreaString = "localStorage"; + window.parent.storageEventList.push(e); +} +</script> +</head> +<body onstorage="handleStorageEvent(event);"> +</body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> +<head> +<script> + +function handleStorageEvent(e) { + window.parent.storageEventList.push(e); +} + +</script> +</head> +<body onstorage="handleStorageEvent(event);"> +</body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> +<head></head> +<body> +<script> + +function handleStorageEvent(e) { + window.parent.storageEventList.push(e); +} + +document.body.setAttribute("onstorage", "handleStorageEvent(event);"); + +</script> +</body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> + <body> + <script> + if (('localStorage' in window) && window.localStorage !== null){ + try { + localStorage.setItem("name", "user1"); + localStorage.setItem("name", "user2"); + } catch (e) { + parent.fail("setItem method is failed."); + } + localStorage.clear(); + } else { + parent.fail("localStorage is not supported."); + } + </script> + </body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> + <body> + <script> + if (('localStorage' in window) && window.localStorage !== null){ + try { + localStorage.setItem("name", "user1"); + } catch (e) { + parent.fail("setItem method is failed."); + } + localStorage.clear(); + } else { + parent.fail("localStorage is not supported."); + } + </script> + </body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> + <body> + <script> + if (('localStorage' in window) && window.localStorage !== null){ + try { + localStorage.setItem("name", "user1"); + } catch (e) { + parent.fail("setItem method is failed."); + } + } else { + parent.fail("localStorage is not supported."); + } + </script> + </body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> + <body> + <script> + parent.step(function() { + localStorage.setItem("name", "user1"); + localStorage.removeItem('name'); + }); + </script> + </body> +</html> 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 @@ +<!doctype html> +<meta charset="utf-8"> +<script> +function getOrCreateID(key) { + if (!localStorage.getItem(key)) { + const newID = +new Date() + "-" + Math.random(); + localStorage.setItem(key, newID); + } + return localStorage.getItem(key); +} + +window.addEventListener("load", () => { + // if we have an opener, we know that we are loaded inside a cross-site + // iframe (because we opened it ourselves). + if (parent.opener) { + const payload = { + message: "cross-site window iframe loaded", + userID: getOrCreateID("userID"), + } + parent.opener.postMessage(payload, parent.opener.origin); + } +}); + +window.addEventListener("message", (e) => { + if (e.data.command == "create ID") { + getOrCreateID(e.data.key); + + // storage is set, call back to window. + const payload = { + message: "ID created", + userID: localStorage.getItem("userID"), + } + + e.source.postMessage(payload, e.source.origin); + } + + if (e.data.command == "clearStorage") { + localStorage.clear(); + } +}); +</script> 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 @@ +<!doctype html> +<meta charset="utf-8"> +<script src="./partitioning-utils.js"></script> +<script> +window.addEventListener("load", () => { + localStorage.clear(); + + const userID = getOrCreateID("userID4"); + const payload = { + message: "window loaded", + userID, + } + + let win = window.opener ? window.opener : window.parent; + win.postMessage(payload, "*"); +}); + +window.addEventListener("message", e => { + let win = window.opener ? parent.window.opener : window.parent; + + if (e.data.command == "open about:blank window") { + window.blankWindow = window.open("about:blank"); + const payload = { + message: "about:blank frame ID", + userID: window.blankWindow?.localStorage["userID4"], + } + + let win = window.opener ? parent.window.opener : window.parent; + win.postMessage(payload, "*"); + } + + if (e.data.command == "close about:blank window") { + window.blankWindow.close(); + win.postMessage({message: "about:blank window closed"}, "*"); + } +}); +</script> 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 @@ +<!doctype html> +<meta charset="utf-8"> +<script> + +function getOrCreateID(key) { + if (!sessionStorage.getItem(key)) { + const newID = new Date() + "-" + Math.random(); + sessionStorage.setItem(key, newID); + } + return sessionStorage.getItem(key); +} + +window.addEventListener("load", () => { + // In this testing set-up, only cross-site iframes will have an opener. + if (parent.opener) { + const payload = { + message: "cross-site window iframe loaded", + userID: getOrCreateID("userID"), + } + // Once the cross-site iframe has loaded, we send a message back to + // the main window with the ID from sessionStorage. + parent.opener.postMessage(payload, parent.opener.origin); + } +}); + +window.addEventListener("message", (e) => { + if (e.data.command == "create ID") { + // e.data.key is equivalent to "userID" + getOrCreateID(e.data.key); + + const payload = { + message: "ID created", + userID: sessionStorage.getItem("userID"), + } + // Return the ID from sessionStorage to the main window. + e.source.postMessage(payload, e.source.origin); + } + + // Additional functionality for clean-up at the end of the test. + if (e.data.command == "clearStorage") { + sessionStorage.clear(); + } +}); +</script> 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 @@ +<!DOCTYPE HTML> +<html> + <body> + <script> + if (('sessionStorage' in window) && window.sessionStorage !== null){ + try { + sessionStorage.setItem("name", "user1"); + sessionStorage.setItem("name", "user2"); + } catch (e) { + parent.fail("setItem method is failed."); + } + sessionStorage.clear(); + } else { + parent.fail("sessionStorage is not supported."); + } + </script> + </body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> + <body> + <script> + if (('sessionStorage' in window) && window.sessionStorage !== null){ + try { + sessionStorage.setItem('name', 'user1'); + } catch (e) { + parent.fail('setItem method is failed.'); + } + sessionStorage.clear(); + } else { + parent.fail('sessionStorage is not supported.'); + } + </script> + </body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> + <body> + <script> + if (('sessionStorage' in window) && window.sessionStorage !== null){ + try { + sessionStorage.setItem('name', 'user1'); + } catch (e) { + parent.fail('setItem method is failed.'); + } + } else { + parent.fail('sessionStorage is not supported.'); + } + </script> + </body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> + <body> + <script> + parent.step(function() { + sessionStorage.setItem("name", "user1"); + sessionStorage.removeItem('name'); + }); + </script> + </body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> +<head> +<title>WebStorage Test: localStorage - second page</title> +</head> +<body> +<script> + +var storage = window.localStorage; + +var assertions = []; + +assertions.push({ + actual: storage.getItem("FOO"), + expected: "BAR", + message: "storage.getItem('FOO')" +}); + +storage.setItem("FOO", "BAR-NEWWINDOW"); + +assertions.push({ + actual: storage.getItem("FOO"), + expected: "BAR-NEWWINDOW", + message: "value for FOO after changing" +}); +assertions.push({ + actual: window.opener.localStorage.getItem("FOO"), + expected: "BAR-NEWWINDOW", + message: "value for FOO in my opening window" +}); + +window.opener.postMessage(assertions, '*'); + +</script> +</body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> +<head> +<title>WebStorage Test: sessionStorage - second page</title> +</head> +<body> +<script> + +var storage = window.sessionStorage; + +var assertions = []; + +assertions.push({ + actual: storage.getItem("FOO"), + expected: null, + message: "storage.getItem('FOO')" +}); + +storage.setItem("FOO", "BAR-NEWWINDOW"); + +assertions.push({ + actual: storage.getItem("FOO"), + expected: "BAR-NEWWINDOW", + message: "value for FOO after changing" +}); + +let channel = new BroadcastChannel('storage_session_window_noopener'); +channel.postMessage(assertions, '*'); + +window.close(); + +</script> +</body> +</html> 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 @@ +<!DOCTYPE HTML> +<html> +<head> +<title>WebStorage Test: sessionStorage - second page</title> +</head> +<body> +<script> + +var storage = window.sessionStorage; + +var assertions = []; + +assertions.push({ + actual: storage.getItem("FOO"), + expected: "BAR", + message: "storage.getItem('FOO')" +}); + +storage.setItem("FOO", "BAR-NEWWINDOW"); + +assertions.push({ + actual: storage.getItem("FOO"), + expected: "BAR-NEWWINDOW", + message: "value for FOO after changing" +}); +assertions.push({ + actual: window.opener.sessionStorage.getItem("FOO"), + expected: "BAR", + message: "value for FOO in my opening window" +}); +assertions.push({ + actual: storage.getItem("BAZ"), + expected: null, + message: "value for BAZ set after window.open(), is not set in new window" +}); + +window.opener.postMessage(assertions, '*'); + +</script> +</body> +</html> |