Bumping manifests a=b2g-bump
[gecko.git] / dom / datastore / tests / file_basic_common.js
blobf73c3bee84239e6803b93e9616a6d8c62146bf58
1 var gStore;
3 function testGetDataStores() {
4   navigator.getDataStores('foo').then(function(stores) {
5     is(stores.length, 1, "getDataStores('foo') returns 1 element");
6     is(stores[0].name, 'foo', 'The dataStore.name is foo');
7     is(stores[0].readOnly, false, 'The dataStore foo is not in readonly');
9     var store = stores[0];
10     ok("get" in store, "store.get exists");
11     ok("put" in store, "store.put exists");
12     ok("add" in store, "store.add exists");
13     ok("remove" in store, "store.remove exists");
14     ok("clear" in store, "store.clear exists");
15     ok("revisionId" in store, "store.revisionId exists");
16     ok("getLength" in store, "store.getLength exists");
17     ok("sync" in store, "store.sync exists");
19     gStore = stores[0];
21     runTest();
22   }, cbError);
25 function testStoreGet(id, value) {
26   gStore.get(id).then(function(what) {
27     ok(true, "store.get() retrieves data");
28     is(what, value, "store.get(" + id + ") returns " + value);
29   }, function() {
30     ok(false, "store.get(" + id + ") retrieves data");
31   }).then(runTest, cbError);
34 function testStoreAdd(value) {
35   return gStore.add(value).then(function(what) {
36     ok(true, "store.add() is called");
37     ok(what > 0, "store.add() returns something");
38     return what;
39   }, cbError);
42 function testStorePut(value, id) {
43   return gStore.put(value, id).then(function() {
44     ok(true, "store.put() is called");
45   }, cbError);
48 function testStoreGetLength(number) {
49   return gStore.getLength().then(function(n) {
50     is(number, n, "store.getLength() returns the right number");
51   }, cbError);
54 function testStoreRemove(id) {
55   return gStore.remove(id).then(function() {
56     ok(true, "store.remove() is called");
57   }, cbError);
60 function testStoreClear() {
61   return gStore.clear().then(function() {
62     ok(true, "store.clear() is called");
63   }, cbError);
66 var tests = [
67   // Test for GetDataStore
68   testGetDataStores,
70   // Unknown ID
71   function() { testStoreGet(42, undefined); },
72   function() { testStoreGet(42, undefined); }, // twice
74   // Add + Get - number
75   function() { testStoreAdd(42).then(function(id) {
76                  gId = id; runTest(); }, cbError); },
77   function() { testStoreGet(gId, 42); },
79   // Add + Get - boolean
80   function() { testStoreAdd(true).then(function(id) {
81                  gId = id; runTest(); }, cbError); },
82   function() { testStoreGet(gId, true); },
84   // Add + Get - string
85   function() { testStoreAdd("hello world").then(function(id) {
86                  gId = id; runTest(); }, cbError); },
87   function() { testStoreGet(gId, "hello world"); },
89   // Put + Get - string
90   function() { testStorePut("hello world 2", gId).then(function() {
91                  runTest(); }, cbError); },
92   function() { testStoreGet(gId, "hello world 2"); },
94   // getLength
95   function() { testStoreGetLength(3).then(function() { runTest(); }, cbError); },
97   // Remove
98   function() { testStoreRemove(gId).then(function(what) {
99                  runTest(); }, cbError); },
100   function() { testStoreGet(gId, undefined); },
102   // Remove - wrong ID
103   function() { testStoreRemove(gId).then(function(what) {
104                  runTest(); }, cbError); },
106   // Clear
107   function() { testStoreClear().then(function(what) {
108                  runTest(); }, cbError); },
111 function runTest() {
112   if (!tests.length) {
113     finish();
114     return;
115   }
117   var test = tests.shift();
118   test();