Bug 451952: activate double id check for mailnews; r=standard8, sr=neil, a=iann
authorKarsten Düsterloh <mnyromyr@tprac.de>
Wed, 17 Sep 2008 01:19:44 +0200
changeset 347 cb70018a34dc44107a5c212e7e8ac31713f0e231
parent 346 6798c5a94726258fa59a8106ce1ee718be76a95f
child 348 428ab4153a1ffc3a71946c8126811e0ca984fbc3
push idunknown
push userunknown
push dateunknown
reviewersstandard8, neil, iann
bugs451952
Bug 451952: activate double id check for mailnews; r=standard8, sr=neil, a=iann
suite/common/tests/chrome/Makefile.in
suite/common/tests/chrome/test_idcheck.xul
--- a/suite/common/tests/chrome/Makefile.in
+++ b/suite/common/tests/chrome/Makefile.in
@@ -40,12 +40,13 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = suite/common/tests/chrome
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES = 	test_idcheck.xul \
+		$(topsrcdir)/mailnews/test/resources/mailTestUtils.js \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(MOZDEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
--- a/suite/common/tests/chrome/test_idcheck.xul
+++ b/suite/common/tests/chrome/test_idcheck.xul
@@ -43,19 +43,24 @@
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         onload="RunTest();">
   <description>Chrome Window ID Checking Tests</description>
 
   <script type="application/javascript" 
           src="chrome://mochikit/content/MochiKit/packed.js"/>
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/chrome/suite/common/tests/chrome/mailTestUtils.js"/>
 
   <script type="application/javascript">
   <![CDATA[
+    // mailTestUtils.js requires these constants, so we may as well use them
+    const Cc = Components.classes;
+    const Ci = Components.interfaces;
     var gLoadedWindows = {};
 
     // Have all loaded windows been closed again?
     function AllWindowsClosed()
     {
       for each (var e in window.gLoadedWindows)
         return false;
       return true;
@@ -118,16 +123,27 @@
           todo(false, "disabled id checks: " + filename + "#" + id);
         }
       }
       
       // finally, close the loaded window
       aDocument.defaultView.close();
     }
 
+    function DisambiguateCharsetMenulist(aDocument, aListID, aPrefix)
+    {
+      let menulist = aDocument.getElementById(aListID)
+                              .getElementsByTagName("menuitem");
+      for each (let menuitem in menulist)
+      {
+        menuitem.id = aPrefix + menuitem.id;
+        menuitem = menuitem.nextSibling;
+      }
+    }
+
     function LoadPaneLoop(aDocument, aPanes, aPaneIndex, aForceLoad)
     {
       if (aPaneIndex < aPanes.length)
       {
         const WAIT_CYCLE = 10;
         // may need to load this pane
         let pane = aPanes[aPaneIndex];
         if (pane.loaded)
@@ -151,25 +167,22 @@
       }
       else
       {
         // All preference panes are loaded now!
 
         // The character_encoding_pane contains two template driven menulists
         // (viewDefaultCharsetList and sendDefaultCharsetList),
         // both of which autogenerate the *same* ids for their menuitems.
-        // We alter one set here to avoid unnecessary test failure.
+        // The same ids are generated by the charset list (defaultCharsetList)
+        // on the languages_pane, too.
+        // We alter two of these sets here to avoid unnecessary test failure.
         // (We probably should remove those RDF templates?)
-        let menulist = aDocument.getElementById("viewDefaultCharsetList")
-                                .getElementsByTagName("menuitem");
-        for each (let menuitem in menulist)
-        {
-          menuitem.id = 'test_idcheck.1.' + menuitem.id;
-          menuitem = menuitem.nextSibling;
-        }
+        DisambiguateCharsetMenulist(aDocument, "viewDefaultCharsetList", "test_idcheck.1.");
+        DisambiguateCharsetMenulist(aDocument, "sendDefaultCharsetList", "test_idcheck.2.");
 
         // now check the ids
         CheckIDs(aDocument, window.gLoadedWindows[aDocument.location.href]);
       }
     }
 
     function CheckPreferences()
     {
@@ -191,27 +204,47 @@
     {
       if (this.location.href in window.gLoadedWindows)
       {
         this.removeEventListener("unload", window.UncountWindow, false);
         delete window.gLoadedWindows[this.location.href];
       }
     }
 
+    function InitTest()
+    {
+      // fake a mail account to avoid the account creation wizard
+      loadLocalMailAccount();
+    }
+
+    function ExitTest()
+    {
+      // remove the mailnews data from the test profile
+      const kPrefService = "@mozilla.org/preferences-service;1";
+      Cc[kPrefService].getService(Ci.nsIPrefService).resetPrefs();
+    }
+
     function FinishTest()
     {
       if (AllWindowsClosed())
+      {
+        ExitTest();
         SimpleTest.finish();
+      }
       else
+      {
         setTimeout(FinishTest, 1000);
+      }
     }
 
     function RunTest()
     {
       SimpleTest.waitForExplicitFinish();
+      InitTest();
+
       // Basically, this test framework is generic enough to check arbitrary
       // chrome windows for doubled ids. But certain stuff like preferences
       // needs some extra processing.
       // The uriList members have the following format:
       //    "chrome://uri/of/xul.window":
       //    [
       //      check function,
       //      array of IDs to be ignored during in the test
@@ -226,47 +259,56 @@
           ],
 
         // Browser
         "chrome://navigator/content/navigator.xul":
           [
             window.CheckGenerics,
             ["contentAreaContextSet"]
           ],
-/* need mail account
+
+        /* MailNews and Addressbook need at least one mail account */
         // MailNews
         "chrome://messenger/content/messenger.xul":
           [
             window.CheckGenerics,
             []
           ],
+        "chrome://messenger/content/messageWindow.xul":
+          [
+            window.CheckGenerics,
+            []
+          ],
         "chrome://messenger/content/messengercompose/messengercompose.xul":
           [
             window.CheckGenerics,
             []
           ],
+
         // Addressbook
         "chrome://messenger/content/addressbook/addressbook.xul":
           [
             window.CheckGenerics,
             []
           ],
-*/
+
         // Composer
         "chrome://editor/content/editor.xul":
           [
             window.CheckGenerics,
             []
           ],
+
         // Error Console
         "chrome://global/content/console.xul":
           [
             window.CheckGenerics,
             []
           ],
+
 /* not available yet in chrome tests
         // Chatzilla
         "chrome://chatzilla/content/chatzilla.xul":
           [
             window.CheckGenerics,
             []
           ],
         // DOM Inspector