Bumping manifests a=b2g-bump
[gecko.git] / dom / base / test / test_bug715041_removal.xul
blob2b77dd5949d6953a5fd63c99a0b3bfd5b65834c8
1 <?xml version="1.0"?>
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
4 <!--
5 https://bugzilla.mozilla.org/show_bug.cgi?id=715041
6 -->
7 <window title="Mozilla Bug 715041"
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
11 <!-- test results are displayed in the html:body -->
12 <body xmlns="http://www.w3.org/1999/xhtml">
13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=715041"
14 target="_blank">Mozilla Bug 715041</a>
15 </body>
17 <!-- test code goes here -->
18 <script type="application/javascript">
19 <![CDATA[
21 /** Mock Idle Service Test for Bug 715041 **/
22 SpecialPowers.setBoolPref("dom.idle-observers-api.fuzz_time.disabled", true);
24 try {
25 var idleServiceCID = Components.ID("6f95d965-4322-4829-8a3c-5dc8a4587f4d");
26 var idleServiceContractID = "@mozilla.org/widget/idleservice;1";
27 var oldIdleService = Components.classes[idleServiceContractID].getService(Components.interfaces.nsIIdleService);
29 catch (ex) {
30 dump("test_bug715041_removal.xul: failed to get old idle service 1.");
33 //class mock javascript idle service
34 var idleServiceObj = {
35 observers: [],
36 windowObservers: [],
37 idleTimeInMS: 5000, //in milli seconds
39 // takes note of the idle observers added as the minimum idle observer
40 //with the idle service
41 timesAdded: [],
43 QueryInterface: function(iid) {
44 if (iid.equals(Components.interfaces.nsISupports) ||
45 iid.equals(Components.interfaces.nsIFactory) ||
46 iid.equals(Components.interfaces.nsIIdleService)) {
47 return this;
49 throw Components.results.NS_ERROR_NO_INTERFACE;
52 createInstance: function(outer, iid) {
53 return this.QueryInterface(iid);
56 get idleTime() {
57 return this.idleTimeInMS; //in milli seconds
60 set idleTime(timeInMS) {
61 this.idleTimeInMS = timeInMS;
64 getWindowFromObserver: function(observer) {
65 try {
66 var interfaceRequestor = observer.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
67 var window = interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow);
68 return window;
70 catch (e) {}
72 return null;
75 testIdleBackService: function(observer, topic) {
76 dump("\nJS FAKE IDLE SERVICE\n");
77 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
79 if (this.observers.length > 1) {
80 this.observers[1].observer.observe(observer, topic, '\0');
81 dump("JS CALLED OBSERVE FUNCTION!!!\n\n");
85 addIdleObserver: function(observer, time) {
86 dump("\nJS FAKE IDLE SERVICE add idle observer before\n");
87 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
88 var window = this.getWindowFromObserver(observer);
90 if (window) {
91 this.observers.push({ observer: observer, time: time, });
92 addedIdleObserver = true;
93 numIdleObserversAdded++;
94 this.timesAdded.push(time);
95 dump ("\nMOCK IDLE SERVICE ADDING idle observer with time: " + time + "\n");
96 dump("MOCK IDLE SERVICE: num idle observers added: " + numIdleObserversAdded + "\n\n");
98 else {
99 dump("SHOULD NEVER GET HERE!");
100 oldIdleService.addIdleObserver(observer, time);
101 addedIdleObserver = false;
104 dump("\nJS FAKE IDLE SERVICE end of add idle observer\n");
105 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
108 removeIdleObserver: function(observer, time) {
109 dump("\nJS REMOVE IDLE OBSERVER () time to be removed: " + time + "\n");
110 var window = this.getWindowFromObserver(observer);
111 if (!window) {
112 oldIdleService.removeIdleObserver(observer, time);
114 else {
115 var observerIndex = -1;
116 for (var i=0; i<this.observers.length; i++) {
117 dump("JS removeIdleObserver() observer time: " + this.observers[i].time + "\n");
118 if (this.observers[i].time === time) {
119 observerIndex = i;
120 break;
124 if (observerIndex != -1 && this.observers.length > 0) {
125 numIdleObserversRemoved++;
126 this.observers.splice(observerIndex, 1);
127 removedIdleObserver = true;
128 dump("MOCK IDLE SERVICE REMOVING idle observer with time " + time + "\n");
129 dump("MOCK IDLE SERVICE numIdleObserversRemoved: " + numIdleObserversRemoved + " numIdleObserversAdded: " + numIdleObserversAdded + "\n\n");
131 else {
132 removedIdleObserver = false;
135 dump("\nJS FAKE IDLE SERVICE end of remove idle observer\n");
136 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
140 /** Test for Bug 715041 **/
141 dump("\n\n\nJS STARTING TESTING FOR BUG 715041 REMOVAL\n");
143 //bool variables
144 var addedIdleObserver = removedIdleObserver = passed = cleanUp = false;
146 //msgXCount
147 var msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
148 msg6Count = tcZero = currTestCaseNum = prevMsgNum = 0;
150 //test case number
151 var tcRemoveHeadIdleObserverWhileActive = 0;
152 var tcRemoveLocalIdleObserverWhileIdle = 1;
153 var tcRemoveHeadIdleObserver = 2;
154 var tcRemoveLocalIdleTimerWhileIdle = 3;
155 var tcRemoveLocalIdleTimerLastElement = 4;
156 var tcRemoveHeadAfterLastLocalFired = 5;
157 var tcRemoveHeadIdleObserverWhileIdleCase1 = 6;
158 var tcRemoveLastAddLast = 7;
160 function ResetMsgCounts() {
161 msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
162 msg6Count = prevMsgNum = 0;
165 function ResetVars() {
166 msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
167 msg6Count = prevMsgNum = 0;
169 numIdleObserversAdded = numIdleObserversRemoved = 0;
170 currTestCaseNum = -1;
171 addedIdleObserver = removedIdleObserver = passed = cleanUp = false;
174 function printVariableValues()
176 dump("\nfunction printVariableValues()\ncurrTestCaseNum: " + currTestCaseNum +
177 "\ncleanUp: " + cleanUp +
178 "\npassed: " + passed +
179 "\nnumIdleObserversRemoved: " + numIdleObserversRemoved +
180 "\nnumIdleObservesAdded: " + numIdleObserversAdded +
181 "\nmsg1Count " + msg1Count +
182 "\nmsg2Count " + msg2Count +
183 "\nmsg3Count " + msg3Count +
184 "\nmsg4Count " + msg4Count +
185 "\nmsg5Count " + msg5Count +
186 "\n");
189 //Place Holder.
190 var idleHandler0 = function() { dump("msg 0, should never be used!\n"); };
192 //idleHandler1
193 function idleHandler1() {
194 msg1Count++;
195 dump("msg 1 Count: " + msg1Count + "\n");
197 switch (currTestCaseNum) {
198 case tcRemoveHeadIdleObserver:
199 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
200 window.navigator.removeIdleObserver(idleObserversArray[1]);
202 break;
203 case tcRemoveLocalIdleObserverWhileIdle:
204 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count) {
205 window.navigator.removeIdleObserver(idleObserversArray[2]);
207 break;
208 case tcRemoveLocalIdleTimerWhileIdle:
209 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count) {
210 idleServiceObj.idleTime = 2000;
211 window.navigator.removeIdleObserver(idleObserversArray[3]);
213 break;
214 case tcRemoveHeadIdleObserverWhileIdleCase1:
215 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count) {
216 for (var i=1; i<4; i++) {
217 window.navigator.addIdleObserver(idleObserversArray[i]);
219 window.navigator.addIdleObserver(idleObserversArray[2]);
220 window.navigator.addIdleObserver(idleObserversArray[3]);
222 idleServiceObj.idleTime = 1200;
223 window.navigator.removeIdleObserver(idleObserversArray[1]);
225 break;
226 case tcRemoveLocalIdleTimerLastElement:
227 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
228 idleServiceObj.idleTime = 1500;
229 window.navigator.removeIdleObserver(idleObserversArray[1]);
230 idleServiceObj.idleTime = 1700;
231 window.navigator.addIdleObserver(idleObserversArray[2]);
232 idleServiceObj.idleTime = 2000;
233 idleServiceObj.testIdleBackService(idleObserversArray[2], "idle");
235 break;
236 case tcRemoveHeadAfterLastLocalFired:
237 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
238 dump("idle handler 1: case tcRemoveHeadAfterLastLocalFired:\n");
239 window.navigator.addIdleObserver(idleObserversArray[2]);
240 window.navigator.addIdleObserver(idleObserversArray[3]);
241 window.navigator.addIdleObserver(idleObserversArray[4]);
243 break;
244 case tcRemoveLastAddLast:
245 window.navigator.addIdleObserver(idleObserversArray[2]);
246 window.navigator.addIdleObserver(idleObserversArray[3]);
247 break;
248 default:
249 break;
253 //idleHandler2
254 function idleHandler2() {
255 msg2Count++;
256 dump("msg 2 Count: " + msg2Count + "\n");
258 switch (currTestCaseNum) {
259 case tcRemoveLocalIdleTimerLastElement:
260 if (msg1Count === 1 && msg2Count === 1 && !msg3Count && !msg4Count) {
261 window.navigator.addIdleObserver(idleObserversArray[3]);
262 window.navigator.addIdleObserver(idleObserversArray[4]);
263 window.navigator.removeIdleObserver(idleObserversArray[3]);
265 break;
266 default:
267 //do nothing.
268 break;
272 //idleHandler3
273 function idleHandler3() {
274 msg3Count++;
275 dump("msg 3 Count: " + msg3Count + "\n");
276 passed = false;
277 switch (currTestCaseNum) {
278 case tcRemoveHeadIdleObserverWhileActive:
279 if (!msg1Count && msg2Count === 1 && msg3Count === 1) {
280 passed = true;
282 dump("idleHandler3: passed: " + passed + "\n");
283 RemoveHeadIdleObserverWhileActiveCleanUp();
284 break;
285 case tcRemoveHeadIdleObserverWhileIdleCase1:
286 if (msg3Count != 2 && msg3Count != 4) {
287 return;
290 if (msg1Count === 2 && msg2Count === 2 && msg3Count === 2 && !msg4Count) {
291 passed = true;
292 ok(passed, "Failed test case remove head idle observer while idle case 1, part 1.\n");
293 idleServiceObj.testIdleBackService(idleObserversArray[1], "active");
294 return;
297 if (msg1Count === 3 && msg2Count === 4 && msg3Count === 4 &&
298 !msg4Count && !msg5Count) {
299 passed = true;
301 RemoveHeadIdleObserverWhileIdleCase1CleanUp();
302 break;
303 case tcRemoveLastAddLast:
304 if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1
305 && !msg4Count && !msg5Count) {
306 idleServiceObj.idleTime = 3200;
307 window.navigator.removeIdleObserver(idleObserversArray[3]);
308 idleServiceObj.idleTime = 3500;
309 window.navigator.addIdleObserver(idleObserversArray[4]);
310 return;
312 break;
313 case tcRemoveHeadAfterLastLocalFired:
314 if (msg3Count === 1) {
315 return;
318 if (msg1Count === 2 && msg2Count === 2 && msg3Count === 2 && msg4Count === 1) {
319 passed = true;
321 RemoveHeadAfterLastLocalFiredCleanUp();
322 break;
323 default:
324 break;
328 //idleHandler4
329 function idleHandler4() {
330 msg4Count++;
331 dump("msg 4 Count: " + msg4Count + "\n");
333 switch (currTestCaseNum) {
334 case tcRemoveLocalIdleObserverWhileIdle:
335 if (msg1Count === 1 && !msg2Count && msg3Count === 1 && msg4Count === 1) {
336 passed = true;
337 RemoveLocalIdleObserverWhileIdleCleanUp();
339 break;
340 case tcRemoveHeadIdleObserver:
341 printVariableValues();
342 if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1 && msg4Count === 1) {
343 passed = true;
344 RemoveHeadIdleObserverCleanUp();
346 break;
347 case tcRemoveLocalIdleTimerWhileIdle:
348 if (msg1Count === 1 && !msg2Count && !msg3Count && msg4Count === 1) {
349 passed = true;
350 RemoveLocalIdleTimerWhileIdleCleanUp();
352 break
353 case tcRemoveLocalIdleTimerLastElement:
354 if (msg1Count === 1 && msg2Count === 1 && !msg3Count && msg4Count === 1) {
355 passed = true;
356 ok(passed, "Failed test case remove local idle timer last element.\n");
357 RemoveLocalIdleTimerLastElementCleanUp();
359 break;
360 case tcRemoveHeadAfterLastLocalFired:
361 if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1 && msg4Count === 1) {
362 window.navigator.removeIdleObserver(idleObserversArray[4]);
363 passed = true;
364 ok(passed, "Failed remove head after last local fired.\n");
365 idleServiceObj.testIdleBackService(idleObserversArray[1], "active");
367 break;
368 case tcRemoveLastAddLast:
369 if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1 && msg4Count == 1) {
370 idleServiceObj.idleTime = 4100;
371 passed = true;
372 RemoveLastAddLastCleanUp();
374 break;
375 default:
376 //do nothing.
377 break;
381 //idleHandler5
382 function idleHandler5() {
383 msg5Count++;
384 dump("msg 5 Count: " + msg5Count + "\n");
386 switch (currTestCaseNum) {
388 default:
389 //do nothing.
390 break;
394 //idleHandler6
395 function idleHandler6() {
396 dump("msg 6 Count: " + msg6Count + "\n");
399 var idleObserversArray = [];
400 idleObserversArray[0] = {time: 0, onidle: idleHandler0, onactive: idleHandler0};
401 idleObserversArray[1] = {time: 1, onidle: idleHandler1, onactive: idleHandler1};
402 idleObserversArray[2] = {time: 2, onidle: idleHandler2, onactive: idleHandler2};
403 idleObserversArray[3] = {time: 3, onidle: idleHandler3, onactive: idleHandler3};
404 idleObserversArray[4] = {time: 4, onidle: idleHandler4, onactive: idleHandler4};
405 idleObserversArray[5] = {time: 5, onidle: idleHandler5, onactive: idleHandler5};
406 idleObserversArray[6] = {time: 0, onidle: idleHandler6, onactive: idleHandler6};
408 //observers array space holder at index zero
409 idleServiceObj.observers.push( {observer: idleObserversArray[0], time: 0, } );
412 * - function RemoveHeadIdleObserverWhileActive1()
413 * - Remove head idle observer before the head idle notification is fired by the
414 * idle service. I.e. remove the head idle observer while the user is active.
415 * - RESULT: prints 2 in 2ms, 3
417 function RemoveHeadIdleObserverWhileActive() {
418 dump("\n\nTESTING CASE RemoveHeadIdleObserverWhileActive\n");
419 dump("=================================\n");
421 ResetVars();
422 currTestCaseNum = tcRemoveHeadIdleObserverWhileActive;
423 idleServiceObj.idleTime = 500;
425 window.navigator.addIdleObserver(idleObserversArray[1]);
426 dump("test_bug715041_removal.xul: RemoveHeadIdleObserverWhileActive() idle time " + idleServiceObj.idleTime + "\n");
427 window.navigator.addIdleObserver(idleObserversArray[2]);
428 window.navigator.addIdleObserver(idleObserversArray[3]);
430 idleServiceObj.idleTime = 800;
431 window.navigator.removeIdleObserver(idleObserversArray[1]);
433 idleServiceObj.idleTime = 1000;
434 idleServiceObj.testIdleBackService(idleObserversArray[2], "idle");
437 function RemoveHeadIdleObserverWhileActiveCleanUp() {
438 dump("\nRemoveHeadIdleObserverWhileActiveCleanUp()\n");
439 dump("=====================================\n");
441 dump("Passed: " + passed + "\n");
442 ok(passed, "Failed test case: RemoveHeadIdleObserverWhileActive");
444 ResetVars();
445 currTestCaseNum = tcRemoveHeadIdleObserverWhileActive;
446 idleServiceObj.idleTime = 3500;
448 for (var i=2; i<4; i++) {
449 window.navigator.removeIdleObserver(idleObserversArray[i]);
452 dump("JS RemoveHeadIdleObserverWhileActiveCleanUp() DONE\n");
453 if (RemoveLocalIdleObserverWhileIdleEnabled) {
454 RemoveLocalIdleObserverWhileIdle();
456 else {
457 dump("Finishing testing idle API.\n");
458 SimpleTest.finish();
463 * function RemoveLocalIdleObserverWhileIdle()
464 * Remove local observer before the local oberver at index 1 is triggered while
465 * the user is idle.
466 * RESULT: should print 1, 3, 4
468 function RemoveLocalIdleObserverWhileIdle() {
469 dump("\n\nTESTING CASE RemoveLocalIdleObserverWhileIdle\n");
470 dump("=================================\n");
472 ResetVars();
473 currTestCaseNum = tcRemoveLocalIdleObserverWhileIdle;
474 idleServiceObj.idleTime = 500;
476 window.navigator.addIdleObserver(idleObserversArray[1]);
477 window.navigator.addIdleObserver(idleObserversArray[2]);
478 window.navigator.addIdleObserver(idleObserversArray[3]);
479 window.navigator.addIdleObserver(idleObserversArray[4]);
481 idleServiceObj.idleTime = 1000;
482 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
485 function RemoveLocalIdleObserverWhileIdleCleanUp() {
486 dump("\nRemoveLocalIdleObserverWhileIdleCleanUp()\n");
487 dump("=====================================\n");
489 ok(passed, "Failed test case: RemoveLocalIdleObserverWhileIdleCleanUp()");
491 ResetVars();
492 currTestCaseNum = tcRemoveHeadIdleObserverWhileActive;
493 idleServiceObj.idleTime = 3500;
495 window.navigator.removeIdleObserver(idleObserversArray[1]);
496 window.navigator.removeIdleObserver(idleObserversArray[3]);
497 window.navigator.removeIdleObserver(idleObserversArray[4]);
499 dump("JS RemoveLocalIdleObserverWhileIdleCleanUp() DONE\n");
500 if (RemoveHeadIdleObserverEnabled) {
501 RemoveHeadIdleObserver();
503 else {
504 dump("Finishing testing idle API.\n");
505 SimpleTest.finish();
511 * function RemoveHeadIdleObserver()
512 * Remove head idle observer while the user has been idle for 2400 ms.
513 * - RESULT: prints 1, 2, remove 2, 3, 4
515 function RemoveHeadIdleObserver() {
516 dump("\n\nTESTING CASE RemoveHeadIdleObserver\n");
517 dump("=================================\n");
519 ResetVars();
520 currTestCaseNum = tcRemoveHeadIdleObserver;
521 idleServiceObj.idleTime = 500;
523 window.navigator.addIdleObserver(idleObserversArray[1]);
524 window.navigator.addIdleObserver(idleObserversArray[2]);
525 window.navigator.addIdleObserver(idleObserversArray[3]);
526 window.navigator.addIdleObserver(idleObserversArray[4]);
528 idleServiceObj.idleTime = 1000;
529 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
532 function RemoveHeadIdleObserverCleanUp() {
533 dump("\nRemoveHeadIdleObserverCleanUp()\n");
534 dump("=====================================\n");
536 ok(passed, "Failed test case: RemoveHeadIdleObserverCleanUp()");
538 ResetVars();
539 currTestCaseNum = tcRemoveHeadIdleObserver;
540 idleServiceObj.idleTime = 3500;
542 for (var i=2; i<5; i++) {
543 window.navigator.removeIdleObserver(idleObserversArray[i]);
546 dump("JS RemoveHeadIdleObserverCleanUp() DONE\n");
547 if (RemoveLocalIdleTimerWhileIdleEnabled) {
548 RemoveLocalIdleTimerWhileIdle();
550 else {
551 dump("Finishing testing idle API.\n");
552 SimpleTest.finish();
557 * RemoveLocalIdleTimerWhileIdle()
558 * - Removes the idle observer that is also set as the current local idle timer callback
559 * local idle observer being removed is NOT at index 1!
560 * - RESULT: should trigger 1 in 1ms and 4 in 4ms
562 function RemoveLocalIdleTimerWhileIdle()
564 dump("\n\nTESTING CASE RemoveLocalIdleTimerWhileIdle\n");
565 dump("=================================\n");
567 ResetVars();
568 currTestCaseNum = tcRemoveLocalIdleTimerWhileIdle;
569 idleServiceObj.idleTime = 500;
571 window.navigator.addIdleObserver(idleObserversArray[1]);
572 window.navigator.addIdleObserver(idleObserversArray[3]);
573 window.navigator.addIdleObserver(idleObserversArray[4]);
575 idleServiceObj.idleTime = 1000;
576 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
579 function RemoveLocalIdleTimerWhileIdleCleanUp()
581 dump("\nRemoveLocalIdleTimerWhileIdleCleanUp()\n");
582 dump("=====================================\n");
584 ok(passed, "Failed test case: RemoveLocalIdleTimerWhileIdleCleanUp()");
586 ResetVars();
587 currTestCaseNum = tcRemoveLocalIdleTimerWhileIdle;
589 window.navigator.removeIdleObserver(idleObserversArray[1]);
590 window.navigator.removeIdleObserver(idleObserversArray[4]);
592 dump("JS RemoveLocalIdleTimerWhileIdleCleanUp() DONE\n");
593 if (RemoveLocalIdleTimerLastElementEnabled) {
594 RemoveLocalIdleTimerLastElement();
596 else {
597 dump("Finishing testing idle API.\n");
598 SimpleTest.finish();
603 * function RemoveLocalIdleTimerLastElement()
605 function RemoveLocalIdleTimerLastElement()
607 dump("\n\nTESTING CASE RemoveLocalIdleTimerLastElement\n");
608 dump("=================================\n");
610 ResetVars();
611 currTestCaseNum = tcRemoveLocalIdleTimerLastElement;
612 idleServiceObj.idleTime = 1200;
614 window.navigator.addIdleObserver(idleObserversArray[1]);
615 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
618 function RemoveLocalIdleTimerLastElementCleanUp() {
619 dump("\nRemoveLocalIdleTimerLastElementCleanUp()\n");
620 dump("=====================================\n");
622 ok(passed, "Failed test case: RemoveLocalIdleTimerLastElementCleanUp()");
624 ResetVars();
625 currTestCaseNum = tcRemoveLocalIdleTimerLastElement;
626 window.navigator.removeIdleObserver(idleObserversArray[2]);
627 window.navigator.removeIdleObserver(idleObserversArray[4]);
629 dump("JS RemoveLocalIdleTimerLastElementCleanUp() DONE\n");
630 if (RemoveHeadAfterLastLocalFiredEnabled) {
631 RemoveHeadAfterLastLocalFired();
633 else {
634 dump("Finishing testing idle API.\n");
635 SimpleTest.finish();
640 - Remove the head after the last local idle timer has been fired
641 - add 1 2 3 4
642 - after 4 has been notified, removed idle observer with time 4
643 - send a back topic
644 - message notification should be 1, 2, 3.
646 function RemoveHeadAfterLastLocalFired()
648 dump("\n\nTESTING CASE RemoveHeadAfterLastLocalFired\n");
649 dump("=================================\n");
651 ResetVars();
652 currTestCaseNum = tcRemoveHeadAfterLastLocalFired;
653 idleServiceObj.idleTime = 1200;
655 window.navigator.addIdleObserver(idleObserversArray[1]);
656 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
659 function RemoveHeadAfterLastLocalFiredCleanUp() {
660 dump("\RemoveHeadAfterLastLocalFiredCleanUp()\n");
661 dump("=====================================\n");
663 ok(passed, "Failed test case: RemoveHeadAfterLastLocalFiredCleanUp()");
665 ResetVars();
666 currTestCaseNum = tcRemoveHeadAfterLastLocalFired;
668 window.navigator.removeIdleObserver(idleObserversArray[1]);
669 window.navigator.removeIdleObserver(idleObserversArray[2]);
670 window.navigator.removeIdleObserver(idleObserversArray[3]);
672 dump("JS RemoveHeadAfterLastLocalFiredCleanUp() DONE\n");
673 if (RemoveHeadIdleObserverWhileIdleCase1Enabled) {
674 RemoveHeadIdleObserverWhileIdleCase1();
676 else {
677 dump("Finishing testing idle API.\n");
678 SimpleTest.finish();
682 function RemoveHeadIdleObserverWhileIdleCase1() {
683 dump("\n\nTESTING CASE RemoveHeadIdleObserverWhileIdleCase1\n");
684 dump("=================================\n");
686 ResetVars();
687 currTestCaseNum = tcRemoveHeadIdleObserverWhileIdleCase1;
688 idleServiceObj.idleTime = 1000;
689 window.navigator.addIdleObserver(idleObserversArray[1]);
690 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
693 function RemoveHeadIdleObserverWhileIdleCase1CleanUp() {
694 dump("\nRemoveHeadIdleObserverWhileIdleCase1CleanUp()\n");
695 dump("=====================================\n");
697 ok(passed, "Failed test case: RemoveHeadIdleObserverWhileIdleCase1CleanUp()");
699 ResetVars();
700 currTestCaseNum = tcRemoveHeadIdleObserverWhileIdleCase1;
702 for (var i=1; i<4; i++) {
703 window.navigator.removeIdleObserver(idleObserversArray[i]);
706 window.navigator.removeIdleObserver(idleObserversArray[2]);
707 window.navigator.removeIdleObserver(idleObserversArray[3]);
709 dump("JS RemoveHeadIdleObserverWhileIdleCase1CleanUp() DONE\n");
710 if (RemoveLastAddLastEnabled) {
711 RemoveLastAddLast();
713 else {
714 dump("Finishing testing idle API.\n");
715 SimpleTest.finish();
720 * - RemoveLastAddLast()
722 * - User is currently idle.
723 * - Add callback 1, 2, 3,
724 * - Remove callback 3 after 3200 MS. I.e. after callback 3 has been notified.
725 * - Add callback 4 after 3500 MS
726 * - Output: 1, 2, 3, 4
728 function RemoveLastAddLast()
730 dump("\n\nTESTING CASE RemoveLastAddLast()\n");
731 dump("=================================\n");
733 ResetVars();
734 currTestCaseNum = tcRemoveLastAddLast;
735 idleServiceObj.idleTime = 1000;
736 window.navigator.addIdleObserver(idleObserversArray[1]);
737 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
740 function RemoveLastAddLastCleanUp()
742 dump("\RemoveLastAddLastCleanUp()\n");
743 dump("=====================================\n");
745 ok(passed, "Failed test case: RemoveLastAddLastCleanUp()");
747 ResetVars();
748 currTestCaseNum = tcRemoveLastAddLast;
750 window.navigator.removeIdleObserver(idleObserversArray[1]);
751 window.navigator.removeIdleObserver(idleObserversArray[2]);
752 window.navigator.removeIdleObserver(idleObserversArray[4]);
754 if (numIdleObserversRemoved === 1 && !numIdleObserversAdded) {
755 ok(true, "Failed test case: RemoveLastAddLastCleanUp()");
757 else {
758 ok(false, "Failed test case: RemoveLastAddLastCleanUp()");
762 try {
763 componentMgr.unregisterFactory(idleServiceCID, idleServiceObj);
765 catch(err) {
766 dump("test_bug715041_removal.xul: RemoveLastAddLastCleanUp() Failed to unregister factory, mock idle service!\n");
769 try {
770 componentMgr.registerFactory(oldIdleServiceCID, "Re registering old idle service", idleServiceContractID, oldIdleServiceFactoryObj);
772 catch(err) {
773 dump("test_bug715041_removal.xul: RemoveLastAddLastCleanUp() Failed to register factory, original idle service!\n");
776 dump("JS RemoveLastAddLastCleanUp() DONE\n");
777 dump("Finishing testing idle API.\n");
778 SimpleTest.finish();
782 // Registering new moch JS idle service
783 SimpleTest.waitForExplicitFinish();
784 SimpleTest.requestLongerTimeout(10);
786 try {
787 var idleServiceCID = Components.ID("0fdc1bbf-3868-4660-9855-0c2e376922bc");
788 var idleServiceContractID = "@mozilla.org/widget/idleservice;1";
789 var oldIdleService = Components.classes[idleServiceContractID].getService(Components.interfaces.nsIIdleService);
791 catch(ex) {
792 dump("test_bug715041_removal.xul: 1) Failed to get old idle service.\n");
795 try {
796 // Registering new moch JS idle service
797 var componentMgr = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
799 catch(err) {
800 dump("test_bug715041_removal.xul: Failed to query component registrar interface.\n");
803 try {
804 var oldIdleServiceFactoryObj = componentMgr.getClassObjectByContractID(idleServiceContractID, Components.interfaces.nsIFactory);
806 catch(err) {
807 dump("test_bug715041_removal.xul: Failed to get old idle service.\n");
810 try {
811 var oldIdleServiceCID = componentMgr.contractIDToCID(idleServiceContractID);
813 catch(err) {
814 dump("test_bug715041._removalxul: Failed to convert ID to CID for old idle service.\n");
817 try {
818 componentMgr.unregisterFactory(oldIdleServiceCID, oldIdleServiceFactoryObj);
820 catch(err) {
821 dump("test_bug715041_removal.xul: Failed to unregister old idle service factory object!\n");
824 try {
825 componentMgr.registerFactory(idleServiceCID, "Test Simple Idle/Back Notifications", idleServiceContractID, idleServiceObj);
827 catch(err) {
828 dump("test_bug715041_removal.xul: Failed to register mock idle service.\n");
831 //test case enabled
832 var RemoveLocalIdleObserverWhileIdleEnabled = true;
833 var RemoveHeadIdleObserverEnabled = true;
834 var RemoveLocalIdleTimerWhileIdleEnabled = true;
835 var RemoveLocalIdleTimerLastElementEnabled = true;
836 var RemoveHeadAfterLastLocalFiredEnabled = true;
837 var RemoveHeadIdleObserverWhileIdleCase1Enabled = true;
838 var RemoveLastAddLastEnabled = true;
840 RemoveHeadIdleObserverWhileActive();
843 </script>
844 </window>