helper-adb.js (1945B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from head.js */ 7 8 async function checkAdbNotRunning() { 9 info("Check if ADB is already running before the test starts"); 10 const { 11 check, 12 } = require("resource://devtools/client/shared/remote-debugging/adb/adb-running-checker.js"); 13 const isAdbAlreadyRunning = await check(); 14 if (isAdbAlreadyRunning) { 15 throw new Error( 16 "The ADB process is already running on this machine, it should be " + 17 "stopped before running this test" 18 ); 19 } 20 } 21 /* exported checkAdbNotRunning */ 22 23 // Returns a promise that resolves when the adb process exists and is running. 24 async function waitForAdbStart() { 25 info("Wait for ADB to start"); 26 const { 27 adbProcess, 28 } = require("resource://devtools/client/shared/remote-debugging/adb/adb-process.js"); 29 const { 30 check, 31 } = require("resource://devtools/client/shared/remote-debugging/adb/adb-running-checker.js"); 32 return asyncWaitUntil(async () => { 33 const isProcessReady = adbProcess.ready; 34 const isRunning = await check(); 35 return isProcessReady && isRunning; 36 }); 37 } 38 /* exported waitForAdbStart */ 39 40 // Attempt to stop ADB. Will only work if ADB was started by the current Firefox instance. 41 // Returns a promise that resolves when the adb process is no longer running. 42 async function stopAdbProcess() { 43 info("Attempt to stop ADB"); 44 const { 45 adbProcess, 46 } = require("resource://devtools/client/shared/remote-debugging/adb/adb-process.js"); 47 await adbProcess.stop(); 48 49 info("Wait for ADB to stop"); 50 const { 51 check, 52 } = require("resource://devtools/client/shared/remote-debugging/adb/adb-running-checker.js"); 53 return asyncWaitUntil(async () => { 54 const isProcessReady = adbProcess.ready; 55 const isRunning = await check(); 56 return !isProcessReady && !isRunning; 57 }); 58 } 59 /* exported stopAdbProcess */