dom/base/test/test_bug715041_removal.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 try {
michael@0 25 var idleServiceCID = Components.ID("6f95d965-4322-4829-8a3c-5dc8a4587f4d");
michael@0 26 var idleServiceContractID = "@mozilla.org/widget/idleservice;1";
michael@0 27 var oldIdleService = Components.classes[idleServiceContractID].getService(Components.interfaces.nsIIdleService);
michael@0 28 }
michael@0 29 catch (ex) {
michael@0 30 dump("test_bug715041_removal.xul: failed to get old idle service 1.");
michael@0 31 }
michael@0 32
michael@0 33 //class mock javascript idle service
michael@0 34 var idleServiceObj = {
michael@0 35 observers: [],
michael@0 36 windowObservers: [],
michael@0 37 idleTimeInMS: 5000, //in milli seconds
michael@0 38
michael@0 39 // takes note of the idle observers added as the minimum idle observer
michael@0 40 //with the idle service
michael@0 41 timesAdded: [],
michael@0 42
michael@0 43 QueryInterface: function(iid) {
michael@0 44 if (iid.equals(Components.interfaces.nsISupports) ||
michael@0 45 iid.equals(Components.interfaces.nsIFactory) ||
michael@0 46 iid.equals(Components.interfaces.nsIIdleService)) {
michael@0 47 return this;
michael@0 48 }
michael@0 49 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 50 },
michael@0 51
michael@0 52 createInstance: function(outer, iid) {
michael@0 53 return this.QueryInterface(iid);
michael@0 54 },
michael@0 55
michael@0 56 get idleTime() {
michael@0 57 return this.idleTimeInMS; //in milli seconds
michael@0 58 },
michael@0 59
michael@0 60 set idleTime(timeInMS) {
michael@0 61 this.idleTimeInMS = timeInMS;
michael@0 62 },
michael@0 63
michael@0 64 getWindowFromObserver: function(observer) {
michael@0 65 try {
michael@0 66 var interfaceRequestor = observer.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
michael@0 67 var window = interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow);
michael@0 68 return window;
michael@0 69 }
michael@0 70 catch (e) {}
michael@0 71
michael@0 72 return null;
michael@0 73 },
michael@0 74
michael@0 75 testIdleBackService: function(observer, topic) {
michael@0 76 dump("\nJS FAKE IDLE SERVICE\n");
michael@0 77 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
michael@0 78
michael@0 79 if (this.observers.length > 1) {
michael@0 80 this.observers[1].observer.observe(observer, topic, '\0');
michael@0 81 dump("JS CALLED OBSERVE FUNCTION!!!\n\n");
michael@0 82 }
michael@0 83 },
michael@0 84
michael@0 85 addIdleObserver: function(observer, time) {
michael@0 86 dump("\nJS FAKE IDLE SERVICE add idle observer before\n");
michael@0 87 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
michael@0 88 var window = this.getWindowFromObserver(observer);
michael@0 89
michael@0 90 if (window) {
michael@0 91 this.observers.push({ observer: observer, time: time, });
michael@0 92 addedIdleObserver = true;
michael@0 93 numIdleObserversAdded++;
michael@0 94 this.timesAdded.push(time);
michael@0 95 dump ("\nMOCK IDLE SERVICE ADDING idle observer with time: " + time + "\n");
michael@0 96 dump("MOCK IDLE SERVICE: num idle observers added: " + numIdleObserversAdded + "\n\n");
michael@0 97 }
michael@0 98 else {
michael@0 99 dump("SHOULD NEVER GET HERE!");
michael@0 100 oldIdleService.addIdleObserver(observer, time);
michael@0 101 addedIdleObserver = false;
michael@0 102 }
michael@0 103
michael@0 104 dump("\nJS FAKE IDLE SERVICE end of add idle observer\n");
michael@0 105 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
michael@0 106 },
michael@0 107
michael@0 108 removeIdleObserver: function(observer, time) {
michael@0 109 dump("\nJS REMOVE IDLE OBSERVER () time to be removed: " + time + "\n");
michael@0 110 var window = this.getWindowFromObserver(observer);
michael@0 111 if (!window) {
michael@0 112 oldIdleService.removeIdleObserver(observer, time);
michael@0 113 }
michael@0 114 else {
michael@0 115 var observerIndex = -1;
michael@0 116 for (var i=0; i<this.observers.length; i++) {
michael@0 117 dump("JS removeIdleObserver() observer time: " + this.observers[i].time + "\n");
michael@0 118 if (this.observers[i].time === time) {
michael@0 119 observerIndex = i;
michael@0 120 break;
michael@0 121 }
michael@0 122 }
michael@0 123
michael@0 124 if (observerIndex != -1 && this.observers.length > 0) {
michael@0 125 numIdleObserversRemoved++;
michael@0 126 this.observers.splice(observerIndex, 1);
michael@0 127 removedIdleObserver = true;
michael@0 128 dump("MOCK IDLE SERVICE REMOVING idle observer with time " + time + "\n");
michael@0 129 dump("MOCK IDLE SERVICE numIdleObserversRemoved: " + numIdleObserversRemoved + " numIdleObserversAdded: " + numIdleObserversAdded + "\n\n");
michael@0 130 }
michael@0 131 else {
michael@0 132 removedIdleObserver = false;
michael@0 133 }
michael@0 134 }
michael@0 135 dump("\nJS FAKE IDLE SERVICE end of remove idle observer\n");
michael@0 136 dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
michael@0 137 },
michael@0 138 };
michael@0 139
michael@0 140 /** Test for Bug 715041 **/
michael@0 141 dump("\n\n\nJS STARTING TESTING FOR BUG 715041 REMOVAL\n");
michael@0 142
michael@0 143 //bool variables
michael@0 144 var addedIdleObserver = removedIdleObserver = passed = cleanUp = false;
michael@0 145
michael@0 146 //msgXCount
michael@0 147 var msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
michael@0 148 msg6Count = tcZero = currTestCaseNum = prevMsgNum = 0;
michael@0 149
michael@0 150 //test case number
michael@0 151 var tcRemoveHeadIdleObserverWhileActive = 0;
michael@0 152 var tcRemoveLocalIdleObserverWhileIdle = 1;
michael@0 153 var tcRemoveHeadIdleObserver = 2;
michael@0 154 var tcRemoveLocalIdleTimerWhileIdle = 3;
michael@0 155 var tcRemoveLocalIdleTimerLastElement = 4;
michael@0 156 var tcRemoveHeadAfterLastLocalFired = 5;
michael@0 157 var tcRemoveHeadIdleObserverWhileIdleCase1 = 6;
michael@0 158 var tcRemoveLastAddLast = 7;
michael@0 159
michael@0 160 function ResetMsgCounts() {
michael@0 161 msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
michael@0 162 msg6Count = prevMsgNum = 0;
michael@0 163 }
michael@0 164
michael@0 165 function ResetVars() {
michael@0 166 msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
michael@0 167 msg6Count = prevMsgNum = 0;
michael@0 168
michael@0 169 numIdleObserversAdded = numIdleObserversRemoved = 0;
michael@0 170 currTestCaseNum = -1;
michael@0 171 addedIdleObserver = removedIdleObserver = passed = cleanUp = false;
michael@0 172 }
michael@0 173
michael@0 174 function printVariableValues()
michael@0 175 {
michael@0 176 dump("\nfunction printVariableValues()\ncurrTestCaseNum: " + currTestCaseNum +
michael@0 177 "\ncleanUp: " + cleanUp +
michael@0 178 "\npassed: " + passed +
michael@0 179 "\nnumIdleObserversRemoved: " + numIdleObserversRemoved +
michael@0 180 "\nnumIdleObservesAdded: " + numIdleObserversAdded +
michael@0 181 "\nmsg1Count " + msg1Count +
michael@0 182 "\nmsg2Count " + msg2Count +
michael@0 183 "\nmsg3Count " + msg3Count +
michael@0 184 "\nmsg4Count " + msg4Count +
michael@0 185 "\nmsg5Count " + msg5Count +
michael@0 186 "\n");
michael@0 187 }
michael@0 188
michael@0 189 //Place Holder.
michael@0 190 var idleHandler0 = function() { dump("msg 0, should never be used!\n"); };
michael@0 191
michael@0 192 //idleHandler1
michael@0 193 function idleHandler1() {
michael@0 194 msg1Count++;
michael@0 195 dump("msg 1 Count: " + msg1Count + "\n");
michael@0 196
michael@0 197 switch (currTestCaseNum) {
michael@0 198 case tcRemoveHeadIdleObserver:
michael@0 199 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
michael@0 200 window.navigator.removeIdleObserver(idleObserversArray[1]);
michael@0 201 }
michael@0 202 break;
michael@0 203 case tcRemoveLocalIdleObserverWhileIdle:
michael@0 204 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count) {
michael@0 205 window.navigator.removeIdleObserver(idleObserversArray[2]);
michael@0 206 }
michael@0 207 break;
michael@0 208 case tcRemoveLocalIdleTimerWhileIdle:
michael@0 209 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count) {
michael@0 210 idleServiceObj.idleTime = 2000;
michael@0 211 window.navigator.removeIdleObserver(idleObserversArray[3]);
michael@0 212 }
michael@0 213 break;
michael@0 214 case tcRemoveHeadIdleObserverWhileIdleCase1:
michael@0 215 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count) {
michael@0 216 for (var i=1; i<4; i++) {
michael@0 217 window.navigator.addIdleObserver(idleObserversArray[i]);
michael@0 218 }
michael@0 219 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 220 window.navigator.addIdleObserver(idleObserversArray[3]);
michael@0 221
michael@0 222 idleServiceObj.idleTime = 1200;
michael@0 223 window.navigator.removeIdleObserver(idleObserversArray[1]);
michael@0 224 }
michael@0 225 break;
michael@0 226 case tcRemoveLocalIdleTimerLastElement:
michael@0 227 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
michael@0 228 idleServiceObj.idleTime = 1500;
michael@0 229 window.navigator.removeIdleObserver(idleObserversArray[1]);
michael@0 230 idleServiceObj.idleTime = 1700;
michael@0 231 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 232 idleServiceObj.idleTime = 2000;
michael@0 233 idleServiceObj.testIdleBackService(idleObserversArray[2], "idle");
michael@0 234 }
michael@0 235 break;
michael@0 236 case tcRemoveHeadAfterLastLocalFired:
michael@0 237 if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
michael@0 238 dump("idle handler 1: case tcRemoveHeadAfterLastLocalFired:\n");
michael@0 239 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 240 window.navigator.addIdleObserver(idleObserversArray[3]);
michael@0 241 window.navigator.addIdleObserver(idleObserversArray[4]);
michael@0 242 }
michael@0 243 break;
michael@0 244 case tcRemoveLastAddLast:
michael@0 245 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 246 window.navigator.addIdleObserver(idleObserversArray[3]);
michael@0 247 break;
michael@0 248 default:
michael@0 249 break;
michael@0 250 }
michael@0 251 }
michael@0 252
michael@0 253 //idleHandler2
michael@0 254 function idleHandler2() {
michael@0 255 msg2Count++;
michael@0 256 dump("msg 2 Count: " + msg2Count + "\n");
michael@0 257
michael@0 258 switch (currTestCaseNum) {
michael@0 259 case tcRemoveLocalIdleTimerLastElement:
michael@0 260 if (msg1Count === 1 && msg2Count === 1 && !msg3Count && !msg4Count) {
michael@0 261 window.navigator.addIdleObserver(idleObserversArray[3]);
michael@0 262 window.navigator.addIdleObserver(idleObserversArray[4]);
michael@0 263 window.navigator.removeIdleObserver(idleObserversArray[3]);
michael@0 264 }
michael@0 265 break;
michael@0 266 default:
michael@0 267 //do nothing.
michael@0 268 break;
michael@0 269 }
michael@0 270 }
michael@0 271
michael@0 272 //idleHandler3
michael@0 273 function idleHandler3() {
michael@0 274 msg3Count++;
michael@0 275 dump("msg 3 Count: " + msg3Count + "\n");
michael@0 276 passed = false;
michael@0 277 switch (currTestCaseNum) {
michael@0 278 case tcRemoveHeadIdleObserverWhileActive:
michael@0 279 if (!msg1Count && msg2Count === 1 && msg3Count === 1) {
michael@0 280 passed = true;
michael@0 281 }
michael@0 282 dump("idleHandler3: passed: " + passed + "\n");
michael@0 283 RemoveHeadIdleObserverWhileActiveCleanUp();
michael@0 284 break;
michael@0 285 case tcRemoveHeadIdleObserverWhileIdleCase1:
michael@0 286 if (msg3Count != 2 && msg3Count != 4) {
michael@0 287 return;
michael@0 288 }
michael@0 289
michael@0 290 if (msg1Count === 2 && msg2Count === 2 && msg3Count === 2 && !msg4Count) {
michael@0 291 passed = true;
michael@0 292 ok(passed, "Failed test case remove head idle observer while idle case 1, part 1.\n");
michael@0 293 idleServiceObj.testIdleBackService(idleObserversArray[1], "active");
michael@0 294 return;
michael@0 295 }
michael@0 296
michael@0 297 if (msg1Count === 3 && msg2Count === 4 && msg3Count === 4 &&
michael@0 298 !msg4Count && !msg5Count) {
michael@0 299 passed = true;
michael@0 300 }
michael@0 301 RemoveHeadIdleObserverWhileIdleCase1CleanUp();
michael@0 302 break;
michael@0 303 case tcRemoveLastAddLast:
michael@0 304 if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1
michael@0 305 && !msg4Count && !msg5Count) {
michael@0 306 idleServiceObj.idleTime = 3200;
michael@0 307 window.navigator.removeIdleObserver(idleObserversArray[3]);
michael@0 308 idleServiceObj.idleTime = 3500;
michael@0 309 window.navigator.addIdleObserver(idleObserversArray[4]);
michael@0 310 return;
michael@0 311 }
michael@0 312 break;
michael@0 313 case tcRemoveHeadAfterLastLocalFired:
michael@0 314 if (msg3Count === 1) {
michael@0 315 return;
michael@0 316 }
michael@0 317
michael@0 318 if (msg1Count === 2 && msg2Count === 2 && msg3Count === 2 && msg4Count === 1) {
michael@0 319 passed = true;
michael@0 320 }
michael@0 321 RemoveHeadAfterLastLocalFiredCleanUp();
michael@0 322 break;
michael@0 323 default:
michael@0 324 break;
michael@0 325 }
michael@0 326 }
michael@0 327
michael@0 328 //idleHandler4
michael@0 329 function idleHandler4() {
michael@0 330 msg4Count++;
michael@0 331 dump("msg 4 Count: " + msg4Count + "\n");
michael@0 332
michael@0 333 switch (currTestCaseNum) {
michael@0 334 case tcRemoveLocalIdleObserverWhileIdle:
michael@0 335 if (msg1Count === 1 && !msg2Count && msg3Count === 1 && msg4Count === 1) {
michael@0 336 passed = true;
michael@0 337 RemoveLocalIdleObserverWhileIdleCleanUp();
michael@0 338 }
michael@0 339 break;
michael@0 340 case tcRemoveHeadIdleObserver:
michael@0 341 printVariableValues();
michael@0 342 if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1 && msg4Count === 1) {
michael@0 343 passed = true;
michael@0 344 RemoveHeadIdleObserverCleanUp();
michael@0 345 }
michael@0 346 break;
michael@0 347 case tcRemoveLocalIdleTimerWhileIdle:
michael@0 348 if (msg1Count === 1 && !msg2Count && !msg3Count && msg4Count === 1) {
michael@0 349 passed = true;
michael@0 350 RemoveLocalIdleTimerWhileIdleCleanUp();
michael@0 351 }
michael@0 352 break
michael@0 353 case tcRemoveLocalIdleTimerLastElement:
michael@0 354 if (msg1Count === 1 && msg2Count === 1 && !msg3Count && msg4Count === 1) {
michael@0 355 passed = true;
michael@0 356 ok(passed, "Failed test case remove local idle timer last element.\n");
michael@0 357 RemoveLocalIdleTimerLastElementCleanUp();
michael@0 358 }
michael@0 359 break;
michael@0 360 case tcRemoveHeadAfterLastLocalFired:
michael@0 361 if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1 && msg4Count === 1) {
michael@0 362 window.navigator.removeIdleObserver(idleObserversArray[4]);
michael@0 363 passed = true;
michael@0 364 ok(passed, "Failed remove head after last local fired.\n");
michael@0 365 idleServiceObj.testIdleBackService(idleObserversArray[1], "active");
michael@0 366 }
michael@0 367 break;
michael@0 368 case tcRemoveLastAddLast:
michael@0 369 if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1 && msg4Count == 1) {
michael@0 370 idleServiceObj.idleTime = 4100;
michael@0 371 passed = true;
michael@0 372 RemoveLastAddLastCleanUp();
michael@0 373 }
michael@0 374 break;
michael@0 375 default:
michael@0 376 //do nothing.
michael@0 377 break;
michael@0 378 }
michael@0 379 }
michael@0 380
michael@0 381 //idleHandler5
michael@0 382 function idleHandler5() {
michael@0 383 msg5Count++;
michael@0 384 dump("msg 5 Count: " + msg5Count + "\n");
michael@0 385
michael@0 386 switch (currTestCaseNum) {
michael@0 387
michael@0 388 default:
michael@0 389 //do nothing.
michael@0 390 break;
michael@0 391 }
michael@0 392 }
michael@0 393
michael@0 394 //idleHandler6
michael@0 395 function idleHandler6() {
michael@0 396 dump("msg 6 Count: " + msg6Count + "\n");
michael@0 397 }
michael@0 398
michael@0 399 var idleObserversArray = [];
michael@0 400 idleObserversArray[0] = {time: 0, onidle: idleHandler0, onactive: idleHandler0};
michael@0 401 idleObserversArray[1] = {time: 1, onidle: idleHandler1, onactive: idleHandler1};
michael@0 402 idleObserversArray[2] = {time: 2, onidle: idleHandler2, onactive: idleHandler2};
michael@0 403 idleObserversArray[3] = {time: 3, onidle: idleHandler3, onactive: idleHandler3};
michael@0 404 idleObserversArray[4] = {time: 4, onidle: idleHandler4, onactive: idleHandler4};
michael@0 405 idleObserversArray[5] = {time: 5, onidle: idleHandler5, onactive: idleHandler5};
michael@0 406 idleObserversArray[6] = {time: 0, onidle: idleHandler6, onactive: idleHandler6};
michael@0 407
michael@0 408 //observers array space holder at index zero
michael@0 409 idleServiceObj.observers.push( {observer: idleObserversArray[0], time: 0, } );
michael@0 410
michael@0 411 /*
michael@0 412 * - function RemoveHeadIdleObserverWhileActive1()
michael@0 413 * - Remove head idle observer before the head idle notification is fired by the
michael@0 414 * idle service. I.e. remove the head idle observer while the user is active.
michael@0 415 * - RESULT: prints 2 in 2ms, 3
michael@0 416 */
michael@0 417 function RemoveHeadIdleObserverWhileActive() {
michael@0 418 dump("\n\nTESTING CASE RemoveHeadIdleObserverWhileActive\n");
michael@0 419 dump("=================================\n");
michael@0 420
michael@0 421 ResetVars();
michael@0 422 currTestCaseNum = tcRemoveHeadIdleObserverWhileActive;
michael@0 423 idleServiceObj.idleTime = 500;
michael@0 424
michael@0 425 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 426 dump("test_bug715041_removal.xul: RemoveHeadIdleObserverWhileActive() idle time " + idleServiceObj.idleTime + "\n");
michael@0 427 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 428 window.navigator.addIdleObserver(idleObserversArray[3]);
michael@0 429
michael@0 430 idleServiceObj.idleTime = 800;
michael@0 431 window.navigator.removeIdleObserver(idleObserversArray[1]);
michael@0 432
michael@0 433 idleServiceObj.idleTime = 1000;
michael@0 434 idleServiceObj.testIdleBackService(idleObserversArray[2], "idle");
michael@0 435 }
michael@0 436
michael@0 437 function RemoveHeadIdleObserverWhileActiveCleanUp() {
michael@0 438 dump("\nRemoveHeadIdleObserverWhileActiveCleanUp()\n");
michael@0 439 dump("=====================================\n");
michael@0 440
michael@0 441 dump("Passed: " + passed + "\n");
michael@0 442 ok(passed, "Failed test case: RemoveHeadIdleObserverWhileActive");
michael@0 443
michael@0 444 ResetVars();
michael@0 445 currTestCaseNum = tcRemoveHeadIdleObserverWhileActive;
michael@0 446 idleServiceObj.idleTime = 3500;
michael@0 447
michael@0 448 for (var i=2; i<4; i++) {
michael@0 449 window.navigator.removeIdleObserver(idleObserversArray[i]);
michael@0 450 }
michael@0 451
michael@0 452 dump("JS RemoveHeadIdleObserverWhileActiveCleanUp() DONE\n");
michael@0 453 if (RemoveLocalIdleObserverWhileIdleEnabled) {
michael@0 454 RemoveLocalIdleObserverWhileIdle();
michael@0 455 }
michael@0 456 else {
michael@0 457 dump("Finishing testing idle API.\n");
michael@0 458 SimpleTest.finish();
michael@0 459 }
michael@0 460 }
michael@0 461
michael@0 462 /*
michael@0 463 * function RemoveLocalIdleObserverWhileIdle()
michael@0 464 * Remove local observer before the local oberver at index 1 is triggered while
michael@0 465 * the user is idle.
michael@0 466 * RESULT: should print 1, 3, 4
michael@0 467 */
michael@0 468 function RemoveLocalIdleObserverWhileIdle() {
michael@0 469 dump("\n\nTESTING CASE RemoveLocalIdleObserverWhileIdle\n");
michael@0 470 dump("=================================\n");
michael@0 471
michael@0 472 ResetVars();
michael@0 473 currTestCaseNum = tcRemoveLocalIdleObserverWhileIdle;
michael@0 474 idleServiceObj.idleTime = 500;
michael@0 475
michael@0 476 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 477 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 478 window.navigator.addIdleObserver(idleObserversArray[3]);
michael@0 479 window.navigator.addIdleObserver(idleObserversArray[4]);
michael@0 480
michael@0 481 idleServiceObj.idleTime = 1000;
michael@0 482 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 483 }
michael@0 484
michael@0 485 function RemoveLocalIdleObserverWhileIdleCleanUp() {
michael@0 486 dump("\nRemoveLocalIdleObserverWhileIdleCleanUp()\n");
michael@0 487 dump("=====================================\n");
michael@0 488
michael@0 489 ok(passed, "Failed test case: RemoveLocalIdleObserverWhileIdleCleanUp()");
michael@0 490
michael@0 491 ResetVars();
michael@0 492 currTestCaseNum = tcRemoveHeadIdleObserverWhileActive;
michael@0 493 idleServiceObj.idleTime = 3500;
michael@0 494
michael@0 495 window.navigator.removeIdleObserver(idleObserversArray[1]);
michael@0 496 window.navigator.removeIdleObserver(idleObserversArray[3]);
michael@0 497 window.navigator.removeIdleObserver(idleObserversArray[4]);
michael@0 498
michael@0 499 dump("JS RemoveLocalIdleObserverWhileIdleCleanUp() DONE\n");
michael@0 500 if (RemoveHeadIdleObserverEnabled) {
michael@0 501 RemoveHeadIdleObserver();
michael@0 502 }
michael@0 503 else {
michael@0 504 dump("Finishing testing idle API.\n");
michael@0 505 SimpleTest.finish();
michael@0 506 }
michael@0 507 }
michael@0 508
michael@0 509
michael@0 510 /*
michael@0 511 * function RemoveHeadIdleObserver()
michael@0 512 * Remove head idle observer while the user has been idle for 2400 ms.
michael@0 513 * - RESULT: prints 1, 2, remove 2, 3, 4
michael@0 514 */
michael@0 515 function RemoveHeadIdleObserver() {
michael@0 516 dump("\n\nTESTING CASE RemoveHeadIdleObserver\n");
michael@0 517 dump("=================================\n");
michael@0 518
michael@0 519 ResetVars();
michael@0 520 currTestCaseNum = tcRemoveHeadIdleObserver;
michael@0 521 idleServiceObj.idleTime = 500;
michael@0 522
michael@0 523 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 524 window.navigator.addIdleObserver(idleObserversArray[2]);
michael@0 525 window.navigator.addIdleObserver(idleObserversArray[3]);
michael@0 526 window.navigator.addIdleObserver(idleObserversArray[4]);
michael@0 527
michael@0 528 idleServiceObj.idleTime = 1000;
michael@0 529 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 530 }
michael@0 531
michael@0 532 function RemoveHeadIdleObserverCleanUp() {
michael@0 533 dump("\nRemoveHeadIdleObserverCleanUp()\n");
michael@0 534 dump("=====================================\n");
michael@0 535
michael@0 536 ok(passed, "Failed test case: RemoveHeadIdleObserverCleanUp()");
michael@0 537
michael@0 538 ResetVars();
michael@0 539 currTestCaseNum = tcRemoveHeadIdleObserver;
michael@0 540 idleServiceObj.idleTime = 3500;
michael@0 541
michael@0 542 for (var i=2; i<5; i++) {
michael@0 543 window.navigator.removeIdleObserver(idleObserversArray[i]);
michael@0 544 }
michael@0 545
michael@0 546 dump("JS RemoveHeadIdleObserverCleanUp() DONE\n");
michael@0 547 if (RemoveLocalIdleTimerWhileIdleEnabled) {
michael@0 548 RemoveLocalIdleTimerWhileIdle();
michael@0 549 }
michael@0 550 else {
michael@0 551 dump("Finishing testing idle API.\n");
michael@0 552 SimpleTest.finish();
michael@0 553 }
michael@0 554 }
michael@0 555
michael@0 556 /*
michael@0 557 * RemoveLocalIdleTimerWhileIdle()
michael@0 558 * - Removes the idle observer that is also set as the current local idle timer callback
michael@0 559 * local idle observer being removed is NOT at index 1!
michael@0 560 * - RESULT: should trigger 1 in 1ms and 4 in 4ms
michael@0 561 */
michael@0 562 function RemoveLocalIdleTimerWhileIdle()
michael@0 563 {
michael@0 564 dump("\n\nTESTING CASE RemoveLocalIdleTimerWhileIdle\n");
michael@0 565 dump("=================================\n");
michael@0 566
michael@0 567 ResetVars();
michael@0 568 currTestCaseNum = tcRemoveLocalIdleTimerWhileIdle;
michael@0 569 idleServiceObj.idleTime = 500;
michael@0 570
michael@0 571 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 572 window.navigator.addIdleObserver(idleObserversArray[3]);
michael@0 573 window.navigator.addIdleObserver(idleObserversArray[4]);
michael@0 574
michael@0 575 idleServiceObj.idleTime = 1000;
michael@0 576 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 577 }
michael@0 578
michael@0 579 function RemoveLocalIdleTimerWhileIdleCleanUp()
michael@0 580 {
michael@0 581 dump("\nRemoveLocalIdleTimerWhileIdleCleanUp()\n");
michael@0 582 dump("=====================================\n");
michael@0 583
michael@0 584 ok(passed, "Failed test case: RemoveLocalIdleTimerWhileIdleCleanUp()");
michael@0 585
michael@0 586 ResetVars();
michael@0 587 currTestCaseNum = tcRemoveLocalIdleTimerWhileIdle;
michael@0 588
michael@0 589 window.navigator.removeIdleObserver(idleObserversArray[1]);
michael@0 590 window.navigator.removeIdleObserver(idleObserversArray[4]);
michael@0 591
michael@0 592 dump("JS RemoveLocalIdleTimerWhileIdleCleanUp() DONE\n");
michael@0 593 if (RemoveLocalIdleTimerLastElementEnabled) {
michael@0 594 RemoveLocalIdleTimerLastElement();
michael@0 595 }
michael@0 596 else {
michael@0 597 dump("Finishing testing idle API.\n");
michael@0 598 SimpleTest.finish();
michael@0 599 }
michael@0 600 }
michael@0 601
michael@0 602 /*
michael@0 603 * function RemoveLocalIdleTimerLastElement()
michael@0 604 */
michael@0 605 function RemoveLocalIdleTimerLastElement()
michael@0 606 {
michael@0 607 dump("\n\nTESTING CASE RemoveLocalIdleTimerLastElement\n");
michael@0 608 dump("=================================\n");
michael@0 609
michael@0 610 ResetVars();
michael@0 611 currTestCaseNum = tcRemoveLocalIdleTimerLastElement;
michael@0 612 idleServiceObj.idleTime = 1200;
michael@0 613
michael@0 614 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 615 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 616 }
michael@0 617
michael@0 618 function RemoveLocalIdleTimerLastElementCleanUp() {
michael@0 619 dump("\nRemoveLocalIdleTimerLastElementCleanUp()\n");
michael@0 620 dump("=====================================\n");
michael@0 621
michael@0 622 ok(passed, "Failed test case: RemoveLocalIdleTimerLastElementCleanUp()");
michael@0 623
michael@0 624 ResetVars();
michael@0 625 currTestCaseNum = tcRemoveLocalIdleTimerLastElement;
michael@0 626 window.navigator.removeIdleObserver(idleObserversArray[2]);
michael@0 627 window.navigator.removeIdleObserver(idleObserversArray[4]);
michael@0 628
michael@0 629 dump("JS RemoveLocalIdleTimerLastElementCleanUp() DONE\n");
michael@0 630 if (RemoveHeadAfterLastLocalFiredEnabled) {
michael@0 631 RemoveHeadAfterLastLocalFired();
michael@0 632 }
michael@0 633 else {
michael@0 634 dump("Finishing testing idle API.\n");
michael@0 635 SimpleTest.finish();
michael@0 636 }
michael@0 637 }
michael@0 638
michael@0 639 /*
michael@0 640 - Remove the head after the last local idle timer has been fired
michael@0 641 - add 1 2 3 4
michael@0 642 - after 4 has been notified, removed idle observer with time 4
michael@0 643 - send a back topic
michael@0 644 - message notification should be 1, 2, 3.
michael@0 645 */
michael@0 646 function RemoveHeadAfterLastLocalFired()
michael@0 647 {
michael@0 648 dump("\n\nTESTING CASE RemoveHeadAfterLastLocalFired\n");
michael@0 649 dump("=================================\n");
michael@0 650
michael@0 651 ResetVars();
michael@0 652 currTestCaseNum = tcRemoveHeadAfterLastLocalFired;
michael@0 653 idleServiceObj.idleTime = 1200;
michael@0 654
michael@0 655 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 656 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 657 }
michael@0 658
michael@0 659 function RemoveHeadAfterLastLocalFiredCleanUp() {
michael@0 660 dump("\RemoveHeadAfterLastLocalFiredCleanUp()\n");
michael@0 661 dump("=====================================\n");
michael@0 662
michael@0 663 ok(passed, "Failed test case: RemoveHeadAfterLastLocalFiredCleanUp()");
michael@0 664
michael@0 665 ResetVars();
michael@0 666 currTestCaseNum = tcRemoveHeadAfterLastLocalFired;
michael@0 667
michael@0 668 window.navigator.removeIdleObserver(idleObserversArray[1]);
michael@0 669 window.navigator.removeIdleObserver(idleObserversArray[2]);
michael@0 670 window.navigator.removeIdleObserver(idleObserversArray[3]);
michael@0 671
michael@0 672 dump("JS RemoveHeadAfterLastLocalFiredCleanUp() DONE\n");
michael@0 673 if (RemoveHeadIdleObserverWhileIdleCase1Enabled) {
michael@0 674 RemoveHeadIdleObserverWhileIdleCase1();
michael@0 675 }
michael@0 676 else {
michael@0 677 dump("Finishing testing idle API.\n");
michael@0 678 SimpleTest.finish();
michael@0 679 }
michael@0 680 }
michael@0 681
michael@0 682 function RemoveHeadIdleObserverWhileIdleCase1() {
michael@0 683 dump("\n\nTESTING CASE RemoveHeadIdleObserverWhileIdleCase1\n");
michael@0 684 dump("=================================\n");
michael@0 685
michael@0 686 ResetVars();
michael@0 687 currTestCaseNum = tcRemoveHeadIdleObserverWhileIdleCase1;
michael@0 688 idleServiceObj.idleTime = 1000;
michael@0 689 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 690 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 691 }
michael@0 692
michael@0 693 function RemoveHeadIdleObserverWhileIdleCase1CleanUp() {
michael@0 694 dump("\nRemoveHeadIdleObserverWhileIdleCase1CleanUp()\n");
michael@0 695 dump("=====================================\n");
michael@0 696
michael@0 697 ok(passed, "Failed test case: RemoveHeadIdleObserverWhileIdleCase1CleanUp()");
michael@0 698
michael@0 699 ResetVars();
michael@0 700 currTestCaseNum = tcRemoveHeadIdleObserverWhileIdleCase1;
michael@0 701
michael@0 702 for (var i=1; i<4; i++) {
michael@0 703 window.navigator.removeIdleObserver(idleObserversArray[i]);
michael@0 704 }
michael@0 705
michael@0 706 window.navigator.removeIdleObserver(idleObserversArray[2]);
michael@0 707 window.navigator.removeIdleObserver(idleObserversArray[3]);
michael@0 708
michael@0 709 dump("JS RemoveHeadIdleObserverWhileIdleCase1CleanUp() DONE\n");
michael@0 710 if (RemoveLastAddLastEnabled) {
michael@0 711 RemoveLastAddLast();
michael@0 712 }
michael@0 713 else {
michael@0 714 dump("Finishing testing idle API.\n");
michael@0 715 SimpleTest.finish();
michael@0 716 }
michael@0 717 }
michael@0 718
michael@0 719 /*
michael@0 720 * - RemoveLastAddLast()
michael@0 721 *
michael@0 722 * - User is currently idle.
michael@0 723 * - Add callback 1, 2, 3,
michael@0 724 * - Remove callback 3 after 3200 MS. I.e. after callback 3 has been notified.
michael@0 725 * - Add callback 4 after 3500 MS
michael@0 726 * - Output: 1, 2, 3, 4
michael@0 727 */
michael@0 728 function RemoveLastAddLast()
michael@0 729 {
michael@0 730 dump("\n\nTESTING CASE RemoveLastAddLast()\n");
michael@0 731 dump("=================================\n");
michael@0 732
michael@0 733 ResetVars();
michael@0 734 currTestCaseNum = tcRemoveLastAddLast;
michael@0 735 idleServiceObj.idleTime = 1000;
michael@0 736 window.navigator.addIdleObserver(idleObserversArray[1]);
michael@0 737 idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
michael@0 738 }
michael@0 739
michael@0 740 function RemoveLastAddLastCleanUp()
michael@0 741 {
michael@0 742 dump("\RemoveLastAddLastCleanUp()\n");
michael@0 743 dump("=====================================\n");
michael@0 744
michael@0 745 ok(passed, "Failed test case: RemoveLastAddLastCleanUp()");
michael@0 746
michael@0 747 ResetVars();
michael@0 748 currTestCaseNum = tcRemoveLastAddLast;
michael@0 749
michael@0 750 window.navigator.removeIdleObserver(idleObserversArray[1]);
michael@0 751 window.navigator.removeIdleObserver(idleObserversArray[2]);
michael@0 752 window.navigator.removeIdleObserver(idleObserversArray[4]);
michael@0 753
michael@0 754 if (numIdleObserversRemoved === 1 && !numIdleObserversAdded) {
michael@0 755 ok(true, "Failed test case: RemoveLastAddLastCleanUp()");
michael@0 756 }
michael@0 757 else {
michael@0 758 ok(false, "Failed test case: RemoveLastAddLastCleanUp()");
michael@0 759 }
michael@0 760
michael@0 761
michael@0 762 try {
michael@0 763 componentMgr.unregisterFactory(idleServiceCID, idleServiceObj);
michael@0 764 }
michael@0 765 catch(err) {
michael@0 766 dump("test_bug715041_removal.xul: RemoveLastAddLastCleanUp() Failed to unregister factory, mock idle service!\n");
michael@0 767 }
michael@0 768
michael@0 769 try {
michael@0 770 componentMgr.registerFactory(oldIdleServiceCID, "Re registering old idle service", idleServiceContractID, oldIdleServiceFactoryObj);
michael@0 771 }
michael@0 772 catch(err) {
michael@0 773 dump("test_bug715041_removal.xul: RemoveLastAddLastCleanUp() Failed to register factory, original idle service!\n");
michael@0 774 }
michael@0 775
michael@0 776 dump("JS RemoveLastAddLastCleanUp() DONE\n");
michael@0 777 dump("Finishing testing idle API.\n");
michael@0 778 SimpleTest.finish();
michael@0 779 }
michael@0 780
michael@0 781
michael@0 782 // Registering new moch JS idle service
michael@0 783 SimpleTest.waitForExplicitFinish();
michael@0 784 SimpleTest.requestLongerTimeout(10);
michael@0 785
michael@0 786 try {
michael@0 787 var idleServiceCID = Components.ID("0fdc1bbf-3868-4660-9855-0c2e376922bc");
michael@0 788 var idleServiceContractID = "@mozilla.org/widget/idleservice;1";
michael@0 789 var oldIdleService = Components.classes[idleServiceContractID].getService(Components.interfaces.nsIIdleService);
michael@0 790 }
michael@0 791 catch(ex) {
michael@0 792 dump("test_bug715041_removal.xul: 1) Failed to get old idle service.\n");
michael@0 793 }
michael@0 794
michael@0 795 try {
michael@0 796 // Registering new moch JS idle service
michael@0 797 var componentMgr = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
michael@0 798 }
michael@0 799 catch(err) {
michael@0 800 dump("test_bug715041_removal.xul: Failed to query component registrar interface.\n");
michael@0 801 }
michael@0 802
michael@0 803 try {
michael@0 804 var oldIdleServiceFactoryObj = componentMgr.getClassObjectByContractID(idleServiceContractID, Components.interfaces.nsIFactory);
michael@0 805 }
michael@0 806 catch(err) {
michael@0 807 dump("test_bug715041_removal.xul: Failed to get old idle service.\n");
michael@0 808 }
michael@0 809
michael@0 810 try {
michael@0 811 var oldIdleServiceCID = componentMgr.contractIDToCID(idleServiceContractID);
michael@0 812 }
michael@0 813 catch(err) {
michael@0 814 dump("test_bug715041._removalxul: Failed to convert ID to CID for old idle service.\n");
michael@0 815 }
michael@0 816
michael@0 817 try {
michael@0 818 componentMgr.unregisterFactory(oldIdleServiceCID, oldIdleServiceFactoryObj);
michael@0 819 }
michael@0 820 catch(err) {
michael@0 821 dump("test_bug715041_removal.xul: Failed to unregister old idle service factory object!\n");
michael@0 822 }
michael@0 823
michael@0 824 try {
michael@0 825 componentMgr.registerFactory(idleServiceCID, "Test Simple Idle/Back Notifications", idleServiceContractID, idleServiceObj);
michael@0 826 }
michael@0 827 catch(err) {
michael@0 828 dump("test_bug715041_removal.xul: Failed to register mock idle service.\n");
michael@0 829 }
michael@0 830
michael@0 831 //test case enabled
michael@0 832 var RemoveLocalIdleObserverWhileIdleEnabled = true;
michael@0 833 var RemoveHeadIdleObserverEnabled = true;
michael@0 834 var RemoveLocalIdleTimerWhileIdleEnabled = true;
michael@0 835 var RemoveLocalIdleTimerLastElementEnabled = true;
michael@0 836 var RemoveHeadAfterLastLocalFiredEnabled = true;
michael@0 837 var RemoveHeadIdleObserverWhileIdleCase1Enabled = true;
michael@0 838 var RemoveLastAddLastEnabled = true;
michael@0 839
michael@0 840 RemoveHeadIdleObserverWhileActive();
michael@0 841
michael@0 842 ]]>
michael@0 843 </script>
michael@0 844 </window>
michael@0 845

mercurial