summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/domstorage/script-tests
diff options
context:
space:
mode:
Diffstat (limited to 'LayoutTests/storage/domstorage/script-tests')
-rw-r--r--LayoutTests/storage/domstorage/script-tests/TEMPLATE.html12
-rw-r--r--LayoutTests/storage/domstorage/script-tests/clear.js34
-rw-r--r--LayoutTests/storage/domstorage/script-tests/complex-keys.js152
-rw-r--r--LayoutTests/storage/domstorage/script-tests/complex-values.js79
-rw-r--r--LayoutTests/storage/domstorage/script-tests/quota.js87
-rw-r--r--LayoutTests/storage/domstorage/script-tests/remove-item.js50
6 files changed, 414 insertions, 0 deletions
diff --git a/LayoutTests/storage/domstorage/script-tests/TEMPLATE.html b/LayoutTests/storage/domstorage/script-tests/TEMPLATE.html
new file mode 100644
index 0000000..239a794
--- /dev/null
+++ b/LayoutTests/storage/domstorage/script-tests/TEMPLATE.html
@@ -0,0 +1,12 @@
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+<script src="../../fast/js/resources/js-test-post-function.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="YOUR_JS_FILE_HERE"></script>
+</body>
+</html>
diff --git a/LayoutTests/storage/domstorage/script-tests/clear.js b/LayoutTests/storage/domstorage/script-tests/clear.js
new file mode 100644
index 0000000..bf6e5f3
--- /dev/null
+++ b/LayoutTests/storage/domstorage/script-tests/clear.js
@@ -0,0 +1,34 @@
+description("Test basic dom storage .clear() functionality.");
+
+function test(storageString)
+{
+ storage = eval(storageString);
+ if (!storage) {
+ testFailed(storageString + " DOES NOT exist");
+ return;
+ }
+
+ debug("Testing " + storageString);
+
+ evalAndLog("storage.clear()");
+ shouldBe("storage.length", "0");
+
+ evalAndLog("storage['FOO'] = 'MyFOO'");
+ evalAndLog("storage['BAR'] = 'MyBar'");
+ shouldBe("storage.length", "2");
+ shouldBeEqualToString("storage['FOO']", "MyFOO");
+ shouldBeEqualToString("storage['BAR']", "MyBar");
+
+ evalAndLog("storage.clear()");
+ shouldBe("storage.length", "0");
+ shouldBe("storage['FOO']", "undefined"); // FIXME: Wait...shouldn't this be null?
+ shouldBe("storage['BAR']", "undefined"); // ditto
+}
+
+test("sessionStorage");
+debug("");
+debug("");
+test("localStorage");
+
+window.successfullyParsed = true;
+isSuccessfullyParsed();
diff --git a/LayoutTests/storage/domstorage/script-tests/complex-keys.js b/LayoutTests/storage/domstorage/script-tests/complex-keys.js
new file mode 100644
index 0000000..2b6919f
--- /dev/null
+++ b/LayoutTests/storage/domstorage/script-tests/complex-keys.js
@@ -0,0 +1,152 @@
+description("Test dom storage with many different types of keys (as opposed to values)");
+
+function test(storageString)
+{
+ storage = eval(storageString);
+ if (!storage) {
+ testFailed(storageString + " DOES NOT exist");
+ return;
+ }
+
+ debug("Testing " + storageString);
+
+ evalAndLog("storage.clear()");
+ shouldBe("storage.length", "0");
+
+ debug("");
+ shouldBeNull("storage.getItem('FOO')");
+ evalAndLog("storage.setItem('FOO', 'BAR')");
+ shouldBe("storage.length", "1");
+
+ shouldBeEqualToString("storage.getItem('FOO')", "BAR");
+ shouldBeNull("storage.getItem('foo')");
+ shouldBeUndefined("storage.foo");
+ shouldBeUndefined("storage['foo']");
+
+ evalAndLog("storage.foo = 'x'");
+ shouldBeEqualToString("storage.foo", "x");
+ shouldBeEqualToString("storage['foo']", "x");
+ shouldBeEqualToString("storage.getItem('foo')", "x");
+ evalAndLog("storage['foo'] = 'y'");
+ shouldBeEqualToString("storage.foo", "y");
+ shouldBeEqualToString("storage['foo']", "y");
+ shouldBeEqualToString("storage.getItem('foo')", "y");
+ evalAndLog("storage.setItem('foo', 'z')");
+ shouldBeEqualToString("storage.foo", "z");
+ shouldBeEqualToString("storage['foo']", "z");
+ shouldBeEqualToString("storage.getItem('foo')", "z");
+ shouldBe("storage.length", "2");
+
+ debug("");
+ debug("Testing a null key");
+ evalAndLog("storage.setItem(null, 'asdf')");
+ shouldBeEqualToString("storage.getItem('null')", "asdf");
+ shouldBeEqualToString("storage.getItem(null)", "asdf");
+ shouldBeEqualToString("storage['null']", "asdf");
+ shouldBeEqualToString("storage[null]", "asdf");
+ shouldBe("storage.length", "3");
+
+ evalAndLog("storage[null] = 1");
+ shouldBeEqualToString("storage.getItem(null)", "1");
+ evalAndLog("storage['null'] = 2");
+ shouldBeEqualToString("storage.getItem(null)", "2");
+ evalAndLog("storage.setItem('null', 3)");
+ shouldBeEqualToString("storage.getItem(null)", "3");
+ shouldBe("storage.length", "3");
+
+ debug("");
+ debug("Testing an undefined key");
+ evalAndLog("storage[undefined] = 'xyz'");
+ shouldBeEqualToString("storage.getItem('undefined')", "xyz");
+ shouldBeEqualToString("storage.getItem(undefined)", "xyz");
+ shouldBeEqualToString("storage['undefined']", "xyz");
+ shouldBeEqualToString("storage[undefined]", "xyz");
+ shouldBe("storage.length", "4");
+
+ evalAndLog("storage['undefined'] = 4");
+ shouldBeEqualToString("storage.getItem(undefined)", "4");
+ evalAndLog("storage.setItem(undefined, 5)");
+ shouldBeEqualToString("storage.getItem(undefined)", "5");
+ evalAndLog("storage.setItem('undefined', 6)");
+ shouldBeEqualToString("storage.getItem(undefined)", "6");
+ shouldBe("storage.length", "4");
+
+ debug("");
+ debug("Testing a numeric key");
+ evalAndLog("storage['2'] = 'ppp'");
+ shouldBeEqualToString("storage.getItem('2')", "ppp");
+ shouldBeEqualToString("storage.getItem(2)", "ppp");
+ shouldBeEqualToString("storage['2']", "ppp");
+ shouldBeEqualToString("storage[2]", "ppp");
+ shouldBe("storage.length", "5");
+
+ evalAndLog("storage[2] = 7");
+ shouldBeEqualToString("storage.getItem(2)", "7");
+ evalAndLog("storage.setItem(2, 8)");
+ shouldBeEqualToString("storage.getItem(2)", "8");
+ evalAndLog("storage.setItem('2', 9)");
+ shouldBeEqualToString("storage.getItem(2)", "9");
+ shouldBe("storage.length", "5");
+
+ debug("");
+ debug("Setting a non-ascii string to foo");
+ k = String.fromCharCode(255425) + String.fromCharCode(255) + String.fromCharCode(2554252321) + String.fromCharCode(0) + 'hello';
+ evalAndLog("storage[k] = 'hello'");
+ shouldBeEqualToString("storage.getItem(k)", "hello");
+ shouldBeEqualToString("storage[k]", "hello");
+ shouldBe("storage.length", "6");
+
+ debug("");
+ debug("Testing case differences");
+ evalAndLog("storage.foo1 = 'lower1'");
+ evalAndLog("storage.FOO1 = 'UPPER1'");
+ evalAndLog("storage['foo2'] = 'lower2'");
+ evalAndLog("storage['FOO2'] = 'UPPER2'");
+ evalAndLog("storage.setItem('foo3', 'lower3')");
+ evalAndLog("storage.setItem('FOO3', 'UPPER3')");
+ shouldBeEqualToString("storage.foo1", "lower1");
+ shouldBeEqualToString("storage.FOO1", "UPPER1");
+ shouldBeEqualToString("storage['foo2']", "lower2");
+ shouldBeEqualToString("storage['FOO2']", "UPPER2");
+ shouldBeEqualToString("storage.getItem('foo3')", "lower3");
+ shouldBeEqualToString("storage.getItem('FOO3')", "UPPER3");
+ shouldBe("storage.length", "12");
+
+
+ debug("");
+ debug("Testing overriding length");
+ shouldBe("storage.length", "12");
+ shouldBe("storage['length']", "12");
+ shouldBeNull("storage.getItem('length')");
+
+ evalAndLog("storage.length = 0");
+ shouldBe("storage.length", "12");
+ shouldBe("storage['length']", "12");
+ shouldBeNull("storage.getItem('length')");
+
+ evalAndLog("storage['length'] = 0");
+ shouldBe("storage.length", "12");
+ shouldBe("storage['length']", "12");
+ shouldBeNull("storage.getItem('length')");
+
+ evalAndLog("storage.setItem('length', 0)");
+ shouldBe("storage.length", "13");
+ shouldBe("storage['length']", "13");
+ shouldBeEqualToString("storage.getItem('length')", "0");
+
+ evalAndLog("storage.removeItem('length')");
+ shouldBe("storage.length", "12");
+ shouldBe("storage['length']", "12");
+ shouldBeNull("storage.getItem('length')");
+
+ evalAndLog("storage.setItem('length', 0)");
+ shouldBe("storage.length", "13");
+}
+
+test("sessionStorage");
+debug("");
+debug("");
+test("localStorage");
+
+window.successfullyParsed = true;
+isSuccessfullyParsed();
diff --git a/LayoutTests/storage/domstorage/script-tests/complex-values.js b/LayoutTests/storage/domstorage/script-tests/complex-values.js
new file mode 100644
index 0000000..8c6e29d
--- /dev/null
+++ b/LayoutTests/storage/domstorage/script-tests/complex-values.js
@@ -0,0 +1,79 @@
+description("Test some corner case DOM Storage values.");
+
+function testKeyValue(key, value)
+{
+ keyString = "storage['" + key + "']";
+ shouldBeEqualToString("typeof " + keyString, "string");
+ shouldBeEqualToString(keyString, value);
+
+ keyString = "storage." + key;
+ shouldBeEqualToString("typeof " + keyString, "string");
+ shouldBeEqualToString(keyString, value);
+
+ keyString = "storage.getItem('" + key + "')";
+ shouldBeEqualToString("typeof " + keyString, "string");
+ shouldBeEqualToString(keyString, value);
+}
+
+function test(storageString)
+{
+ storage = eval(storageString);
+ if (!storage) {
+ testFailed(storageString + " DOES NOT exist");
+ return;
+ }
+
+ debug("Testing " + storageString);
+
+ evalAndLog("storage.clear()");
+ shouldBe("storage.length", "0");
+
+ debug("");
+ shouldBeEqualToString("typeof storage['foo']", "undefined");
+ shouldBeUndefined("storage['foo']");
+ shouldBeEqualToString("typeof storage.foo", "undefined");
+ shouldBeUndefined("storage.foo");
+ shouldBeEqualToString("typeof storage.getItem('foo')", "object");
+ shouldBeNull("storage.getItem('foo')");
+
+ debug("");
+ evalAndLog("storage.foo1 = null");
+ testKeyValue("foo1", "null");
+ evalAndLog("storage['foo2'] = null");
+ testKeyValue("foo2", "null");
+ evalAndLog("storage.setItem('foo3', null)");
+ testKeyValue("foo3", "null");
+
+ debug("");
+ evalAndLog("storage.foo4 = undefined");
+ testKeyValue("foo4", "undefined");
+ evalAndLog("storage['foo5'] = undefined");
+ testKeyValue("foo5", "undefined");
+ evalAndLog("storage.setItem('foo6', undefined)");
+ testKeyValue("foo6", "undefined");
+
+ debug("");
+ evalAndLog("storage.foo7 = 2");
+ testKeyValue("foo7", "2");
+ evalAndLog("storage['foo8'] = 2");
+ testKeyValue("foo8", "2");
+ evalAndLog("storage.setItem('foo9', 2)");
+ testKeyValue("foo9", "2");
+
+ debug("");
+ k = String.fromCharCode(255425) + String.fromCharCode(255) + String.fromCharCode(2554252321) + String.fromCharCode(0) + 'hello';
+ evalAndLog("storage.foo10 = k");
+ testKeyValue("foo10", k);
+ evalAndLog("storage['foo11'] = k");
+ testKeyValue("foo11", k);
+ evalAndLog("storage.setItem('foo12', k)");
+ testKeyValue("foo12", k);
+}
+
+test("sessionStorage");
+debug("");
+debug("");
+test("localStorage");
+
+window.successfullyParsed = true;
+isSuccessfullyParsed();
diff --git a/LayoutTests/storage/domstorage/script-tests/quota.js b/LayoutTests/storage/domstorage/script-tests/quota.js
new file mode 100644
index 0000000..ad9afe9
--- /dev/null
+++ b/LayoutTests/storage/domstorage/script-tests/quota.js
@@ -0,0 +1,87 @@
+description("Test the DOM Storage quota code.");
+
+function testQuota(storageString)
+{
+ storage = eval(storageString);
+ if (!storage) {
+ testFailed(storageString + " DOES NOT exist");
+ return;
+ }
+
+ debug("Testing " + storageString);
+
+ evalAndLog("storage.clear()");
+ shouldBe("storage.length", "0");
+
+ debug("Creating 'data' which contains 64K of data");
+ data = "X";
+ for (var i=0; i<16; i++)
+ data += data;
+ shouldBe("data.length", "65536");
+
+ debug("Putting 'data' into 39 " + storageString + " buckets.");
+ for (var i=0; i<39; i++)
+ storage[i] = data;
+
+ debug("Putting 'data' into another bucket.h");
+ try {
+ storage[39] = data;
+ testFailed("Did not hit quota error.");
+ } catch (e) {
+ testPassed("Hit exception as expected");
+ }
+
+ debug("Verify that data was never inserted.");
+ shouldBeNull("storage.getItem(39)");
+
+ debug("Removing bucket 38.");
+ storage.removeItem('38');
+
+ debug("Adding 'Hello!' into a new bucket.");
+ try {
+ storage['foo'] = "Hello!";
+ testPassed("Insertion worked.");
+ } catch (e) {
+ testFailed("Exception: " + e);
+ }
+}
+
+function testNoQuota(storageString)
+{
+ storage = eval(storageString);
+ if (!storage) {
+ testFailed(storageString + " DOES NOT exist");
+ return;
+ }
+
+ debug("Testing " + storageString);
+
+ evalAndLog("storage.clear()");
+ shouldBe("storage.length", "0");
+
+ debug("Creating 'data' which contains 64K of data");
+ data = "X";
+ for (var i=0; i<16; i++)
+ data += data;
+ shouldBe("data.length", "65536");
+
+ debug("Putting 'data' into 40 " + storageString + " buckets.");
+ for (var i=0; i<40; i++)
+ storage[i] = data;
+
+ debug("Putting 'data' into another bucket.h");
+ try {
+ storage[40] = data;
+ testPassed("Insertion worked.");
+ } catch (e) {
+ testFailed("Exception: " + e);
+ }
+}
+
+testNoQuota("sessionStorage");
+debug("");
+debug("");
+testQuota("localStorage");
+
+window.successfullyParsed = true;
+isSuccessfullyParsed();
diff --git a/LayoutTests/storage/domstorage/script-tests/remove-item.js b/LayoutTests/storage/domstorage/script-tests/remove-item.js
new file mode 100644
index 0000000..62731f1
--- /dev/null
+++ b/LayoutTests/storage/domstorage/script-tests/remove-item.js
@@ -0,0 +1,50 @@
+description("Test .removeItem within DOM Storage.");
+
+function test(storageString)
+{
+ storage = eval(storageString);
+ if (!storage) {
+ testFailed(storageString + " DOES NOT exist");
+ return;
+ }
+
+ debug("Testing " + storageString);
+
+ evalAndLog("storage.clear()");
+ shouldBe("storage.length", "0");
+
+ debug("");
+ shouldBeUndefined("storage.foo1");
+ evalAndLog("storage.foo1 = 'bar'");
+ shouldBeEqualToString("storage.foo1", "bar");
+ evalAndLog("storage.removeItem('foo1')");
+ shouldBeUndefined("storage.foo1");
+ evalAndLog("storage.removeItem('foo1')");
+ shouldBeUndefined("storage.foo1");
+
+ debug("");
+ shouldBeUndefined("storage['foo2']");
+ evalAndLog("storage['foo2'] = 'bar'");
+ shouldBeEqualToString("storage['foo2']", "bar");
+ evalAndLog("storage.removeItem('foo2')");
+ shouldBeUndefined("storage['foo2']");
+ evalAndLog("storage.removeItem('foo2')");
+ shouldBeUndefined("storage['foo2']");
+
+ debug("");
+ shouldBeNull("storage.getItem('foo3')");
+ evalAndLog("storage.setItem('foo3', 'bar')");
+ shouldBeEqualToString("storage.getItem('foo3')", "bar");
+ evalAndLog("storage.removeItem('foo3')");
+ shouldBeNull("storage.getItem('foo3')");
+ evalAndLog("storage.removeItem('foo3')");
+ shouldBeNull("storage.getItem('foo3')");
+}
+
+test("sessionStorage");
+debug("");
+debug("");
+test("localStorage");
+
+window.successfullyParsed = true;
+isSuccessfullyParsed();