AppTestDelegate.sys.mjs (2682B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /** 5 * This file offers the test helpers that are directly exposed to mochitests. 6 * Their implementations are in app-specific "AppUiTestDelegate.sys.mjs" files. 7 * 8 * For documentation, see AppTestDelegateParent.sys.mjs. 9 * For documentation on the methods of AppUiTestDelegate, see below. 10 */ 11 12 class AppTestDelegateImplementation { 13 actor(window) { 14 return window.windowGlobalChild.getActor("AppTestDelegate"); 15 } 16 17 /** 18 * Click on the pageAction button, to open its popup, or to trigger 19 * pageAction.onClicked if there is no popup. 20 */ 21 clickPageAction(window, extension) { 22 return this.actor(window).sendQuery("clickPageAction", { 23 extensionId: extension.id, 24 }); 25 } 26 27 /** 28 * Click on the browserAction button, to open its popup, or to trigger 29 * browserAction.onClicked if there is no popup. 30 */ 31 clickBrowserAction(window, extension) { 32 return this.actor(window).sendQuery("clickBrowserAction", { 33 extensionId: extension.id, 34 }); 35 } 36 37 /** 38 * Close the browserAction popup, if any. 39 * Do not use this for pageAction popups, use closePageAction instead. 40 */ 41 closeBrowserAction(window, extension) { 42 return this.actor(window).sendQuery("closeBrowserAction", { 43 extensionId: extension.id, 44 }); 45 } 46 47 /** 48 * Close the pageAction popup, if any. 49 * Do not use this for browserAction popups, use closeBrowserAction instead. 50 */ 51 closePageAction(window, extension) { 52 return this.actor(window).sendQuery("closePageAction", { 53 extensionId: extension.id, 54 }); 55 } 56 57 /** 58 * Wait for the pageAction or browserAction/action popup panel to open. 59 * This must be called BEFORE any attempt to open the popup. 60 */ 61 awaitExtensionPanel(window, extension) { 62 return this.actor(window).sendQuery("awaitExtensionPanel", { 63 extensionId: extension.id, 64 }); 65 } 66 67 /** 68 * Open a tab with the given url in the given window. 69 * Returns an opaque object that can be passed to AppTestDelegate.removeTab. 70 */ 71 async openNewForegroundTab(window, url, waitForLoad = true) { 72 const tabId = await this.actor(window).sendQuery("openNewForegroundTab", { 73 url, 74 waitForLoad, 75 }); 76 // Note: this id is only meaningful to AppTestDelegate and independent of 77 // any other concept of "tab id". 78 return { id: tabId }; 79 } 80 81 /** 82 * Close a tab opened by AppTestDelegate.openNewForegroundTab. 83 */ 84 removeTab(window, tab) { 85 return this.actor(window).sendQuery("removeTab", { tabId: tab.id }); 86 } 87 } 88 89 export var AppTestDelegate = new AppTestDelegateImplementation();