Mercurial > browser-couch
changeset 68:c6db5e897d6b
Added test for LocalStorage.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 15 Apr 2009 10:39:23 -0700 |
parents | 5e1e88d1c3f5 |
children | 4a90574aa5a2 |
files | js/browser-couch.js js/tests.js |
diffstat | 2 files changed, 37 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/js/browser-couch.js Wed Apr 15 10:23:37 2009 -0700 +++ b/js/browser-couch.js Wed Apr 15 10:39:23 2009 -0700 @@ -106,7 +106,7 @@ } }; -// == MapReducers == +// == MapReducer Implementations == // // //MapReducer// is a generic interface for any map-reduce // implementation. Any object implementing this interface will need @@ -298,7 +298,7 @@ } }; -// == Storage == +// == Storage Implementations == // // //Storage// is a generic interface for a persistent storage // implementation capable of storing JSON-able objects. @@ -398,6 +398,10 @@ }; } +LocalStorage.isAvailable = (this.location && + this.location.protocol != "file:" && + (this.globalStorage || this.localStorage)); + // == BrowserCouch == // // {{{BrowserCouch}}} is the main object that clients will use. It's
--- a/js/tests.js Wed Apr 15 10:23:37 2009 -0700 +++ b/js/tests.js Wed Apr 15 10:39:23 2009 -0700 @@ -273,5 +273,36 @@ self.done(); }}); }); + }, + testLocalStorage_async: function(self) { + if (LocalStorage.isAvailable) { + ModuleLoader.require( + "JSON", + function() { + var storage = new LocalStorage(JSON); + var name = "BrowserCouch_test_DB"; + + var data = {test: "hi", + foo: [1,2,3]}; + + storage.put( + name, + data, + function() { + storage.get( + name, + function(returnedData) { + if (data == returnedData) + throw new Error("Returned data should not be " + + "the same object as passed-in " + + "data."); + self.assertEqual(JSON.stringify(data), + JSON.stringify(returnedData)); + self.done(); + }); + }); + }); + } else + self.skip(); } };