# HG changeset patch # User Atul Varma # Date 1239817163 25200 # Node ID c6db5e897d6bdb9f366969acb9c63289d3e7293f # Parent 5e1e88d1c3f57de997877e0ed926b3e628279406 Added test for LocalStorage. diff -r 5e1e88d1c3f5 -r c6db5e897d6b js/browser-couch.js --- 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 diff -r 5e1e88d1c3f5 -r c6db5e897d6b js/tests.js --- 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(); } };