mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
Base: Add test page for Web Storage API
This commit is contained in:
parent
b162b7eec6
commit
4fcdbd57e9
Notes:
sideshowbarker
2024-07-17 18:06:52 +09:00
Author: https://github.com/Sauler Commit: https://github.com/SerenityOS/serenity/commit/4fcdbd57e9 Pull-request: https://github.com/SerenityOS/serenity/pull/13963 Reviewed-by: https://github.com/linusg
2 changed files with 129 additions and 0 deletions
128
Base/res/html/misc/storage.html
Normal file
128
Base/res/html/misc/storage.html
Normal file
|
@ -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>
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Reference in a new issue