mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 949325 - C++ wrapper to support DataStore API on the worker (part 3-3, test sync cases on workers). r=baku
This commit is contained in:
parent
3ec5d165f0
commit
cd8398b088
@ -372,7 +372,7 @@
|
|||||||
var steps = [ { operation: 'clear', },
|
var steps = [ { operation: 'clear', },
|
||||||
{ operation: 'add', id: 1, data: 123 },
|
{ operation: 'add', id: 1, data: 123 },
|
||||||
{ operation: 'add', id: 2, data: 42 },
|
{ operation: 'add', id: 2, data: 42 },
|
||||||
{ operation: 'add', id: 'foobar', data: 2 } ]
|
{ operation: 'add', id: 'foobar', data: 2 } ]
|
||||||
testCursor(gCursor, steps);
|
testCursor(gCursor, steps);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -387,7 +387,7 @@
|
|||||||
var steps = [ { operation: 'clear', },
|
var steps = [ { operation: 'clear', },
|
||||||
{ operation: 'add', id: 1, data: 123 },
|
{ operation: 'add', id: 1, data: 123 },
|
||||||
{ operation: 'add', id: 2, data: 43 },
|
{ operation: 'add', id: 2, data: 43 },
|
||||||
{ operation: 'add', id: 'foobar', data: 2 } ]
|
{ operation: 'add', id: 'foobar', data: 2 } ]
|
||||||
testCursor(gCursor, steps);
|
testCursor(gCursor, steps);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -401,7 +401,7 @@
|
|||||||
function() {
|
function() {
|
||||||
var steps = [ { operation: 'clear', },
|
var steps = [ { operation: 'clear', },
|
||||||
{ operation: 'add', id: 1, data: 123 },
|
{ operation: 'add', id: 1, data: 123 },
|
||||||
{ operation: 'add', id: 'foobar', data: 2 } ]
|
{ operation: 'add', id: 'foobar', data: 2 } ]
|
||||||
testCursor(gCursor, steps);
|
testCursor(gCursor, steps);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -417,7 +417,7 @@
|
|||||||
var steps = [ { operation: 'clear', },
|
var steps = [ { operation: 'clear', },
|
||||||
{ operation: 'add', id: 1, data: 123 },
|
{ operation: 'add', id: 1, data: 123 },
|
||||||
{ operation: 'add', id: 4, data: 42 },
|
{ operation: 'add', id: 4, data: 42 },
|
||||||
{ operation: 'add', id: 'foobar', data: 2 } ]
|
{ operation: 'add', id: 'foobar', data: 2 } ]
|
||||||
testCursor(gCursor, steps);
|
testCursor(gCursor, steps);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
30
dom/datastore/tests/file_sync_worker.html
Normal file
30
dom/datastore/tests/file_sync_worker.html
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Test for DataStore - sync</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="container"></div>
|
||||||
|
<script type="application/javascript;version=1.7">
|
||||||
|
|
||||||
|
var messages = [];
|
||||||
|
var worker = new Worker("file_sync_worker.js");
|
||||||
|
|
||||||
|
worker.onmessage = function(event) {
|
||||||
|
messages.push(event.data)
|
||||||
|
|
||||||
|
if (event.data == 'DONE') {
|
||||||
|
// Free the worker when all the tests are done.
|
||||||
|
worker.terminate();
|
||||||
|
|
||||||
|
// Fire message to the test_sync_worker.html.
|
||||||
|
for (var i = 0; i < messages.length; i++) {
|
||||||
|
alert(messages[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
477
dom/datastore/tests/file_sync_worker.js
Normal file
477
dom/datastore/tests/file_sync_worker.js
Normal file
@ -0,0 +1,477 @@
|
|||||||
|
var gStore;
|
||||||
|
var gRevisions = [];
|
||||||
|
var gCursor;
|
||||||
|
var gExpectedEvents = true;
|
||||||
|
|
||||||
|
function is(a, b, msg) {
|
||||||
|
postMessage((a === b ? 'OK' : 'KO') + ' ' + msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ok(a, msg) {
|
||||||
|
postMessage((a ? 'OK' : 'KO')+ ' ' + msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
function cbError() {
|
||||||
|
postMessage('KO error');
|
||||||
|
}
|
||||||
|
|
||||||
|
function finish() {
|
||||||
|
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");
|
||||||
|
|
||||||
|
// TODO This needs more love for running on workers. Tend to fire a
|
||||||
|
// follow-up for this...
|
||||||
|
// 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 '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");
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
runTest();
|
@ -13,6 +13,8 @@ support-files =
|
|||||||
file_app2.template.webapp
|
file_app2.template.webapp
|
||||||
file_arrays.html
|
file_arrays.html
|
||||||
file_sync.html
|
file_sync.html
|
||||||
|
file_sync_worker.html
|
||||||
|
file_sync_worker.js
|
||||||
file_bug924104.html
|
file_bug924104.html
|
||||||
file_certifiedApp.html
|
file_certifiedApp.html
|
||||||
file_keys.html
|
file_keys.html
|
||||||
@ -37,6 +39,7 @@ skip-if = (toolkit == 'gonk' && debug) #debug-only failure; time out
|
|||||||
[test_oop.html]
|
[test_oop.html]
|
||||||
skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug)) # b2g-debug(debug-only failure; time out) b2g-desktop(Bug 931116, b2g desktop specific, initial triage)
|
skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug)) # b2g-debug(debug-only failure; time out) b2g-desktop(Bug 931116, b2g desktop specific, initial triage)
|
||||||
[test_sync.html]
|
[test_sync.html]
|
||||||
|
[test_sync_worker.html]
|
||||||
skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug)) # b2g-debug(debug-only failure; time out) b2g-desktop(Bug 931116, b2g desktop specific, initial triage)
|
skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug)) # b2g-debug(debug-only failure; time out) b2g-desktop(Bug 931116, b2g desktop specific, initial triage)
|
||||||
[test_bug924104.html]
|
[test_bug924104.html]
|
||||||
[test_certifiedApp.html]
|
[test_certifiedApp.html]
|
||||||
|
126
dom/datastore/tests/test_sync_worker.html
Normal file
126
dom/datastore/tests/test_sync_worker.html
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Test for DataStore - sync</title>
|
||||||
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="container"></div>
|
||||||
|
<script type="application/javascript;version=1.7">
|
||||||
|
|
||||||
|
var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_sync_worker.html';
|
||||||
|
var gApp;
|
||||||
|
|
||||||
|
function cbError() {
|
||||||
|
ok(false, "Error callback invoked");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
function installApp() {
|
||||||
|
var request = navigator.mozApps.install(gHostedManifestURL);
|
||||||
|
request.onerror = cbError;
|
||||||
|
request.onsuccess = function() {
|
||||||
|
gApp = request.result;
|
||||||
|
runTest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function uninstallApp() {
|
||||||
|
// Uninstall the app.
|
||||||
|
var request = navigator.mozApps.mgmt.uninstall(gApp);
|
||||||
|
request.onerror = cbError;
|
||||||
|
request.onsuccess = function() {
|
||||||
|
// All done.
|
||||||
|
info("All done");
|
||||||
|
runTest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testApp() {
|
||||||
|
var ifr = document.createElement('iframe');
|
||||||
|
ifr.setAttribute('mozbrowser', 'true');
|
||||||
|
ifr.setAttribute('mozapp', gApp.manifestURL);
|
||||||
|
ifr.setAttribute('src', gApp.manifest.launch_path);
|
||||||
|
var domParent = document.getElementById('container');
|
||||||
|
|
||||||
|
// Set us up to listen for messages from the app.
|
||||||
|
var listener = function(e) {
|
||||||
|
var message = e.detail.message;
|
||||||
|
if (/^OK/.exec(message)) {
|
||||||
|
ok(true, "Message from app: " + message);
|
||||||
|
} else if (/KO/.exec(message)) {
|
||||||
|
ok(false, "Message from app: " + message);
|
||||||
|
} else if (/DONE/.exec(message)) {
|
||||||
|
ok(true, "Messaging from app complete");
|
||||||
|
ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
|
||||||
|
domParent.removeChild(ifr);
|
||||||
|
runTest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This event is triggered when the app calls "alert".
|
||||||
|
ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
|
||||||
|
domParent.appendChild(ifr);
|
||||||
|
}
|
||||||
|
|
||||||
|
var tests = [
|
||||||
|
// Permissions
|
||||||
|
function() {
|
||||||
|
SpecialPowers.pushPermissions(
|
||||||
|
[{ "type": "browser", "allow": 1, "context": document },
|
||||||
|
{ "type": "embed-apps", "allow": 1, "context": document },
|
||||||
|
{ "type": "webapps-manage", "allow": 1, "context": document }], runTest);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Preferences
|
||||||
|
function() {
|
||||||
|
SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
|
||||||
|
["dom.testing.ignore_ipc_principal", true],
|
||||||
|
["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
|
||||||
|
},
|
||||||
|
|
||||||
|
function() {
|
||||||
|
SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
|
||||||
|
runTest();
|
||||||
|
},
|
||||||
|
|
||||||
|
// No confirmation needed when an app is installed
|
||||||
|
function() {
|
||||||
|
SpecialPowers.autoConfirmAppInstall(runTest);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Installing the app
|
||||||
|
installApp,
|
||||||
|
|
||||||
|
// Run tests in app
|
||||||
|
testApp,
|
||||||
|
|
||||||
|
// Uninstall the app
|
||||||
|
uninstallApp
|
||||||
|
];
|
||||||
|
|
||||||
|
function runTest() {
|
||||||
|
if (!tests.length) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var test = tests.shift();
|
||||||
|
test();
|
||||||
|
}
|
||||||
|
|
||||||
|
function finish() {
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SpecialPowers.isMainProcess()) {
|
||||||
|
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
runTest();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user