diff --git a/lib/edit/editsStore.js b/lib/edit/editsStore.js index 396b1fa..e571862 100644 --- a/lib/edit/editsStore.js +++ b/lib/edit/editsStore.js @@ -1,6 +1,6 @@ "use strict" -define(["esri/graphic"],function(Graphic) +define(["esri/graphic"], function(Graphic) { /* private consts */ var EDITS_QUEUE_KEY = "esriEditsQueue"; @@ -19,6 +19,19 @@ define(["esri/graphic"],function(Graphic) UPDATE: "update", DELETE:"delete", + isSupported: function() + { + // http://stackoverflow.com/questions/11214404/how-to-detect-if-browser-supports-html5-local-storage + var mod = 'esriLocalStorageTest'; + try { + window.localStorage.setItem(mod, mod); + window.localStorage.removeItem(mod); + return true; + } catch(e) { + return false; + } + }, + pushEdit: function(operation,layer,graphic) { var edit = { @@ -126,6 +139,24 @@ define(["esri/graphic"],function(Graphic) return editToRedo; }, + getEditsStoreSizeBytes: function() + { + return window.localStorage.getItem(EDITS_QUEUE_KEY).length + + window.localStorage.getItem(REDO_STACK_KEY).length; + + }, + + getLocalStorageSizeBytes: function() + { + var bytes = 0; + for( var key in window.localStorage ) + { + var value = window.localStorage.getItem(key); + bytes += value.length; + } + return bytes; + }, + // // internal methods // diff --git a/test/spec/editsStoreSpec.js b/test/spec/editsStoreSpec.js index c851483..2ed046a 100644 --- a/test/spec/editsStoreSpec.js +++ b/test/spec/editsStoreSpec.js @@ -190,6 +190,14 @@ describe("Internal Methods", function() describe("Public Interface", function() { + describe("Support detection", function() + { + it("detect local storage support", function() + { + expect(g_editsStore.isSupported()).toBeTruthy(); + }) + }); + describe("Edit queue management", function() { describe("Normal edits", function() @@ -420,6 +428,23 @@ describe("Public Interface", function() }); }); }); + + describe("Local Storage size", function() + { + var usedBytes, totalBytes; + + it("report edit store size", function() + { + usedBytes = g_editsStore.getEditsStoreSizeBytes(); + expect(usedBytes).toBe(678); + }); + + it("report total local storage size", function() + { + totalBytes = g_editsStore.getLocalStorageSizeBytes(); + expect(usedBytes).not.toBeGreaterThan(totalBytes); + }) + }) }); describe("Reset store", function()