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

Side by Side Diff: LayoutTests/http/tests/websocket/tests/hybi/workers/resources/connect-error-by-no-websocket-server.js

Issue 14071008: WebSocket object should fire error event when WebSocket server can't be connected. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Add new layouttests into TestExceptions because it depends on chromium side patch Created 7 years, 8 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
(Empty)
1 function postResult(result, actual, expected)
2 {
3 var message = result ? "PASS" : "FAIL";
4 message += ": worker: " + actual + " is ";
5 if (!result)
6 message += "not ";
7 message += expected;
8 postMessage(message);
9 }
10
11 function testPassed(message)
12 {
13 postMessage("PASS: " + message);
14 }
15
16 function testFailed(message)
17 {
18 postMessage("FAIL: " + message);
19 }
20
21 function debug(message)
22 {
23 postMessage(message);
24 }
25
26 function endTest()
27 {
28 clearTimeout(timeoutID);
29 postMessage("DONE");
30 }
31
32 var url = "ws://localhost:8888"; // Here it should have no websocket server to l isten.
33
34 function doTest(index)
35 {
36 debug("test" + index + " Start");
37
38 var ws = new WebSocket(url);
39
40 ws.onopen = function()
41 {
42 testFailed("Connected");
43 endTest();
44 };
45
46 ws.onmessage = function(messageEvent)
47 {
48 testFailed("Received Message");
49 ws.close();
50 endTest();
51 };
52
53 if (index == 0) {
54 ws.onclose = function()
55 {
56 testPassed("onclose was called");
57 doTest(index + 1);
58 };
59
60 ws.onerror = function()
61 {
62 testPassed("onerror was called");
63 };
64 } else if (index == 1) {
65 ws.onclose = function()
66 {
67 testPassed("onclose was called");
68 ws.close();
69 doTest(index + 1);
70 };
71 ws.onerror = function()
72 {
73 testPassed("onerror was called");
74 };
75 } else {
76 ws.onclose = function()
77 {
78 testPassed("onclose was called");
79 endTest();
80 };
81 ws.onerror = function()
82 {
83 testPassed("onerror was called");
84 ws.close();
85 };
86 }
87 }
88
89 function timeOutCallback()
90 {
91 debug("Timed out...");
92 endTest();
93 }
94
95 var timeoutID = setTimeout(timeOutCallback, 3000);
96
97 doTest(0);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698