Html程序  |  52行  |  1.68 KB

<html>
<head>
<script src="resources/clearLocalStorage.js"></script>
<script>

if (window.layoutTestController)
    layoutTestController.dumpAsText();

function log(a)
{
    document.getElementById('logger').appendChild(document.createTextNode(a));
    document.getElementById('logger').appendChild(document.createElement("br"));
}

function runTest()
{
    if (!window.localStorage) {
        log("window.localStorage DOES NOT exist");
        return;
    }
    
    log("foo (before anything) is: " + localStorage.foo);
    localStorage.foo = "bar";
    log("foo (after a named property settter set) is: " + localStorage.foo);
    delete localStorage.foo;
    log("foo (after a delete) is: " + localStorage.foo);
    localStorage["foo"] = "bar";
    log("foo (after an indexed setter set) is: " + localStorage.foo);
    delete localStorage.FOO;
    log("foo (after deleting FOO (not foo)) is: " + localStorage.foo);
    delete localStorage.foo;
    log("foo (after a delete) is: " + localStorage.foo);
    localStorage.setItem("foo", "bar");
    log("foo (after calling setItem) is: " + localStorage.foo);
    delete localStorage.foo;
    log("foo (after a delete) is: " + localStorage.foo);
    delete localStorage.foo;
    log("foo (after a redundant delete) is: " + localStorage.foo);
    localStorage.foo = "bar";
    log("foo (after an implicit settter set) is: " + localStorage.foo);
    delete localStorage["foo"];
    log("foo (after an indexed delete) is: " + localStorage.foo);
}

</script>
</head>
<body onload="runTest();">
This test makes sure that using the syntax `delete localStorage.keyName` works as an alias to `localStorage.removeItem(keyName).`<br><hr>
<div id="logger"></div>
</body>
</html>