Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: LayoutTests/http/tests/eventsource/eventsource-cors-with-credentials.html

Issue 345813005: Rework EventSource CORS tests to be usable from Workers. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Generalize redirect.php?cors_enabled to cors_allow_origin Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <html> 1 <!DOCTYPE HTML>
2 <body> 2 <script src="/js-test-resources/js-test.js"></script>
3 <p>Test that EventSource cross-origin requests with credentials fail until the c orrect CORS headers are sent. Should print a series of PASS messages followed by DONE.</p> 3 <script src="script-tests/eventsource-cors-with-credentials.js"></script>
4 <div id="result"></div>
5 <script>
6 function log(msg) {
7 document.getElementById("result").innerHTML += msg + "<br>";
8 }
9
10 if (window.testRunner) {
11 testRunner.dumpAsText();
12 testRunner.waitUntilDone();
13 }
14
15 function end() {
16 if (window.testRunner)
17 testRunner.notifyDone();
18 }
19
20 var count = 1;
21 var base_url = location.href.substr(0, location.href.lastIndexOf('/')).replace(" 127.0.0.1", "localhost");
22
23 function create_es() {
24 try {
25 var es = new EventSource(base_url + "/resources/es-cors-credentials.php? count=" + count, {"withCredentials": true});
26 }
27 catch (ex) {
28 log("FAIL: EventSource constructor threw exception: " + ex);
29 end();
30 return;
31 }
32
33 if (!es.withCredentials) {
34 log("FAIL: withCredentials is false");
35 es.close();
36 end();
37 }
38
39 es.onerror = function () {
40 if (es.readyState == es.CLOSED) {
41 if (count != 4 && count != 5) {
42 log("PASS: got error event and readyState is CLOSED");
43 count++;
44 setTimeout(create_es);
45 }
46 else {
47 log("FAIL: got unexpected error event");
48 end();
49 }
50 }
51 else if (count != 5) {
52 log("FAIL: got error event but readyState is not CLOSED");
53 es.close();
54 end();
55 }
56 };
57
58 es.onmessage = function (evt) {
59 if (evt.origin != location.origin && !evt.origin.indexOf("http://localho st")) {
60 if (count == 4 && evt.data == "DATA1" && evt.lastEventId == "77") {
61 log("PASS: got cross-origin message event with data \"DATA1\" an d lastEventId \"77\"");
62 count++;
63 return;
64 }
65 if (count == 5 && evt.data == "DATA2") {
66 log("PASS: got cross-origin message event with data \"DATA2\"");
67 log("DONE");
68 }
69 else
70 log("FAIL: got unexpected cross-origin message event");
71 }
72 else
73 log("FAIL: got message event from same or unexpected origin");
74
75 es.close();
76 end();
77 };
78 }
79 create_es();
80 </script>
81 </body>
82 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698