// baseUrl is always the initial connection attempt and is handled by // failResponseHandler since every test expects that request will either be // redirected or cancelled. var baseUrl;
function failResponseHandler(metadata, response) { var text = "failure response";
response.setHeader("Content-Type", "text/plain", false);
response.bodyOutputStream.write(text, text.length); Assert.ok(false, "Received request when we shouldn't.");
}
function successResponseHandler(metadata, response) { var text = "success response";
response.setHeader("Content-Type", "text/plain", false);
response.bodyOutputStream.write(text, text.length); Assert.ok(true, "Received expected request.");
}
// Test a request that will get redirected asynchronously. baseUrl should // not be requested, we should receive the request for the redirectedUrl.
add_test(function testAsyncRedirect() {
onModifyListener(chan => { // Suspend the channel then yield to make this async.
chan.suspend();
Promise.resolve().then(() => {
chan.redirectTo(ios.newURI(`${baseUrl}/success`));
chan.resume();
});
});
startChannelRequest(baseUrl, undefined, "success response");
});
// Test request that will get redirected and cancelled asynchronously, // ensure no connection is made.
add_test(function testAsyncCancelRedirect() {
onModifyListener(chan => { // Suspend the channel then yield to make this async.
chan.suspend();
Promise.resolve().then(() => {
chan.cancel(Cr.NS_BINDING_ABORTED);
chan.redirectTo(ios.newURI(`${baseUrl}/fail`));
chan.resume();
});
});
startChannelRequest(baseUrl, CL_EXPECT_FAILURE);
});
// Test a request that will get cancelled synchronously, ensure async redirect // is not made.
add_test(function testSyncCancelRedirect() {
onModifyListener(chan => {
chan.suspend();
chan.cancel(Cr.NS_BINDING_ABORTED);
Promise.resolve().then(() => {
chan.redirectTo(ios.newURI(`${baseUrl}/fail`));
chan.resume();
});
});
startChannelRequest(baseUrl, CL_EXPECT_FAILURE);
});
function run_test() { var httpServer = new HttpServer();
httpServer.registerPathHandler("/", failResponseHandler);
httpServer.registerPathHandler("/fail", failResponseHandler);
httpServer.registerPathHandler("/success", successResponseHandler);
httpServer.start(-1);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.