Bug 1693677 Comment 9 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

If you need `setTimeout` (there is probably not alternative here) you can use `requestFlakyTimeout`: https://searchfox.org/mozilla-central/rev/87a8afd9f57ee4bc542ba0ec3f96a891042b6db7/testing/mochitest/tests/SimpleTest/SimpleTest.js#924
If you still get linting errors when using that, you can additionally add the eslint exception :karlt mentioned.

I don't think you actually need to open another tab in the individual test cases, since the WebRTC test wrapper already does that for you. It should pass you the browser of the test tab, for example `run: async function checkAudioVideoGracePastStop(browser) {`.

Concerning the test failure: I see an unexpected permission prompt in `checkAudioVideoGracePastStop`. Is that the issue you're describing?
If I add log statements to `SitePermissions.getForPrincipal` and `SitePermissions.setForPrincipal` I can see that there is a temporary permission set for `microphone^someId`, but `camera^someOtherId` is not set. I assume the lack of the camera permission is triggering the prompt?

Note that I've tested this on an artifact build.

```
 0:04.09 INFO closing the stream
 0:04.10 GECKO(23660) console.debug: "setForPrincipal" ({principal:"https://example.com", permissionID:"microphone^B7CBD7C1-53EF-42F9-8353-73F61C70C092", state:1, scope:"{SitePermissions.SCOPE_TEMPORARY}", browser:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html", browserURI:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html"})
 0:04.10 PASS WebRTC indicator hidden - 
 0:04.10 PASS camera global indicator as expected - 
 0:04.10 PASS microphone global indicator as expected - 
 0:04.10 PASS screen global indicator as expected - 
 0:04.10 PASS WebRTC menu should be hidden - 
 0:04.10 PASS popup WebRTC indicator hidden - 
 0:04.10 INFO Reload through the page
 0:04.12 GECKO(23660) TEST DEVICES: Using media devices:
 0:04.13 GECKO(23660) audio:
 0:04.13 GECKO(23660) video:
 0:04.13 INFO After page reload, gUM(camera+mic) returns a stream without prompting within grace period.
 0:04.13 INFO requesting devices
 0:04.22 GECKO(23660) console.log: "Failed: Observer topic getUserMedia:request not expected in content process"
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"microphone", browser:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html"})
 0:04.22 GECKO(23660) console.debug: "result" ({state:0, scope:"{SitePermissions.SCOPE_PERSISTENT}"})
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"camera", browser:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html"})
 0:04.22 GECKO(23660) console.debug: "result" ({state:0, scope:"{SitePermissions.SCOPE_PERSISTENT}"})
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"microphone", browser:(void 0)})
 0:04.22 GECKO(23660) console.debug: "result" ({state:0, scope:"{SitePermissions.SCOPE_PERSISTENT}"})
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"camera", browser:(void 0)})
 0:04.22 GECKO(23660) console.debug: "result" ({state:0, scope:"{SitePermissions.SCOPE_PERSISTENT}"})
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"camera^1041FCBD-3F12-4F7B-9E9B-1EC556DD5676", browser:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html"})
 0:04.22 GECKO(23660) console.debug: "result" ({state:0, scope:"{SitePermissions.SCOPE_PERSISTENT}"})
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"microphone^B7CBD7C1-53EF-42F9-8353-73F61C70C092", browser:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html"})
 0:04.22 GECKO(23660) console.debug: "result" ({state:1, scope:"{SitePermissions.SCOPE_TEMPORARY}"})
```
If you need `setTimeout` (there is probably no alternative here) you can use `requestFlakyTimeout`: https://searchfox.org/mozilla-central/rev/87a8afd9f57ee4bc542ba0ec3f96a891042b6db7/testing/mochitest/tests/SimpleTest/SimpleTest.js#924
If you still get linting errors when using that, you can additionally add the eslint exception :karlt mentioned.

I don't think you actually need to open another tab in the individual test cases, since the WebRTC test wrapper already does that for you. It should pass you the browser of the test tab, for example `run: async function checkAudioVideoGracePastStop(browser) {`.

Concerning the test failure: I see an unexpected permission prompt in `checkAudioVideoGracePastStop`. Is that the issue you're describing?
If I add log statements to `SitePermissions.getForPrincipal` and `SitePermissions.setForPrincipal` I can see that there is a temporary permission set for `microphone^someId`, but `camera^someOtherId` is not set. I assume the lack of the camera permission is triggering the prompt?

Note that I've tested this on an artifact build.

```
 0:04.09 INFO closing the stream
 0:04.10 GECKO(23660) console.debug: "setForPrincipal" ({principal:"https://example.com", permissionID:"microphone^B7CBD7C1-53EF-42F9-8353-73F61C70C092", state:1, scope:"{SitePermissions.SCOPE_TEMPORARY}", browser:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html", browserURI:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html"})
 0:04.10 PASS WebRTC indicator hidden - 
 0:04.10 PASS camera global indicator as expected - 
 0:04.10 PASS microphone global indicator as expected - 
 0:04.10 PASS screen global indicator as expected - 
 0:04.10 PASS WebRTC menu should be hidden - 
 0:04.10 PASS popup WebRTC indicator hidden - 
 0:04.10 INFO Reload through the page
 0:04.12 GECKO(23660) TEST DEVICES: Using media devices:
 0:04.13 GECKO(23660) audio:
 0:04.13 GECKO(23660) video:
 0:04.13 INFO After page reload, gUM(camera+mic) returns a stream without prompting within grace period.
 0:04.13 INFO requesting devices
 0:04.22 GECKO(23660) console.log: "Failed: Observer topic getUserMedia:request not expected in content process"
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"microphone", browser:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html"})
 0:04.22 GECKO(23660) console.debug: "result" ({state:0, scope:"{SitePermissions.SCOPE_PERSISTENT}"})
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"camera", browser:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html"})
 0:04.22 GECKO(23660) console.debug: "result" ({state:0, scope:"{SitePermissions.SCOPE_PERSISTENT}"})
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"microphone", browser:(void 0)})
 0:04.22 GECKO(23660) console.debug: "result" ({state:0, scope:"{SitePermissions.SCOPE_PERSISTENT}"})
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"camera", browser:(void 0)})
 0:04.22 GECKO(23660) console.debug: "result" ({state:0, scope:"{SitePermissions.SCOPE_PERSISTENT}"})
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"camera^1041FCBD-3F12-4F7B-9E9B-1EC556DD5676", browser:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html"})
 0:04.22 GECKO(23660) console.debug: "result" ({state:0, scope:"{SitePermissions.SCOPE_PERSISTENT}"})
 0:04.22 GECKO(23660) console.debug: "getForPrincipal" ({principal:"https://example.com", permissionID:"microphone^B7CBD7C1-53EF-42F9-8353-73F61C70C092", browser:"https://example.com/browser/browser/base/content/test/webrtc/get_user_media.html"})
 0:04.22 GECKO(23660) console.debug: "result" ({state:1, scope:"{SitePermissions.SCOPE_TEMPORARY}"})
```

Back to Bug 1693677 Comment 9