|
1 <!DOCTYPE html> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=836519 |
|
5 --> |
|
6 <head> |
|
7 <title>Mozilla Bug 836519</title> |
|
8 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
|
9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
11 </head> |
|
12 <body> |
|
13 |
|
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=836519">Mozilla Bug 836519</a> |
|
15 <p id="display"></p> |
|
16 <div id="content" style="display: none"> |
|
17 |
|
18 </div> |
|
19 <pre id="test"> |
|
20 <script type="text/javascript;version=1.8" src="http://mochi.test:8888/tests/dom/contacts/tests/shared.js"></script> |
|
21 <script class="testbody" type="text/javascript;version=1.8"> |
|
22 "use strict"; |
|
23 |
|
24 let req; |
|
25 |
|
26 let steps = [ |
|
27 function start() { |
|
28 SpecialPowers.Cc["@mozilla.org/tools/profiler;1"].getService(SpecialPowers.Ci.nsIProfiler).AddMarker("GETALL_START"); |
|
29 next(); |
|
30 }, |
|
31 clearDatabase, |
|
32 addContacts, |
|
33 |
|
34 function() { |
|
35 ok(true, "Delete the current contact while iterating"); |
|
36 req = mozContacts.getAll({}); |
|
37 let count = 0; |
|
38 let previousId = null; |
|
39 req.onsuccess = function() { |
|
40 if (req.result) { |
|
41 ok(true, "on success"); |
|
42 if (previousId) { |
|
43 isnot(previousId, req.result.id, "different contacts returned"); |
|
44 } |
|
45 previousId = req.result.id; |
|
46 count++; |
|
47 let delReq = mozContacts.remove(req.result); |
|
48 delReq.onsuccess = function() { |
|
49 ok(true, "deleted current contact"); |
|
50 req.continue(); |
|
51 }; |
|
52 } else { |
|
53 is(count, 40, "returned 40 contacts"); |
|
54 next(); |
|
55 } |
|
56 }; |
|
57 }, |
|
58 |
|
59 clearDatabase, |
|
60 addContacts, |
|
61 |
|
62 function() { |
|
63 ok(true, "Iterating through the contact list inside a cursor callback"); |
|
64 let count1 = 0, count2 = 0; |
|
65 let req1 = mozContacts.getAll({}); |
|
66 let req2; |
|
67 req1.onsuccess = function() { |
|
68 if (count1 == 0) { |
|
69 count1++; |
|
70 req2 = mozContacts.getAll({}); |
|
71 req2.onsuccess = function() { |
|
72 if (req2.result) { |
|
73 count2++; |
|
74 req2.continue(); |
|
75 } else { |
|
76 is(count2, 40, "inner cursor returned 40 contacts"); |
|
77 req1.continue(); |
|
78 } |
|
79 }; |
|
80 } else { |
|
81 if (req1.result) { |
|
82 count1++; |
|
83 req1.continue(); |
|
84 } else { |
|
85 is(count1, 40, "outer cursor returned 40 contacts"); |
|
86 next(); |
|
87 } |
|
88 } |
|
89 }; |
|
90 }, |
|
91 |
|
92 clearDatabase, |
|
93 addContacts, |
|
94 |
|
95 function() { |
|
96 ok(true, "20 concurrent cursors"); |
|
97 const NUM_CURSORS = 20; |
|
98 let completed = 0; |
|
99 for (let i = 0; i < NUM_CURSORS; ++i) { |
|
100 mozContacts.getAll({}).onsuccess = (function(i) { |
|
101 let count = 0; |
|
102 return function(event) { |
|
103 let req = event.target; |
|
104 if (req.result) { |
|
105 count++; |
|
106 req.continue(); |
|
107 } else { |
|
108 is(count, 40, "cursor " + i + " returned 40 contacts"); |
|
109 if (++completed == NUM_CURSORS) { |
|
110 next(); |
|
111 } |
|
112 } |
|
113 }; |
|
114 })(i); |
|
115 } |
|
116 }, |
|
117 |
|
118 clearDatabase, |
|
119 addContacts, |
|
120 |
|
121 function() { |
|
122 if (!SpecialPowers.isMainProcess()) { |
|
123 // We stop calling continue() intentionally here to see if the cursor gets |
|
124 // cleaned up properly in the parent. |
|
125 ok(true, "Leaking a cursor"); |
|
126 req = mozContacts.getAll({ |
|
127 sortBy: "familyName", |
|
128 sortOrder: "ascending" |
|
129 }); |
|
130 req.onsuccess = function(event) { |
|
131 next(); |
|
132 }; |
|
133 req.onerror = onFailure; |
|
134 } else { |
|
135 next(); |
|
136 } |
|
137 }, |
|
138 |
|
139 clearDatabase, |
|
140 |
|
141 function() { |
|
142 ok(true, "all done!\n"); |
|
143 SpecialPowers.Cc["@mozilla.org/tools/profiler;1"].getService(SpecialPowers.Ci.nsIProfiler).AddMarker("GETALL_END"); |
|
144 SimpleTest.finish(); |
|
145 } |
|
146 ]; |
|
147 |
|
148 start_tests(); |
|
149 </script> |
|
150 </pre> |
|
151 </body> |
|
152 </html> |