/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; const override = Cc["@mozilla.org/network/native-dns-override;1"].getService( Ci.nsINativeDNSResolverOverride ); trr_test_setup(); registerCleanupFunction(async () => { Services.prefs.clearUserPref("network.connectivity-service.nat64-prefix"); override.clearOverrides(); trr_clear_prefs(); }); /** * Waits for an observer notification to fire. * * @param {String} topic The notification topic. * @returns {Promise} A promise that fulfills when the notification is fired. */ function promiseObserverNotification(topic, matchFunc) { return new Promise((resolve, reject) => { Services.obs.addObserver(function observe(subject, topic, data) { let matches = typeof matchFunc != "function" || matchFunc(subject, data); if (!matches) { return; } Services.obs.removeObserver(observe, topic); resolve({ subject, data }); }, topic); }); } function makeChan(url) { let chan = NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true, }).QueryInterface(Ci.nsIHttpChannel); return chan; } function channelOpenPromise(chan) { return new Promise(resolve => { function finish(req, buffer) { resolve([req, buffer]); } chan.asyncOpen(new ChannelListener(finish)); }); } add_task(async function test_add_nat64_prefix_to_trr() { let trrServer = new TRRServer(); registerCleanupFunction(async () => { await trrServer.stop(); }); await trrServer.start(); dump(`port = ${trrServer.port}\n`); let chan = makeChan(`https://localhost:${trrServer.port}/test?bla=some`); let [, resp] = await channelOpenPromise(chan); equal(resp, "