test_bug338583.html (22762B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=338583 5 --> 6 <head> 7 <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> 8 <title>Test for Bug 338583</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 11 12 </head> 13 <body bgColor=white> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=338583">Mozilla Bug 338583</a> 15 <p id="display"></p> 16 <div id="content" style="display: none"> 17 18 </div> 19 <pre id="test"> 20 <script class="testbody" type="text/javascript"> 21 /** Tests for Bug 338583 */ 22 23 // we test: 24 // 1) the EventSource behaviour 25 // 2) if the events are trusted 26 // 3) possible invalid eventsources 27 // 4) the close method when the object is just been used 28 // 5) access-control 29 // 6) the data parameter 30 // 7) delayed server responses 31 32 // -- 33 34 var gTestsHaveFinished = []; 35 36 function setTestHasFinished(test_id) 37 { 38 if (gTestsHaveFinished[test_id]) { 39 return; 40 } 41 42 gTestsHaveFinished[test_id] = true; 43 for (var i=0; i < gTestsHaveFinished.length; ++i) { 44 if (!gTestsHaveFinished[i]) { 45 return; 46 } 47 } 48 49 SimpleTest.finish(); 50 } 51 52 function runAllTests() { 53 // these tests run asynchronously, and they will take 8000 ms 54 var all_tests = [ 55 doTest1, doTest1_e, doTest1_f, doTest2, doTest3, doTest3_b, doTest3_c, doTest3_d, 56 doTest3_e, doTest3_f, doTest3_g, doTest3_h, doTest4, doTest4_b, 57 doTest5, doTest5_b, doTest5_c, doTest5_e, doTest6, doTest7 58 ]; 59 60 for (let test_id=0; test_id < all_tests.length; ++test_id) { 61 gTestsHaveFinished[test_id] = false; 62 var fn = all_tests[test_id]; 63 fn(test_id); 64 } 65 66 setTimeout(function() { 67 for (let test_id=0; test_id < all_tests.length; ++test_id) { 68 if (!gTestsHaveFinished[test_id]) { 69 ok(false, "Test " + test_id + " took too long"); 70 setTestHasFinished(test_id); 71 } 72 } 73 }, 60000 * stress_factor); // all tests together are supposed to take less than 1 minute 74 } 75 76 function fn_onmessage(e) { 77 if (e.currentTarget == e.target && e.target.hits != null) 78 e.target.hits.fn_onmessage++; 79 } 80 81 function fn_event_listener_message(e) { 82 if (e.currentTarget == e.target && e.target.hits != null) 83 e.target.hits.fn_event_listener_message++; 84 } 85 86 function fn_other_event_name(e) { 87 if (e.currentTarget == e.target && e.target.hits != null) 88 e.target.hits.fn_other_event_name++; 89 } 90 91 var gEventSourceObj1 = null, gEventSourceObj1_e, gEventSourceObj1_f; 92 var gEventSourceObj2 = null; 93 var gEventSourceObj3_a = null, gEventSourceObj3_b = null, 94 gEventSourceObj3_c = null, gEventSourceObj3_d = null, 95 gEventSourceObj3_e = null, gEventSourceObj3_f = null, 96 gEventSourceObj3_g = null, gEventSourceObj3_h = null; 97 var gEventSourceObj4_a = null, gEventSourceObj4_b = null; 98 var gEventSourceObj5_a = null, gEventSourceObj5_b = null, 99 gEventSourceObj5_c = null, gEventSourceObj5_d = null, 100 gEventSourceObj5_e = null, gEventSourceObj5_f = null; 101 var gEventSourceObj6 = null; 102 var gEventSourceObj7 = null; 103 var stress_factor; // used in the setTimeouts in order to help 104 // the test when running in slow machines 105 106 function hasBeenHitFor1And2(obj, min) { 107 if (obj.hits.fn_onmessage < min || 108 obj.hits.fn_event_listener_message < min || 109 obj.hits.fn_other_event_name < min) 110 return false; 111 return true; 112 } 113 114 // in order to test (1): 115 // a) if the EventSource constructor parameter is equal to its url attribute 116 // b) let its fn_onmessage, fn_event_listener_message, and fn_other_event_name functions listeners be hit four times each 117 // c) the close method (we expect readyState == CLOSED) 118 // d) the close method (we expect no message events anymore) 119 // e) use the default for withCredentials when passing dictionary arguments that don't explicitly set it 120 // f) if a 204 HTTP response closes (interrupts) connections. See bug 869432. 121 122 function doTest1(test_id) { 123 gEventSourceObj1 = new EventSource("eventsource.resource"); 124 ok(gEventSourceObj1.url == "http://mochi.test:8888/tests/dom/base/test/eventsource.resource", "Test 1.a failed."); 125 ok(gEventSourceObj1.readyState == 0 || gEventSourceObj1.readyState == 1, "Test 1.a failed."); 126 127 doTest1_b(test_id); 128 } 129 130 function doTest1_b(test_id) { 131 gEventSourceObj1.hits = []; 132 gEventSourceObj1.hits.fn_onmessage = 0; 133 gEventSourceObj1.onmessage = fn_onmessage; 134 gEventSourceObj1.hits.fn_event_listener_message = 0; 135 gEventSourceObj1.addEventListener('message', fn_event_listener_message, true); 136 gEventSourceObj1.hits.fn_other_event_name = 0; 137 gEventSourceObj1.addEventListener('other_event_name', fn_other_event_name, true); 138 139 // the eventsources.res always use a retry of 0.5 second, so for four hits a timeout of 6 seconds is enough 140 setTimeout(function(){ 141 bhits = hasBeenHitFor1And2(gEventSourceObj1, 4); 142 ok(bhits, "Test 1.b failed."); 143 144 doTest1_c(test_id); 145 }, parseInt(6000*stress_factor)); 146 } 147 148 function doTest1_c(test_id) { 149 gEventSourceObj1.close(); 150 ok(gEventSourceObj1.readyState == 2, "Test 1.c failed."); 151 152 doTest1_d(test_id); 153 } 154 155 function doTest1_d(test_id) { 156 gEventSourceObj1.hits.fn_onmessage = 0; 157 gEventSourceObj1.hits.fn_event_listener_message = 0; 158 gEventSourceObj1.hits.fn_other_event_name = 0; 159 160 setTimeout(function(){ 161 bhits = hasBeenHitFor1And2(gEventSourceObj1, 1); 162 ok(!bhits, "Test 1.d failed."); 163 gEventSourceObj1.close(); 164 setTestHasFinished(test_id); 165 }, parseInt(2000*stress_factor)); 166 } 167 168 function doTest1_e(test_id) { 169 try { 170 for (var options of [null, undefined, {}]) { 171 gEventSourceObj1_e = new EventSource("eventsource.resource", options); 172 is(gEventSourceObj1_e.withCredentials, false, "withCredentials should default to false"); 173 gEventSourceObj1_e.close(); 174 } 175 } catch (e) { 176 ok(false, "Test 1.e failed"); 177 } 178 setTestHasFinished(test_id); 179 } 180 181 function doTest1_f(test_id) { 182 var called_on_error = false; 183 184 gEventSourceObj1_f = new EventSource("file_bug869432.eventsource"); 185 gEventSourceObj1_f.onopen = function(e) { 186 ok(false, "Test 1.f failed: onopen was called"); 187 }; 188 gEventSourceObj1_f.onmessage = function(e) { 189 ok(false, "Test 1.f failed: onmessage was called"); 190 }; 191 gEventSourceObj1_f.onerror = function(e) { 192 if (called_on_error) { 193 ok(false, "Test 1.f failed: onerror was called twice"); 194 } 195 called_on_error = true; 196 ok(gEventSourceObj1_f.readyState == 2, "Test 1.f failed: onerror was called with readyState = " + gEventSourceObj1_f.readyState); 197 }; 198 199 setTimeout(function() { // just to clean... 200 ok(called_on_error, "Test 1.f failed: onerror was not called"); 201 setTestHasFinished(test_id); 202 }, parseInt(5000*stress_factor)); 203 } 204 205 // in order to test (2) 206 // a) set a eventsource that give the dom events messages 207 // b) expect trusted events 208 209 function doTest2(test_id) { 210 var func = function(e) { 211 ok(e.isTrusted, "Test 2 failed"); 212 gEventSourceObj2.close(); 213 }; 214 215 gEventSourceObj2 = new EventSource("eventsource.resource"); 216 gEventSourceObj2.onmessage = func; 217 218 setTimeout(function() { // just to clean... 219 gEventSourceObj2.close(); 220 setTestHasFinished(test_id); 221 }, parseInt(5000*stress_factor)); 222 } 223 224 // in order to test (3) 225 // a) XSite domain error test 226 // b) protocol file:// test 227 // c) protocol javascript: test 228 // d) wrong Content-Type test 229 // e) bad http response code test 230 // f) message eventsource without a data test 231 // g) DNS error 232 // h) EventSource which last message doesn't end with an empty line. See bug 710546 233 234 function doTest3(test_id) { 235 gEventSourceObj3_a = new EventSource("http://example.org/tests/dom/base/test/eventsource.resource"); 236 237 gEventSourceObj3_a.onmessage = fn_onmessage; 238 gEventSourceObj3_a.hits = []; 239 gEventSourceObj3_a.hits.fn_onmessage = 0; 240 241 setTimeout(function() { 242 ok(gEventSourceObj3_a.hits.fn_onmessage == 0, "Test 3.a failed"); 243 gEventSourceObj3_a.close(); 244 setTestHasFinished(test_id); 245 }, parseInt(1500*stress_factor)); 246 } 247 248 function doTest3_b(test_id) { 249 // currently no support yet for local files for b2g/Android mochitest, see bug 838726 250 if (navigator.appVersion.includes("Android") || SpecialPowers.Services.appinfo.name == "B2G") { 251 setTestHasFinished(test_id); 252 return; 253 } 254 255 var xhr = new XMLHttpRequest; 256 xhr.open("GET", "/dynamic/getMyDirectory.sjs", false); 257 xhr.send(); 258 var basePath = xhr.responseText; 259 260 gEventSourceObj3_b = new EventSource("file://" + basePath + "eventsource.resource"); 261 262 gEventSourceObj3_b.onmessage = fn_onmessage; 263 gEventSourceObj3_b.hits = []; 264 gEventSourceObj3_b.hits.fn_onmessage = 0; 265 266 setTimeout(function() { 267 ok(gEventSourceObj3_b.hits.fn_onmessage == 0, "Test 3.b failed"); 268 gEventSourceObj3_b.close(); 269 setTestHasFinished(test_id); 270 }, parseInt(1500*stress_factor)); 271 } 272 273 function jsEvtSource() 274 { 275 return "event: message\n" + 276 "data: 1\n\n"; 277 } 278 279 function doTest3_c(test_id) { 280 gEventSourceObj3_c = new EventSource("javascript: return jsEvtSource()"); 281 282 gEventSourceObj3_c.onmessage = fn_onmessage; 283 gEventSourceObj3_c.hits = []; 284 gEventSourceObj3_c.hits.fn_onmessage = 0; 285 286 setTimeout(function() { 287 ok(gEventSourceObj3_c.hits.fn_onmessage == 0, "Test 3.c failed"); 288 gEventSourceObj3_c.close(); 289 setTestHasFinished(test_id); 290 }, parseInt(1500*stress_factor)); 291 } 292 293 function doTest3_d(test_id) { 294 gEventSourceObj3_d = new EventSource("badContentType.eventsource"); 295 296 gEventSourceObj3_d.onmessage = fn_onmessage; 297 gEventSourceObj3_d.hits = []; 298 gEventSourceObj3_d.hits.fn_onmessage = 0; 299 300 setTimeout(function() { 301 ok(gEventSourceObj3_d.hits.fn_onmessage == 0, "Test 3.d failed"); 302 gEventSourceObj3_d.close(); 303 setTestHasFinished(test_id); 304 }, parseInt(1500*stress_factor)); 305 } 306 307 function doTest3_e(test_id) { 308 gEventSourceObj3_e = new EventSource("badHTTPResponseCode.eventsource"); 309 310 gEventSourceObj3_e.onmessage = fn_onmessage; 311 gEventSourceObj3_e.hits = []; 312 gEventSourceObj3_e.hits.fn_onmessage = 0; 313 314 setTimeout(function() { 315 ok(gEventSourceObj3_e.hits.fn_onmessage == 0, "Test 3.e failed"); 316 gEventSourceObj3_e.close(); 317 setTestHasFinished(test_id); 318 }, parseInt(1500*stress_factor)); 319 } 320 321 function doTest3_f(test_id) { 322 gEventSourceObj3_f = new EventSource("badMessageEvent.eventsource"); 323 324 gEventSourceObj3_f.onmessage = fn_onmessage; 325 gEventSourceObj3_f.hits = []; 326 gEventSourceObj3_f.hits.fn_onmessage = 0; 327 328 setTimeout(function() { 329 ok(gEventSourceObj3_f.hits.fn_onmessage == 0, "Test 3.f failed"); 330 gEventSourceObj3_f.close(); 331 setTestHasFinished(test_id); 332 }, parseInt(1500*stress_factor)); 333 } 334 335 function fnInvalidNCName() { 336 fnInvalidNCName.hits++; 337 } 338 339 function doTest3_g(test_id) { 340 gEventSourceObj3_g = new EventSource("http://hdfskjghsbg.jtiyoejowe.example.com"); 341 342 gEventSourceObj3_g.onmessage = fn_onmessage; 343 gEventSourceObj3_g.hits = []; 344 gEventSourceObj3_g.hits.fn_onmessage = 0; 345 346 setTimeout(function() { 347 ok(gEventSourceObj3_g.hits.fn_onmessage == 0, "Test 3.g failed"); 348 gEventSourceObj3_g.close(); 349 setTestHasFinished(test_id); 350 }, parseInt(1500*stress_factor)); 351 } 352 353 function fnMessageListenerTest3h(e) { 354 fnMessageListenerTest3h.msg_ok = (fnMessageListenerTest3h.msg_ok && e.data == "ok"); 355 fnMessageListenerTest3h.id_ok = (fnMessageListenerTest3h.id_ok && e.lastEventId == ""); 356 } 357 358 function doTest3_h(test_id) { 359 gEventSourceObj3_h = new EventSource("badMessageEvent2.eventsource"); 360 361 gEventSourceObj3_h.addEventListener('message', fnMessageListenerTest3h, true); 362 fnMessageListenerTest3h.msg_ok = true; 363 fnMessageListenerTest3h.id_ok = true; 364 365 gEventSourceObj3_h.onmessage = fn_onmessage; 366 gEventSourceObj3_h.hits = []; 367 gEventSourceObj3_h.hits.fn_onmessage = 0; 368 369 setTimeout(function() { 370 ok(gEventSourceObj3_h.hits.fn_onmessage > 1, "Test 3.h.1 failed"); 371 if (gEventSourceObj3_h.hits.fn_onmessage > 1) { 372 ok(fnMessageListenerTest3h.msg_ok, "Test 3.h.2 failed"); 373 ok(fnMessageListenerTest3h.id_ok, "Test 3.h.3 failed"); 374 } 375 gEventSourceObj3_h.close(); 376 setTestHasFinished(test_id); 377 }, parseInt(6000*stress_factor)); 378 } 379 380 // in order to test (4) 381 // a) close the object when it is in use, which is being processed and that is expected 382 // to dispatch more eventlisteners 383 // b) remove an eventlistener in use 384 385 function fn_onmessage4_a(e) 386 { 387 if (e.data > gEventSourceObj4_a.lastData) 388 gEventSourceObj4_a.lastData = e.data; 389 if (e.data == 2) 390 gEventSourceObj4_a.close(); 391 } 392 393 function fn_onmessage4_b(e) 394 { 395 if (e.data > gEventSourceObj4_b.lastData) 396 gEventSourceObj4_b.lastData = e.data; 397 if (e.data == 2) 398 gEventSourceObj4_b.removeEventListener('message', fn_onmessage4_b, true); 399 } 400 401 function doTest4(test_id) { 402 gEventSourceObj4_a = new EventSource("forRemoval.resource"); 403 gEventSourceObj4_a.lastData = 0; 404 gEventSourceObj4_a.onmessage = fn_onmessage4_a; 405 406 setTimeout(function() { 407 ok(gEventSourceObj4_a.lastData == 2, "Test 4.a failed"); 408 gEventSourceObj4_a.close(); 409 setTestHasFinished(test_id); 410 }, parseInt(3000*stress_factor)); 411 } 412 413 function doTest4_b(test_id) 414 { 415 gEventSourceObj4_b = new EventSource("forRemoval.resource"); 416 gEventSourceObj4_b.lastData = 0; 417 gEventSourceObj4_b.addEventListener('message', fn_onmessage4_b, true); 418 419 setTimeout(function() { 420 ok(gEventSourceObj4_b.lastData == 2, "Test 4.b failed"); 421 gEventSourceObj4_b.close(); 422 setTestHasFinished(test_id); 423 }, parseInt(3000*stress_factor)); 424 } 425 426 // in order to test (5) 427 // a) valid access-control xsite request 428 // b) invalid access-control xsite request 429 // c) valid access-control xsite request on a restricted page with credentials 430 // d) valid access-control xsite request on a restricted page without credentials 431 // e) valid access-control xsite request on a restricted page when the parameter withCredentials is a getter 432 // f) valid access-control xsite request on a restricted page when the parameter withCredentials is missing 433 434 function doTest5(test_id) 435 { 436 gEventSourceObj5_a = new EventSource("http://example.org/tests/dom/base/test/accesscontrol.resource"); 437 438 gEventSourceObj5_a.onmessage = fn_onmessage; 439 gEventSourceObj5_a.hits = []; 440 gEventSourceObj5_a.hits.fn_onmessage = 0; 441 442 setTimeout(function() { 443 ok(gEventSourceObj5_a.hits.fn_onmessage != 0, "Test 5.a failed"); 444 gEventSourceObj5_a.close(); 445 setTestHasFinished(test_id); 446 }, parseInt(3000*stress_factor)); 447 } 448 449 function doTest5_b(test_id) 450 { 451 gEventSourceObj5_b = new EventSource("http://example.org/tests/dom/base/test/invalid_accesscontrol.resource"); 452 453 gEventSourceObj5_b.onmessage = fn_onmessage; 454 gEventSourceObj5_b.hits = []; 455 gEventSourceObj5_b.hits.fn_onmessage = 0; 456 457 setTimeout(function() { 458 ok(gEventSourceObj5_b.hits.fn_onmessage == 0, "Test 5.b failed"); 459 gEventSourceObj5_b.close(); 460 setTestHasFinished(test_id); 461 }, parseInt(3000*stress_factor)); 462 } 463 464 function doTest5_c(test_id) 465 { 466 // credentials using the auth cache 467 var xhr = new XMLHttpRequest({mozAnon: true, mozSystem: true}); 468 // also, test mixed mode UI 469 xhr.open("GET", "https://example.com/tests/dom/base/test/file_restrictedEventSource.sjs?test=user1_xhr", true, "user 1", "password 1"); 470 xhr.send(); 471 xhr.onloadend = function() { 472 ok(xhr.status == 200, "Failed to set credentials in test 5.c"); 473 474 gEventSourceObj5_c = new EventSource("https://example.com/tests/dom/base/test/file_restrictedEventSource.sjs?test=user1_evtsrc", 475 { withCredentials: true } ); 476 ok(gEventSourceObj5_c.withCredentials, "Wrong withCredentials in test 5.c"); 477 478 gEventSourceObj5_c.onmessage = function(e) { 479 ok(e.origin == "https://example.com", "Wrong Origin in test 5.c"); 480 fn_onmessage(e); 481 }; 482 gEventSourceObj5_c.hits = []; 483 gEventSourceObj5_c.hits.fn_onmessage = 0; 484 485 setTimeout(function() { 486 ok(gEventSourceObj5_c.hits.fn_onmessage > 0, "Test 5.c failed"); 487 gEventSourceObj5_c.close(); 488 doTest5_d(test_id); 489 }, parseInt(3000*stress_factor)); 490 }; 491 } 492 493 function doTest5_d(test_id) 494 { 495 var xhr = new XMLHttpRequest({mozAnon: true, mozSystem: true}); 496 xhr.open("GET", "https://example.com/tests/dom/base/test/file_restrictedEventSource.sjs?test=user2_xhr", true, "user 2", "password 2"); 497 xhr.send(); 498 xhr.onloadend = function() { 499 ok(xhr.status == 200, "Failed to set credentials in test 5.d"); 500 501 gEventSourceObj5_d = new EventSource("https://example.com/tests/dom/base/test/file_restrictedEventSource.sjs?test=user2_evtsrc"); 502 ok(!gEventSourceObj5_d.withCredentials, "Wrong withCredentials in test 5.d"); 503 504 gEventSourceObj5_d.onmessage = function(e) { 505 ok(e.origin == "https://example.com", "Wrong Origin in test 5.d"); 506 fn_onmessage(e); 507 }; 508 gEventSourceObj5_d.hits = []; 509 gEventSourceObj5_d.hits.fn_onmessage = 0; 510 511 setTimeout(function() { 512 ok(gEventSourceObj5_d.hits.fn_onmessage == 0, "Test 5.d failed"); 513 gEventSourceObj5_d.close(); 514 setTestHasFinished(test_id); 515 }, parseInt(3000*stress_factor)); 516 }; 517 } 518 519 function doTest5_e(test_id) 520 { 521 // credentials using the auth cache 522 var xhr = new XMLHttpRequest({mozAnon: true, mozSystem: true}); 523 xhr.open("GET", "http://example.org/tests/dom/base/test/file_restrictedEventSource.sjs?test=user1_xhr", true, "user 1", "password 1"); 524 xhr.send(); 525 xhr.onloadend = function() { 526 ok(xhr.status == 200, "Failed to set credentials in test 5.e"); 527 528 gEventSourceObj5_e = new EventSource("http://example.org/tests/dom/base/test/file_restrictedEventSource.sjs?test=user1_evtsrc", 529 { get withCredentials() { return true; } } ); 530 ok(gEventSourceObj5_e.withCredentials, "Wrong withCredentials in test 5.e"); 531 532 gEventSourceObj5_e.onmessage = function(e) { 533 ok(e.origin == "http://example.org", "Wrong Origin in test 5.e"); 534 fn_onmessage(e); 535 }; 536 gEventSourceObj5_e.hits = []; 537 gEventSourceObj5_e.hits.fn_onmessage = 0; 538 539 setTimeout(function() { 540 ok(gEventSourceObj5_e.hits.fn_onmessage > 0, "Test 5.e failed"); 541 gEventSourceObj5_e.close(); 542 doTest5_f(test_id); 543 }, parseInt(5000*stress_factor)); 544 }; 545 } 546 547 function doTest5_f(test_id) 548 { 549 var xhr = new XMLHttpRequest({mozAnon: true, mozSystem: true}); 550 xhr.open("GET", "http://example.org/tests/dom/base/test/file_restrictedEventSource.sjs?test=user2_xhr", true, "user 2", "password 2"); 551 xhr.send(); 552 xhr.onloadend = function() { 553 ok(xhr.status == 200, "Failed to set credentials in test 5.f"); 554 555 gEventSourceObj5_f = new EventSource("http://example.org/tests/dom/base/test/file_restrictedEventSource.sjs?test=user2_evtsrc", 556 { }); 557 ok(!gEventSourceObj5_f.withCredentials, "Wrong withCredentials in test 5.f"); 558 559 gEventSourceObj5_f.onmessage = function(e) { 560 ok(e.origin == "http://example.org", "Wrong Origin in test 5.f"); 561 fn_onmessage(e); 562 }; 563 gEventSourceObj5_f.hits = []; 564 gEventSourceObj5_f.hits.fn_onmessage = 0; 565 566 setTimeout(function() { 567 ok(gEventSourceObj5_f.hits.fn_onmessage == 0, "Test 5.f failed"); 568 gEventSourceObj5_f.close(); 569 setTestHasFinished(test_id); 570 }, parseInt(3000*stress_factor)); 571 }; 572 } 573 574 function doTest6(test_id) 575 { 576 gEventSourceObj6 = new EventSource("somedatas.resource"); 577 var fn_somedata = function(e) { 578 if (fn_somedata.expected == 0) { 579 ok(e.data == "123456789\n123456789123456789\n123456789123456789123456789123456789\n 123456789123456789123456789123456789123456789123456789123456789123456789\nçãá\"\'@`~Ý Ḿyyyy", 580 "Test 6.a failed"); 581 } else if (fn_somedata.expected == 1) { 582 ok(e.data == " :xxabcdefghij\nçãá\"\'@`~Ý Ḿyyyy : zz", 583 "Test 6.b failed"); 584 gEventSourceObj6.close(); 585 } else { 586 ok(false, "Test 6 failed (unexpected message event)"); 587 } 588 fn_somedata.expected++; 589 } 590 fn_somedata.expected = 0; 591 gEventSourceObj6.onmessage = fn_somedata; 592 593 setTimeout(function() { 594 gEventSourceObj6.close(); 595 setTestHasFinished(test_id); 596 }, parseInt(2500*stress_factor)); 597 } 598 599 function doTest7(test_id) 600 { 601 gEventSourceObj7 = new EventSource("delayedServerEvents.sjs"); 602 gEventSourceObj7.msg_received = []; 603 gEventSourceObj7.onmessage = function(e) 604 { 605 e.target.msg_received.push(e.data); 606 } 607 608 setTimeout(function() { 609 gEventSourceObj7.close(); 610 611 ok(gEventSourceObj7.msg_received[0] == "" && 612 gEventSourceObj7.msg_received[1] == "delayed1" && 613 gEventSourceObj7.msg_received[2] == "delayed2", "Test 7 failed"); 614 615 document.getElementById('waitSpan').innerHTML = ''; 616 setTestHasFinished(test_id); 617 }, parseInt(8000*stress_factor)); 618 } 619 620 function doTest() 621 { 622 // Allow all cookies, then run the actual test 623 SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 0]]}, 624 function() { 625 SpecialPowers.pushPermissions([{'type': 'systemXHR', 'allow': true, 'context': document}], 626 doTestCallback); 627 }); 628 } 629 630 function doTestCallback() 631 { 632 633 // we get a good stress_factor by testing 10 setTimeouts and some float 634 // arithmetic taking my machine as stress_factor==1 (time=589) 635 636 var begin_time = (new Date()).getTime(); 637 638 var f = function() { 639 for (var j=0; j<f.i; ++j) 640 // eslint-disable-next-line no-eval 641 eval("Math.log(Math.atan(Math.sqrt(Math.pow(3.1415, 13.1415))/0.0007))"); 642 if (f.i < 10) { 643 f.i++; 644 setTimeout(f, 10 + 10*f.i); 645 } else { 646 stress_factor = ((new Date()).getTime()-begin_time)*1/589; 647 stress_factor *= 1.50; // also, a margin of 50% 648 649 runAllTests(); 650 } 651 } 652 f.i = 0; 653 654 setTimeout(f, 10); 655 } 656 657 SimpleTest.waitForExplicitFinish(); 658 SimpleTest.requestFlakyTimeout("untriaged"); 659 addLoadEvent(doTest); 660 661 </script> 662 </pre> 663 <span id=waitSpan>Wait please...</span> 664 </body> 665 </html>