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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/websocket/resources/get-request-header.js

Issue 2102993002: Fix WebSocket to set first party for cookies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: a Created 4 years, 5 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 var ECHO_REQUEST_HEADERS_WS_URL = 'ws://127.0.0.1:8880/echo-request-headers'; 1 var SAME_ORIGIN_WS_SERVER = 'ws://127.0.0.1:8880';
2 var CROSS_ORIGIN_WS_SERVER = 'ws://localhost:8880';
2 3
3 // Returns a Promise which will create a new WebSocket, and resolve to the value 4 // Returns a Promise which will create a new WebSocket, and resolve to the value
4 // of the specified header in the request, or reject with an error message if 5 // of the specified header in the request, or reject with an error message if
5 // something goes wrong. The header must be specified in lower-case. 6 // something goes wrong. The header must be specified in lower-case.
6 function connectAndGetRequestHeader(request_header) 7 function connectAndGetRequestHeader(request_header)
7 { 8 {
8 return connectAndGetRequestHeaders().then(function(headers) 9 return connectAndGetRequestHeaders(SAME_ORIGIN_WS_SERVER).then(
9 { 10 headers => headers[request_header]);
10 return headers[request_header]; 11 }
11 }); 12
13 function connectAndGetRequestHeaders()
14 {
15 return connectAndGetRequestHeadersFrom(SAME_ORIGIN_WS_SERVER);
12 } 16 }
13 17
14 // Returns a Promise which will create a new WebSocket, and return all the 18 // Returns a Promise which will create a new WebSocket, and return all the
15 // request headers as an object, with the header names as keys in lower-case. 19 // request headers as an object, with the header names as keys in lower-case.
16 function connectAndGetRequestHeaders() 20 function connectAndGetRequestHeadersFrom(server)
17 { 21 {
18 return new Promise(function(resolve, reject) { 22 return new Promise(function(resolve, reject) {
19 var header_ws = new WebSocket(ECHO_REQUEST_HEADERS_WS_URL); 23 var header_ws = new WebSocket(server + '/echo-request-headers');
20 header_ws.onmessage = function (evt) { 24 header_ws.onmessage = function (evt) {
21 try { 25 try {
22 var headers = JSON.parse(evt.data); 26 var headers = JSON.parse(evt.data);
23 resolve(headers); 27 resolve(headers);
24 } catch (e) { 28 } catch (e) {
25 reject("Unexpected exception from JSON.parse: " + e); 29 reject("Unexpected exception from JSON.parse: " + e);
26 } 30 }
27 // The stringify() call in header_ws.onclose can cause a 31 // The stringify() call in header_ws.onclose can cause a
28 // "'WebSocket.URL' is deprecated." error as a side-effect even 32 // "'WebSocket.URL' is deprecated." error as a side-effect even
29 // though the reject() call itself does nothing. Clear out the 33 // though the reject() call itself does nothing. Clear out the
(...skipping 20 matching lines...) Expand all
50 function finishAsFailed(message) { 54 function finishAsFailed(message) {
51 testFailed(message); 55 testFailed(message);
52 finishJSTest(); 56 finishJSTest();
53 } 57 }
54 58
55 // Extracts the value of a header from a WebSocket MessageEvent. 59 // Extracts the value of a header from a WebSocket MessageEvent.
56 function getRequestHeaderFromEvent(message_event, request_header) 60 function getRequestHeaderFromEvent(message_event, request_header)
57 { 61 {
58 return JSON.parse(message_event.data)[request_header]; 62 return JSON.parse(message_event.data)[request_header];
59 } 63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698