permission-helper.js (1029B)
1 // Set permissions for camera and microphone using Web Driver 2 // Status can be one of "granted" or "denied" 3 // Scope take values from permission names 4 async function setMediaPermission(status="granted", scope=["camera", "microphone"]) { 5 try { 6 for (let s of scope) { 7 await test_driver.set_permission({ name: s }, status); 8 } 9 } catch (e) { 10 const noSetPermissionSupport = typeof e === "string" && (e.match(/set_permission not implemented/) || e.match(/Unknown permission name/)); 11 if (!(noSetPermissionSupport || 12 (e instanceof Error && e.message.match("unimplemented")) )) { 13 throw e; 14 } 15 // Web Driver not implemented action 16 // FF: https://bugzilla.mozilla.org/show_bug.cgi?id=1524074 17 18 // with current WPT runners, will default to granted state for FF and Safari 19 // throw if status!="granted" to invalidate test results 20 if (status === "denied") { 21 assert_implements_optional(!noSetPermissionSupport, "Unable to set permission to denied for this test"); 22 } 23 } 24 }