content/base/test/test_bug338583.html

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

mercurial