From bccbcc8f23a59c9229e1f2d6611eb26e328b38d6 Mon Sep 17 00:00:00 2001 From: Gene Lian Date: Mon, 12 May 2014 14:42:01 +0800 Subject: [PATCH] Bug 1006566 - Unify the common DataStore tests between the main thread and the worker thread (part 2, unify the common parts). r=baku --- dom/datastore/tests/file_basic.html | 121 +----- dom/datastore/tests/file_basic_common.js | 119 ++++++ dom/datastore/tests/file_basic_worker.js | 120 +----- dom/datastore/tests/file_sync.html | 463 +---------------------- dom/datastore/tests/file_sync_common.js | 461 ++++++++++++++++++++++ dom/datastore/tests/file_sync_worker.js | 462 +--------------------- dom/datastore/tests/mochitest.ini | 2 + 7 files changed, 586 insertions(+), 1162 deletions(-) create mode 100644 dom/datastore/tests/file_basic_common.js create mode 100644 dom/datastore/tests/file_sync_common.js diff --git a/dom/datastore/tests/file_basic.html b/dom/datastore/tests/file_basic.html index cdf51e2c95be..d8b1d40d73f1 100644 --- a/dom/datastore/tests/file_basic.html +++ b/dom/datastore/tests/file_basic.html @@ -3,13 +3,12 @@ Test for DataStore - basic operation on a readonly db +
diff --git a/dom/datastore/tests/file_basic_common.js b/dom/datastore/tests/file_basic_common.js new file mode 100644 index 000000000000..f73c3bee8423 --- /dev/null +++ b/dom/datastore/tests/file_basic_common.js @@ -0,0 +1,119 @@ +var gStore; + +function testGetDataStores() { + navigator.getDataStores('foo').then(function(stores) { + is(stores.length, 1, "getDataStores('foo') returns 1 element"); + is(stores[0].name, 'foo', 'The dataStore.name is foo'); + is(stores[0].readOnly, false, 'The dataStore foo is not in readonly'); + + var store = stores[0]; + ok("get" in store, "store.get exists"); + ok("put" in store, "store.put exists"); + ok("add" in store, "store.add exists"); + ok("remove" in store, "store.remove exists"); + ok("clear" in store, "store.clear exists"); + ok("revisionId" in store, "store.revisionId exists"); + ok("getLength" in store, "store.getLength exists"); + ok("sync" in store, "store.sync exists"); + + gStore = stores[0]; + + runTest(); + }, cbError); +} + +function testStoreGet(id, value) { + gStore.get(id).then(function(what) { + ok(true, "store.get() retrieves data"); + is(what, value, "store.get(" + id + ") returns " + value); + }, function() { + ok(false, "store.get(" + id + ") retrieves data"); + }).then(runTest, cbError); +} + +function testStoreAdd(value) { + return gStore.add(value).then(function(what) { + ok(true, "store.add() is called"); + ok(what > 0, "store.add() returns something"); + return what; + }, cbError); +} + +function testStorePut(value, id) { + return gStore.put(value, id).then(function() { + ok(true, "store.put() is called"); + }, cbError); +} + +function testStoreGetLength(number) { + return gStore.getLength().then(function(n) { + is(number, n, "store.getLength() returns the right number"); + }, cbError); +} + +function testStoreRemove(id) { + return gStore.remove(id).then(function() { + ok(true, "store.remove() is called"); + }, cbError); +} + +function testStoreClear() { + return gStore.clear().then(function() { + ok(true, "store.clear() is called"); + }, cbError); +} + +var tests = [ + // Test for GetDataStore + testGetDataStores, + + // Unknown ID + function() { testStoreGet(42, undefined); }, + function() { testStoreGet(42, undefined); }, // twice + + // Add + Get - number + function() { testStoreAdd(42).then(function(id) { + gId = id; runTest(); }, cbError); }, + function() { testStoreGet(gId, 42); }, + + // Add + Get - boolean + function() { testStoreAdd(true).then(function(id) { + gId = id; runTest(); }, cbError); }, + function() { testStoreGet(gId, true); }, + + // Add + Get - string + function() { testStoreAdd("hello world").then(function(id) { + gId = id; runTest(); }, cbError); }, + function() { testStoreGet(gId, "hello world"); }, + + // Put + Get - string + function() { testStorePut("hello world 2", gId).then(function() { + runTest(); }, cbError); }, + function() { testStoreGet(gId, "hello world 2"); }, + + // getLength + function() { testStoreGetLength(3).then(function() { runTest(); }, cbError); }, + + // Remove + function() { testStoreRemove(gId).then(function(what) { + runTest(); }, cbError); }, + function() { testStoreGet(gId, undefined); }, + + // Remove - wrong ID + function() { testStoreRemove(gId).then(function(what) { + runTest(); }, cbError); }, + + // Clear + function() { testStoreClear().then(function(what) { + runTest(); }, cbError); }, +]; + +function runTest() { + if (!tests.length) { + finish(); + return; + } + + var test = tests.shift(); + test(); +} diff --git a/dom/datastore/tests/file_basic_worker.js b/dom/datastore/tests/file_basic_worker.js index 492bb3f57041..c411b876a2aa 100644 --- a/dom/datastore/tests/file_basic_worker.js +++ b/dom/datastore/tests/file_basic_worker.js @@ -1,5 +1,3 @@ - var gStore; - function is(a, b, msg) { postMessage((a === b ? 'OK' : 'KO') + ' ' + msg) } @@ -16,122 +14,6 @@ postMessage('DONE'); } - function testGetDataStores() { - navigator.getDataStores('foo').then(function(stores) { - is(stores.length, 1, "getDataStores('foo') returns 1 element"); - is(stores[0].name, 'foo', 'The dataStore.name is foo'); - is(stores[0].readOnly, false, 'The dataStore foo is not in readonly'); - - var store = stores[0]; - ok("get" in store, "store.get exists"); - ok("put" in store, "store.put exists"); - ok("add" in store, "store.add exists"); - ok("remove" in store, "store.remove exists"); - ok("clear" in store, "store.clear exists"); - ok("revisionId" in store, "store.revisionId exists"); - ok("getLength" in store, "store.getLength exists"); - ok("sync" in store, "store.sync exists"); - - gStore = stores[0]; - - runTest(); - }, cbError); - } - - function testStoreGet(id, value) { - gStore.get(id).then(function(what) { - ok(true, "store.get() retrieves data"); - is(what, value, "store.get(" + id + ") returns " + value); - }, function() { - ok(false, "store.get(" + id + ") retrieves data"); - }).then(runTest, cbError); - } - - function testStoreAdd(value) { - return gStore.add(value).then(function(what) { - ok(true, "store.add() is called"); - ok(what > 0, "store.add() returns something"); - return what; - }, cbError); - } - - function testStorePut(value, id) { - return gStore.put(value, id).then(function() { - ok(true, "store.put() is called"); - }, cbError); - } - - function testStoreGetLength(number) { - return gStore.getLength().then(function(n) { - is(number, n, "store.getLength() returns the right number"); - }, cbError); - } - - function testStoreRemove(id) { - return gStore.remove(id).then(function() { - ok(true, "store.remove() is called"); - }, cbError); - } - - function testStoreClear() { - return gStore.clear().then(function() { - ok(true, "store.clear() is called"); - }, cbError); - } - - var tests = [ - // Test for GetDataStore - testGetDataStores, - - // Unknown ID - function() { testStoreGet(42, undefined); }, - function() { testStoreGet(42, undefined); }, // twice - - // Add + Get - number - function() { testStoreAdd(42).then(function(id) { - gId = id; runTest(); }, cbError); }, - function() { testStoreGet(gId, 42); }, - - // Add + Get - boolean - function() { testStoreAdd(true).then(function(id) { - gId = id; runTest(); }, cbError); }, - function() { testStoreGet(gId, true); }, - - // Add + Get - string - function() { testStoreAdd("hello world").then(function(id) { - gId = id; runTest(); }, cbError); }, - function() { testStoreGet(gId, "hello world"); }, - - // Put + Get - string - function() { testStorePut("hello world 2", gId).then(function() { - runTest(); }, cbError); }, - function() { testStoreGet(gId, "hello world 2"); }, - - // getLength - function() { testStoreGetLength(3).then(function() { runTest(); }, cbError); }, - - // Remove - function() { testStoreRemove(gId).then(function(what) { - runTest(); }, cbError); }, - function() { testStoreGet(gId, undefined); }, - - // Remove - wrong ID - function() { testStoreRemove(gId).then(function(what) { - runTest(); }, cbError); }, - - // Clear - function() { testStoreClear().then(function(what) { - runTest(); }, cbError); }, - ]; - - function runTest() { - if (!tests.length) { - finish(); - return; - } - - var test = tests.shift(); - test(); - } + importScripts("file_basic_common.js"); runTest(); \ No newline at end of file diff --git a/dom/datastore/tests/file_sync.html b/dom/datastore/tests/file_sync.html index 3eb1b3c01643..44201f9dd359 100644 --- a/dom/datastore/tests/file_sync.html +++ b/dom/datastore/tests/file_sync.html @@ -3,16 +3,12 @@ Test for DataStore - sync +
diff --git a/dom/datastore/tests/file_sync_common.js b/dom/datastore/tests/file_sync_common.js new file mode 100644 index 000000000000..4ff97371ee2b --- /dev/null +++ b/dom/datastore/tests/file_sync_common.js @@ -0,0 +1,461 @@ +var gStore; +var gRevisions = []; +var gCursor; +var gExpectedEvents = true; + +function testGetDataStores() { + navigator.getDataStores('foo').then(function(stores) { + is(stores.length, 1, "getDataStores('foo') returns 1 element"); + + gStore = stores[0]; + gRevisions.push(gStore.revisionId); + + gStore.onchange = function(aEvent) { + ok(gExpectedEvents, "Events received!"); + runTest(); + } + + runTest(); + }, cbError); +} + +function testBasicInterface() { + var cursor = gStore.sync(); + ok(cursor, "Cursor is created"); + is(cursor.store, gStore, "Cursor.store is the store"); + + ok("next" in cursor, "Cursor.next exists"); + ok("close" in cursor, "Cursor.close exists"); + + cursor.close(); + + runTest(); +} + +function testCursor(cursor, steps) { + if (!steps.length) { + runTest(); + return; + } + + var step = steps.shift(); + cursor.next().then(function(data) { + ok(!!data, "Cursor.next returns data"); + is(data.operation, step.operation, "Waiting for operation: '" + step.operation + "' received '" + data.operation + "'"); + + + switch (data.operation) { + case 'clear': + is (data.id, null, "'clear' operation wants a null id"); + break; + + case 'done': + is(/[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}/.test(data.revisionId), true, "done has a valid revisionId"); + is (data.revisionId, gRevisions[gRevisions.length-1], "Last revision matches"); + is (data.id, null, "'done' operation wants a null id"); + break; + + case 'add': + case 'update': + if ('id' in step) { + is(data.id, step.id, "next() add: id matches: " + data.id + " " + step.id); + } + + if ('data' in step) { + is(data.data, step.data, "next() add: data matches: " + data.data + " " + step.data); + } + + break; + + case 'remove': + if ('id' in step) { + is(data.id, step.id, "next() add: id matches: " + data.id + " " + step.id); + } + + break; + } + + testCursor(cursor, steps); + }); +} + +var tests = [ + // Test for GetDataStore + testGetDataStores, + + // interface test + testBasicInterface, + + // empty DataStore + function() { + var cursor = gStore.sync(); + var steps = [ { operation: 'clear' }, + { operation: 'done' }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + gExpectedEvents = false; + var cursor = gStore.sync('wrong revision ID'); + var steps = [ { operation: 'clear' }, + { operation: 'done' }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[0]); + var steps = [ { operation: 'done' }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + // Test add from scratch + function() { + gExpectedEvents = true; + + gStore.add(1).then(function(id) { + gRevisions.push(gStore.revisionId); + ok(true, "Item: " + id + " added"); + }); + }, + + function() { + gStore.add(2,"foobar").then(function(id) { + gRevisions.push(gStore.revisionId); + ok(true, "Item: " + id + " added"); + }); + }, + + function() { + gStore.add(3,3).then(function(id) { + gRevisions.push(gStore.revisionId); + ok(true, "Item: " + id + " added"); + }); + }, + + function() { + gExpectedEvents = false; + var cursor = gStore.sync(); + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 1, data: 1 }, + { operation: 'add', id: 3, data: 3 }, + { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync('wrong revision ID'); + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 1, data: 1 }, + { operation: 'add', id: 3, data: 3 }, + { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[0]); + var steps = [ { operation: 'add', id: 1, data: 1 }, + { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'add', id: 3, data: 3 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[1]); + var steps = [ { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'add', id: 3, data: 3 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[2]); + var steps = [ { operation: 'add', id: 3, data: 3 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[3]); + var steps = [ { operation: 'done' }]; + testCursor(cursor, steps); + }, + + // Test after an update + function() { + gExpectedEvents = true; + gStore.put(123, 1).then(function() { + gRevisions.push(gStore.revisionId); + }); + }, + + function() { + gExpectedEvents = false; + var cursor = gStore.sync(); + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 1, data: 123 }, + { operation: 'add', id: 3, data: 3 }, + { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync('wrong revision ID'); + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 1, data: 123 }, + { operation: 'add', id: 3, data: 3 }, + { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[0]); + var steps = [ { operation: 'add', id: 1, data: 123 }, + { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'add', id: 3, data: 3 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[1]); + var steps = [ { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'add', id: 3, data: 3 }, + { operation: 'update', id: 1, data: 123 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[2]); + var steps = [ { operation: 'add', id: 3, data: 3 }, + { operation: 'update', id: 1, data: 123 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[3]); + var steps = [ { operation: 'update', id: 1, data: 123 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[4]); + var steps = [ { operation: 'done' }]; + testCursor(cursor, steps); + }, + + // Test after a remove + function() { + gExpectedEvents = true; + gStore.remove(3).then(function() { + gRevisions.push(gStore.revisionId); + }); + }, + + function() { + gExpectedEvents = false; + var cursor = gStore.sync(); + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 1, data: 123 }, + { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync('wrong revision ID'); + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 1, data: 123 }, + { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[0]); + var steps = [ { operation: 'add', id: 1, data: 123 }, + { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[1]); + var steps = [ { operation: 'add', id: 'foobar', data: 2 }, + { operation: 'update', id: 1, data: 123 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[2]); + var steps = [ { operation: 'update', id: 1, data: 123 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[3]); + var steps = [ { operation: 'update', id: 1, data: 123 }, + { operation: 'remove', id: 3 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[4]); + var steps = [ { operation: 'remove', id: 3 }, + { operation: 'done' }]; + testCursor(cursor, steps); + }, + + function() { + var cursor = gStore.sync(gRevisions[5]); + var steps = [ { operation: 'done' }]; + testCursor(cursor, steps); + }, + + // New events when the cursor is active + function() { + gCursor = gStore.sync(); + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 1, data: 123 }, + { operation: 'add', id: 'foobar', data: 2 } ]; + testCursor(gCursor, steps); + }, + + function() { + gStore.add(42, 2).then(function(id) { + ok(true, "Item: " + id + " added"); + gRevisions.push(gStore.revisionId); + runTest(); + }); + }, + + function() { + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 1, data: 123 }, + { operation: 'add', id: 2, data: 42 }, + { operation: 'add', id: 'foobar', data: 2 } ] + testCursor(gCursor, steps); + }, + + function() { + gStore.put(43, 2).then(function(id) { + gRevisions.push(gStore.revisionId); + runTest(); + }); + }, + + function() { + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 1, data: 123 }, + { operation: 'add', id: 2, data: 43 }, + { operation: 'add', id: 'foobar', data: 2 } ] + testCursor(gCursor, steps); + }, + + function() { + gStore.remove(2).then(function(id) { + gRevisions.push(gStore.revisionId); + runTest(); + }); + }, + + function() { + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 1, data: 123 }, + { operation: 'add', id: 'foobar', data: 2 } ] + testCursor(gCursor, steps); + }, + + function() { + gStore.add(42).then(function(id) { + ok(true, "Item: " + id + " added"); + gRevisions.push(gStore.revisionId); + runTest(); + }); + }, + + function() { + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 1, data: 123 }, + { operation: 'add', id: 4, data: 42 }, + { operation: 'add', id: 'foobar', data: 2 } ] + testCursor(gCursor, steps); + }, + + function() { + gStore.clear().then(function() { + gRevisions.push(gStore.revisionId); + runTest(); + }); + }, + + function() { + var steps = [ { operation: 'clear' } ]; + testCursor(gCursor, steps); + }, + + function() { + gStore.add(42).then(function(id) { + ok(true, "Item: " + id + " added"); + gRevisions.push(gStore.revisionId); + runTest(); + }); + }, + + function() { + var steps = [ { operation: 'clear', }, + { operation: 'add', id: 5, data: 42 } ]; + testCursor(gCursor, steps); + }, + + function() { + gStore.clear().then(function() { + gRevisions.push(gStore.revisionId); + runTest(); + }); + }, + + function() { + gStore.add(42).then(function(id) { + ok(true, "Item: " + id + " added"); + gRevisions.push(gStore.revisionId); + runTest(); + }); + }, + + function() { + var steps = [ { operation: 'clear' }, + { operation: 'add', id: 6, data: 42 }, + { operation: 'done'} ]; + testCursor(gCursor, steps); + }, + + function() { + gExpectedEvents = true; + gStore.add(42).then(function(id) { + }); + } +]; + +function runTest() { + if (!tests.length) { + finish(); + return; + } + + var test = tests.shift(); + test(); +} diff --git a/dom/datastore/tests/file_sync_worker.js b/dom/datastore/tests/file_sync_worker.js index 7d621c384f35..d1e7c98c757d 100644 --- a/dom/datastore/tests/file_sync_worker.js +++ b/dom/datastore/tests/file_sync_worker.js @@ -1,8 +1,3 @@ - var gStore; - var gRevisions = []; - var gCursor; - var gExpectedEvents = true; - function is(a, b, msg) { postMessage((a === b ? 'OK' : 'KO') + ' ' + msg) } @@ -19,461 +14,6 @@ postMessage('DONE'); } - function testGetDataStores() { - navigator.getDataStores('foo').then(function(stores) { - is(stores.length, 1, "getDataStores('foo') returns 1 element"); - - gStore = stores[0]; - gRevisions.push(gStore.revisionId); - - gStore.onchange = function(aEvent) { - ok(gExpectedEvents, "Events received!"); - runTest(); - } - - runTest(); - }, cbError); - } - - function testBasicInterface() { - var cursor = gStore.sync(); - ok(cursor, "Cursor is created"); - is(cursor.store, gStore, "Cursor.store is the store"); - - ok("next" in cursor, "Cursor.next exists"); - ok("close" in cursor, "Cursor.close exists"); - - cursor.close(); - - runTest(); - } - - function testCursor(cursor, steps) { - if (!steps.length) { - runTest(); - return; - } - - var step = steps.shift(); - cursor.next().then(function(data) { - ok(!!data, "Cursor.next returns data"); - is(data.operation, step.operation, "Waiting for operation: '" + step.operation + "' received '" + data.operation + "'"); - - - switch (data.operation) { - case 'clear': - is (data.id, null, "'clear' operation wants a null id"); - break; - - case 'done': - is(/[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}/.test(data.revisionId), true, "done has a valid revisionId"); - is (data.revisionId, gRevisions[gRevisions.length-1], "Last revision matches"); - is (data.id, null, "'done' operation wants a null id"); - break; - - case 'add': - case 'update': - if ('id' in step) { - is(data.id, step.id, "next() add: id matches: " + data.id + " " + step.id); - } - - if ('data' in step) { - is(data.data, step.data, "next() add: data matches: " + data.data + " " + step.data); - } - - break; - - case 'remove': - if ('id' in step) { - is(data.id, step.id, "next() add: id matches: " + data.id + " " + step.id); - } - - break; - } - - testCursor(cursor, steps); - }); - } - - var tests = [ - // Test for GetDataStore - testGetDataStores, - - // interface test - testBasicInterface, - - // empty DataStore - function() { - var cursor = gStore.sync(); - var steps = [ { operation: 'clear' }, - { operation: 'done' }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - gExpectedEvents = false; - var cursor = gStore.sync('wrong revision ID'); - var steps = [ { operation: 'clear' }, - { operation: 'done' }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[0]); - var steps = [ { operation: 'done' }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - // Test add from scratch - function() { - gExpectedEvents = true; - - gStore.add(1).then(function(id) { - gRevisions.push(gStore.revisionId); - ok(true, "Item: " + id + " added"); - }); - }, - - function() { - gStore.add(2,"foobar").then(function(id) { - gRevisions.push(gStore.revisionId); - ok(true, "Item: " + id + " added"); - }); - }, - - function() { - gStore.add(3,3).then(function(id) { - gRevisions.push(gStore.revisionId); - ok(true, "Item: " + id + " added"); - }); - }, - - function() { - gExpectedEvents = false; - var cursor = gStore.sync(); - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 1, data: 1 }, - { operation: 'add', id: 3, data: 3 }, - { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync('wrong revision ID'); - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 1, data: 1 }, - { operation: 'add', id: 3, data: 3 }, - { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[0]); - var steps = [ { operation: 'add', id: 1, data: 1 }, - { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'add', id: 3, data: 3 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[1]); - var steps = [ { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'add', id: 3, data: 3 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[2]); - var steps = [ { operation: 'add', id: 3, data: 3 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[3]); - var steps = [ { operation: 'done' }]; - testCursor(cursor, steps); - }, - - // Test after an update - function() { - gExpectedEvents = true; - gStore.put(123, 1).then(function() { - gRevisions.push(gStore.revisionId); - }); - }, - - function() { - gExpectedEvents = false; - var cursor = gStore.sync(); - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 1, data: 123 }, - { operation: 'add', id: 3, data: 3 }, - { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync('wrong revision ID'); - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 1, data: 123 }, - { operation: 'add', id: 3, data: 3 }, - { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[0]); - var steps = [ { operation: 'add', id: 1, data: 123 }, - { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'add', id: 3, data: 3 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[1]); - var steps = [ { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'add', id: 3, data: 3 }, - { operation: 'update', id: 1, data: 123 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[2]); - var steps = [ { operation: 'add', id: 3, data: 3 }, - { operation: 'update', id: 1, data: 123 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[3]); - var steps = [ { operation: 'update', id: 1, data: 123 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[4]); - var steps = [ { operation: 'done' }]; - testCursor(cursor, steps); - }, - - // Test after a remove - function() { - gExpectedEvents = true; - gStore.remove(3).then(function() { - gRevisions.push(gStore.revisionId); - }); - }, - - function() { - gExpectedEvents = false; - var cursor = gStore.sync(); - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 1, data: 123 }, - { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync('wrong revision ID'); - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 1, data: 123 }, - { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[0]); - var steps = [ { operation: 'add', id: 1, data: 123 }, - { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[1]); - var steps = [ { operation: 'add', id: 'foobar', data: 2 }, - { operation: 'update', id: 1, data: 123 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[2]); - var steps = [ { operation: 'update', id: 1, data: 123 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[3]); - var steps = [ { operation: 'update', id: 1, data: 123 }, - { operation: 'remove', id: 3 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[4]); - var steps = [ { operation: 'remove', id: 3 }, - { operation: 'done' }]; - testCursor(cursor, steps); - }, - - function() { - var cursor = gStore.sync(gRevisions[5]); - var steps = [ { operation: 'done' }]; - testCursor(cursor, steps); - }, - - // New events when the cursor is active - function() { - gCursor = gStore.sync(); - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 1, data: 123 }, - { operation: 'add', id: 'foobar', data: 2 } ]; - testCursor(gCursor, steps); - }, - - function() { - gStore.add(42, 2).then(function(id) { - ok(true, "Item: " + id + " added"); - gRevisions.push(gStore.revisionId); - runTest(); - }); - }, - - function() { - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 1, data: 123 }, - { operation: 'add', id: 2, data: 42 }, - { operation: 'add', id: 'foobar', data: 2 } ] - testCursor(gCursor, steps); - }, - - function() { - gStore.put(43, 2).then(function(id) { - gRevisions.push(gStore.revisionId); - runTest(); - }); - }, - - function() { - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 1, data: 123 }, - { operation: 'add', id: 2, data: 43 }, - { operation: 'add', id: 'foobar', data: 2 } ] - testCursor(gCursor, steps); - }, - - function() { - gStore.remove(2).then(function(id) { - gRevisions.push(gStore.revisionId); - runTest(); - }); - }, - - function() { - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 1, data: 123 }, - { operation: 'add', id: 'foobar', data: 2 } ] - testCursor(gCursor, steps); - }, - - function() { - gStore.add(42).then(function(id) { - ok(true, "Item: " + id + " added"); - gRevisions.push(gStore.revisionId); - runTest(); - }); - }, - - function() { - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 1, data: 123 }, - { operation: 'add', id: 4, data: 42 }, - { operation: 'add', id: 'foobar', data: 2 } ] - testCursor(gCursor, steps); - }, - - function() { - gStore.clear().then(function() { - gRevisions.push(gStore.revisionId); - runTest(); - }); - }, - - function() { - var steps = [ { operation: 'clear' } ]; - testCursor(gCursor, steps); - }, - - function() { - gStore.add(42).then(function(id) { - ok(true, "Item: " + id + " added"); - gRevisions.push(gStore.revisionId); - runTest(); - }); - }, - - function() { - var steps = [ { operation: 'clear', }, - { operation: 'add', id: 5, data: 42 } ]; - testCursor(gCursor, steps); - }, - - function() { - gStore.clear().then(function() { - gRevisions.push(gStore.revisionId); - runTest(); - }); - }, - - function() { - gStore.add(42).then(function(id) { - ok(true, "Item: " + id + " added"); - gRevisions.push(gStore.revisionId); - runTest(); - }); - }, - - function() { - var steps = [ { operation: 'clear' }, - { operation: 'add', id: 6, data: 42 }, - { operation: 'done'} ]; - testCursor(gCursor, steps); - }, - - function() { - gExpectedEvents = true; - gStore.add(42).then(function(id) { - }); - } - ]; - - function runTest() { - if (!tests.length) { - finish(); - return; - } - - var test = tests.shift(); - test(); - } + importScripts("file_sync_common.js"); runTest(); \ No newline at end of file diff --git a/dom/datastore/tests/mochitest.ini b/dom/datastore/tests/mochitest.ini index 6da817d0894a..34727da14957 100644 --- a/dom/datastore/tests/mochitest.ini +++ b/dom/datastore/tests/mochitest.ini @@ -26,6 +26,8 @@ support-files = file_event_maker.html file_event_receiver.html file_transactions.html + file_basic_common.js + file_sync_common.js [test_app_install.html] [test_readonly.html]