Skip to content

Commit

Permalink
Bug 1528042 - Test correct device list order in enumerateDevices(). r…
Browse files Browse the repository at this point in the history
…=karlt

Differential Revision: https://phabricator.services.mozilla.com/D155430

UltraBlame original commit: 6c8c76da9ab72b9901733e6475496c83fea9988c
  • Loading branch information
marco-c committed May 31, 2023
1 parent 542c62a commit fa25379
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ <h1 class="instructions">Description</h1>
1, "there should be zero or one audio input device.");
assert_less_than_equal(devices.filter(({kind}) => kind == "videoinput").length,
1, "there should be zero or one video input device.");
assert_equals(devices.filter(({kind}) => kind == "audiooutput").length,
0, "there should be no audio output devices.");
assert_less_than_equal(devices.length, 2,
"there should be no more than two devices.");
if (devices.length > 1) {
assert_equals(devices[0].kind, "audioinput", "audioinput is first");
assert_equals(devices[1].kind, "videoinput", "videoinput is second");
}
}, "mediaDevices.enumerateDevices() is present and working - before capture");

promise_test(async t => {
Expand Down Expand Up @@ -66,9 +74,9 @@ <h1 class="instructions">Description</h1>
assert_equals(devices.filter(({kind}) => kind != "audiooutput").length,
devices1.filter(({kind}) => kind != "audiooutput").length,
"same number of input devices");
const kinds = ["audioinput", "videoinput", "audiooutput"];
const order = ["audioinput", "videoinput", "audiooutput"];
for (const {kind, deviceId} of devices) {
assert_in_array(kind, kinds, "expected kind");
assert_in_array(kind, order, "expected kind");
assert_equals(typeof deviceId, "string", "deviceId is a string.");
switch (kind) {
case "videoinput":
Expand All @@ -79,6 +87,9 @@ <h1 class="instructions">Description</h1>
break;
}
}
const kinds = devices.map(({kind}) => kind);
const correct = [...kinds].sort((a, b) => order.indexOf(a) - order.indexOf(b));
assert_equals(JSON.stringify(kinds), JSON.stringify(correct), "correct order");
}, "mediaDevices.enumerateDevices() is working - after video then audio capture");

promise_test(async () => {
Expand Down

0 comments on commit fa25379

Please sign in to comment.