Bug 405007 - Create unittest buildbots for Calendar. r=mschroeder
authorPhilipp Kewisch <mozilla@kewis.ch>
Fri, 05 Aug 2011 21:00:48 +0200
changeset 8242 ec28666abc48ffbaa96b8bcbf1daf39fca9c4001
parent 8241 67346373f6d18bab7147a0b2178cf047957a46a3
child 8243 9cf88871ec0936c854ddd5b2f33e4ff844f6ad98
push id6338
push usermozilla@kewis.ch
push dateFri, 05 Aug 2011 19:14:54 +0000
treeherdercomm-central@9cf88871ec09 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmschroeder
bugs405007
Bug 405007 - Create unittest buildbots for Calendar. r=mschroeder
calendar/base/jar.mn
calendar/lightning/Makefile.in
calendar/providers/memory/calMemoryCalendar.js
calendar/providers/storage/calStorageCalendar.js
calendar/providers/storage/calStorageUpgrade.jsm
calendar/test/unit/head_consts.js
calendar/test/unit/xpcshell.ini
mail/test/xpcshell.ini
--- a/calendar/base/jar.mn
+++ b/calendar/base/jar.mn
@@ -1,10 +1,11 @@
 #filter substitution
 calendar.jar:
+% resource calendar .
 % content calendar %content/calendar/
     content/calendar/agenda-listbox.js                     (content/agenda-listbox.js)
     content/calendar/agenda-listbox.xml                    (content/agenda-listbox.xml)
     content/calendar/calendar-bindings.css                 (content/calendar-bindings.css)
     content/calendar/calendar-calendars-list.xul           (content/calendar-calendars-list.xul)
     content/calendar/calendar-chrome-startup.js            (content/calendar-chrome-startup.js)
     content/calendar/calendar-clipboard.js                 (content/calendar-clipboard.js)
 *   content/calendar/calendar-common-sets.xul              (content/calendar-common-sets.xul)
--- a/calendar/lightning/Makefile.in
+++ b/calendar/lightning/Makefile.in
@@ -111,16 +111,20 @@ DIRS = ../libical \
        ../base \
        ../providers \
        ../import-export \
        ../itip \
        components \
        locales \
        $(NULL)
 
+ifdef ENABLE_TESTS
+DIRS += ../test
+endif
+
 # Select a theme from which to pull our skin goodness
 # OS X: pinstripe
 # Others: winstripe
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 THEME=pinstripe
 else
 THEME=winstripe
 endif
