Bug 1807268 - Re-enable verifyShowClipboardSuggestionsToggleTest UI test r=jajohnson
[gecko.git] / netwerk / test / unit / test_brotli_unknown_content_type.js
blob7df0d4f8477147eaf60457a649272c50457e8de2
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // This test file makes sure that we can decode brotli files when the
6 // Content-Type header is missing (Bug 1715401)
8 "use strict";
10 function emptyBrotli(metadata, response) {
11   response.setHeader("Content-Encoding", "br", false);
12   response.write("\x01\x03\x06\x03");
15 function largeEmptyBrotli(metadata, response) {
16   response.setHeader("Content-Encoding", "br", false);
17   response.write("\x01\x03" + "\x06".repeat(600) + "\x03");
20 const { HttpServer } = ChromeUtils.importESModule(
21   "resource://testing-common/httpd.sys.mjs"
24 ChromeUtils.defineLazyGetter(this, "URL_EMPTY_BROTLI", function () {
25   return (
26     "http://localhost:" + httpServer.identity.primaryPort + "/empty-brotli"
27   );
28 });
30 ChromeUtils.defineLazyGetter(this, "URL_LARGE_EMPTY_BROTLI", function () {
31   return (
32     "http://localhost:" +
33     httpServer.identity.primaryPort +
34     "/large-empty-brotli"
35   );
36 });
38 var httpServer = null;
40 add_task(async function check_brotli() {
41   httpServer = new HttpServer();
42   httpServer.registerPathHandler("/empty-brotli", emptyBrotli);
43   httpServer.registerPathHandler("/large-empty-brotli", largeEmptyBrotli);
44   httpServer.start(-1);
46   async function test(url) {
47     let chan = NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
48     let [, response] = await new Promise(resolve => {
49       chan.asyncOpen(
50         new ChannelListener(
51           (req, buff) => {
52             resolve([req, buff]);
53           },
54           null,
55           CL_IGNORE_CL
56         )
57       );
58     });
59     return response;
60   }
61   equal(
62     await test(URL_EMPTY_BROTLI),
63     "",
64     "Should decode brotli even when brotli output is empty"
65   );
66   equal(
67     await test(URL_LARGE_EMPTY_BROTLI),
68     "",
69     "Should decode brotli even when the nsUnknownDecoder can't get any decoded output"
70   );
71   Services.prefs.clearUserPref("network.http.accept-encoding");
72   Services.prefs.clearUserPref("network.http.encoding.trustworthy_is_https");
73   await httpServer.stop();
74 });