|
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 --> |
|
8 |
|
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"/> |
|
13 |
|
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); |
|
19 |
|
20 // |
|
21 // Mock message manager |
|
22 // |
|
23 function MockMessageManager() { } |
|
24 MockMessageManager.prototype.assertPermission = function() { return true; }; |
|
25 MockMessageManager.prototype.sendAsyncMessage = function(name, data) { }; |
|
26 |
|
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() { } |
|
36 |
|
37 let realContactDB = ContactService._db; |
|
38 |
|
39 function before() { |
|
40 ok(true, "Install mock ContactDB object"); |
|
41 ContactService._db = new MockContactDB(); |
|
42 } |
|
43 |
|
44 function after() { |
|
45 ok(true, "Restore real ContactDB object"); |
|
46 ContactService._db = realContactDB; |
|
47 } |
|
48 |
|
49 function steps() { |
|
50 let mm1 = new MockMessageManager(); |
|
51 let mm2 = new MockMessageManager(); |
|
52 |
|
53 is(ContactService._cursors.size, 0, "Verify clean contact init"); |
|
54 |
|
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"); |
|
62 |
|
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"); |
|
70 |
|
71 ContactService.receiveMessage({ |
|
72 target: mm1, |
|
73 name: "child-process-shutdown" |
|
74 }); |
|
75 is(ContactService._cursors.size, 1, "Shutdown contact cursor 1"); |
|
76 |
|
77 ContactService.receiveMessage({ |
|
78 target: mm2, |
|
79 name: "child-process-shutdown" |
|
80 }); |
|
81 is(ContactService._cursors.size, 0, "Shutdown contact cursor 2"); |
|
82 } |
|
83 |
|
84 function runTests() { |
|
85 SimpleTest.waitForExplicitFinish(); |
|
86 try { |
|
87 before(); |
|
88 steps(); |
|
89 } finally { |
|
90 after(); |
|
91 SimpleTest.finish(); |
|
92 } |
|
93 } |
|
94 |
|
95 runTests(); |
|
96 ]]> |
|
97 </script> |
|
98 |
|
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> |