dom/base/test/test_bug715041.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
michael@0 3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
michael@0 4 <!--
michael@0 5 https://bugzilla.mozilla.org/show_bug.cgi?id=715041
michael@0 6 -->
michael@0 7 <window title="Mozilla Bug 715041"
michael@0 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 10
michael@0 11 <!-- test results are displayed in the html:body -->
michael@0 12 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=715041"
michael@0 14 target="_blank">Mozilla Bug 715041</a>
michael@0 15 </body>
michael@0 16
michael@0 17 <!-- test code goes here -->
michael@0 18 <script type="application/javascript">
michael@0 19 <![CDATA[
michael@0 20
michael@0 21 /** Mock Idle Service Test for Bug 715041 **/
michael@0 22 SpecialPowers.setBoolPref("dom.idle-observers-api.fuzz_time.disabled", true);
michael@0 23
michael@0 24 //class mock javascript idle service
michael@0 25 var idleServiceObj = {
michael@0 26 observers: [],
michael@0 27 windowObservers: [],
michael@0 28 idleTimeInMS: 5000, //in milli seconds
michael@0 29
michael@0 30 // takes note of the idle observers added as the minimum idle observer
michael@0 31 // with the idle service
michael@0 32 timesAdded: [],
michael@0 33
michael@0 34 QueryInterface: function(iid) {
michael@0 35 if (iid.equals(Components.interfaces.nsISupports) ||
michael@0 36 iid.equals(Components.interfaces.nsIFactory) ||
michael@0 37 iid.equals(Components.interfaces.nsIIdleService)) {
michael@0 38 return this;
michael@0 39 }
michael@0 40 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 41 },
michael@0 42
michael@0 43 createInstance: function(outer, iid) {
michael@0 44 return this.QueryInterface(iid);
michael@0 45 },
michael@0 46
michael@0 47 get idleTime() {
michael@0 48 return this.idleTimeInMS; //in milli seconds
michael@0 49 },
michael@0 50
michael@0 51 set idleTime(timeInMS) {
michael@0 52 this.idleTimeInMS = timeInMS;
michael@0 53 },
michael@0 54
michael@0 55 getWindowFromObserver: function(observer) {
michael@0 56 try {
michael@0 57 var interfaceRequestor = observer.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
michael@0 58 var window = interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow);
michael@0 59 return window;
michael@0 60 }
michael@0 61 catch (e) {}
michael@0 62
michael@0 63 return null;
michael@0 64 },
michael@0 65
michael@0 66 testIdleBackService: function(observer, topic) {
michael@0 67 dump("\nJS FAKE IDLE SERVICE\n");
michael@0 68 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
michael@0 69
michael@0 70 if (this.observers.length > 1) {
michael@0 71 this.observers[1].observer.observe(observer, topic, '\0');
michael@0 72 dump("JS CALLED OBSERVE FUNCTION!!!\n\n");
michael@0 73 }
michael@0 74 },
michael@0 75
michael@0 76 addIdleObserver: function(observer, time) {
michael@0 77 dump("\nJS FAKE IDLE SERVICE add idle observer before\n");
michael@0 78 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
michael@0 79
michael@0 80 var window = this.getWindowFromObserver(observer);
michael@0 81 dump("window is: " + window + "\n");
michael@0 82
michael@0 83 if (window) {
michael@0 84 this.observers.push({ observer: observer, time: time, });
michael@0 85 addedIdleObserver = true;
michael@0 86 numIdleObserversAdded++;
michael@0 87 this.timesAdded.push(time);
michael@0 88
michael@0 89 dump ("\nMOCK IDLE SERVICE ADDING idle observer with time: " + time + "\n");
michael@0 90 dump("MOCK IDLE SERVICE: num idle observers added: " + numIdleObserversAdded + "\n\n");
michael@0 91 }
michael@0 92 else {
michael@0 93 dump("SHOULD NEVER GET HERE!");
michael@0 94 oldIdleService.addIdleObserver(observer, time);
michael@0 95 addedIdleObserver = false;
michael@0 96 }
michael@0 97
michael@0 98 dump("\nJS FAKE IDLE SERVICE end of add idle observer\n");
michael@0 99 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
michael@0 100 },
michael@0 101
michael@0 102 removeIdleObserver: function(observer, time) {
michael@0 103 dump("\nJS REMOVE IDLE OBSERVER () time to be removed: " + time + "\n");
michael@0 104 var window = this.getWindowFromObserver(observer);
michael@0 105 if (!window) {
michael@0 106 oldIdleService.removeIdleObserver(observer, time);
michael@0 107 }
michael@0 108 else {
michael@0 109 var observerIndex = -1;
michael@0 110 for (var i=0; i<this.observers.length; i++) {
michael@0 111 dump("JS removeIdleObserver() observer time: " + this.observers[i].time + "\n");
michael@0 112 if (this.observers[i].time === time) {
michael@0 113 observerIndex = i;
michael@0 114 break;
michael@0 115 }
michael@0 116 }
michael@0 117
michael@0 118 if (observerIndex != -1 && this.observers.length > 0) {
michael@0 119 numIdleObserversRemoved++;
michael@0 120 this.observers.splice(observerIndex, 1);
michael@0 121 removedIdleObserver = true;
michael@0 122 dump("MOCK IDLE SERVICE REMOVING idle observer with time " + time + "\n");
michael@0 123 dump("MOCK IDLE SERVICE numIdleObserversRemoved: " + numIdleObserversRemoved + " numIdleObserversAdded: " + numIdleObserversAdded + "\n\n");
michael@0 124 }
michael@0 125 else {
michael@0 126 removedIdleObserver = false;
michael@0 127 }
michael@0 128 }
michael@0 129 dump("\nJS FAKE IDLE SERVICE end of remove idle observer\n");
michael@0 130 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
michael@0 131 },
michael@0 132 };
michael@0 133
michael@0 134 /** Test for Bug 715041 **/
michael@0 135 dump("\n\n\nJS STARTING TESTING FOR BUG 715041\n");
michael@0 136
michael@0 137 //bool variables
michael@0 138 var addedIdleObserver = removedIdleObserver = passed = cleanUp = false;
michael@0 139
michael@0 140 //test case enabled
michael@0 141 var AddOutOfOrderActiveEnabled = AddOutOfOrderIdleEnabled =
michael@0 142 AddShiftLocalEnabled = AddNewLocalWhileAllIdleEnabled =
michael@0 143 TestActiveToActiveNotification = ShiftLocalTimerBackEnabled =
michael@0 144 AddRemoveIdleObserverWithInvalidTimeEnabled = true;
michael@0 145
michael@0 146 //msgXCount
michael@0 147 var msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
michael@0 148 msg6Count = tcZero = currTestCaseNum = prevMsgNum =
michael@0 149 numIdleObserversRemoved = numIdleObserversAdded = 0;
michael@0 150
michael@0 151 //test case number
michael@0 152 var tcZero = 0;
michael@0 153 var tcAddOutOfOrderActive = 1;
michael@0 154 var tcAddOutOfOrderIdle = 2;
michael@0 155 var tcAddShiftLocal = 3;
michael@0 156 var tcAddNewLocalWhileAllIdle = 4;
michael@0 157 var tcShiftLocalTimerBack = 5;
michael@0 158 var tcAddRemoveIdleObserverWithInvalidTime = 6;
michael@0 159 var tcTestActiveToActiveNotification = 7;
michael@0 160
michael@0 161 function ResetMsgCounts() {
michael@0 162 msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
michael@0 163 msg6Count = prevMsgNum = 0;
michael@0 164 }
michael@0 165
michael@0 166 function ResetVars() {
michael@0 167 msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
michael@0 168 msg6Count = prevMsgNum = 0;
michael@0 169
michael@0 170 numIdleObserversAdded = numIdleObserversRemoved = 0;
michael@0 171 currTestCaseNum = -1;
michael@0 172 addedIdleObserver = removedIdleObserver = passed = cleanUp = false;
michael@0 173 }
michael@0 174
michael@0 175 /*
michael@0 176 * - function printMsgCounts()
michael@0 177 */
michael@0 178 function printMsgCounts() {
michael@0 179 dump("\nmsg0Count: " + msg0Count +
michael@0 180 "\nmsg1Count: " + msg1Count +
michael@0 181 "\nmsg2Count: " + msg2Count +
michael@0 182 "\nmsg3Count: " + msg3Count +
michael@0 183 "\nmsg5Count: " + msg5Count +
michael@0 184 "\nmsg6Count: " + msg6Count +
michael@0 185 "\n"
michael@0 186 );
michael@0 187 }
michael@0 188
michael@0 189 function performNextTest() {
michael@0 190 dump("\nfunction performNextTest()\ncurrTestCaseNum: " + currTestCaseNum +
michael@0 191 "\ncleanUp: " + cleanUp +
michael@0 192 "\npassed: " + passed +
michael@0 193 "\nnumIdleObserversRemoved: " + numIdleObserversRemoved +
michael@0 194 "\nnumIdleObservesAdded: " + numIdleObserversAdded + "\n");
michael@0 195
michael@0 196 switch (currTestCaseNum) {
michael@0 197 case tcZero:
michael@0 198 ok(passed, "Test case 0 failed clean up!");
michael@0 199 caseZeroCleanUp();
michael@0 200 break;
michael@0 201 case tcAddShiftLocal:
michael@0 202 if (cleanUp && numIdleObserversRemoved === 1) {
michael@0 203 passed = true;
michael@0 204 ok(passed, "Failed test case AddShiftLocalCleanUp()");
michael@0 205 if (AddNewLocalWhileAllIdleEnabled) {
michael@0 206 AddNewLocalWhileAllIdle();
michael@0 207 }
michael@0 208 else {
michael@0 209 SimpleTest.finish();
michael@0 210 }
michael@0 211 }
michael@0 212 break;
michael@0 213 case tcAddNewLocalWhileAllIdle:
michael@0 214 ok(passed, "Failed test case: AddNewLocalWhileAllIdle()");
michael@0 215 AddNewLocalWhileAllIdleCleanUp();
michael@0 216 break;
michael@0 217 default:
michael@0 218 //do nothing.
michael@0 219 break;
michael@0 220 }
michael@0 221 }
michael@0 222
michael@0 223 //Place Holder.
michael@0 224 var idleHandler0 = function() { dump("rmsg 0, should never be used!\n"); };
michael@0 225
michael@0 226 //idleHandler1
michael@0 227 function idleHandler1() {
michael@0 228 msg1Count++;
michael@0 229 dump("msg 1 Count: " + msg1Count + "\n");
michael@0 230
michael@0 231 switch (currTestCaseNum) {
michael@0 232 case tcAddOutOfOrderIdle:
michael@0 233 if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1) {
michael@0 234 idleServiceObj.idleTime = 0;
michael@0 235 idleServiceObj.testIdleBackService(idleObserversArray[1], "active");
michael@0 236 }
michael@0 237 else if (msg1Count === 4 && msg2Count === 4 && msg3Count === 4) {
michael@0 238 passed = true;
michael@0 239 AddOutOfOrderIdleCleanUp();
michael@0 240 }
michael@0 241 break;
michael@0 242 case tcTestActiveToActiveNotification:
michael@0 243 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
michael@0 244 idleServiceObj.idleTime = 500;
michael@0 245 idleServiceObj.testIdleBackService(idleObserversArray[1], "active");
michael@0 246 return;
michael@0 247 }
michael@0 248
michael@0 249 if (msg1Count === 2 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
michael@0 250 idleServiceObj.idleTime = 1000;
michael@0 251 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 252 return;
michael@0 253 }
michael@0 254
michael@0 255 if (msg1Count === 3 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
michael@0 256 return;
michael@0 257 }
michael@0 258 ok(false, "Failed test active to active notification.");
michael@0 259 SimpleTest.finish();
michael@0 260 break;
michael@0 261 default:
michael@0 262 break;
michael@0 263 }
michael@0 264 }
michael@0 265
michael@0 266 //idleHandler2
michael@0 267 function idleHandler2() {
michael@0 268 msg2Count++;
michael@0 269 dump("msg 2 Count: " + msg2Count + "\n");
michael@0 270
michael@0 271 switch (currTestCaseNum) {
michael@0 272 case tcZero:
michael@0 273 switch (msg2Count) {
michael@0 274 case 2:
michael@0 275 passed = true;
michael@0 276 performNextTest();
michael@0 277 break;
michael@0 278 default:
michael@0 279 break;
michael@0 280 }
michael@0 281 break;
michael@0 282 case tcAddOutOfOrderIdle:
michael@0 283 if (msg3Count === 1 && msg2Count === 1 && !msg1Count) {
michael@0 284 idleServiceObj.idleTime = 4000;
michael@0 285 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 286 }
michael@0 287 break;
michael@0 288 case tcAddShiftLocal:
michael@0 289 if (!msg1Count && msg2Count === 1 && !msg3Count && !msg4Count) {
michael@0 290 window.navigator.addIdleObserver(idleObserversArray[3]);
michael@0 291 }
michael@0 292 AddShiftLocalCleanUp();
michael@0 293 break;
michael@0 294 case tcAddNewLocalWhileAllIdle:
michael@0 295 if (msg1Count === 1 && msg2Count === 2) {
michael@0 296 idleServiceObj.idleTime = 3500;
michael@0 297 window.navigator.addIdleObserver(idleObserversArray[5]);
michael@0 298 }
michael@0 299 break;
michael@0 300 case (tcShiftLocalTimerBack):
michael@0 301 if (!msg1Count && msg2Count === 1 && !msg3Count && !msg4Count && !msg5Count) {
michael@0 302 window.navigator.addIdleObserver(idleObserversArray[5]);
michael@0 303 window.navigator.addIdleObserver(idleObserversArray[4]);
michael@0 304 }
michael@0 305 break;
michael@0 306 default:
michael@0 307 //do nothing.
michael@0 308 break;
michael@0 309 }
michael@0 310 }
michael@0 311
michael@0 312 //idleHandler3
michael@0 313 function idleHandler3() {
michael@0 314 msg3Count++;
michael@0 315 dump("msg 3 Count: " + msg3Count + "\n");
michael@0 316
michael@0 317 switch (currTestCaseNum) {
michael@0 318 case (tcAddOutOfOrderIdle):
michael@0 319 if (msg3Count === 1) {
michael@0 320 idleServiceObj.idleTime = 3500;
michael@0 321 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 322 }
michael@0 323 if (msg1Count === 2 && msg2Count === 2 && msg3Count === 2) {
michael@0 324 idleServiceObj.idleTime = 1000;
michael@0 325 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 326 }
michael@0 327 else if (msg1Count === 3 && msg2Count === 3 && msg3Count === 3) {
michael@0 328 AddOutOfOrderIdle();
michael@0 329 }
michael@0 330 else if (msg1Count === 3 && msg2Count === 3 && msg3Count === 4) {
michael@0 331 passed = true;
michael@0 332 AddOutOfOrderIdleCleanUp();
michael@0 333 }
michael@0 334 break;
michael@0 335 default:
michael@0 336 break;
michael@0 337 }
michael@0 338 }
michael@0 339
michael@0 340 //idleHandler4
michael@0 341 function idleHandler4() {
michael@0 342 msg4Count++;
michael@0 343 dump("msg 4 Count: " + msg4Count + "\n");
michael@0 344
michael@0 345 switch (currTestCaseNum) {
michael@0 346 case tcAddOutOfOrderActive:
michael@0 347 if (msg1Count && msg2Count && msg3Count && msg4Count) {
michael@0 348 passed = true;
michael@0 349 ok(passed, "idleHandler4: failed AddOutOfOrderActive()");
michael@0 350 AddOutOfOrderActiveCleanUp();
michael@0 351 cleanUp = true;
michael@0 352 }
michael@0 353 break;
michael@0 354 case tcAddShiftLocal:
michael@0 355 if (msg1Count === 1 && msg3Count === 1 && msg4Count === 1) {
michael@0 356 idleServiceObj.idleTime = 3200;
michael@0 357 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 358 }
michael@0 359 break;
michael@0 360 default:
michael@0 361 //do nothing.
michael@0 362 break;
michael@0 363 }
michael@0 364 }
michael@0 365
michael@0 366 //idleHandler5
michael@0 367 function idleHandler5() {
michael@0 368 msg5Count++;
michael@0 369 dump("msg 5 Count: " + msg5Count + "\n");
michael@0 370
michael@0 371 switch (currTestCaseNum) {
michael@0 372 case tcAddNewLocalWhileAllIdle:
michael@0 373 if (msg1Count === 1 && msg2Count === 2 && msg5Count === 1) {
michael@0 374 passed = true;
michael@0 375 performNextTest();
michael@0 376 }
michael@0 377 break;
michael@0 378 case tcShiftLocalTimerBack:
michael@0 379 if (!msg1Count && msg2Count === 1 && !msg3Count && msg4Count === 1 && msg5Count === 1) {
michael@0 380 passed = true;
michael@0 381 ShiftLocalTimerBackCleanUp();
michael@0 382 }
michael@0 383 break;
michael@0 384 case tcTestActiveToActiveNotification:
michael@0 385 passed = false;
michael@0 386 if (msg1Count === 3 && !msg2Count && !msg3Count && !msg4Count && msg5Count === 1) {
michael@0 387 passed = true;
michael@0 388 }
michael@0 389 ok(passed, "Failed TestActiveToActiveNotification.");
michael@0 390 TestActiveNotificationCleanUp();
michael@0 391 break;
michael@0 392 default:
michael@0 393 //do nothing.
michael@0 394 break;
michael@0 395 }
michael@0 396 }
michael@0 397
michael@0 398 //idleHandler6
michael@0 399 function idleHandler6() {
michael@0 400 dump("msg 6 Count: " + msg6Count + "\n");
michael@0 401 }
michael@0 402
michael@0 403 var idleObserversArray = [];
michael@0 404 idleObserversArray[0] = {time: 0, onidle: idleHandler0, onactive: idleHandler0};
michael@0 405 idleObserversArray[1] = {time: 1, onidle: idleHandler1, onactive: idleHandler1};
michael@0 406 idleObserversArray[2] = {time: 2, onidle: idleHandler2, onactive: idleHandler2};
michael@0 407 idleObserversArray[3] = {time: 3, onidle: idleHandler3, onactive: idleHandler3};
michael@0 408 idleObserversArray[4] = {time: 4, onidle: idleHandler4, onactive: idleHandler4};
michael@0 409 idleObserversArray[5] = {time: 5, onidle: idleHandler5, onactive: idleHandler5};
michael@0 410 idleObserversArray[6] = {time: 0, onidle: idleHandler6, onactive: idleHandler6};
michael@0 411 idleObserversArray[7] = {time: 2, onidle: null, onactive: null};
michael@0 412
michael@0 413 idleServiceObj.observers.push( {observer: idleObserversArray[0], time: 0, } );
michael@0 414
michael@0 415 /*
michael@0 416 * - case 0
michael@0 417 * - AddSingleIdleObserver
michael@0 418 * - takes care of adding duplicate local too
michael@0 419 * - user is currently idle since the
michael@0 420 * requested idle time of 2s < current idle time of 5000ms set below.
michael@0 421 */
michael@0 422 function caseZero() {
michael@0 423 dump("\n\nTESTING CASE 0\n");
michael@0 424 dump("==============\n");
michael@0 425
michael@0 426 ResetVars();
michael@0 427 currTestCaseNum = tcZero;
michael@0 428 idleServiceObj.idleTime = 5000;
michael@0 429
michael@0 430 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 431 idleServiceObj.testIdleBackService(idleObserversArray[2], "idle");
michael@0 432 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 433 }
michael@0 434
michael@0 435 function caseZeroCleanUp() {
michael@0 436 dump("\ncaseZeroCleanUp()\n");
michael@0 437 dump("==============\n");
michael@0 438 ResetVars();
michael@0 439 currTestCaseNum = tcZero;
michael@0 440 cleanUp = false;
michael@0 441
michael@0 442 window.navigator.removeIdleObserver(idleObserversArray[2]);
michael@0 443 window.navigator.removeIdleObserver(idleObserversArray[2]);
michael@0 444
michael@0 445 if (AddOutOfOrderActiveEnabled) {
michael@0 446 AddOutOfOrderActive();
michael@0 447 }
michael@0 448 else {
michael@0 449 dump("Finishing testing idle API.\n");
michael@0 450 SimpleTest.finish();
michael@0 451 }
michael@0 452 }
michael@0 453
michael@0 454 /*
michael@0 455 AddOutOfOrderActive()
michael@0 456 - Tests if the idle observer with the min time is always registered correctly
michael@0 457 with the idle service.
michael@0 458 */
michael@0 459 function AddOutOfOrderActive() {
michael@0 460 dump("\n\nTESTING CASE AddOutOfOrderActive\n");
michael@0 461 dump("==============\n");
michael@0 462
michael@0 463 ResetVars();
michael@0 464 currTestCaseNum = tcAddOutOfOrderActive;
michael@0 465 idleServiceObj.idleTime = 500;
michael@0 466
michael@0 467 window.navigator.addIdleObserver(idleObserversArray[3]); //msg3
michael@0 468 window.navigator.addIdleObserver(idleObserversArray[4]); //msg4
michael@0 469 window.navigator.addIdleObserver(idleObserversArray[1]); //msg1
michael@0 470 window.navigator.addIdleObserver(idleObserversArray[2]); //msg2
michael@0 471 passed = false;
michael@0 472
michael@0 473 idleServiceObj.idleTime = 1000;
michael@0 474 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 475 }
michael@0 476
michael@0 477 /*
michael@0 478 - AddOutOfOrderActiveCleanUp()
michael@0 479 */
michael@0 480 function AddOutOfOrderActiveCleanUp() {
michael@0 481 dump("\nAddOutOfOrderActiveCleanUp()\n");
michael@0 482 dump("==============================\n");
michael@0 483 ResetVars();
michael@0 484 currTestCaseNum = tcAddOutOfOrderActive;
michael@0 485 cleanUp = false;
michael@0 486 idleServiceObj.idleTime = 4500;
michael@0 487
michael@0 488 for (var i=1; i<5; i++) {
michael@0 489 window.navigator.removeIdleObserver(idleObserversArray[i]);
michael@0 490 }
michael@0 491 dump("JS AddOutOfOrderActiveCleanUp() DONE\n");
michael@0 492 if (AddOutOfOrderIdleEnabled) {
michael@0 493 AddOutOfOrderIdle();
michael@0 494 }
michael@0 495 else {
michael@0 496 dump("Finishing testing idle API.\n");
michael@0 497 SimpleTest.finish();
michael@0 498 }
michael@0 499 }
michael@0 500
michael@0 501 /*
michael@0 502 - AddOutOfOrderIdle()
michael@0 503 */
michael@0 504 function AddOutOfOrderIdle() {
michael@0 505 dump("\nAddOutOfOrderIdle()\n");
michael@0 506 dump("======================================================================\n");
michael@0 507
michael@0 508 dump("\nJS AddOutOfOrderIdle\n");
michael@0 509 dump("JS NUM OBSERVERS: " + idleServiceObj.observers.length + "\n");
michael@0 510
michael@0 511 if (!msg1Count && !msg2Count && !msg3Count) {
michael@0 512 ResetVars();
michael@0 513 }
michael@0 514 currTestCaseNum = tcAddOutOfOrderIdle;
michael@0 515 cleanUp = false;
michael@0 516
michael@0 517 if (!msg1Count && !msg2Count && !msg3Count) {
michael@0 518 idleServiceObj.idleTime = 3100;
michael@0 519 }
michael@0 520 window.navigator.addIdleObserver(idleObserversArray[3]);
michael@0 521 if (!msg1Count && !msg2Count && !msg3Count) {
michael@0 522 idleServiceObj.testIdleBackService(idleObserversArray[3], "idle");
michael@0 523 }
michael@0 524 }
michael@0 525
michael@0 526 /*
michael@0 527 - AddOutOfOrderIdleCleanUp()
michael@0 528 */
michael@0 529 function AddOutOfOrderIdleCleanUp() {
michael@0 530 ok(passed, "Failed test case: AddOutOfOrderIdle()");
michael@0 531 dump("\nAddOutOfOrderIdleCleanUp()\n");
michael@0 532 dump("==========================\n");
michael@0 533 ResetVars();
michael@0 534 currTestCaseNum = tcAddOutOfOrderIdle;
michael@0 535 cleanUp = true;
michael@0 536 idleServiceObj.idleTime = 4100;
michael@0 537
michael@0 538 for (var j=1; j<4; j++) {
michael@0 539 window.navigator.removeIdleObserver(idleObserversArray[j]);
michael@0 540 }
michael@0 541 window.navigator.removeIdleObserver(idleObserversArray[3]);
michael@0 542
michael@0 543 if (idleServiceObj.observers.length === 1) {
michael@0 544 passed = true;
michael@0 545 }
michael@0 546 else {
michael@0 547 passed = false;
michael@0 548 }
michael@0 549 ok(passed, "Failed test case: AddOutOfOrderIdleCleanUp()");
michael@0 550 if (AddShiftLocalEnabled) {
michael@0 551 AddShiftLocal();
michael@0 552 }
michael@0 553 else {
michael@0 554 dump("Finished AddOutOfOrderIdleCleanUp() test.\n");
michael@0 555 SimpleTest.finish();
michael@0 556 }
michael@0 557 }
michael@0 558
michael@0 559 /*
michael@0 560 * function AddShiftLocal()
michael@0 561 * - user is idle
michael@0 562 * - check that local idle timer is shifted correctly
michael@0 563 * - msg 1 fired when user is idle
michael@0 564 * - msg 3 fired when 3000
michael@0 565 * - msg 2 fired immediately when added at 3200 ms
michael@0 566 * - msg 4 fired by local timer.
michael@0 567 */
michael@0 568 function AddShiftLocal()
michael@0 569 {
michael@0 570 dump("\n\nTESTING CASE AddShiftLocal\n");
michael@0 571 dump("==============\n");
michael@0 572
michael@0 573 ResetVars();
michael@0 574 currTestCaseNum = tcAddShiftLocal;
michael@0 575 idleServiceObj.idleTime = 500;
michael@0 576
michael@0 577 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 578 window.navigator.addIdleObserver(idleObserversArray[3]);
michael@0 579 window.navigator.addIdleObserver(idleObserversArray[4]);
michael@0 580
michael@0 581 idleServiceObj.idleTime = 1000;
michael@0 582 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 583 }
michael@0 584
michael@0 585 /*
michael@0 586 * function AddShiftLocalCleanUp()
michael@0 587 */
michael@0 588 function AddShiftLocalCleanUp()
michael@0 589 {
michael@0 590 dump("\n\nTESTING CASE AddShiftLocalCleanUp\n");
michael@0 591 dump("==============\n");
michael@0 592
michael@0 593 ResetVars();
michael@0 594 currTestCaseNum = tcAddShiftLocal;
michael@0 595
michael@0 596 for (var i=1; i<5; i++) {
michael@0 597 window.navigator.removeIdleObserver(idleObserversArray[i]);
michael@0 598 }
michael@0 599 dump("AddShiftLocalCleanUp() done clean up\n");
michael@0 600 if (AddNewLocalWhileAllIdleEnabled) {
michael@0 601 AddNewLocalWhileAllIdle();
michael@0 602 }
michael@0 603 else {
michael@0 604 dump("Finished testing AddShiftLocal()\n");
michael@0 605 SimpleTest.finish();
michael@0 606 }
michael@0 607 }
michael@0 608
michael@0 609 /*
michael@0 610 * AddNewLocalWhileAllIdle()
michael@0 611 * - no local idle timer exists because all of the idle observers that were added had a requested
michael@0 612 * idle time of < curr user idle time and so were fired immediately. No local timer was required.
michael@0 613 * - now add an idle observer whose requested idle time is > current use idle time and > min idle
michael@0 614 * requested time in the list of idle observers.
michael@0 615 */
michael@0 616 function AddNewLocalWhileAllIdle()
michael@0 617 {
michael@0 618 dump("\n\nTESTING CASE AddNewLocalWhileAllIdle\n");
michael@0 619 dump("==============\n");
michael@0 620
michael@0 621 ResetVars();
michael@0 622 currTestCaseNum = tcAddNewLocalWhileAllIdle;
michael@0 623 idleServiceObj.idleTime = 500;
michael@0 624
michael@0 625 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 626 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 627 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 628
michael@0 629 idleServiceObj.idleTime = 1000;
michael@0 630 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 631 }
michael@0 632
michael@0 633 function AddNewLocalWhileAllIdleCleanUp()
michael@0 634 {
michael@0 635 dump("\n\nTESTING CASE AddNewLocalWhileAllIdleCleanUp\n");
michael@0 636 dump("==============\n");
michael@0 637
michael@0 638 ResetVars();
michael@0 639 currTestCaseNum = tcAddNewLocalWhileAllIdle;
michael@0 640
michael@0 641 window.navigator.removeIdleObserver(idleObserversArray[1]);
michael@0 642 window.navigator.removeIdleObserver(idleObserversArray[2]);
michael@0 643 window.navigator.removeIdleObserver(idleObserversArray[2]);
michael@0 644 window.navigator.removeIdleObserver(idleObserversArray[5]);
michael@0 645
michael@0 646 if (ShiftLocalTimerBackEnabled) {
michael@0 647 ShiftLocalTimerBack();
michael@0 648 }
michael@0 649 else {
michael@0 650 dump("Finished testing TestActiveToActiveNotificationCleanUp()\n");
michael@0 651 SimpleTest.finish();
michael@0 652 }
michael@0 653 }
michael@0 654
michael@0 655 /*
michael@0 656 * ShiftLocalTimerBack()
michael@0 657 * - add a new idle observer whose requested time is > current user idle time
michael@0 658 * but < the current local timer that has been set.
michael@0 659 * - the local timer will need to be reset to fire the new msg added.
michael@0 660 * RESULT
michael@0 661 * - should print all of them in order
michael@0 662 */
michael@0 663 function ShiftLocalTimerBack()
michael@0 664 {
michael@0 665 dump("\n\nTESTING CASE ShiftLocalTimerBack()\n");
michael@0 666 dump("==============\n");
michael@0 667
michael@0 668 ResetVars();
michael@0 669 currTestCaseNum = tcShiftLocalTimerBack;
michael@0 670 idleServiceObj.idleTime = 2100;
michael@0 671
michael@0 672 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 673 idleServiceObj.testIdleBackService(idleObserversArray[2], "idle");
michael@0 674 }
michael@0 675
michael@0 676 function ShiftLocalTimerBackCleanUp()
michael@0 677 {
michael@0 678 dump("\n\nTESTING CASE ShiftLocalTimerBackCleanUp\n");
michael@0 679 dump("==============\n");
michael@0 680
michael@0 681 ResetVars();
michael@0 682 currTestCaseNum = tcShiftLocalTimerBack;
michael@0 683 window.navigator.removeIdleObserver(idleObserversArray[2]);
michael@0 684 window.navigator.removeIdleObserver(idleObserversArray[4]);
michael@0 685 window.navigator.removeIdleObserver(idleObserversArray[5]);
michael@0 686 dump("ShiftLocalTimerBackCleanUp() done clean up\n");
michael@0 687
michael@0 688 if (TestActiveToActiveNotificationEnabled) {
michael@0 689 TestActiveNotification();
michael@0 690 }
michael@0 691 else {
michael@0 692 dump("Finished testing AddNewLocalWhileAllIdle()\n");
michael@0 693 SimpleTest.finish();
michael@0 694 }
michael@0 695 }
michael@0 696
michael@0 697 function TestActiveNotification()
michael@0 698 {
michael@0 699 dump("\n\nTESTING CASE TestActiveNotification\n");
michael@0 700 dump("===============================================\n");
michael@0 701
michael@0 702 ResetVars();
michael@0 703 currTestCaseNum = tcTestActiveToActiveNotification;
michael@0 704
michael@0 705 idleServiceObj.idleTime = 500;
michael@0 706 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 707 window.navigator.addIdleObserver(idleObserversArray[5]);
michael@0 708 idleServiceObj.idleTime = 1000;
michael@0 709 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 710 }
michael@0 711
michael@0 712 function TestActiveNotificationCleanUp()
michael@0 713 {
michael@0 714 dump("\n\nTESTING CASE TestActiveNotificationCleanUp\n");
michael@0 715 dump("===============================================\n");
michael@0 716
michael@0 717 try {
michael@0 718 componentMgr.unregisterFactory(idleServiceCID, idleServiceObj);
michael@0 719 }
michael@0 720 catch(err) {
michael@0 721 dump("test_bug715041.xul: ShiftLocalTimerBackCleanUp() Failed to unregister factory, mock idle service!\n");
michael@0 722 }
michael@0 723
michael@0 724 try {
michael@0 725 componentMgr.registerFactory(oldIdleServiceCID, "Re registering old idle service", idleServiceContractID, oldIdleServiceFactoryObj);
michael@0 726 }
michael@0 727 catch(err) {
michael@0 728 dump("test_bug715041.xul: ShiftLocalTimerBackCleanUp() Failed to register factory, original idle service!\n");
michael@0 729 }
michael@0 730
michael@0 731 SimpleTest.finish();
michael@0 732 }
michael@0 733
michael@0 734 /*
michael@0 735 * function AddRemoveIdleObserverWithInvalidTime()
michael@0 736 */
michael@0 737 function AddRemoveIdleObserverWithInvalidTime()
michael@0 738 {
michael@0 739 dump("\n\nTESTING CASE AddRemoveIdleObserverWithInvalidTime()\n");
michael@0 740 dump("==============\n");
michael@0 741
michael@0 742 ResetVars();
michael@0 743 currTestCaseNum = tcAddRemoveIdleObserverWithInvalidTime;
michael@0 744
michael@0 745 //while idle
michael@0 746 idleServiceObj.idleTime = 2100;
michael@0 747 var rv = window.navigator.addIdleObserver(idleObserversArray[6]);
michael@0 748 dump("rv: " + rv + "\n");
michael@0 749 rv = window.navigator.removeIdleObserver(idleObserversArray[6]);
michael@0 750
michael@0 751 idleServiceObj.idleTime = 0;
michael@0 752 window.navigator.addIdleObserver(idleObserversArray[6]);
michael@0 753 window.navigator.removeIdleObserver(idleObserversArray[6]);
michael@0 754
michael@0 755 SimpleTest.finish();
michael@0 756 }
michael@0 757
michael@0 758 try {
michael@0 759 var idleServiceCID = Components.ID("287075a6-f968-4516-8043-406c46f503b4");
michael@0 760 var idleServiceContractID = "@mozilla.org/widget/idleservice;1";
michael@0 761 var oldIdleService = Components.classes[idleServiceContractID].getService(Components.interfaces.nsIIdleService);
michael@0 762 }
michael@0 763 catch(ex) {
michael@0 764 dump("test_bug715041.xul: 1) Failed to get old idle service.\n");
michael@0 765 }
michael@0 766
michael@0 767 try {
michael@0 768 // Registering new moch JS idle service
michael@0 769 var componentMgr = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
michael@0 770 }
michael@0 771 catch(err) {
michael@0 772 dump("test_bug715041.xul: Failed to query component registrar interface.\n");
michael@0 773 }
michael@0 774
michael@0 775 try {
michael@0 776 var oldIdleServiceFactoryObj = componentMgr.getClassObjectByContractID(idleServiceContractID, Components.interfaces.nsIFactory);
michael@0 777 }
michael@0 778 catch(err) {
michael@0 779 dump("test_bug715041.xul: Failed to get old idle service.\n");
michael@0 780 }
michael@0 781
michael@0 782 try {
michael@0 783 var oldIdleServiceCID = componentMgr.contractIDToCID(idleServiceContractID);
michael@0 784 }
michael@0 785 catch(err) {
michael@0 786 dump("test_bug715041.xul: Failed to convert ID to CID for old idle service.\n");
michael@0 787 }
michael@0 788
michael@0 789 try {
michael@0 790 componentMgr.unregisterFactory(oldIdleServiceCID, oldIdleServiceFactoryObj);
michael@0 791 }
michael@0 792 catch(err) {
michael@0 793 dump("test_bug715041.xul: Failed to unregister old idle service factory object!\n");
michael@0 794 }
michael@0 795
michael@0 796 try {
michael@0 797 componentMgr.registerFactory(idleServiceCID, "Test Simple Idle/Back Notifications", idleServiceContractID, idleServiceObj);
michael@0 798 }
michael@0 799 catch(err) {
michael@0 800 dump("test_bug715041.xul: Failed to register mock idle service.\n");
michael@0 801 }
michael@0 802
michael@0 803 SimpleTest.waitForExplicitFinish();
michael@0 804 SimpleTest.requestLongerTimeout(10);
michael@0 805
michael@0 806 AddOutOfOrderActiveEnabled = true;
michael@0 807 AddOutOfOrderIdleEnabled = true;
michael@0 808 AddNewLocalWhileAllIdleEnabled = true;
michael@0 809 TestActiveToActiveNotificationEnabled = true;
michael@0 810 AddShiftLocalEnabled = true;
michael@0 811 AddIdleObserverWithInvalidTimeEnabled = false;
michael@0 812
michael@0 813 caseZero();
michael@0 814
michael@0 815 ]]>
michael@0 816 </script>
michael@0 817 </window>
michael@0 818

mercurial