diff options
author | Rafał Babiarz <5783815+Sauler@users.noreply.github.com> | 2022-05-08 10:20:01 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-05-28 23:54:06 +0100 |
commit | 4fcdbd57e90dad823af9d2eb6bbd648d04678d07 (patch) | |
tree | 6db049574cecd46cb0008ab4c5f21e20dada10a6 /Base/res/html/misc | |
parent | b162b7eec68c1b75ded1923fcd2be968183447e3 (diff) | |
download | serenity-4fcdbd57e90dad823af9d2eb6bbd648d04678d07.zip |
Base: Add test page for Web Storage API
Diffstat (limited to 'Base/res/html/misc')
-rw-r--r-- | Base/res/html/misc/storage.html | 128 | ||||
-rw-r--r-- | Base/res/html/misc/welcome.html | 1 |
2 files changed, 129 insertions, 0 deletions
diff --git a/Base/res/html/misc/storage.html b/Base/res/html/misc/storage.html new file mode 100644 index 0000000000..6c03a004c3 --- /dev/null +++ b/Base/res/html/misc/storage.html @@ -0,0 +1,128 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <title>Storage test</title> +</head> +<body> + <h1>Storage test</h1> + <p> + <h2>Local Storage</h2> + <label>Key: </label><input type="text" size="30" id="localStorageKey" /> + <label>Value: </label><input type="text" size="30" id="localStorageValue" /> + <br> + <br> + <input type="button" id="addLS" value="Add" /> + <input type="button" id="removeLS" value="Remove" /> + <input type="button" id="getLS" value="Get" /> + + <p id="localStorageGetValue"></p> + </p> + + <p> + <h2>Session Storage</h2> + <label>Key: </label><input type="text" size="30" id="sessionStorageKey" /> + <label>Value: </label><input type="text" size="30" id="sessionStorageValue" /> + <br> + <br> + <input type="button" id="addSS" value="Add" /> + <input type="button" id="removeSS" value="Remove" /> + <input type="button" id="getSS" value="Get" /> + + <p id="sessionStorageGetValue"></p> + </p> + + +</body> + +<script> + document.getElementById('addLS').addEventListener('click', function () { + const key = getTextBoxValue("localStorageKey"); + const value = getTextBoxValue("localStorageValue"); + addValue('local', key, value); + }); + + document.getElementById('removeLS').addEventListener('click', function () { + const key = getTextBoxValue("localStorageKey"); + removeValue('local', key); + }); + + document.getElementById('getLS').addEventListener('click', function () { + const key = getTextBoxValue("localStorageKey"); + getValue('local', key, "localStorageGetValue"); + }); + + document.getElementById('addSS').addEventListener('click', function () { + const key = getTextBoxValue("sessionStorageKey"); + const value = getTextBoxValue("sessionStorageValue"); + addValue('session', key, value); + }); + + document.getElementById('removeSS').addEventListener('click', function () { + const key = getTextBoxValue("sessionStorageKey"); + removeValue('session', key); + }); + + document.getElementById('getSS').addEventListener('click', function () { + const key = getTextBoxValue("sessionStorageKey"); + getValue('session', key, "sessionStorageGetValue"); + }); + + function getTextBoxValue(id) { + const textBox = document.getElementById(id); + if (!textBox.value) + return ""; + + return textBox.value; + } + + function addValue(storageType, key, value) { + if (!key) + return; + + if (!value) + return; + + let storage; + if (storageType === 'local') + storage = window.localStorage; + else + storage = window.sessionStorage; + + storage.setItem(key, value) + } + + function removeValue(storageType, key) { + if (!key) + return; + + let storage; + if (storageType === 'local') + storage = window.localStorage; + else + storage = window.sessionStorage; + + storage.removeItem(key) + } + + function getValue(storageType, key, resultID) { + if (!key) { + document.getElementById(resultID).innerHTML = "No value found for '" + key + "'"; + return; + } + + let storage; + if (storageType === 'local') + storage = window.localStorage; + else + storage = window.sessionStorage; + + const value = storage.getItem(key); + if (!value) { + document.getElementById(resultID).innerHTML = "No value found for '" + key + "'"; + return; + } + + document.getElementById(resultID).innerHTML = "Value for key '" + key + "' = " + storage.getItem(key); + } +</script> +</html> diff --git a/Base/res/html/misc/welcome.html b/Base/res/html/misc/welcome.html index c2bc0319e0..65a648f736 100644 --- a/Base/res/html/misc/welcome.html +++ b/Base/res/html/misc/welcome.html @@ -167,6 +167,7 @@ <li><a href="script-preparation-test.html">Test for the early return steps 6-8 of the "prepare a script" algorithm</a></li> <li><a href="async-js.html">Basic test for async functions and their integration with the LibWeb event loop</a></li> <li><a href="worker_parent.html">Workers</a></li> + <li><a href="storage.html">Web Storage API</a></li> <li><h3>Canvas</h3></li> <li><a href="canvas.html">canvas 2D test</a></li> <li><a href="canvas-rotate.html">canvas rotate()</a></li> |