Chromium Code Reviews| Index: content/test/data/dom_storage/sanity_check.js |
| =================================================================== |
| --- content/test/data/dom_storage/sanity_check.js (revision 0) |
| +++ content/test/data/dom_storage/sanity_check.js (revision 0) |
| @@ -0,0 +1,79 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +function startTestSoon() { |
| + window.setTimeout(test, 0); |
| +} |
| + |
| +function test() { |
| + try { |
| + debug('Checking window.localStorage'); |
| + sanityCheck(window.localStorage); |
| + debug('Checking window.sessionStorage'); |
| + sanityCheck(window.sessionStorage); |
| + done(); |
| + } catch(e) { |
| + fail(e); |
| + } |
| +} |
| + |
| +function sanityCheck(storage) { |
| + storage.clear(); |
| + |
| + checkEqual(0, storage.length, |
| + "storage.length != 0 at start"); |
| + checkEqual(undefined, storage.getItem("foo"), |
| + "getItem('foo') != undefined prior to addition"); |
| + checkEqual(undefined, storage.key(0), |
| + "key(0) != undefined prior to addition"); |
| + |
| + storage.setItem("foo", "bar"); |
| + |
| + checkEqual(1, storage.length, |
| + "storage.length != 1 after addition"); |
| + checkEqual("bar", storage.getItem("foo"), |
| + "getItem('foo') != 'bar' after addition"); |
| + checkEqual("foo", storage.key(0), |
| + "key(0) != 'foo' after addition"); |
| + |
| + storage.removeItem("foo"); |
| + |
| + checkEqual(undefined, storage.getItem("foo"), |
| + "getItem('foo') != undefined after removal"); |
| + |
| + storage["foo"] = "baz"; |
| + storage["name"] = "value"; |
| + |
| + checkEqual(2, storage.length, |
| + "storage.length != 2 after 2 additions"); |
| + checkEqual("baz", storage["foo"], |
| + "storage['foo'] != 'baz' after addition"); |
| + checkEqual("value", storage["name"], |
| + "storage['name'] != 'value' after addition"); |
| + |
| + storage.clear(); |
| + |
| + checkEqual(0, storage.length, |
| + "storage.length != 0 after clear"); |
| + |
| + try { |
| + storage.setItem("tooLarge", makeLargeString((5 * 1024 * 1024) + 1)); |
| + throw "failed to throw execption for very large value"; |
| + } catch(ex) { |
| + checkEqual(ex.code, 22, |
| + "ex.code != 22 for attempt to store a very large value"); |
| + } |
| +} |
| + |
| +function checkEqual(lhs, rhs, errorMessage) { |
| + if (lhs != rhs) |
|
jsbell
2012/04/04 18:37:56
Nit: I'd prefer the stricter !== comparison, which
michaeln
2012/04/04 19:03:21
Right, some of my checkEquals should be testing ag
|
| + throw errorMessage; |
| +} |
| + |
| +function makeLargeString(minimumSize) { |
| + var x = "a large string of gibberish_"; |
| + while (x.length < minimumSize) |
|
jsbell
2012/04/04 18:37:56
Per dgrogan's advice to me, watch out for this sty
michaeln
2012/04/04 19:03:21
At the sizes i'm working with, i haven't noticed t
|
| + x = x.concat(x); |
| + return x; |
| +} |
| Property changes on: content\test\data\dom_storage\sanity_check.js |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |