gecko-dev/testing/web-platform/tests/background-fetch/mixed-content-and-allowed-schemes.https.window.js
Mugdha Lakhani 42fdb3d024 Bug 1492125 [wpt PR 13047] - [Background Fetch] Move mixed content checks to the controller., a=testonly
Automatic update from web-platform-tests[Background Fetch] Move mixed content checks to the controller.

Change-Id: Iff2fac58c58042d4ddf55ef962df61954414a1fd
Reviewed-on: https://chromium-review.googlesource.com/1230025
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: Peter Beverloo <peter@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595085}

--

wpt-commits: 56941492f34854ac48ae5f910e6b1d409a1aa78a
wpt-pr: 13047
2018-10-08 16:45:28 +00:00

51 lines
2 KiB
JavaScript

// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
// META: script=resources/utils.js
'use strict';
// Tests that Mixed Content requests are blocked.
// https://w3c.github.io/webappsec-mixed-content/#should-block-fetch
// https://w3c.github.io/webappsec-mixed-content/#a-priori-authenticated-url
// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
// With an additional restriction that only https:// and loopback http://
// requests are allowed. Hence the wss:, file:, data:, etc schemes are blocked.
// https://github.com/WICG/background-fetch/issues/44
// This is not a comprehensive test of mixed content blocking - it is just
// intended to check that blocking is enabled.
backgroundFetchTest((t, bgFetch) => {
return bgFetch.fetch(uniqueId(), 'https://example.com');
}, 'https: fetch should register ok');
backgroundFetchTest((t, bgFetch) => {
return bgFetch.fetch(uniqueId(), 'http://127.0.0.1');
}, 'loopback IPv4 http: fetch should register ok');
backgroundFetchTest((t, bgFetch) => {
return bgFetch.fetch(uniqueId(), 'http://[::1]');
}, 'loopback IPv6 http: fetch should register ok');
backgroundFetchTest((t, bgFetch) => {
return bgFetch.fetch(uniqueId(), 'http://localhost');
}, 'localhost http: fetch should register ok');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
bgFetch.fetch(uniqueId(), 'wss:127.0.0.1'));
}, 'wss: fetch should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
bgFetch.fetch(uniqueId(), 'file:///'));
}, 'file: fetch should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
bgFetch.fetch(uniqueId(), 'data:text/plain,foo'));
}, 'data: fetch should reject');
backgroundFetchTest((t, bgFetch) => {
return promise_rejects(t, new TypeError(),
bgFetch.fetch(uniqueId(), 'foobar:bazqux'));
}, 'unknown scheme fetch should reject');