browser_103_cleanup.js (1498B)
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/. */ 4 5 "use strict"; 6 7 add_task(async function test_103_cancel_parent_connect() { 8 await SpecialPowers.pushPrefEnv({ 9 set: [ 10 ["network.early-hints.enabled", true], 11 ["network.early-hints.parent-connect-timeout", 1], 12 ], 13 }); 14 15 let callback; 16 let promise = new Promise(resolve => { 17 callback = resolve; 18 }); 19 let observed_cancel_reason = ""; 20 let observer = { 21 QueryInterface: ChromeUtils.generateQI(["nsIObserver"]), 22 observe(aSubject, aTopic) { 23 aSubject = aSubject.QueryInterface(Ci.nsIChannel); 24 if ( 25 aTopic == "http-on-stop-request" && 26 aSubject.URI.spec == 27 "https://example.com/browser/netwerk/test/browser/square2.png" 28 ) { 29 observed_cancel_reason = aSubject.canceledReason; 30 Services.obs.removeObserver(observer, "http-on-stop-request"); 31 callback(); 32 } 33 }, 34 }; 35 Services.obs.addObserver(observer, "http-on-stop-request"); 36 37 // test that no crash or memory leak happens when cancelling before 38 await BrowserTestUtils.withNewTab( 39 { 40 gBrowser, 41 url: "https://example.com/browser/netwerk/test/browser/103_preload_no_img.html", 42 waitForLoad: true, 43 }, 44 async function () {} 45 ); 46 await promise; 47 Assert.equal(observed_cancel_reason, "parent-connect-timeout"); 48 });