Bug 945948 - Part 2: Test contacts shutdown of cursors. r=reuben, a=1.3+
authorBen Kelly <ben@wanderview.com>
Thu, 12 Dec 2013 17:05:18 -0500
changeset 175248 18037644cdec33c4a59756086fa7dfbbef3fc70f
parent 175247 8ec38365f7cc61922b58b953cc18048d8c862366
child 175249 3b49d533319a0075a6342f3fdfadf2f9b45a3679
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersreuben, 1
bugs945948
milestone28.0a2
Bug 945948 - Part 2: Test contacts shutdown of cursors. r=reuben, a=1.3+
dom/contacts/fallback/ContactService.jsm
dom/contacts/tests/chrome.ini
dom/contacts/tests/test_contacts_shutdown.xul
--- a/dom/contacts/fallback/ContactService.jsm
+++ b/dom/contacts/fallback/ContactService.jsm
@@ -6,17 +6,17 @@
 
 const DEBUG = false;
 function debug(s) { dump("-*- Fallback ContactService component: " + s + "\n"); }
 
 const Cu = Components.utils;
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
-this.EXPORTED_SYMBOLS = [];
+this.EXPORTED_SYMBOLS = ["ContactService"];
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/ContactDB.jsm");
 Cu.import("resource://gre/modules/PhoneNumberUtils.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
                                    "@mozilla.org/parentprocessmessagemanager;1",
--- a/dom/contacts/tests/chrome.ini
+++ b/dom/contacts/tests/chrome.ini
@@ -1,3 +1,6 @@
 [DEFAULT]
 
+[test_contacts_shutdown.xul]
+skip-if = os == "android"
+
 [test_contacts_upgrade.xul]
new file mode 100644
--- /dev/null
+++ b/dom/contacts/tests/test_contacts_shutdown.xul
@@ -0,0 +1,103 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+
+<window title="Mozilla Bug 945948"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+  <script type="application/javascript;version=1.7">
+  <![CDATA[
+  "use strict";
+  const { 'utils': Cu } = Components;
+  Cu.import("resource://gre/modules/ContactService.jsm", window);
+
+  //
+  // Mock message manager
+  //
+  function MockMessageManager() { }
+  MockMessageManager.prototype.assertPermission = function() { return true; };
+  MockMessageManager.prototype.sendAsyncMessage = function(name, data) { };
+
+  //
+  // Mock ContactDB
+  //
+  function MockContactDB() { }
+  MockContactDB.prototype.getAll = function(cb) {
+    cb([]);
+  };
+  MockContactDB.prototype.clearDispatcher = function() { }
+  MockContactDB.prototype.close = function() { }
+
+  let realContactDB = ContactService._db;
+
+  function before() {
+    ok(true, "Install mock ContactDB object");
+    ContactService._db = new MockContactDB();
+  }
+
+  function after() {
+    ok(true, "Restore real ContactDB object");
+    ContactService._db = realContactDB;
+  }
+
+  function steps() {
+    let mm1 = new MockMessageManager();
+    let mm2 = new MockMessageManager();
+
+    is(ContactService._cursors.size, 0, "Verify clean contact init");
+
+    ContactService.receiveMessage({
+      target: mm1,
+      name: "Contacts:GetAll",
+      data: { cursorId: 1 },
+      findOptions: {}
+    });
+    is(ContactService._cursors.size, 1, "Add contact cursor 1");
+
+    ContactService.receiveMessage({
+      target: mm2,
+      name: "Contacts:GetAll",
+      data: { cursorId: 2 },
+      findOptions: {}
+    });
+    is(ContactService._cursors.size, 2, "Add contact cursor 2");
+
+    ContactService.receiveMessage({
+      target: mm1,
+      name: "child-process-shutdown"
+    });
+    is(ContactService._cursors.size, 1, "Shutdown contact cursor 1");
+
+    ContactService.receiveMessage({
+      target: mm2,
+      name: "child-process-shutdown"
+    });
+    is(ContactService._cursors.size, 0, "Shutdown contact cursor 2");
+  }
+
+  function runTests() {
+    SimpleTest.waitForExplicitFinish();
+    try {
+      before();
+      steps();
+    } finally {
+      after();
+      SimpleTest.finish();
+    }
+  }
+
+  runTests();
+  ]]>
+  </script>
+
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=945948"
+     target="_blank">Mozilla Bug 945948</a>
+  </body>
+</window>