diff --git a/dom/datastore/DataStore.jsm b/dom/datastore/DataStore.jsm index 953edd7b043a..115642ee56ad 100644 --- a/dom/datastore/DataStore.jsm +++ b/dom/datastore/DataStore.jsm @@ -293,12 +293,14 @@ this.DataStore.prototype = { sendNotification: function(aId, aOperation, aRevisionId) { debug("SendNotification"); - if (aOperation != REVISION_VOID) { - cpmm.sendAsyncMessage("DataStore:Changed", - { store: this.name, owner: this.owner, - message: { revisionId: aRevisionId, id: aId, - operation: aOperation } } ); + if (aOperation == REVISION_VOID) { + aOperation = "cleared"; } + + cpmm.sendAsyncMessage("DataStore:Changed", + { store: this.name, owner: this.owner, + message: { revisionId: aRevisionId, id: aId, + operation: aOperation } } ); }, receiveMessage: function(aMessage) { diff --git a/dom/datastore/tests/file_changes.html b/dom/datastore/tests/file_changes.html index 8f54936fad16..8cd714a81d9c 100644 --- a/dom/datastore/tests/file_changes.html +++ b/dom/datastore/tests/file_changes.html @@ -61,10 +61,16 @@ }, cbError); } + function testStoreClear() { + gStore.clear().catch(cbError); + } + function eventListener(evt) { ok(evt, "OnChangeListener is called with data"); 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(evt.revisionId), true, "event.revisionId returns something"); - is(evt.id, gChangeId, "OnChangeListener is called with the right ID: " + evt.id); + if (gChangeId) { + is(evt.id, gChangeId, "OnChangeListener is called with the right ID: " + evt.id); + } is(evt.operation, gChangeOperation, "OnChangeListener is called with the right operation:" + evt.operation + " " + gChangeOperation); runTest(); } @@ -92,6 +98,10 @@ function() { gChangeId = 1; gChangeOperation = 'removed'; testStoreRemove(1, true); }, + // Clear + function() { gChangeId = 0; gChangeOperation = 'cleared'; + testStoreClear(); }, + // Remove onchange function and replace it with addEventListener function() { gStore.onchange = null; @@ -111,6 +121,10 @@ function() { gChangeId = 2; gChangeOperation = 'removed'; testStoreRemove(2, true); }, + // Clear + function() { gChangeId = 0; gChangeOperation = 'cleared'; + testStoreClear(); }, + // Remove event listener function() { gStore.removeEventListener('change', eventListener);