Skip to content

Commit

Permalink
Rewrite as promise_test to suppress testharness error
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D35449

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1556907
gecko-commit: 99157e588004cdf0a9a5e3183b9c86351ea5459b
gecko-integration-branch: central
gecko-reviewers: annevk
  • Loading branch information
EdgarChen authored and jgraham committed Aug 28, 2019
1 parent 56b070d commit d312abb
Showing 1 changed file with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,42 @@ importScripts("{{location[server]}}/resources/testharness.js");
importScripts("{{location[server]}}/content-security-policy/support/testharness-helper.js");

// Same-origin
async_test(t => {
promise_test(t => {
var url = "{{location[server]}}/common/text-plain.txt?same-origin-fetch";
assert_no_csp_event_for_url(t, url);

fetch(url)
.then(t.step_func_done(r => assert_equals(r.status, 200)));
return fetch(url)
.then(t.step_func(r => assert_equals(r.status, 200)));
}, "Same-origin 'fetch()' in " + self.location.protocol + self.location.search);

async_test(t => {
promise_test(t => {
var url = "{{location[server]}}/common/text-plain.txt?same-origin-xhr";
assert_no_csp_event_for_url(t, url);

var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onload = t.step_func_done();
xhr.onerror = t.unreached_func();
xhr.send();
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onload = t.step_func(resolve);
xhr.onerror = t.step_func(_ => reject("xhr.open should success."));
xhr.send();
});
}, "Same-origin XHR in " + self.location.protocol + self.location.search);

// Cross-origin
async_test(t => {
promise_test(t => {
var url = "http://{{domains[www]}}:{{ports[http][1]}}/common/text-plain.txt?cross-origin-fetch";

Promise.all([
return Promise.all([
// TODO(mkwst): A 'securitypolicyviolation' event should fire.
fetch(url)
.catch(t.step_func(e => assert_true(e instanceof TypeError)))
]).then(t.step_func_done());
]);
}, "Cross-origin 'fetch()' in " + self.location.protocol + self.location.search);

async_test(t => {
promise_test(t => {
var url = "http://{{domains[www]}}:{{ports[http][1]}}/common/text-plain.txt?cross-origin-xhr";

Promise.all([
return Promise.all([
// TODO(mkwst): A 'securitypolicyviolation' event should fire.
new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
Expand All @@ -44,16 +46,15 @@ async_test(t => {
xhr.onerror = t.step_func(resolve);
xhr.send();
})
]).then(t.step_func_done());
]);
}, "Cross-origin XHR in " + self.location.protocol + self.location.search);

// Same-origin redirecting to cross-origin
async_test(t => {
promise_test(t => {
var url = "{{location[server]}}/common/redirect-opt-in.py?status=307&location=http://{{domains[www]}}:{{ports[http][1]}}/common/text-plain.txt?cross-origin-fetch";

// TODO(mkwst): A 'securitypolicyviolation' event should fire.
fetch(url)
.catch(t.step_func_done(e => assert_true(e instanceof TypeError)))
return promise_rejects(t, new TypeError, fetch(url));
}, "Same-origin => cross-origin 'fetch()' in " + self.location.protocol + self.location.search);

done();

0 comments on commit d312abb

Please sign in to comment.