Bug 933049 - Remove DataStore getChanges, r=ehsan

This commit is contained in:
Andrea Marchesini 2013-11-08 23:07:50 +00:00
Родитель 2142e2edae
Коммит 4abbe765f1
6 изменённых файлов: 0 добавлений и 447 удалений

Просмотреть файл

@ -458,104 +458,6 @@ this.DataStore.prototype = {
return this._revisionId;
},
getChanges: function(aRevisionId) {
debug("GetChanges: " + aRevisionId);
if (aRevisionId === null || aRevisionId === undefined) {
return this._window.Promise.reject(
new this._window.DOMError("SyntaxError", "Invalid revisionId"));
}
let self = this;
// Promise<DataStoreChanges>
return new this._window.Promise(function(aResolve, aReject) {
debug("GetChanges promise started");
self._db.revisionTxn(
'readonly',
function(aTxn, aStore) {
debug("GetChanges transaction success");
let request = self._db.getInternalRevisionId(
aRevisionId,
aStore,
function(aInternalRevisionId) {
if (aInternalRevisionId == undefined) {
aResolve(undefined);
return;
}
// This object is the return value of this promise.
// Initially we use maps, and then we convert them in array.
let changes = {
revisionId: '',
addedIds: {},
updatedIds: {},
removedIds: {}
};
let request = aStore.mozGetAll(IDBKeyRange.lowerBound(aInternalRevisionId, true));
request.onsuccess = function(aEvent) {
for (let i = 0; i < aEvent.target.result.length; ++i) {
let data = aEvent.target.result[i];
switch (data.operation) {
case REVISION_ADDED:
changes.addedIds[data.objectId] = true;
break;
case REVISION_UPDATED:
// We don't consider an update if this object has been added
// or if it has been already modified by a previous
// operation.
if (!(data.objectId in changes.addedIds) &&
!(data.objectId in changes.updatedIds)) {
changes.updatedIds[data.objectId] = true;
}
break;
case REVISION_REMOVED:
let id = data.objectId;
// If the object has been added in this range of revisions
// we can ignore it and remove it from the list.
if (id in changes.addedIds) {
delete changes.addedIds[id];
} else {
changes.removedIds[id] = true;
}
if (id in changes.updatedIds) {
delete changes.updatedIds[id];
}
break;
}
}
// The last revisionId.
if (aEvent.target.result.length) {
changes.revisionId = aEvent.target.result[aEvent.target.result.length - 1].revisionId;
}
// From maps to arrays.
changes.addedIds = Object.keys(changes.addedIds).map(function(aKey) { return parseInt(aKey, 10); });
changes.updatedIds = Object.keys(changes.updatedIds).map(function(aKey) { return parseInt(aKey, 10); });
changes.removedIds = Object.keys(changes.removedIds).map(function(aKey) { return parseInt(aKey, 10); });
let wrappedObject = ObjectWrapper.wrap(changes, self._window);
aResolve(wrappedObject);
};
}
);
},
function(aEvent) {
debug("GetChanges transaction failed");
aReject(createDOMError(self._window, aEvent));
}
);
});
},
getLength: function() {
let self = this;

Просмотреть файл

@ -39,7 +39,6 @@
ok("remove" in store, "store.remove exists");
ok("clear" in store, "store.clear exists");
ok("revisionId" in store, "store.revisionId exists");
ok("getChanges" in store, "store.getChanges exists");
ok("getLength" in store, "store.getLength exists");
ok("sync" in store, "store.sync exists");

Просмотреть файл

@ -1,196 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for DataStore - basic operation on a readonly db</title>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript;version=1.7">
var gStore;
var gPreviousRevisionId = '';
function is(a, b, msg) {
alert((a === b ? 'OK' : 'KO') + ' ' + msg)
}
function isnot(a, b, msg) {
alert((a !== b ? 'OK' : 'KO') + ' ' + msg)
}
function ok(a, msg) {
alert((a ? 'OK' : 'KO')+ ' ' + msg)
}
function cbError() {
alert('KO error');
}
function finish() {
alert('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');
gStore = stores[0];
runTest();
}, cbError);
}
function testStoreAdd(value, expectedId) {
return gStore.add(value).then(function(id) {
is(id, expectedId, "store.add() is called");
runTest();
}, cbError);
}
function testStoreUpdate(id, value) {
return gStore.update(id, value).then(function(retId) {
is(id, retId, "store.update() is called with the right id");
runTest();
}, cbError);
}
function testStoreRemove(id, expectedSuccess) {
return gStore.remove(id).then(function(success) {
is(success, expectedSuccess, "store.remove() returns the right value");
runTest();
}, cbError);
}
function testStoreRevisionId() {
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(gStore.revisionId), true, "store.revisionId returns something");
runTest();
}
function testStoreWrongRevisions(id) {
return gStore.getChanges(id).then(
function(what) {
is(what, undefined, "Wrong revisionId == undefined object");
runTest();
}, cbError);
}
function testStoreRevisions(id, changes) {
return gStore.getChanges(id).then(function(what) {
is(JSON.stringify(changes.addedIds),
JSON.stringify(what.addedIds), "store.revisions - addedIds: " +
JSON.stringify(what.addedIds) + " | " + JSON.stringify(changes.addedIds));
is(JSON.stringify(changes.updatedIds),
JSON.stringify(what.updatedIds), "store.revisions - updatedIds: " +
JSON.stringify(what.updatedIds) + " | " + JSON.stringify(changes.updatedIds));
is(JSON.stringify(changes.removedIds),
JSON.stringify(what.removedIds), "store.revisions - removedIds: " +
JSON.stringify(what.removedIds) + " | " + JSON.stringify(changes.removedIds));
runTest();
}, cbError);
}
function testStoreRevisionIdChanged() {
isnot(gStore.revisionId, gPreviousRevisionId, "Revision changed");
gPreviousRevisionId = gStore.revisionId;
runTest();
}
function testStoreRevisionIdNotChanged() {
is(gStore.revisionId, gPreviousRevisionId, "Revision changed");
runTest();
}
var revisions = [];
var tests = [
// Test for GetDataStore
testGetDataStores,
// The first revision is not empty
testStoreRevisionIdChanged,
// wrong revision ID
function() { testStoreWrongRevisions('foobar'); },
// Add
function() { testStoreAdd({ number: 42 }, 1); },
function() { revisions.push(gStore.revisionId); testStoreRevisionId(); },
testStoreRevisionIdChanged,
function() { testStoreRevisions(revisions[0], { addedIds: [], updatedIds: [], removedIds: [] }); },
// Add
function() { testStoreAdd({ number: 42 }, 2); },
function() { revisions.push(gStore.revisionId); runTest(); },
testStoreRevisionIdChanged,
function() { testStoreRevisions(revisions[0], { addedIds: [2], updatedIds: [], removedIds: [] }); },
function() { testStoreRevisions(revisions[1], { addedIds: [], updatedIds: [], removedIds: [] }); },
// Add
function() { testStoreAdd({ number: 42 }, 3); },
function() { revisions.push(gStore.revisionId); runTest(); },
testStoreRevisionIdChanged,
function() { testStoreRevisions(revisions[0], { addedIds: [2,3], updatedIds: [], removedIds: [] }); },
function() { testStoreRevisions(revisions[1], { addedIds: [3], updatedIds: [], removedIds: [] }); },
function() { testStoreRevisions(revisions[2], { addedIds: [], updatedIds: [], removedIds: [] }); },
// Update
function() { testStoreUpdate(3, { number: 43 }); },
function() { revisions.push(gStore.revisionId); runTest(); },
testStoreRevisionIdChanged,
function() { testStoreRevisions(revisions[0], { addedIds: [2,3], updatedIds: [], removedIds: [] }); },
function() { testStoreRevisions(revisions[1], { addedIds: [3], updatedIds: [], removedIds: [] }); },
function() { testStoreRevisions(revisions[2], { addedIds: [], updatedIds: [3], removedIds: [] }); },
function() { testStoreRevisions(revisions[3], { addedIds: [], updatedIds: [], removedIds: [] }); },
// Update
function() { testStoreUpdate(3, { number: 42 }); },
function() { revisions.push(gStore.revisionId); runTest(); },
testStoreRevisionIdChanged,
function() { testStoreRevisions(revisions[0], { addedIds: [2,3], updatedIds: [], removedIds: [] }); },
function() { testStoreRevisions(revisions[1], { addedIds: [3], updatedIds: [], removedIds: [] }); },
function() { testStoreRevisions(revisions[2], { addedIds: [], updatedIds: [3], removedIds: [] }); },
function() { testStoreRevisions(revisions[3], { addedIds: [], updatedIds: [3], removedIds: [] }); },
function() { testStoreRevisions(revisions[4], { addedIds: [], updatedIds: [], removedIds: [] }); },
// Remove
function() { testStoreRemove(3, true); },
function() { revisions.push(gStore.revisionId); runTest(); },
testStoreRevisionIdChanged,
function() { testStoreRevisions(revisions[0], { addedIds: [2], updatedIds: [], removedIds: [] }); },
function() { testStoreRevisions(revisions[1], { addedIds: [], updatedIds: [], removedIds: [] }); },
function() { testStoreRevisions(revisions[2], { addedIds: [], updatedIds: [], removedIds: [3] }); },
function() { testStoreRevisions(revisions[3], { addedIds: [], updatedIds: [], removedIds: [3] }); },
function() { testStoreRevisions(revisions[4], { addedIds: [], updatedIds: [], removedIds: [3] }); },
function() { testStoreRevisions(revisions[5], { addedIds: [], updatedIds: [], removedIds: [] }); },
function() { testStoreRemove(3, false); },
testStoreRevisionIdNotChanged,
// Remove
function() { testStoreRemove(42, false); },
testStoreRevisionIdNotChanged,
];
function runTest() {
if (!tests.length) {
finish();
return;
}
var test = tests.shift();
test();
}
runTest();
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -3,7 +3,6 @@ support-files =
file_app_install.html
file_readonly.html
file_basic.html
file_revision.html
file_changes.html
file_changes2.html
file_app.sjs
@ -16,7 +15,6 @@ support-files =
[test_app_install.html]
[test_readonly.html]
[test_basic.html]
[test_revision.html]
[test_changes.html]
[test_arrays.html]
[test_oop.html]

