Commit 77791b40 authored by Tom Schuster's avatar Tom Schuster
Browse files

Bug 1800890 - Test r=asuth

Depends on D162827

Differential Revision: https://phabricator.services.mozilla.com/D163124
parent 28cc7e26
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -68,4 +68,15 @@ promise_test(t => {
}, "Same-origin => cross-origin 'fetch()' in " + self.location.protocol +
           " without CSP");

// WebSocket
promise_test(async function(t) {
  let url = "wss://{{host}}:{{ports[wss][0]}}/echo";
  assert_no_csp_event_for_url(t, url);

  return new Promise(resolve => {
    let ws = new WebSocket(url);
    ws.onopen = resolve;
  });
}, "WebSocket without CSP");

done();
+15 −2
Original line number Diff line number Diff line
@@ -77,9 +77,22 @@ promise_test(t => {
  ]);
}, "Same-origin => cross-origin 'fetch()'.");

let websocket_url = "wss://{{host}}:{{ports[wss][0]}}/echo";

// The WebSocket URL is not the same as 'self'
promise_test(t => {
  return Promise.all([
    waitUntilCSPEventForURL(t, websocket_url),
    new Promise(resolve => {
      let ws = new WebSocket(websocket_url);
      ws.onopen = resolve;
    })
  ]);
}, "WebSocket.");

let expected_blocked_urls = self.XMLHttpRequest
    ? [ fetch_cross_origin_url, xhr_cross_origin_url, redirect_url ]
    : [ fetch_cross_origin_url, redirect_url ];
    ? [ fetch_cross_origin_url, xhr_cross_origin_url, redirect_url, websocket_url ]
    : [ fetch_cross_origin_url, redirect_url, websocket_url ];

promise_test(async t => {
  let report_url = `{{location[server]}}/reporting/resources/report.py?` +
+22 −2
Original line number Diff line number Diff line
@@ -88,9 +88,29 @@ promise_test(t => {
}, "Same-origin => cross-origin 'fetch()' in " + self.location.protocol +
             " with {{GET[test-name]}}");


let websocket_url = "wss://{{host}}:{{ports[wss][0]}}/echo";

// The WebSocket URL is not the same as 'self'
promise_test(t => {
  return Promise.all([
    waitUntilCSPEventForURL(t, websocket_url),
    new Promise((resolve, reject) => {
      // Firefox throws in the constructor, Chrome triggers the error event.
      try {
        let ws = new WebSocket(websocket_url);
        ws.onerror = resolve;
        ws.onopen = reject; // unexpected
      } catch (e) {
        resolve();
      }
    })
  ]);
}, "WebSocket in " + self.location.protocol + " with {{GET[test-name]}}");

let expected_blocked_urls = self.XMLHttpRequest
    ? [ fetch_cross_origin_url, xhr_cross_origin_url, redirect_url ]
    : [ fetch_cross_origin_url, redirect_url ];
    ? [ fetch_cross_origin_url, xhr_cross_origin_url, redirect_url, websocket_url ]
    : [ fetch_cross_origin_url, redirect_url, websocket_url ];

promise_test(async t => {
  let report_url = `{{location[server]}}/reporting/resources/report.py` +