@@ -135,16 +139,24 @@ DEFINES += -DTHUNDERBIRD_VERSION=$(THUND
            $(NULL)
 
 GRE_BUILDID = $(shell $(PYTHON) $(MOZILLA_SRCDIR)/config/printconfigsetting.py $(LIBXUL_DIST)/bin/platform.ini Build BuildID)
 DEFINES += -DGRE_BUILDID=$(GRE_BUILDID)
 
 # xxx todo: unless our packaging story is revised (bug 406579) we package up timezones.sqlite
 libs::
 	$(NSINSTALL) $(srcdir)/../timezones/timezones.sqlite $(FINAL_TARGET)
+ifdef ENABLE_TESTS
+	$(PYTHON) $(MOZILLA_DIR)/config/buildlist.py \
+		$(MOZDEPTH)/_tests/xpcshell/xpcshell.ini \
+		"[include:calendar/test/unit/xpcshell.ini]"
+	$(PYTHON) $(MOZILLA_DIR)/config/buildlist.py \
+		$(topsrcdir)/mail/test/xpcshell.ini \
+		"[include:calendar/test/unit/xpcshell.ini]"
+endif
 
 include $(topsrcdir)/config/rules.mk
 include $(srcdir)/lightning-packager.mk
 
 ident:
 	@printf "comm_revision "
 	@$(PYTHON) $(MOZILLA_SRCDIR)/config/printconfigsetting.py \
 	    $(FINAL_TARGET)/application.ini App SourceStamp
--- a/calendar/providers/memory/calMemoryCalendar.js
+++ b/calendar/providers/memory/calMemoryCalendar.js
@@ -101,23 +101,23 @@ calMemoryCalendar.prototype = {
     get displayName() {
         return cal.calGetString("calendar", "memoryName");
     },
 
     createCalendar: function mem_createCal() {
         throw NS_ERROR_NOT_IMPLEMENTED;
     },
 
-    deleteCalendar: function mem_deleteCal(cal, listener) {
-        cal = cal.wrappedJSObject;
-        cal.mItems = {};
-        cal.mMetaData = new cal.calPropertyBag();
+    deleteCalendar: function mem_deleteCal(calendar, listener) {
+        calendar = calendar.wrappedJSObject;
+        calendar.mItems = {};
+        calendar.mMetaData = new cal.calPropertyBag();
 
         try {
-            listener.onDeleteCalendar(cal, Components.results.NS_OK, null);
+            listener.onDeleteCalendar(calendar, Components.results.NS_OK, null);
         } catch(ex) {}
     },
 
     mRelaxedMode: undefined,
     get relaxedMode() {
         if (this.mRelaxedMode === undefined) {
             this.mRelaxedMode = this.getProperty("relaxedMode");
         }
--- a/calendar/providers/storage/calStorageCalendar.js
+++ b/calendar/providers/storage/calStorageCalendar.js
@@ -236,22 +236,23 @@ calStorageCalendar.prototype = {
 
     /**
      * Initialize the Database. This should only be called from the uri or id
      * setter and requires those two attributes to be set.
      */
     prepareInitDB: function cSC_prepareInitDB() {
         if (this.uri.schemeIs("file")) {
             let fileURL = this.uri.QueryInterface(Components.interfaces.nsIFileURL);
-            if (!fileURL)
-                throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
-
+            if (!fileURL) {
+                throw new Components.Exception("Invalid file", Components.results.NS_ERROR_NOT_IMPLEMENTED);
+            }
             // open the database
             this.mDB = Services.storage.openDatabase(fileURL.file);
             upgradeDB(this.mDB);
+
         } else if (this.uri.schemeIs("moz-profile-calendar")) {
             // This is an old-style moz-profile-calendar. It requires some
             // migration steps.
 
             let localDB = cal.getCalendarDirectory();
             localDB.append("local.sqlite");
             localDB = Services.storage.openDatabase(localDB);
 
@@ -392,16 +393,18 @@ calStorageCalendar.prototype = {
         } else if (this.uri.schemeIs("moz-storage-calendar")) {
             // New style uri, no need for migration here
             let localDB = cal.getCalendarDirectory();
             localDB.append("local.sqlite");
             localDB = Services.storage.openDatabase(localDB);
 
             this.mDB = localDB;
             upgradeDB(this.mDB);
+        } else {
+            throw new Components.Exception("Invalid Scheme " + this.uri.spec);
         }
 
         this.initDB();
     },
 
 
     /**
      * Takes care of necessary preparations for most of our statements.
@@ -2276,29 +2279,30 @@ calStorageCalendar.prototype = {
     },
 
     deleteMetaData: function cSC_deleteMetaData(id) {
         this.mDeleteMetaData(id, this.id);
     },
 
     getMetaData: function cSC_getMetaData(id) {
         let query = this.mSelectMetaData;
+        let value = null;
         try {
             this.prepareStatement(query);
             query.params.item_id = id;
-            let value = null;
 
             if (query.step()) {
                 value = query.row.value;
             }
         } catch (e) {
             this.logError("Error getting metadata for id " + id + "!", e);
         } finally {
             query.reset();
         }
+
         return value;
     },
 
     getAllMetaData: function cSC_getAllMetaData(out_count,
                                                  out_ids,
                                                  out_values) {
         let query = this.mSelectAllMetaData;
         try {
--- a/calendar/providers/storage/calStorageUpgrade.jsm
+++ b/calendar/providers/storage/calStorageUpgrade.jsm
@@ -405,17 +405,18 @@ function ensureUpdatedTimezones(db) {
     if (version) {
         versionComp = Components.classes["@mozilla.org/xpcom/version-comparator;1"]
                                 .getService(Components.interfaces.nsIVersionComparator)
                                 .compare(cal.getTimezoneService().version, version);
     }
 
     if (versionComp < 0) {
         // A timezones downgrade has happened!
-        throw Components.interfaces.calIErrors.STORAGE_UNKNOWN_TIMEZONES_ERROR;
+        throw new Components.Exception("Attempt to downgrade timezones",
+                                       Components.interfaces.calIErrors.STORAGE_UNKNOWN_TIMEZONES_ERROR);
     } else if (versionComp > 0) {
         cal.LOG("Timezones have been updated, updating calendar data.");
 
         let zonesToUpdate = [];
         let getZones = createStatement(db,
             "SELECT DISTINCT(zone) FROM ("+
             "SELECT recurrence_id_tz AS zone FROM cal_attendees    WHERE recurrence_id_tz IS NOT NULL UNION " +
             "SELECT recurrence_id_tz AS zone FROM cal_events       WHERE recurrence_id_tz IS NOT NULL UNION " +
--- a/calendar/test/unit/head_consts.js
+++ b/calendar/test/unit/head_consts.js
@@ -36,27 +36,31 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
-let protHandler = Components.classes["@mozilla.org/network/io-service;1"]
-                     .getService(Components.interfaces.nsIIOService2)
-                     .getProtocolHandler("resource")
-                     .QueryInterface(Components.interfaces.nsIResProtocolHandler);
-protHandler.setSubstitution("calendar", protHandler.getSubstitution("gre"));
+(function load_lightning_manifest() {
+  let bindir = Components.classes["@mozilla.org/file/directory_service;1"]
+                         .getService(Components.interfaces.nsIProperties)
+                         .get("CurProcD", Components.interfaces.nsIFile);
+  bindir.append("extensions");
+  bindir.append("{e2fda1a4-762b-4020-b5ad-a41df1933103}");
+  bindir.append("chrome.manifest");
+  Components.manager.autoRegister(bindir);
+})();
 
 Components.utils.import("resource://calendar/modules/calUtils.jsm");
 
 // we might want to use calUtils.jsm only in the future throughout all tests,
 // but for now source in good old calUtils.js:
-cal.loadScripts(["calUtils.js"], Components.utils.getGlobalForObject(protHandler));
+cal.loadScripts(["calUtils.js"], Components.utils.getGlobalForObject(Cc));
 
 function createDate(aYear, aMonth, aDay, aHasTime, aHour, aMinute, aSecond, aTimezone) {
     var cd = Cc["@mozilla.org/calendar/datetime;1"]
              .createInstance(Ci.calIDateTime);
     cd.resetTo(aYear,
                aMonth,
                aDay,
                aHour || 0,
@@ -108,29 +112,35 @@ function getStorageCal() {
     var dirSvc = Cc["@mozilla.org/file/directory_service;1"]
                  .getService(Ci.nsIProperties);
     var db = dirSvc.get("TmpD", Ci.nsIFile);
     db.append("test_storage.sqlite");
 
     // create URI
     var uri = cal.getIOService().newFileURI(db);
 
+    // Make sure timezone service is initialized
+    Components.classes["@mozilla.org/calendar/timezone-service;1"]
+              .getService(Components.interfaces.calIStartupService)
+              .startup(null);
+
     // create storage calendar
-    var cal = Cc["@mozilla.org/calendar/calendar;1?type=storage"]
+    var stor = Cc["@mozilla.org/calendar/calendar;1?type=storage"]
               .createInstance(Ci.calISyncWriteCalendar);
-    cal.uri = uri;
+    stor.uri = uri;
+    stor.id = cal.getUUID();
 
     // remove existing items
-    var calendar = cal.QueryInterface(Ci.calICalendarProvider);
+    var calendar = stor.QueryInterface(Ci.calICalendarProvider);
     try {
         calendar.deleteCalendar(calendar, null);
     } catch (e) {
         print("*** error purging calendar: " + e);
     }
-    return cal;
+    return stor;
 }
 
 /**
  * Return an item property as string.
  * @param aItem
  * @param string aProp possible item properties: start, end, duration,
  *                     generation, title,
  *                     id, calendar, creationDate, lastModifiedTime,
new file mode 100644
--- /dev/null
+++ b/calendar/test/unit/xpcshell.ini
@@ -0,0 +1,23 @@
+[DEFAULT]
+head = head_consts.js
+tail =
+
+[test_alarm.js]
+[test_attachment.js]
+[test_attendee.js]
+[test_bug272411.js]
+[test_bug343792.js]
+[test_bug350845.js]
+[test_bug356207.js]
+[test_bug485571.js]
+[test_bug486186.js]
+[test_bug494140.js]
+[test_bug668222.js]
+[test_datetime.js]
+[test_freebusy.js]
+[test_hashedarray.js]
+[test_ics.js]
+[test_providers.js]
+[test_recur.js]
+[test_relation.js]
+[test_webcal.js]
--- a/mail/test/xpcshell.ini
+++ b/mail/test/xpcshell.ini
@@ -18,8 +18,9 @@ run-if.os = mac
 [include:mail/steel/notmac/xpcshell.ini]
 skip-if.os = mac
 
 [include:mail/components/test/unit/xpcshell.ini]
 [include:ldap/xpcom/tests/unit/xpcshell.ini]
 
 # Include all the core tests.
 [include:xpcshell-core.ini]
+[include:calendar/test/unit/xpcshell.ini]