| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 function startTestSoon() { |
| 6 window.setTimeout(test, 0); |
| 7 } |
| 8 |
| 9 function test() { |
| 10 try { |
| 11 debug('Checking window.localStorage'); |
| 12 sanityCheck(window.localStorage); |
| 13 debug('Checking window.sessionStorage'); |
| 14 sanityCheck(window.sessionStorage); |
| 15 done(); |
| 16 } catch(e) { |
| 17 fail(e); |
| 18 } |
| 19 } |
| 20 |
| 21 function sanityCheck(storage) { |
| 22 storage.clear(); |
| 23 |
| 24 checkEqual(0, storage.length, |
| 25 "storage.length != 0 at start"); |
| 26 checkEqual(null, storage.getItem("foo"), |
| 27 "getItem('foo') != null prior to addition"); |
| 28 checkEqual(null, storage.key(0), |
| 29 "key(0) != null prior to addition"); |
| 30 |
| 31 storage.setItem("foo", "bar"); |
| 32 |
| 33 checkEqual(1, storage.length, |
| 34 "storage.length != 1 after addition"); |
| 35 checkEqual("bar", storage.getItem("foo"), |
| 36 "getItem('foo') != 'bar' after addition"); |
| 37 checkEqual("foo", storage.key(0), |
| 38 "key(0) != 'foo' after addition"); |
| 39 |
| 40 storage.removeItem("foo"); |
| 41 |
| 42 checkEqual(null, storage.getItem("foo"), |
| 43 "getItem('foo') != null after removal"); |
| 44 |
| 45 storage["foo"] = "baz"; |
| 46 storage["name"] = "value"; |
| 47 |
| 48 checkEqual(2, storage.length, |
| 49 "storage.length != 2 after 2 additions"); |
| 50 checkEqual("baz", storage["foo"], |
| 51 "storage['foo'] != 'baz' after addition"); |
| 52 checkEqual("value", storage["name"], |
| 53 "storage['name'] != 'value' after addition"); |
| 54 |
| 55 storage.clear(); |
| 56 |
| 57 checkEqual(0, storage.length, |
| 58 "storage.length != 0 after clear"); |
| 59 |
| 60 try { |
| 61 storage.setItem("tooLarge", makeLargeString((5 * 1024 * 1024) + 1)); |
| 62 throw "failed to throw execption for very large value"; |
| 63 } catch(ex) { |
| 64 checkEqual(ex.code, 22, |
| 65 "ex.code != 22 for attempt to store a very large value"); |
| 66 } |
| 67 } |
| 68 |
| 69 function checkEqual(lhs, rhs, errorMessage) { |
| 70 if (lhs !== rhs) |
| 71 throw errorMessage; |
| 72 } |
| 73 |
| 74 function makeLargeString(minimumSize) { |
| 75 return Array(minimumSize).join("X"); |
| 76 } |
| OLD | NEW |