dom/contacts/tests/test_contacts_shutdown.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     3 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
     4 <!--
     5   Any copyright is dedicated to the Public Domain.
     6   http://creativecommons.org/publicdomain/zero/1.0/
     7 -->
     9 <window title="Mozilla Bug 945948"
    10         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    11   <script type="application/javascript"
    12           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    14   <script type="application/javascript;version=1.7">
    15   <![CDATA[
    16   "use strict";
    17   const { 'utils': Cu } = Components;
    18   Cu.import("resource://gre/modules/ContactService.jsm", window);
    20   //
    21   // Mock message manager
    22   //
    23   function MockMessageManager() { }
    24   MockMessageManager.prototype.assertPermission = function() { return true; };
    25   MockMessageManager.prototype.sendAsyncMessage = function(name, data) { };
    27   //
    28   // Mock ContactDB
    29   //
    30   function MockContactDB() { }
    31   MockContactDB.prototype.getAll = function(cb) {
    32     cb([]);
    33   };
    34   MockContactDB.prototype.clearDispatcher = function() { }
    35   MockContactDB.prototype.close = function() { }
    37   let realContactDB = ContactService._db;
    39   function before() {
    40     ok(true, "Install mock ContactDB object");
    41     ContactService._db = new MockContactDB();
    42   }
    44   function after() {
    45     ok(true, "Restore real ContactDB object");
    46     ContactService._db = realContactDB;
    47   }
    49   function steps() {
    50     let mm1 = new MockMessageManager();
    51     let mm2 = new MockMessageManager();
    53     is(ContactService._cursors.size, 0, "Verify clean contact init");
    55     ContactService.receiveMessage({
    56       target: mm1,
    57       name: "Contacts:GetAll",
    58       data: { cursorId: 1 },
    59       findOptions: {}
    60     });
    61     is(ContactService._cursors.size, 1, "Add contact cursor 1");
    63     ContactService.receiveMessage({
    64       target: mm2,
    65       name: "Contacts:GetAll",
    66       data: { cursorId: 2 },
    67       findOptions: {}
    68     });
    69     is(ContactService._cursors.size, 2, "Add contact cursor 2");
    71     ContactService.receiveMessage({
    72       target: mm1,
    73       name: "child-process-shutdown"
    74     });
    75     is(ContactService._cursors.size, 1, "Shutdown contact cursor 1");
    77     ContactService.receiveMessage({
    78       target: mm2,
    79       name: "child-process-shutdown"
    80     });
    81     is(ContactService._cursors.size, 0, "Shutdown contact cursor 2");
    82   }
    84   function runTests() {
    85     SimpleTest.waitForExplicitFinish();
    86     try {
    87       before();
    88       steps();
    89     } finally {
    90       after();
    91       SimpleTest.finish();
    92     }
    93   }
    95   runTests();
    96   ]]>
    97   </script>
    99   <body xmlns="http://www.w3.org/1999/xhtml">
   100   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=945948"
   101      target="_blank">Mozilla Bug 945948</a>
   102   </body>
   103 </window>

mercurial