2 <?xml-stylesheet type=
"text/css" href=
"chrome://global/skin"?>
3 <?xml-stylesheet type=
"text/css" href=
"chrome://mochikit/content/tests/SimpleTest/test.css"?>
5 https://bugzilla.mozilla.org/show_bug.cgi?id=715041
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>
17 <!-- test code goes here -->
18 <script type=
"application/javascript">
21 /** Mock Idle Service Test for Bug
715041 **/
22 SpecialPowers.setBoolPref(
"dom.idle-observers-api.fuzz_time.disabled", true);
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);
30 dump(
"test_bug715041_removal.xul: failed to get old idle service 1.");
33 //class mock javascript idle service
34 var idleServiceObj = {
37 idleTimeInMS:
5000, //in milli seconds
39 // takes note of the idle observers added as the minimum idle observer
40 //with the idle service
43 QueryInterface: function(iid) {
44 if (iid.equals(Components.interfaces.nsISupports) ||
45 iid.equals(Components.interfaces.nsIFactory) ||
46 iid.equals(Components.interfaces.nsIIdleService)) {
49 throw Components.results.NS_ERROR_NO_INTERFACE;
52 createInstance: function(outer, iid) {
53 return this.QueryInterface(iid);
57 return this.idleTimeInMS; //in milli seconds
60 set idleTime(timeInMS) {
61 this.idleTimeInMS = timeInMS;
64 getWindowFromObserver: function(observer) {
66 var interfaceRequestor = observer.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
67 var window = interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow);
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);
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");
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);
112 oldIdleService.removeIdleObserver(observer, time);
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) {
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");
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");
144 var addedIdleObserver = removedIdleObserver = passed = cleanUp = false;
147 var msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
148 msg6Count = tcZero = currTestCaseNum = prevMsgNum =
0;
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 +
190 var idleHandler0 = function() { dump(
"msg 0, should never be used!\n"); };
193 function idleHandler1() {
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]);
203 case tcRemoveLocalIdleObserverWhileIdle:
204 if (msg1Count ===
1 && !msg2Count && !msg3Count && !msg4Count) {
205 window.navigator.removeIdleObserver(idleObserversArray[
2]);
208 case tcRemoveLocalIdleTimerWhileIdle:
209 if (msg1Count ===
1 && !msg2Count && !msg3Count && !msg4Count) {
210 idleServiceObj.idleTime =
2000;
211 window.navigator.removeIdleObserver(idleObserversArray[
3]);
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]);
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");
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]);
244 case tcRemoveLastAddLast:
245 window.navigator.addIdleObserver(idleObserversArray[
2]);
246 window.navigator.addIdleObserver(idleObserversArray[
3]);
254 function idleHandler2() {
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]);
273 function idleHandler3() {
275 dump(
"msg 3 Count: " + msg3Count +
"\n");
277 switch (currTestCaseNum) {
278 case tcRemoveHeadIdleObserverWhileActive:
279 if (!msg1Count && msg2Count ===
1 && msg3Count ===
1) {
282 dump(
"idleHandler3: passed: " + passed +
"\n");
283 RemoveHeadIdleObserverWhileActiveCleanUp();
285 case tcRemoveHeadIdleObserverWhileIdleCase1:
286 if (msg3Count !=
2 && msg3Count !=
4) {
290 if (msg1Count ===
2 && msg2Count ===
2 && msg3Count ===
2 && !msg4Count) {
292 ok(passed,
"Failed test case remove head idle observer while idle case 1, part 1.\n");
293 idleServiceObj.testIdleBackService(idleObserversArray[
1],
"active");
297 if (msg1Count ===
3 && msg2Count ===
4 && msg3Count ===
4 &&
298 !msg4Count && !msg5Count) {
301 RemoveHeadIdleObserverWhileIdleCase1CleanUp();
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]);
313 case tcRemoveHeadAfterLastLocalFired:
314 if (msg3Count ===
1) {
318 if (msg1Count ===
2 && msg2Count ===
2 && msg3Count ===
2 && msg4Count ===
1) {
321 RemoveHeadAfterLastLocalFiredCleanUp();
329 function idleHandler4() {
331 dump(
"msg 4 Count: " + msg4Count +
"\n");
333 switch (currTestCaseNum) {
334 case tcRemoveLocalIdleObserverWhileIdle:
335 if (msg1Count ===
1 && !msg2Count && msg3Count ===
1 && msg4Count ===
1) {
337 RemoveLocalIdleObserverWhileIdleCleanUp();
340 case tcRemoveHeadIdleObserver:
341 printVariableValues();
342 if (msg1Count ===
1 && msg2Count ===
1 && msg3Count ===
1 && msg4Count ===
1) {
344 RemoveHeadIdleObserverCleanUp();
347 case tcRemoveLocalIdleTimerWhileIdle:
348 if (msg1Count ===
1 && !msg2Count && !msg3Count && msg4Count ===
1) {
350 RemoveLocalIdleTimerWhileIdleCleanUp();
353 case tcRemoveLocalIdleTimerLastElement:
354 if (msg1Count ===
1 && msg2Count ===
1 && !msg3Count && msg4Count ===
1) {
356 ok(passed,
"Failed test case remove local idle timer last element.\n");
357 RemoveLocalIdleTimerLastElementCleanUp();
360 case tcRemoveHeadAfterLastLocalFired:
361 if (msg1Count ===
1 && msg2Count ===
1 && msg3Count ===
1 && msg4Count ===
1) {
362 window.navigator.removeIdleObserver(idleObserversArray[
4]);
364 ok(passed,
"Failed remove head after last local fired.\n");
365 idleServiceObj.testIdleBackService(idleObserversArray[
1],
"active");
368 case tcRemoveLastAddLast:
369 if (msg1Count ===
1 && msg2Count ===
1 && msg3Count ===
1 && msg4Count ==
1) {
370 idleServiceObj.idleTime =
4100;
372 RemoveLastAddLastCleanUp();
382 function idleHandler5() {
384 dump(
"msg 5 Count: " + msg5Count +
"\n");
386 switch (currTestCaseNum) {
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");
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");
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();
457 dump(
"Finishing testing idle API.\n");
463 * function RemoveLocalIdleObserverWhileIdle()
464 * Remove local observer before the local oberver at index
1 is triggered while
466 * RESULT: should print
1,
3,
4
468 function RemoveLocalIdleObserverWhileIdle() {
469 dump(
"\n\nTESTING CASE RemoveLocalIdleObserverWhileIdle\n");
470 dump(
"=================================\n");
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()");
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();
504 dump(
"Finishing testing idle API.\n");
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");
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()");
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();
551 dump(
"Finishing testing idle API.\n");
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");
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()");
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();
597 dump(
"Finishing testing idle API.\n");
603 * function RemoveLocalIdleTimerLastElement()
605 function RemoveLocalIdleTimerLastElement()
607 dump(
"\n\nTESTING CASE RemoveLocalIdleTimerLastElement\n");
608 dump(
"=================================\n");
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()");
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();
634 dump(
"Finishing testing idle API.\n");
640 - Remove the head after the last local idle timer has been fired
642 - after
4 has been notified, removed idle observer with time
4
644 - message notification should be
1,
2,
3.
646 function RemoveHeadAfterLastLocalFired()
648 dump(
"\n\nTESTING CASE RemoveHeadAfterLastLocalFired\n");
649 dump(
"=================================\n");
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()");
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();
677 dump(
"Finishing testing idle API.\n");
682 function RemoveHeadIdleObserverWhileIdleCase1() {
683 dump(
"\n\nTESTING CASE RemoveHeadIdleObserverWhileIdleCase1\n");
684 dump(
"=================================\n");
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()");
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) {
714 dump(
"Finishing testing idle API.\n");
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");
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()");
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()");
758 ok(false,
"Failed test case: RemoveLastAddLastCleanUp()");
763 componentMgr.unregisterFactory(idleServiceCID, idleServiceObj);
766 dump(
"test_bug715041_removal.xul: RemoveLastAddLastCleanUp() Failed to unregister factory, mock idle service!\n");
770 componentMgr.registerFactory(oldIdleServiceCID,
"Re registering old idle service", idleServiceContractID, oldIdleServiceFactoryObj);
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");
782 // Registering new moch JS idle service
783 SimpleTest.waitForExplicitFinish();
784 SimpleTest.requestLongerTimeout(
10);
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);
792 dump(
"test_bug715041_removal.xul: 1) Failed to get old idle service.\n");
796 // Registering new moch JS idle service
797 var componentMgr = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
800 dump(
"test_bug715041_removal.xul: Failed to query component registrar interface.\n");
804 var oldIdleServiceFactoryObj = componentMgr.getClassObjectByContractID(idleServiceContractID, Components.interfaces.nsIFactory);
807 dump(
"test_bug715041_removal.xul: Failed to get old idle service.\n");
811 var oldIdleServiceCID = componentMgr.contractIDToCID(idleServiceContractID);
814 dump(
"test_bug715041._removalxul: Failed to convert ID to CID for old idle service.\n");
818 componentMgr.unregisterFactory(oldIdleServiceCID, oldIdleServiceFactoryObj);
821 dump(
"test_bug715041_removal.xul: Failed to unregister old idle service factory object!\n");
825 componentMgr.registerFactory(idleServiceCID,
"Test Simple Idle/Back Notifications", idleServiceContractID, idleServiceObj);
828 dump(
"test_bug715041_removal.xul: Failed to register mock idle service.\n");
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();