Просмотреть файл

@ -1,140 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for DataStore - basic operation on a readonly db</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript;version=1.7">
var gBaseURL = 'http://test/tests/dom/datastore/tests/';
var gHostedManifestURL = gBaseURL + 'file_app.sjs?testToken=file_revision.html';
var gApp;
var gStore;
var gPreviousRevisionId = '';
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.
ok(true, "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('content');
// 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 revisions = [];
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.promise.enabled", true]]}, runTest);
},
function() {
SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true]]}, runTest);
},
// Enabling mozBrowser
function() {
SpecialPowers.setAllAppsLaunchable(true);
SpecialPowers.pushPrefEnv({"set": [["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>
</pre>
</body>
</html>

Просмотреть файл

@ -39,22 +39,12 @@ interface DataStore : EventTarget {
attribute EventHandler onchange;
// Promise<DataStoreChanges>
Promise getChanges(DOMString revisionId);
// Promise<unsigned long>
Promise getLength();
DataStoreCursor sync(optional DOMString revisionId = "");
};
dictionary DataStoreChanges {
DOMString revisionId;
sequence<unsigned long> addedIds;
sequence<unsigned long> updatedIds;
sequence<unsigned long> removedIds;
};
[Pref="dom.datastore.enabled",
JSImplementation="@mozilla.org/dom/datastore-cursor;1"]
interface DataStoreCursor {