dom/contacts/tests/test_contacts_shutdown.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/contacts/tests/test_contacts_shutdown.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     1.6 +<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
     1.7 +<!--
     1.8 +  Any copyright is dedicated to the Public Domain.
     1.9 +  http://creativecommons.org/publicdomain/zero/1.0/
    1.10 +-->
    1.11 +
    1.12 +<window title="Mozilla Bug 945948"
    1.13 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.14 +  <script type="application/javascript"
    1.15 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.16 +
    1.17 +  <script type="application/javascript;version=1.7">
    1.18 +  <![CDATA[
    1.19 +  "use strict";
    1.20 +  const { 'utils': Cu } = Components;
    1.21 +  Cu.import("resource://gre/modules/ContactService.jsm", window);
    1.22 +
    1.23 +  //
    1.24 +  // Mock message manager
    1.25 +  //
    1.26 +  function MockMessageManager() { }
    1.27 +  MockMessageManager.prototype.assertPermission = function() { return true; };
    1.28 +  MockMessageManager.prototype.sendAsyncMessage = function(name, data) { };
    1.29 +
    1.30 +  //
    1.31 +  // Mock ContactDB
    1.32 +  //
    1.33 +  function MockContactDB() { }
    1.34 +  MockContactDB.prototype.getAll = function(cb) {
    1.35 +    cb([]);
    1.36 +  };
    1.37 +  MockContactDB.prototype.clearDispatcher = function() { }
    1.38 +  MockContactDB.prototype.close = function() { }
    1.39 +
    1.40 +  let realContactDB = ContactService._db;
    1.41 +
    1.42 +  function before() {
    1.43 +    ok(true, "Install mock ContactDB object");
    1.44 +    ContactService._db = new MockContactDB();
    1.45 +  }
    1.46 +
    1.47 +  function after() {
    1.48 +    ok(true, "Restore real ContactDB object");
    1.49 +    ContactService._db = realContactDB;
    1.50 +  }
    1.51 +
    1.52 +  function steps() {
    1.53 +    let mm1 = new MockMessageManager();
    1.54 +    let mm2 = new MockMessageManager();
    1.55 +
    1.56 +    is(ContactService._cursors.size, 0, "Verify clean contact init");
    1.57 +
    1.58 +    ContactService.receiveMessage({
    1.59 +      target: mm1,
    1.60 +      name: "Contacts:GetAll",
    1.61 +      data: { cursorId: 1 },
    1.62 +      findOptions: {}
    1.63 +    });
    1.64 +    is(ContactService._cursors.size, 1, "Add contact cursor 1");
    1.65 +
    1.66 +    ContactService.receiveMessage({
    1.67 +      target: mm2,
    1.68 +      name: "Contacts:GetAll",
    1.69 +      data: { cursorId: 2 },
    1.70 +      findOptions: {}
    1.71 +    });
    1.72 +    is(ContactService._cursors.size, 2, "Add contact cursor 2");
    1.73 +
    1.74 +    ContactService.receiveMessage({
    1.75 +      target: mm1,
    1.76 +      name: "child-process-shutdown"
    1.77 +    });
    1.78 +    is(ContactService._cursors.size, 1, "Shutdown contact cursor 1");
    1.79 +
    1.80 +    ContactService.receiveMessage({
    1.81 +      target: mm2,
    1.82 +      name: "child-process-shutdown"
    1.83 +    });
    1.84 +    is(ContactService._cursors.size, 0, "Shutdown contact cursor 2");
    1.85 +  }
    1.86 +
    1.87 +  function runTests() {
    1.88 +    SimpleTest.waitForExplicitFinish();
    1.89 +    try {
    1.90 +      before();
    1.91 +      steps();
    1.92 +    } finally {
    1.93 +      after();
    1.94 +      SimpleTest.finish();
    1.95 +    }
    1.96 +  }
    1.97 +
    1.98 +  runTests();
    1.99 +  ]]>
   1.100 +  </script>
   1.101 +
   1.102 +  <body xmlns="http://www.w3.org/1999/xhtml">
   1.103 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=945948"
   1.104 +     target="_blank">Mozilla Bug 945948</a>
   1.105 +  </body>
   1.106 +</window>

mercurial