summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webstorage/resources/localstorage-about-blank-partitioned-iframe.html
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--testing/web-platform/tests/webstorage/resources/localstorage-about-blank-partitioned-iframe.html41
1 files changed, 41 insertions, 0 deletions
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>