Bug 1264782 - Fix calendar xpcshell regression in test_calmgr from bug 1258835. r=Fallen
authoraleth <aleth@instantbird.org>
Thu, 21 Apr 2016 12:09:36 +0200
changeset 24837 a5f12c8dc64f4061f86d1292208bd3a53c6d1c34
parent 24836 aaf73ae87441d3361d7656c6bbec41f949b304f7
child 24838 6d308b9180291cdf249d25c8771bfe1ad9dc6b18
push id1657
push userclokep@gmail.com
push dateMon, 06 Jun 2016 19:50:21 +0000
treeherdercomm-beta@9fac989284b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFallen
bugs1264782, 1258835
Bug 1264782 - Fix calendar xpcshell regression in test_calmgr from bug 1258835. r=Fallen
calendar/test/unit/test_calmgr.js
calendar/test/unit/test_deleted_items.js
--- a/calendar/test/unit/test_calmgr.js
+++ b/calendar/test/unit/test_calmgr.js
@@ -7,97 +7,16 @@ Components.utils.import("resource://gre/
 
 /**
  * Tests the calICalendarManager interface
  */
 function run_test() {
     do_calendar_startup(run_next_test);
 }
 
-add_test(function test_calobserver() {
-    function checkCounters(add, modify, del, alladd, allmodify, alldel) {
-        equal(calcounter.addItem, add);
-        equal(calcounter.modifyItem, modify);
-        equal(calcounter.deleteItem, del);
-        equal(allcounter.addItem, alladd === undefined ? add : alladd);
-        equal(allcounter.modifyItem, allmodify === undefined ? modify : allmodify);
-        equal(allcounter.deleteItem, alldel === undefined ? del : alldel);
-        resetCounters();
-    }
-    function resetCounters() {
-        calcounter = { addItem: 0, modifyItem: 0, deleteItem: 0 };
-        allcounter = { addItem: 0, modifyItem: 0, deleteItem: 0 };
-    }
-
-    // First of all we need a local calendar to work on and some variables
-    let calmgr = cal.getCalendarManager();
-    let memory = calmgr.createCalendar("memory", Services.io.newURI("moz-memory-calendar://", null, null));
-    let memory2 = calmgr.createCalendar("memory", Services.io.newURI("moz-memory-calendar://", null, null));
-    let calcounter, allcounter;
-
-    // These observers will end up counting calls which we will use later on
-    let calobs = cal.createAdapter(Components.interfaces.calIObserver, {
-        onAddItem: itm => calcounter.addItem++,
-        onModifyItem: itm => calcounter.modifyItem++,
-        onDeleteItem: itm => calcounter.deleteItem++
-    });
-    let allobs = cal.createAdapter(Components.interfaces.calIObserver, {
-        onAddItem: itm => allcounter.addItem++,
-        onModifyItem: itm => allcounter.modifyItem++,
-        onDeleteItem: itm => allcounter.deleteItem++
-    });
-
-    // Set up counters and observers
-    resetCounters();
-    calmgr.registerCalendar(memory);
-    calmgr.registerCalendar(memory2);
-    calmgr.addCalendarObserver(allobs);
-    memory.addObserver(calobs);
-
-    // Add an item
-    let item = cal.createEvent();
-    item.id = cal.getUUID()
-    item.startDate = cal.now();
-    item.endDate = cal.now();
-    memory.addItem(item, null);
-    checkCounters(1, 0, 0);
-
-    // Modify the item
-    let newItem = item.clone();
-    newItem.title = "title";
-    memory.modifyItem(newItem, item, null);
-    checkCounters(0, 1, 0);
-
-    // Delete the item
-    newItem.generation++; // circumvent generation checks for easier code
-    memory.deleteItem(newItem, null);
-    checkCounters(0, 0, 1);
-
-    // Now check the same for adding the item to a calendar only observed by the
-    // calendar manager. The calcounters should still be 0, but the calendar
-    // manager counter should have an item added, modified and deleted
-    memory2.addItem(item, null);
-    memory2.modifyItem(newItem, item, null);
-    memory2.deleteItem(newItem, null);
-    checkCounters(0, 0, 0, 1, 1, 1);
-
-    // Remove observers
-    memory.removeObserver(calobs);
-    calmgr.removeCalendarObserver(allobs);
-
-    // Make sure removing it actually worked
-    memory.addItem(item, null);
-    memory.modifyItem(newItem, item, null);
-    memory.deleteItem(newItem, null);
-    checkCounters(0, 0, 0);
-
-    // We are done now, start the next test
-    run_next_test();
-});
-
 add_test(function test_registration() {
     function checkCalendarCount(net, rdonly, all) {
         equal(calmgr.networkCalendarCount, net);
         equal(calmgr.readOnlyCalendarCount , rdonly);
         equal(calmgr.calendarCount, all);
     }
     function checkRegistration(reg, unreg, del) {
         equal(registered, reg);
@@ -180,16 +99,97 @@ add_test(function test_registration() {
     checkRegistration(false, false, false);
     equal(readOnly, true);
     checkCalendarCount(0, 0, 0);
 
     // We are done now, start the next test
     run_next_test();
 });
 
+add_test(function test_calobserver() {
+    function checkCounters(add, modify, del, alladd, allmodify, alldel) {
+        equal(calcounter.addItem, add);
+        equal(calcounter.modifyItem, modify);
+        equal(calcounter.deleteItem, del);
+        equal(allcounter.addItem, alladd === undefined ? add : alladd);
+        equal(allcounter.modifyItem, allmodify === undefined ? modify : allmodify);
+        equal(allcounter.deleteItem, alldel === undefined ? del : alldel);
+        resetCounters();
+    }
+    function resetCounters() {
+        calcounter = { addItem: 0, modifyItem: 0, deleteItem: 0 };
+        allcounter = { addItem: 0, modifyItem: 0, deleteItem: 0 };
+    }
+
+    // First of all we need a local calendar to work on and some variables
+    let calmgr = cal.getCalendarManager();
+    let memory = calmgr.createCalendar("memory", Services.io.newURI("moz-memory-calendar://", null, null));
+    let memory2 = calmgr.createCalendar("memory", Services.io.newURI("moz-memory-calendar://", null, null));
+    let calcounter, allcounter;
+
+    // These observers will end up counting calls which we will use later on
+    let calobs = cal.createAdapter(Components.interfaces.calIObserver, {
+        onAddItem: itm => calcounter.addItem++,
+        onModifyItem: itm => calcounter.modifyItem++,
+        onDeleteItem: itm => calcounter.deleteItem++
+    });
+    let allobs = cal.createAdapter(Components.interfaces.calIObserver, {
+        onAddItem: itm => allcounter.addItem++,
+        onModifyItem: itm => allcounter.modifyItem++,
+        onDeleteItem: itm => allcounter.deleteItem++
+    });
+
+    // Set up counters and observers
+    resetCounters();
+    calmgr.registerCalendar(memory);
+    calmgr.registerCalendar(memory2);
+    calmgr.addCalendarObserver(allobs);
+    memory.addObserver(calobs);
+
+    // Add an item
+    let item = cal.createEvent();
+    item.id = cal.getUUID()
+    item.startDate = cal.now();
+    item.endDate = cal.now();
+    memory.addItem(item, null);
+    checkCounters(1, 0, 0);
+
+    // Modify the item
+    let newItem = item.clone();
+    newItem.title = "title";
+    memory.modifyItem(newItem, item, null);
+    checkCounters(0, 1, 0);
+
+    // Delete the item
+    newItem.generation++; // circumvent generation checks for easier code
+    memory.deleteItem(newItem, null);
+    checkCounters(0, 0, 1);
+
+    // Now check the same for adding the item to a calendar only observed by the
+    // calendar manager. The calcounters should still be 0, but the calendar
+    // manager counter should have an item added, modified and deleted
+    memory2.addItem(item, null);
+    memory2.modifyItem(newItem, item, null);
+    memory2.deleteItem(newItem, null);
+    checkCounters(0, 0, 0, 1, 1, 1);
+
+    // Remove observers
+    memory.removeObserver(calobs);
+    calmgr.removeCalendarObserver(allobs);
+
+    // Make sure removing it actually worked
+    memory.addItem(item, null);
+    memory.modifyItem(newItem, item, null);
+    memory.deleteItem(newItem, null);
+    checkCounters(0, 0, 0);
+
+    // We are done now, start the next test
+    run_next_test();
+});
+
 add_test(function test_removeModes() {
     function checkCounts(modes, shouldDelete, expectCount, extraFlags=0) {
         if (calmgr.calendarCount == baseCalendarCount) {
             calmgr.registerCalendar(memory);
             equal(calmgr.calendarCount, baseCalendarCount + 1);
         }
         deleteCalled = false;
         removeModes = modes;
--- a/calendar/test/unit/test_deleted_items.js
+++ b/calendar/test/unit/test_deleted_items.js
@@ -19,17 +19,17 @@ function check_delmgr_call(aFunc) {
             } else {
                 reject(aReason);
             };
         };
         aFunc();
     });
 }
 
-add_task(function test_deleted_items() {
+add_task(function* test_deleted_items() {
     let calmgr = cal.getCalendarManager();
     let delmgr = Components.classes["@mozilla.org/calendar/deleted-items-manager;1"]
                            .getService(Components.interfaces.calIDeletedItems);
     // No items have been deleted, retrieving one should return null.
     equal(delmgr.getDeletedDate("random"), null);
     equal(delmgr.getDeletedDate("random", "random"), null);
 
     // Make sure the cache is initially flushed and that this doesn't throw an