browser/fuel/test/browser_ApplicationStorage.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/fuel/test/browser_ApplicationStorage.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,30 @@
     1.4 +function test() {
     1.5 +  // test for existence of values
     1.6 +  var hasItem = Application.storage.has("fuel-test-missing");
     1.7 +  is(hasItem, false, "Check 'Application.storage.has' for nonexistent item");
     1.8 +  Application.storage.set("fuel-test", "dummy");
     1.9 +  hasItem = Application.storage.has("fuel-test");
    1.10 +  is(hasItem, true, "Check 'Application.storage.has' for existing item");
    1.11 +
    1.12 +  // test getting nonexistent and existing values
    1.13 +  var itemValue = Application.storage.get("fuel-test-missing", "default");
    1.14 +  is(itemValue, "default", "Check 'Application.storage.get' for nonexistent item");
    1.15 +  itemValue = Application.storage.get("fuel-test", "default");
    1.16 +  is(itemValue, "dummy", "Check 'Application.storage.get' for existing item");
    1.17 +
    1.18 +  // test for overwriting an existing value
    1.19 +  Application.storage.set("fuel-test", "smarty");
    1.20 +  itemValue = Application.storage.get("fuel-test", "default");
    1.21 +  is(itemValue, "smarty", "Check 'Application.storage.get' for overwritten item");
    1.22 +
    1.23 +  // check for change event when setting a value
    1.24 +  waitForExplicitFinish();
    1.25 +  Application.storage.events.addListener("change", onStorageChange);
    1.26 +  Application.storage.set("fuel-test", "change event");
    1.27 +}
    1.28 +
    1.29 +function onStorageChange(evt) {
    1.30 +  is(evt.data, "fuel-test", "Check 'Application.storage.set' fired a change event");
    1.31 +  Application.storage.events.removeListener("change", onStorageChange);
    1.32 +  finish();
    1.33 +}

mercurial