2020-04-07 19:00:03 +03:00
|
|
|
"use strict";
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
|
2012-08-14 18:06:04 +04:00
|
|
|
|
|
|
|
var httpserver = new HttpServer();
|
2012-02-08 07:46:43 +04:00
|
|
|
var index = 0;
|
|
|
|
var tests = [
|
2012-08-14 18:06:04 +04:00
|
|
|
{
|
|
|
|
url: "/test/cegzip1",
|
2012-02-08 07:46:43 +04:00
|
|
|
flags: CL_EXPECT_GZIP,
|
|
|
|
ce: "gzip",
|
|
|
|
body: [
|
|
|
|
0x1f,
|
|
|
|
0x8b,
|
|
|
|
0x08,
|
|
|
|
0x08,
|
|
|
|
0x5a,
|
|
|
|
0xa0,
|
|
|
|
0x31,
|
|
|
|
0x4f,
|
|
|
|
0x00,
|
|
|
|
0x03,
|
|
|
|
0x74,
|
|
|
|
0x78,
|
|
|
|
0x74,
|
|
|
|
0x00,
|
|
|
|
0x2b,
|
|
|
|
0xc9,
|
|
|
|
0xc8,
|
|
|
|
0x2c,
|
|
|
|
0x56,
|
|
|
|
0x00,
|
|
|
|
0xa2,
|
|
|
|
0x92,
|
|
|
|
0xd4,
|
|
|
|
0xe2,
|
|
|
|
0x12,
|
|
|
|
0x43,
|
|
|
|
0x2e,
|
|
|
|
0x00,
|
|
|
|
0xb9,
|
|
|
|
0x23,
|
|
|
|
0xd7,
|
|
|
|
0x3b,
|
|
|
|
0x0e,
|
|
|
|
0x00,
|
|
|
|
0x00,
|
|
|
|
0x00,
|
|
|
|
],
|
|
|
|
datalen: 14, // the data length of the uncompressed document
|
|
|
|
},
|
2019-07-05 11:55:23 +03:00
|
|
|
|
2015-09-22 19:55:23 +03:00
|
|
|
{
|
|
|
|
url: "/test/cegzip2",
|
|
|
|
flags: CL_EXPECT_GZIP,
|
2015-10-06 18:03:50 +03:00
|
|
|
ce: "gzip, gzip",
|
2015-09-22 19:55:23 +03:00
|
|
|
body: [
|
|
|
|
0x1f,
|
|
|
|
0x8b,
|
|
|
|
0x08,
|
|
|
|
0x00,
|
|
|
|
0x72,
|
|
|
|
0xa1,
|
|
|
|
0x31,
|
2019-07-05 11:55:23 +03:00
|
|
|
0x4f,
|
2015-09-22 19:55:23 +03:00
|
|
|
0x00,
|
|
|
|
0x03,
|
2019-07-05 11:55:23 +03:00
|
|
|
0x93,
|
|
|
|
0xef,
|
|
|
|
0xe6,
|
|
|
|
0xe0,
|
|
|
|
0x88,
|
|
|
|
0x5a,
|
2015-09-22 19:55:23 +03:00
|
|
|
0x60,
|
2019-07-05 11:55:23 +03:00
|
|
|
0xe8,
|
|
|
|
0xcf,
|
|
|
|
0xc0,
|
|
|
|
0x5c,
|
|
|
|
0x52,
|
|
|
|
0x51,
|
|
|
|
0xc2,
|
|
|
|
0xa0,
|
2015-09-22 19:55:23 +03:00
|
|
|
0x7d,
|
2019-07-05 11:55:23 +03:00
|
|
|
0xf2,
|
2015-09-22 19:55:23 +03:00
|
|
|
0x84,
|
2019-07-05 11:55:23 +03:00
|
|
|
0x4e,
|
|
|
|
0x18,
|
|
|
|
0xc3,
|
|
|
|
0xa2,
|
|
|
|
0x49,
|
|
|
|
0x57,
|
|
|
|
0x1e,
|
|
|
|
0x09,
|
|
|
|
0x39,
|
|
|
|
0xeb,
|
|
|
|
0x31,
|
|
|
|
0xec,
|
2015-09-22 19:55:23 +03:00
|
|
|
0x54,
|
2019-07-05 11:55:23 +03:00
|
|
|
0xbe,
|
|
|
|
0x6e,
|
|
|
|
0xcd,
|
|
|
|
0xc7,
|
|
|
|
0xc0,
|
|
|
|
0xc0,
|
|
|
|
0x00,
|
|
|
|
0x00,
|
|
|
|
0x6e,
|
|
|
|
0x90,
|
2015-09-22 19:55:23 +03:00
|
|
|
0x7a,
|
|
|
|
0x85,
|
2019-07-05 11:55:23 +03:00
|
|
|
0x24,
|
|
|
|
0x00,
|
|
|
|
0x00,
|
|
|
|
0x00,
|
|
|
|
],
|
2015-09-22 19:55:23 +03:00
|
|
|
datalen: 14, // the data length of the uncompressed document
|
|
|
|
},
|
2019-07-05 11:55:23 +03:00
|
|
|
|
|
|
|
{
|
2015-09-22 19:55:23 +03:00
|
|
|
url: "/test/cebrotli1",
|
2012-02-08 07:46:43 +04:00
|
|
|
flags: CL_EXPECT_GZIP,
|
2019-07-05 11:55:23 +03:00
|
|
|
ce: "br",
|
2012-02-08 07:46:43 +04:00
|
|
|
body: [0x0b, 0x02, 0x80, 0x74, 0x65, 0x73, 0x74, 0x0a, 0x03],
|
2019-07-05 11:55:23 +03:00
|
|
|
|
2012-02-08 07:46:43 +04:00
|
|
|
datalen: 5, // the data length of the uncompressed document
|
2019-07-05 11:55:23 +03:00
|
|
|
},
|
|
|
|
|
2015-09-22 19:55:23 +03:00
|
|
|
// this is not a brotli document
|
|
|
|
{
|
|
|
|
url: "/test/cebrotli2",
|
|
|
|
flags: CL_EXPECT_GZIP | CL_EXPECT_FAILURE,
|
2015-10-06 18:03:50 +03:00
|
|
|
ce: "br",
|
2015-09-22 19:55:23 +03:00
|
|
|
body: [0x0b, 0x0a, 0x09],
|
|
|
|
datalen: 3,
|
|
|
|
},
|
2019-07-05 11:55:23 +03:00
|
|
|
|
2015-09-22 19:55:23 +03:00
|
|
|
// this is brotli but should come through as identity due to prefs
|
|
|
|
{
|
|
|
|
url: "/test/cebrotli3",
|
|
|
|
flags: 0,
|
2015-10-06 18:03:50 +03:00
|
|
|
ce: "br",
|
2015-09-22 19:55:23 +03:00
|
|
|
body: [0x0b, 0x02, 0x80, 0x74, 0x65, 0x73, 0x74, 0x0a, 0x03],
|
2019-07-05 11:55:23 +03:00
|
|
|
|
2015-09-22 19:55:23 +03:00
|
|
|
datalen: 9,
|
|
|
|
},
|
2012-02-08 07:46:43 +04:00
|
|
|
];
|
|
|
|
|
|
|
|
function setupChannel(url) {
|
2015-12-22 03:29:26 +03:00
|
|
|
return NetUtil.newChannel({
|
|
|
|
uri: "http://localhost:" + httpserver.identity.primaryPort + url,
|
|
|
|
loadUsingSystemPrincipal: true,
|
|
|
|
});
|
2012-02-08 07:46:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function startIter() {
|
2015-09-22 19:55:23 +03:00
|
|
|
if (tests[index].url === "/test/cebrotli3") {
|
|
|
|
// this test wants to make sure we don't do brotli when not in a-e
|
|
|
|
prefs.setCharPref("network.http.accept-encoding", "gzip, deflate");
|
|
|
|
}
|
2012-02-08 07:46:43 +04:00
|
|
|
var channel = setupChannel(tests[index].url);
|
2019-02-12 19:08:25 +03:00
|
|
|
channel.asyncOpen(
|
|
|
|
new ChannelListener(completeIter, channel, tests[index].flags)
|
|
|
|
);
|
2012-02-08 07:46:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function completeIter(request, data, ctx) {
|
2015-09-22 19:55:23 +03:00
|
|
|
if (!(tests[index].flags & CL_EXPECT_FAILURE)) {
|
|
|
|
Assert.equal(data.length, tests[index].datalen);
|
|
|
|
}
|
2012-02-08 07:46:43 +04:00
|
|
|
if (++index < tests.length) {
|
|
|
|
startIter();
|
|
|
|
} else {
|
|
|
|
httpserver.stop(do_test_finished);
|
2015-09-22 19:55:23 +03:00
|
|
|
prefs.setCharPref("network.http.accept-encoding", cePref);
|
2012-02-08 07:46:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-22 19:55:23 +03:00
|
|
|
var prefs;
|
|
|
|
var cePref;
|
2012-02-08 07:46:43 +04:00
|
|
|
function run_test() {
|
2015-09-22 19:55:23 +03:00
|
|
|
prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
|
|
|
cePref = prefs.getCharPref("network.http.accept-encoding");
|
2015-10-06 18:03:50 +03:00
|
|
|
prefs.setCharPref("network.http.accept-encoding", "gzip, deflate, br");
|
2015-09-22 19:55:23 +03:00
|
|
|
|
2012-02-08 07:46:43 +04:00
|
|
|
httpserver.registerPathHandler("/test/cegzip1", handler);
|
|
|
|
httpserver.registerPathHandler("/test/cegzip2", handler);
|
2015-09-22 19:55:23 +03:00
|
|
|
httpserver.registerPathHandler("/test/cebrotli1", handler);
|
|
|
|
httpserver.registerPathHandler("/test/cebrotli2", handler);
|
|
|
|
httpserver.registerPathHandler("/test/cebrotli3", handler);
|
2013-07-19 21:19:28 +04:00
|
|
|
httpserver.start(-1);
|
2012-02-08 07:46:43 +04:00
|
|
|
|
|
|
|
startIter();
|
|
|
|
do_test_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
function handler(metadata, response) {
|
|
|
|
response.setStatusLine(metadata.httpVersion, 200, "OK");
|
|
|
|
response.setHeader("Content-Type", "text/plain", false);
|
|
|
|
response.setHeader("Content-Encoding", tests[index].ce, false);
|
|
|
|
response.setHeader("Content-Length", "" + tests[index].body.length, false);
|
2019-07-05 11:55:23 +03:00
|
|
|
|
2012-02-08 07:46:43 +04:00
|
|
|
var bos = Cc["@mozilla.org/binaryoutputstream;1"].createInstance(
|
|
|
|
Ci.nsIBinaryOutputStream
|
|
|
|
);
|
|
|
|
bos.setOutputStream(response.bodyOutputStream);
|
2019-07-05 11:55:23 +03:00
|
|
|
|
2012-02-08 07:46:43 +04:00
|
|
|
response.processAsync();
|
2019-07-22 23:27:39 +03:00
|
|
|
bos.writeByteArray(tests[index].body);
|
2012-02-08 07:46:43 +04:00
|
|
|
response.finish();
|
|
|
|
}
|