head.js (6249B)
1 "use strict"; 2 3 /** 4 * Return a web-based URL for a given file based on the testing directory. 5 * 6 * @param {string} fileName 7 * file that caller wants its web-based url 8 * @param {boolean} cors [optional] 9 * if set, then return a url with different origin 10 */ 11 function GetTestWebBasedURL(fileName) { 12 const origin = "https://example.com"; 13 return ( 14 getRootDirectory(gTestPath).replace("chrome://mochitests/content", origin) + 15 fileName 16 ); 17 } 18 19 /** 20 * Return current process Id for the Media Foundation CDM process. 21 */ 22 async function getMFCDMProcessId() { 23 const process = (await ChromeUtils.requestProcInfo()).children.find( 24 p => 25 p.type === "utility" && 26 p.utilityActors.find(a => a.actorName === "mfMediaEngineCDM") 27 ); 28 return process.pid; 29 } 30 31 /** 32 * Make the utility process with given process id crash. 33 * 34 * @param {int} pid 35 * the process id for the process which is going to crash 36 */ 37 async function crashUtilityProcess(utilityPid) { 38 info(`Crashing process ${utilityPid}`); 39 SimpleTest.expectChildProcessCrash(); 40 41 const crashMan = Services.crashmanager; 42 const utilityProcessGone = TestUtils.topicObserved( 43 "ipc:utility-shutdown", 44 (subject, data) => { 45 info(`ipc:utility-shutdown: data=${data} subject=${subject}`); 46 return parseInt(data, 10) === utilityPid; 47 } 48 ); 49 50 info("Prune any previous crashes"); 51 const future = new Date(Date.now() + 1000 * 60 * 60 * 24); 52 await crashMan.pruneOldCrashes(future); 53 54 info("Crash Utility Process"); 55 const ProcessTools = Cc["@mozilla.org/processtools-service;1"].getService( 56 Ci.nsIProcessToolsService 57 ); 58 59 info(`Crash Utility Process ${utilityPid}`); 60 ProcessTools.crash(utilityPid); 61 62 info(`Waiting for utility process ${utilityPid} to go away.`); 63 let [subject, data] = await utilityProcessGone; 64 Assert.strictEqual( 65 parseInt(data, 10), 66 utilityPid, 67 `Should match the crashed PID ${utilityPid} with ${data}` 68 ); 69 ok( 70 subject instanceof Ci.nsIPropertyBag2, 71 "Subject needs to be a nsIPropertyBag2 to clean up properly" 72 ); 73 74 const dumpID = subject.getPropertyAsAString("dumpID"); 75 ok(dumpID, "There should be a dumpID"); 76 77 await crashMan.ensureCrashIsPresent(dumpID); 78 await crashMan.getCrashes().then(crashes => { 79 is(crashes.length, 1, "There should be only one record"); 80 const crash = crashes[0]; 81 ok( 82 crash.isOfType( 83 crashMan.processTypes[Ci.nsIXULRuntime.PROCESS_TYPE_UTILITY], 84 crashMan.CRASH_TYPE_CRASH 85 ), 86 "Record should be a utility process crash" 87 ); 88 Assert.strictEqual(crash.id, dumpID, "Record should have an ID"); 89 }); 90 91 let minidumpDirectory = Services.dirsvc.get("ProfD", Ci.nsIFile); 92 minidumpDirectory.append("minidumps"); 93 94 let dumpfile = minidumpDirectory.clone(); 95 dumpfile.append(dumpID + ".dmp"); 96 if (dumpfile.exists()) { 97 info(`Removal of ${dumpfile.path}`); 98 dumpfile.remove(false); 99 } 100 101 let extrafile = minidumpDirectory.clone(); 102 extrafile.append(dumpID + ".extra"); 103 info(`Removal of ${extrafile.path}`); 104 if (extrafile.exists()) { 105 extrafile.remove(false); 106 } 107 } 108 109 /** 110 * Make video in the tab play. 111 * 112 * @param {object} tab 113 * the tab contains at least one video element 114 */ 115 async function playVideo(tab) { 116 return SpecialPowers.spawn(tab.linkedBrowser, [], async _ => { 117 const video = content.document.querySelector("video"); 118 ok( 119 await video.play().then( 120 () => true, 121 () => false 122 ), 123 "video started playing" 124 ); 125 }); 126 } 127 128 /** 129 * Check whether the video playback is performed in the right process and right decoder. 130 * 131 * @param {object} tab 132 * the tab which has a playing video 133 * @param {string} expectedProcess 134 * the expected process name 135 * @param {string} expectedDecoder 136 * the expected decoder name 137 */ 138 async function assertRunningProcessAndDecoderName( 139 tab, 140 { expectedProcess, expectedDecoder } = {} 141 ) { 142 return SpecialPowers.spawn( 143 tab.linkedBrowser, 144 [expectedProcess, expectedDecoder], 145 // eslint-disable-next-line no-shadow 146 async (expectedProcess, expectedDecoder) => { 147 const video = content.document.querySelector("video"); 148 ok(!video.paused, "checking a playing video"); 149 150 const debugInfo = await SpecialPowers.wrap(video).mozRequestDebugInfo(); 151 const videoDecoderName = debugInfo.decoder.reader.videoDecoderName; 152 153 const isExpectedDecoder = 154 videoDecoderName.indexOf(`${expectedDecoder}`) == 0; 155 ok( 156 isExpectedDecoder, 157 `Playback running by decoder '${videoDecoderName}', expected '${expectedDecoder}'` 158 ); 159 160 const isExpectedProcess = 161 videoDecoderName.indexOf(`(${expectedProcess} remote)`) > 0; 162 ok( 163 isExpectedProcess, 164 `Playback running in process '${videoDecoderName}', expected '${expectedProcess}'` 165 ); 166 } 167 ); 168 } 169 170 /** 171 * Check whether the video playback is not performed in the given process and given decoder. 172 * 173 * @param {object} tab 174 * the tab which has a playing video 175 * @param {string} givenProcess 176 * the process name on which the video playback should not be running 177 * @param {string} givenDecoder 178 * the decoder name with which the video playback should not be running 179 */ 180 async function assertNotEqualRunningProcessAndDecoderName( 181 tab, 182 { givenProcess, givenDecoder } = {} 183 ) { 184 return SpecialPowers.spawn( 185 tab.linkedBrowser, 186 [givenProcess, givenDecoder], 187 // eslint-disable-next-line no-shadow 188 async (givenProcess, givenDecoder) => { 189 const video = content.document.querySelector("video"); 190 ok(!video.paused, "checking a playing video"); 191 192 const debugInfo = await SpecialPowers.wrap(video).mozRequestDebugInfo(); 193 const videoDecoderName = debugInfo.decoder.reader.videoDecoderName; 194 const pattern = /(.+?)\s+\((\S+)\s+remote\)/; 195 const match = videoDecoderName.match(pattern); 196 if (match) { 197 const decoder = match[1]; 198 const process = match[2]; 199 isnot(decoder, givenDecoder, `Decoder name is not equal`); 200 isnot(process, givenProcess, `Process name is not equal`); 201 } else { 202 ok(false, "failed to match decoder/process name?"); 203 } 204 } 205 ); 206 }