|
1 function test() { |
|
2 // test for existence of values |
|
3 var hasItem = Application.storage.has("fuel-test-missing"); |
|
4 is(hasItem, false, "Check 'Application.storage.has' for nonexistent item"); |
|
5 Application.storage.set("fuel-test", "dummy"); |
|
6 hasItem = Application.storage.has("fuel-test"); |
|
7 is(hasItem, true, "Check 'Application.storage.has' for existing item"); |
|
8 |
|
9 // test getting nonexistent and existing values |
|
10 var itemValue = Application.storage.get("fuel-test-missing", "default"); |
|
11 is(itemValue, "default", "Check 'Application.storage.get' for nonexistent item"); |
|
12 itemValue = Application.storage.get("fuel-test", "default"); |
|
13 is(itemValue, "dummy", "Check 'Application.storage.get' for existing item"); |
|
14 |
|
15 // test for overwriting an existing value |
|
16 Application.storage.set("fuel-test", "smarty"); |
|
17 itemValue = Application.storage.get("fuel-test", "default"); |
|
18 is(itemValue, "smarty", "Check 'Application.storage.get' for overwritten item"); |
|
19 |
|
20 // check for change event when setting a value |
|
21 waitForExplicitFinish(); |
|
22 Application.storage.events.addListener("change", onStorageChange); |
|
23 Application.storage.set("fuel-test", "change event"); |
|
24 } |
|
25 |
|
26 function onStorageChange(evt) { |
|
27 is(evt.data, "fuel-test", "Check 'Application.storage.set' fired a change event"); |
|
28 Application.storage.events.removeListener("change", onStorageChange); |
|
29 finish(); |
|
30 } |