retry.sys.mjs (2686B)
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 import { Module } from "chrome://remote/content/shared/messagehandler/Module.sys.mjs"; 6 7 // Store counters in the JSM scope to persist them across reloads. 8 let callsToBlockedOneTime = 0; 9 let callsToBlockedTenTimes = 0; 10 let callsToBlockedElevenTimes = 0; 11 12 // This module provides various commands which all hang for various reasons. 13 // The test is supposed to trigger the command and then destroy the 14 // JSWindowActor pair by any mean (eg a navigation) in order to trigger an 15 // AbortError and a retry. 16 class RetryModule extends Module { 17 destroy() {} 18 19 /** 20 * Commands 21 */ 22 23 async _internalForward() {} 24 25 // Resolves only if called while on the example.net domain. 26 async blockedOnNetDomain(params) { 27 // Note: we do not store a call counter here, because this is used for a 28 // cross-group navigation test, and the JSM will be loaded in different 29 // processes. 30 const uri = this.messageHandler.window.document.baseURI; 31 if (!uri.includes("example.net")) { 32 await new Promise(() => {}); 33 } 34 35 return { ...params }; 36 } 37 38 // Resolves only if called more than once. 39 async blockedOneTime(params) { 40 callsToBlockedOneTime++; 41 if (callsToBlockedOneTime < 2) { 42 await new Promise(() => {}); 43 } 44 45 // Return: 46 // - params sent to the command to check that retries have correct params 47 // - the call counter 48 return { ...params, callsToCommand: callsToBlockedOneTime }; 49 } 50 51 // Resolves only if called more than ten times (which is exactly the maximum 52 // of retry attempts). 53 async blockedTenTimes(params) { 54 callsToBlockedTenTimes++; 55 if (callsToBlockedTenTimes < 11) { 56 await new Promise(() => {}); 57 } 58 59 // Return: 60 // - params sent to the command to check that retries have correct params 61 // - the call counter 62 return { ...params, callsToCommand: callsToBlockedTenTimes }; 63 } 64 65 // Resolves only if called more than eleven times (which is greater than the 66 // maximum of retry attempts). 67 async blockedElevenTimes(params) { 68 callsToBlockedElevenTimes++; 69 if (callsToBlockedElevenTimes < 12) { 70 await new Promise(() => {}); 71 } 72 73 // Return: 74 // - params sent to the command to check that retries have correct params 75 // - the call counter 76 return { ...params, callsToCommand: callsToBlockedElevenTimes }; 77 } 78 79 cleanup() { 80 callsToBlockedOneTime = 0; 81 callsToBlockedTenTimes = 0; 82 callsToBlockedElevenTimes = 0; 83 } 84 } 85 86 export const retry = RetryModule;