Fix bug 1258835 - Give tests easier means to spin up calendar services. r=darktrojan
authorPhilipp Kewisch <mozilla@kewis.ch>
Wed, 13 Apr 2016 21:53:35 +0200
changeset 19221 69b4c4164312c107137efa4fae17c63608fa30d1
parent 19220 307947d546f5e3466ba6ab33405910301bcf16a8
child 19222 f2ceef87101203f6113998b279c923280121bc64
push id11800
push useracelists@atlas.sk
push dateThu, 14 Apr 2016 17:49:32 +0000
treeherdercomm-central@69b4c4164312 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdarktrojan
bugs1258835
Fix bug 1258835 - Give tests easier means to spin up calendar services. r=darktrojan
calendar/base/src/calStartupService.js
calendar/test/unit/head_consts.js
calendar/test/unit/test_alarmservice.js
calendar/test/unit/test_alarmutils.js
calendar/test/unit/test_bug343792.js
calendar/test/unit/test_bug356207.js
calendar/test/unit/test_calmgr.js
calendar/test/unit/test_datetime.js
calendar/test/unit/test_deleted_items.js
calendar/test/unit/test_freebusy.js
calendar/test/unit/test_freebusy_service.js
calendar/test/unit/test_gdata_provider.js
calendar/test/unit/test_ics_parser.js
calendar/test/unit/test_ics_service.js
calendar/test/unit/test_items.js
calendar/test/unit/test_ltninvitationutils.js
calendar/test/unit/test_recur.js
calendar/test/unit/test_rfc3339_parser.js
calendar/test/unit/test_storage.js
calendar/test/unit/test_timezone_definition.js
calendar/test/unit/test_utils.js
--- a/calendar/base/src/calStartupService.js
+++ b/calendar/base/src/calStartupService.js
@@ -49,39 +49,44 @@ calStartupService.prototype = {
      * Sets up the needed observers for noticing startup/shutdown
      */
     setupObservers: function ccm_setUpStartupObservers() {
         Services.obs.addObserver(this, "profile-after-change", false);
         Services.obs.addObserver(this, "profile-before-change", false);
         Services.obs.addObserver(this, "xpcom-shutdown", false);
     },
 
+    started: false,
+
     /**
      * Gets the startup order of services. This is an array of service objects
      * that should be called in order at startup.
      *
      * @return      The startup order as an array.
      */
     getStartupOrder: function getStartupOrder() {
+        let self = this;
         let tzService = Components.classes["@mozilla.org/calendar/timezone-service;1"]
                                   .getService(Components.interfaces.calITimezoneService);
         let calMgr = Components.classes["@mozilla.org/calendar/manager;1"]
                                .getService(Components.interfaces.calICalendarManager);
 
         // Notification object
         let notify = {
             startup: function(aCompleteListener) {
+                self.started = true;
                 Services.obs.notifyObservers(null, "calendar-startup-done", null);
                 aCompleteListener.onResult(null, Components.results.NS_OK);
             },
             shutdown: function shutdown(aCompleteListener) {
                 // Argh, it would have all been so pretty! Since we just reverse
                 // the array, the shutdown notification would happen before the
                 // other shutdown calls. For lack of pretty code, I'm
                 // leaving this out! Users can still listen to xpcom-shutdown.
+                self.started = false;
                 aCompleteListener.onResult(null, Components.results.NS_OK);
             }
         };
 
         // We need to spin up the timezone service before the calendar manager
         // to ensure we have the timezones initialized. Make sure "notify" is
         // last in this array!
         return [tzService, calMgr, notify];
--- a/calendar/test/unit/head_consts.js
+++ b/calendar/test/unit/head_consts.js
@@ -200,8 +200,47 @@ function readJSONFile(aFile) {
       return data;
   } catch(ex) {
       dump("readJSONFile: Error reading JSON file: " + ex);
   } finally {
       stream.close();
   }
   return false;
 }
+
+function do_load_timezoneservice(callback) {
+    do_test_pending();
+    cal.getTimezoneService().startup({onResult: function() {
+        do_test_finished();
+        callback();
+    }});
+}
+
+function do_load_calmgr(callback) {
+    do_test_pending();
+    cal.getCalendarManager().startup({onResult: function() {
+        do_test_finished();
+        callback();
+    }});
+}
+
+function do_calendar_startup(callback) {
+    let obs = {
+      observe: function() {
+        Services.obs.removeObserver(this, "calendar-startup-done");
+        do_execute_soon(callback);
+      }
+    };
+
+    let ss = Components.classes['@mozilla.org/calendar/startup-service;1']
+                       .getService(Components.interfaces.nsISupports).wrappedJSObject;
+
+    if (ss.started) {
+        callback();
+    } else {
+        Services.obs.addObserver(obs, "calendar-startup-done", false);
+        if (_profileInitialized) {
+            Services.obs.notifyObservers(null, "profile-after-change", "xpcshell-do-get-profile");
+        } else {
+            do_get_profile(true);
+        }
+    }
+}
--- a/calendar/test/unit/test_alarmservice.js
+++ b/calendar/test/unit/test_alarmservice.js
@@ -109,37 +109,34 @@ var alarmObserver = {
 };
 
 function run_test() {
     do_get_profile();
 
     add_test(() => {
         // initialization needs to be done within the first test in order for
         // the subsequent tests to run properly
-        initializeAlarmService();
-        cal.getCalendarManager().startup({onResult: function() {
-            cal.getTimezoneService().startup({onResult: function() {
-                run_next_test();
-            }});
-        }});
+        do_calendar_startup(function() {
+            initializeAlarmService();
+            run_next_test();
+        });
     });
     add_test(test_addItems);
     add_test(test_loadCalendar);
     add_test(test_modifyItems);
 
     run_next_test();
 }
 
 function initializeAlarmService() {
     alarmObserver.service = Components.classes["@mozilla.org/calendar/alarm-service;1"]
                                        .getService(Components.interfaces.calIAlarmService)
                                        .wrappedJSObject;
     ok(!alarmObserver.service.mStarted);
-
-    alarmObserver.service.startup();
+    alarmObserver.service.startup(null);
     ok(alarmObserver.service.mStarted);
 
     // we need to replace the existing observers with our observer
     for (let obs of alarmObserver.service.mObservers.mInterfaces) {
         alarmObserver.service.removeObserver(obs);
     }
     alarmObserver.service.addObserver(alarmObserver);
 }
--- a/calendar/test/unit/test_alarmutils.js
+++ b/calendar/test/unit/test_alarmutils.js
@@ -3,24 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://calendar/modules/calAlarmUtils.jsm");
 Components.utils.import("resource://gre/modules/Preferences.jsm");
 Components.utils.import("resource://calendar/modules/calUtils.jsm");
 Components.utils.import("resource://calendar/modules/calXMLUtils.jsm");
 
 function run_test() {
-    do_get_profile();
-    do_test_pending();
-    cal.getCalendarManager().startup({onResult: function() {
-        cal.getTimezoneService().startup({onResult: function() {
-            do_test_finished();
-            run_next_test();
-        }});
-    }});
+    do_calendar_startup(run_next_test);
 }
 
 add_task(function* test_setDefaultValues_events() {
     let item, alarm;
 
     Preferences.set("calendar.alarms.onforevents", 1);
     Preferences.set("calendar.alarms.eventalarmunit", "hours");
     Preferences.set("calendar.alarms.eventalarmlen", 60);
--- a/calendar/test/unit/test_bug343792.js
+++ b/calendar/test/unit/test_bug343792.js
@@ -1,13 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function run_test() {
+    do_calendar_startup(really_run_test);
+}
+
+function really_run_test() {
     // Check that Bug 343792 doesn't regress:
     // Freeze (hang) on RRULE which has INTERVAL=0
 
     let icalString =
         "BEGIN:VCALENDAR\n" +
         "CALSCALE:GREGORIAN\n" +
         "PRODID:-//Ximian//NONSGML Evolution Calendar//EN\n" +
         "VERSION:2.0\n" +
--- a/calendar/test/unit/test_bug356207.js
+++ b/calendar/test/unit/test_bug356207.js
@@ -1,13 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function run_test() {
+    do_calendar_startup(really_run_test);
+}
+
+function really_run_test() {
     // Check that Bug 356207 doesn't regress:
     // Freeze (hang) on RRULE which has BYMONTHDAY and BYDAY
 
     let icalString =
         "BEGIN:VCALENDAR\n" +
         "PRODID:-//Randy L Pearson//NONSGML Outlook2vCal V1.1//EN\n" +
         "VERSION:2.0\n" +
         "BEGIN:VEVENT\n" +
--- a/calendar/test/unit/test_calmgr.js
+++ b/calendar/test/unit/test_calmgr.js
@@ -4,29 +4,20 @@
 
 Components.utils.import("resource://calendar/modules/calUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 /**
  * Tests the calICalendarManager interface
  */
 function run_test() {
-    do_get_profile();
-    // Initialize the floating timezone without actually starting the service.
-    cal.getTimezoneService().floating;
-    add_test(test_registration);
-    add_test(test_calobserver);
-    add_test(test_calprefs);
-    add_test(test_removeModes);
-    cal.getCalendarManager().startup({ onResult: function() {
-        run_next_test();
-    }});
+    do_calendar_startup(run_next_test);
 }
 
-function test_calobserver() {
+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();
@@ -95,19 +86,19 @@ function test_calobserver() {
     // 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();
-}
+});
 
-function test_registration() {
+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);
         equal(unregistered, unreg);
@@ -187,19 +178,19 @@ function test_registration() {
     calmgr.removeCalendar(memory);
     memory.setProperty("readOnly", false);
     checkRegistration(false, false, false);
     equal(readOnly, true);
     checkCalendarCount(0, 0, 0);
 
     // We are done now, start the next test
     run_next_test();
-}
+});
 
-function test_removeModes() {
+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;
 
@@ -238,19 +229,19 @@ function test_removeModes() {
 
     checkCounts([], SHOULD_NOT_DELETE, 1);
     checkCounts(["unsubscribe"], SHOULD_NOT_DELETE, 0);
     checkCounts(["unsubscribe", "delete"], SHOULD_DELETE, 0);
     checkCounts(["unsubscribe", "delete"], SHOULD_NOT_DELETE, 0, cICM.REMOVE_NO_DELETE);
     checkCounts(["delete"], SHOULD_DELETE, 0);
 
     run_next_test();
-}
+});
 
-function test_calprefs() {
+add_test(function test_calprefs() {
     let prop;
     let calmgr = cal.getCalendarManager();
     let memory = calmgr.createCalendar("memory", Services.io.newURI("moz-memory-calendar://", null, null));
     calmgr.registerCalendar(memory);
     let memid = memory.id;
 
     // First set a few values, one of each relevant type
     memory.setProperty("stringpref", "abc");
@@ -301,9 +292,9 @@ function test_calprefs() {
     memory = calmgr.createCalendar("memory", Services.io.newURI("moz-memory-calendar://", null, null));
     memory.id = memid;
     prop = memory.getProperty("intpref");
     ok(prop === null);
 
 
     // We are done now, start the next test
     run_next_test();
-}
+});
--- a/calendar/test/unit/test_datetime.js
+++ b/calendar/test/unit/test_datetime.js
@@ -1,20 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function run_test() {
-    do_test_pending();
-    cal.getTimezoneService().startup({
-        onResult: function() {
-            really_run_test();
-            do_test_finished();
-        }
-    });
+    do_calendar_startup(really_run_test);
 }
 
 function really_run_test() {
     function getMozTimezone(tzid) {
         return cal.getTimezoneService().getTimezone(tzid);
     }
 
     let cd = cal.createDateTime();
--- a/calendar/test/unit/test_deleted_items.js
+++ b/calendar/test/unit/test_deleted_items.js
@@ -1,25 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://gre/modules/Promise.jsm");
 
 function run_test() {
-    do_get_profile();
-    // Initialize the floating timezone without actually starting the service.
-    cal.getTimezoneService().floating;
-    let delmgr = Components.classes["@mozilla.org/calendar/deleted-items-manager;1"]
-                           .getService(Components.interfaces.calIDeletedItems);
-    delmgr.observe(null, "profile-after-change", null);
-
-    cal.getCalendarManager().startup({ onResult: function() {
-        run_next_test();
-    }});
+    do_calendar_startup(run_next_test);
 }
 
 function check_delmgr_call(aFunc) {
     const mISSC = Components.interfaces.mozIStorageStatementCallback;
     let delmgr = Components.classes["@mozilla.org/calendar/deleted-items-manager;1"]
                            .getService(Components.interfaces.calIDeletedItems);
     return new Promise(function(resolve, reject) {
         delmgr.wrappedJSObject.completedNotifier.handleCompletion = (aReason) => {
--- a/calendar/test/unit/test_freebusy.js
+++ b/calendar/test/unit/test_freebusy.js
@@ -1,13 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function run_test() {
+    do_calendar_startup(really_run_test);
+}
+
+function really_run_test() {
     test_freebusy();
     test_period();
 }
 
 function test_freebusy() {
     var icsService = Components.classes["@mozilla.org/calendar/ics-service;1"]
                                .getService(Components.interfaces.calIICSService);
 
--- a/calendar/test/unit/test_freebusy_service.js
+++ b/calendar/test/unit/test_freebusy_service.js
@@ -5,16 +5,20 @@
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://calendar/modules/calProviderUtils.jsm");
 
 var cIFI = Components.interfaces.calIFreeBusyInterval;
 var freebusy = Components.classes["@mozilla.org/calendar/freebusy-service;1"]
                          .getService(Components.interfaces.calIFreeBusyService);
 
 function run_test() {
+    do_calendar_startup(really_run_test);
+}
+
+function really_run_test() {
     test_found();
     test_failure();
     test_cancel();
 }
 
 function test_found() {
     _clearProviders();
 
--- a/calendar/test/unit/test_gdata_provider.js
+++ b/calendar/test/unit/test_gdata_provider.js
@@ -443,26 +443,19 @@ function getAllMeta(calendar) {
     let keys = {}, values = {};
     calendar.getAllMetaData({}, keys, values);
     return new Map(keys.value.map((k,i) => [k,values.value[i]]));
 }
 
 function run_test() {
     replaceAlertsService();
 
-    do_get_profile();
-    do_test_pending();
-    cal.getCalendarManager().startup({onResult: function() {
-        gServer = new GDataServer("xpcshell@example.com", "tasksId");
-        gServer.start();
-        cal.getTimezoneService().startup({onResult: function() {
-            run_next_test();
-            do_test_finished();
-        }});
-    }});
+    gServer = new GDataServer("xpcshell@example.com", "tasksId");
+    gServer.start();
+    do_calendar_startup(run_next_test);
 }
 
 add_task(function* test_migrate_cache() {
     let uriString = "googleapi://xpcshell/?calendar=xpcshell%40example.com";
     let uri = Services.io.newURI(uriString, null, null);
     let client = cal.getCalendarManager().createCalendar("gdata", uri);
     let unwrapped = client.wrappedJSObject;
     let migrateStorageCache = unwrapped.migrateStorageCache.bind(unwrapped);
--- a/calendar/test/unit/test_ics_parser.js
+++ b/calendar/test/unit/test_ics_parser.js
@@ -1,13 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function run_test() {
+    do_calendar_startup(really_run_test);
+}
+
+function really_run_test() {
     test_roundtrip();
     test_async();
     if (Preferences.get("calendar.icaljs", false)) test_failures();
     test_fake_parent();
     test_props_comps();
     test_timezone();
 }
 
--- a/calendar/test/unit/test_ics_service.js
+++ b/calendar/test/unit/test_ics_service.js
@@ -1,13 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function run_test() {
+    do_calendar_startup(really_run_test);
+}
+
+function really_run_test() {
     test_iterator();
     test_icalcomponent();
     test_icsservice();
     test_icalstring();
     test_param();
 
     // Only supported with ical.js
     if (Preferences.get("calendar.icaljs", false)) test_icalproperty();
--- a/calendar/test/unit/test_items.js
+++ b/calendar/test/unit/test_items.js
@@ -1,22 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function run_test() {
-    do_test_pending();
-    cal.getTimezoneService().startup({
-        onResult: function() {
-            really_run_test();
-            do_test_finished();
-        }
-    });
+    do_calendar_startup(really_run_test);
 }
 
 function really_run_test() {
     test_aclmanager();
     test_calendar();
     test_immutable();
     test_attendee();
     test_attachment();
--- a/calendar/test/unit/test_ltninvitationutils.js
+++ b/calendar/test/unit/test_ltninvitationutils.js
@@ -3,22 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://calendar/modules/calXMLUtils.jsm");
 Components.utils.import("resource://calendar/modules/ltnInvitationUtils.jsm");
 Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource://gre/modules/Preferences.jsm");
 
 function run_test() {
-    do_test_pending();
-    //do_get_profile();
-    cal.getTimezoneService().startup({onResult: function() {
-        do_test_finished();
-        run_next_test();
-    }});
+    do_calendar_startup(run_next_test);
 }
 
 // tests for ltnInvitationUtils.jsm
 
 function getIcs() {
     // we use an unfolded ics blueprint here to make replacing of properties easier
     return [
         "BEGIN:VCALENDAR",
--- a/calendar/test/unit/test_recur.js
+++ b/calendar/test/unit/test_recur.js
@@ -2,23 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function makeEvent(str) {
     return createEventFromIcalString("BEGIN:VEVENT\n" + str + "END:VEVENT");
 }
 
 function run_test() {
-    do_test_pending();
-    cal.getTimezoneService().startup({
-        onResult: function() {
-            really_run_test();
-            do_test_finished();
-        }
-    });
+    do_calendar_startup(really_run_test);
 }
 
 function really_run_test() {
     test_interface();
     test_rrule_interface();
     test_rules();
     test_failures();
     test_limit();
--- a/calendar/test/unit/test_rfc3339_parser.js
+++ b/calendar/test/unit/test_rfc3339_parser.js
@@ -1,22 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://calendar/modules/calProviderUtils.jsm");
 
 function run_test() {
-    do_test_pending();
-    cal.getTimezoneService().startup({
-        onResult: function() {
-            really_run_test();
-            do_test_finished();
-        }
-    });
+    do_calendar_startup(really_run_test);
 }
 
 function really_run_test() {
     // Check if the RFC 3339 date and timezone are properly parsed to the
     // expected result and if the result is properly mapped back into the RFC
     // 3339 date.
     function testRfc3339(aRfc3339Date, aTimezone, aExpectedDateTime,
                           aExpectedRfc3339Date=aRfc3339Date) {
--- a/calendar/test/unit/test_storage.js
+++ b/calendar/test/unit/test_storage.js
@@ -1,23 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function run_test() {
-    do_test_pending();
-    cal.getTimezoneService().startup({
-        onResult: function() {
-            testAttachRoundtrip();
-            do_test_finished();
-        }
-    });
+    do_calendar_startup(run_next_test);
 }
 
-function testAttachRoundtrip() {
+add_test(function testAttachRoundtrip() {
     let storage = getStorageCal();
     let str = ["BEGIN:VEVENT",
                "UID:attachItem",
                "DTSTART:20120101T010101Z",
                "ATTACH;FMTTYPE=text/calendar;ENCODING=BASE64;FILENAME=test.ics:http://example.com/test.ics",
                "ATTENDEE;RSVP=TRUE;CUTYPE=INDIVIDUAL;CN=Name;PARTSTAT=ACCEPTED;ROLE=REQ-PARTICIPANT;X-THING=BAR:mailto:test@example.com",
                "RELATED-TO;RELTYPE=SIBLING;FOO=BAR:VALUE",
                "RRULE:FREQ=MONTHLY;INTERVAL=2;COUNT=5;BYDAY=MO",
@@ -98,11 +92,12 @@ function testAttachRoundtrip() {
 
             this.found = true;
         },
         onOperationComplete: function() {
             if (!this.found) {
                 do_throw("Could not find item");
             }
             do_test_finished();
+            run_next_test();
         }
     };
-}
+});
--- a/calendar/test/unit/test_timezone_definition.js
+++ b/calendar/test/unit/test_timezone_definition.js
@@ -1,18 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function run_test() {
-    do_test_pending();
-    cal.getTimezoneService().startup({onResult: function() {
-        do_test_finished();
-        run_next_test();
-    }});
+    do_calendar_startup(run_next_test);
 }
 
 /**
  * Checks whether the pased string is a valid tz version number
  * @param    {String}         aVersionString
  * @returns  {boolean}
  */
 function valid_tz_version(aVersionString) {
--- a/calendar/test/unit/test_utils.js
+++ b/calendar/test/unit/test_utils.js
@@ -1,20 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function run_test() {
-    do_test_pending();
-    cal.getTimezoneService().startup({
-        onResult: function() {
-            really_run_test();
-            do_test_finished();
-        }
-    });
+    do_calendar_startup(really_run_test);
 }
 
 function really_run_test() {
     test_recentzones();
     test_formatcss();
     test_attendeeMatchesAddresses();
     test_getDefaultStartDate();
     test_getStartEndProps();