-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathappearin-deny-allow.js
68 lines (59 loc) · 2.21 KB
/
appearin-deny-allow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"use strict";
const webdriver = require('selenium-webdriver');
const buildDriver = require('./webdriver').buildDriver;
const TIMEOUT = 30000;
function waitNVideosExist(driver, n) {
return driver.wait(() => driver.executeScript(n => document.querySelectorAll('.video-wrapper video').length === n, n), TIMEOUT, 'Timed out waiting for N videos to exist');
}
function waitAllVideosHaveEnoughData(driver) {
return driver.wait(() => driver.executeScript(() => {
var videos = document.querySelectorAll('.video-wrapper video');
var ready = 0;
for (var i = 0; i < videos.length; i++) {
if (videos[i].readyState >= videos[i].HAVE_ENOUGH_DATA) {
ready++;
}
}
return ready === videos.length;
}), TIMEOUT, 'Timed out waiting for N video to HAVE_ENOUGH_DATA');
}
function denyAllow(browser) {
console.log("getUserMedia deny-allow test", browser);
const baseUrl = "https://appear.in/";
const url = baseUrl + "/automated-testing-" + Math.random().toString(36).substr(2, 10);
// assumes https://github.com/fippo/dynamic-getUserMedia was cloned into current directory
const driver = buildDriver(browser, {
devices: {
domain: "appear.in",
extension: "dynamic-getUserMedia",
audio: true,
video: true,
}
});
const drivers = [driver];
return driver.get(baseUrl)
.then(() => {
return driver.executeScript(() => {
localStorage.returningVisitorStore = "true";
sessionStorage.__getUserMediaAudioError = "NotAllowedError";
});
})
.then(() => driver.get(url))
.then(() => driver.sleep(3000)) // here one would make assertions that the error page is shown
.then(() => {
return driver.executeScript(() => {
delete sessionStorage.__getUserMediaAudioError;
});
})
.then(() => waitNVideosExist(driver, 1))
.then(() => waitAllVideosHaveEnoughData(driver))
.then(() => driver.sleep(3000)) // wait a bit.
.then(() => driver.quit());
}
Promise.resolve()
.then(() => denyAllow("chrome"))
.then(() => denyAllow("firefox"))
.catch((e) => {
console.error("FAIL", e);
process.exit(1);
});