Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: content/test/data/dom_storage/sanity_check.js

Issue 9956117: DomStorageBrowserTest sanity check (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 test() {
6 try {
7 debug('Checking window.localStorage');
8 sanityCheck(window.localStorage);
9 debug('Checking window.sessionStorage');
10 sanityCheck(window.sessionStorage);
11 done();
12 } catch(e) {
13 fail(e);
14 }
15 }
16
17 function sanityCheck(storage) {
18 storage.clear();
19
20 checkEqual(0, storage.length,
21 "storage.length != 0 at start");
22 checkEqual(undefined, storage.getItem("foo"),
23 "getItem('foo') != undefined prior to addition");
24
25 storage.setItem("foo", "bar");
26
27 checkEqual(1, storage.length,
28 "storage.length != 1 after addition");
29 checkEqual("bar", storage.getItem("foo"),
30 "getItem('foo') != 'bar' after addition");
31
32 storage.removeItem("foo");
33
34 checkEqual(undefined, storage.getItem("foo"),
35 "getItem('foo') != undefined after removal");
36
37 storage["foo"] = "baz";
38 storage["name"] = "value";
michaeln 2012/04/03 21:12:37 i should also add some calls to the storage.key(in
39
40 checkEqual("baz", storage["foo"],
41 "storage['foo'] != 'baz' after addition");
42 checkEqual("value", storage["name"],
43 "storage['name'] != 'value' after addition");
44 checkEqual(2, storage.length,
45 "storage.length != 2 after 2 additions");
46
47 storage.clear();
48
49 checkEqual(0, storage.length,
50 "storage.length != 0 after clear");
51
52 try {
53 storage.setItem("tooLarge", makeLargeString((5 * 1024 * 1024) + 1));
54 throw "failed to throw execption for very large value";
55 } catch(ex) {
56 checkEqual(ex.code, 22,
57 "ex.code != 22 for attempt to store a very large value");
58 }
59 }
60
61 function checkEqual(lsh, rhs, errorMessage) {
62 if (lsh != rhs)
63 throw errorMessage;
64 }
65
66 function makeLargeString(minimumSize) {
67 var x = "a large string of gibberish_";
68 while (x.length < minimumSize)
69 x = x.concat(x);
70 return x;
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698