Bug 732372 - Search fails - a.contact is undefined in gloda.js. Part 2 - add some tests. r=bienvenu,a=Standard8 COMM110_20120307_RELBRANCH
authorAndrew Sutherland <bugmail@asutherland.org>
Thu, 08 Mar 2012 16:05:28 +0000
branchCOMM110_20120307_RELBRANCH
changeset 10253 3b9a5b68fdebc7b13439bb45a61e9809b6b88a11
parent 10252 ac82f70dfe844dd6495d8388ebc4f79f84bc13a1
child 10254 c79197dcbc30179fab5a23b357f7d15e40313704
push idunknown
push userunknown
push dateunknown
reviewersbienvenu, Standard8
bugs732372
Bug 732372 - Search fails - a.contact is undefined in gloda.js. Part 2 - add some tests. r=bienvenu,a=Standard8
mailnews/db/gloda/test/unit/base_index_messages.js
mailnews/db/gloda/test/unit/head_gloda.js
mailnews/db/gloda/test/unit/resources/glodaTestHelper.js
mailnews/db/gloda/test/unit/test_index_addressbook.js
--- a/mailnews/db/gloda/test/unit/base_index_messages.js
+++ b/mailnews/db/gloda/test/unit/base_index_messages.js
@@ -691,17 +691,44 @@ function test_attributes_cant_query() {
   yield sqlExpectCount(0, "SELECT COUNT(*) FROM messageAttributes WHERE attributeID = ?1",
                        readId);
 
   // -- Replied To
 
   // -- Forwarded
 }
 
-/* ===== Fulltext Indexing ===== */
+/**
+ * Have the participants be in our addressbook prior to indexing so that we can
+ *  verify that the hand-off to the addressbook indexer does not cause breakage.
+ */
+function test_people_in_addressbook() {
+  var senderPair = msgGen.makeNameAndAddress(),
+      recipPair = msgGen.makeNameAndAddress();
+  
+  // - add both people to the address book
+  makeABCardForAddressPair(senderPair);
+  makeABCardForAddressPair(recipPair);
+
+  let [folder, msgSet] = make_folder_with_sets([
+    { count: 1, to: [recipPair], from: senderPair }]);
+  yield wait_for_message_injection();
+  yield wait_for_gloda_indexer(msgSet, {augment: true});
+  let gmsg = msgSet.glodaMessages[0],
+      senderIdentity = gmsg.from,
+      recipIdentity = gmsg.to[0];
+
+  do_check_neq(senderIdentity.contact, null);
+  do_check_true(senderIdentity.inAddressBook);
+
+  do_check_neq(recipIdentity.contact, null);
+  do_check_true(recipIdentity.inAddressBook);
+}
+
+/* ===== fulltexts Indexing ===== */
 
 /**
  * Make sure that we are using the saneBodySize flag.  This is basically the
  *  test_sane_bodies test from test_mime_emitter but we pull the indexedBodyText
  *  off the message to check and also make sure that the text contents slice
  *  off the end rather than the beginning.
  */
 function test_streamed_bodies_are_size_capped() {
@@ -1225,16 +1252,18 @@ var tests = [
   test_threading,
   test_attachment_flag,
   test_attributes_fundamental,
   test_attributes_fundamental_from_disk,
   test_attributes_explicit,
   test_moved_message_attributes,
   test_attributes_cant_query,
 
+  test_people_in_addressbook,
+
   test_streamed_bodies_are_size_capped,
 
   test_imap_add_unread_to_folder,
   test_message_moving,
 
   test_message_deletion,
   test_moving_to_trash_marks_deletion,
   test_folder_nuking_message_deletion,
--- a/mailnews/db/gloda/test/unit/head_gloda.js
+++ b/mailnews/db/gloda/test/unit/head_gloda.js
@@ -1,4 +1,1 @@
 gDEPTH = "../../../../../";
-
-// Import the required setup scripts.
-load("../../../../resources/abSetup.js");
--- a/mailnews/db/gloda/test/unit/resources/glodaTestHelper.js
+++ b/mailnews/db/gloda/test/unit/resources/glodaTestHelper.js
@@ -48,19 +48,28 @@
  *  the function.
  * There is no need to tell us to expect the messages to be indexed prior to the
  *  waiting as long as nothing spins the event loop after you perform the action
  *  that triggers indexing.  None of our existing xpcshell tests do this, but it
  *  is part of the mozmill idiom for its waiting mechanism, so be sure to not
  *  perform a mozmill wait without first telling us to expect the messages.
  */
 
+// Services
+Components.utils.import("resource://gre/modules/Services.jsm");
+// MailServices
+Components.utils.import("resource:///modules/mailServices.js");
+
+Services.prefs.setCharPref("mail.serverDefaultStoreContractID",
+                           "@mozilla.org/msgstore/berkeleystore;1");
+
 // Import the main scripts that mailnews tests need to set up and tear down
 load("../../../../resources/mailDirService.js");
 load("../../../../resources/mailTestUtils.js");
+load("../../../../resources/abSetup.js");
 load("../../../../resources/logHelper.js");
 load("../../../../resources/asyncTestUtils.js");
 
 load("../../../../resources/messageGenerator.js");
 load("../../../../resources/messageModifier.js");
 load("../../../../resources/messageInjection.js");
 
 load("../../../../resources/folderEventLogHelper.js");
@@ -1262,8 +1271,31 @@ function nukeGlodaCachesAndCollections()
   // caches aren't intended to be cleared, but we also don't want to lose our
   //  caches, so we need to create new ones from the ashes of the old ones.
   let oldCaches = GlodaCollectionManager._cachesByNoun;
   GlodaCollectionManager._cachesByNoun = {};
   for each (let cache in oldCaches) {
     GlodaCollectionManager.defineCache(cache._nounDef, cache._maxCacheSize);
   }
 }
+
+
+/**
+ * Add a name-and-address pair as generated by `makeNameAndAddress` to the
+ *  personal address book.
+ */
+function makeABCardForAddressPair(nameAndAddress) {
+  let abManager = Components.classes["@mozilla.org/abmanager;1"]
+                            .getService(Components.interfaces.nsIAbManager);
+  // kPABData is from abSetup.js
+  let addressBook = abManager.getDirectory(kPABData.URI);
+
+  let card = Components.classes["@mozilla.org/addressbook/cardproperty;1"]
+                       .createInstance(Components.interfaces.nsIAbCard);
+  card.displayName = nameAndAddress[0];
+  card.primaryEmail = nameAndAddress[1];
+
+  // Just save the new node straight away.
+  addressBook.addCard(card);
+
+  mark_action("glodaTestHelper",
+              "adding address book card for:", nameAndAddress);
+}
--- a/mailnews/db/gloda/test/unit/test_index_addressbook.js
+++ b/mailnews/db/gloda/test/unit/test_index_addressbook.js
@@ -137,16 +137,17 @@ function test_remove_card_cache_indicati
   delete_card(EMAIL_ADDRESS);
 
   let identity = get_cached_gloda_identity_for_email(EMAIL_ADDRESS);
   do_check_eq(identity._hasAddressBookCard, false);
 }
 
 
 let tests = [
+  // - events update identity._hasAddressBookCard correctly
   setup_create_identity,
   test_add_card_cache_indication,
   test_remove_card_cache_indication,
   // add it back again
   test_add_card_cache_indication,
 ];
 
 function run_test() {