Bug 1186209 - Check for VTYPE_EMPTY_ARRAY in enumerateDevices + test. r=jesup

--HG--
extra : transplant_source : %A7%B5%7D%3FM%A1%0A%5C7%853%A1%F4%DB%220cU7%C7
This commit is contained in:
Jan-Ivar Bruaroey 2015-07-22 13:04:12 -04:00
parent 39499d18e0
commit c76b35c716
2 changed files with 28 additions and 20 deletions

View File

@ -52,31 +52,34 @@ public:
OnSuccess(nsIVariant* aDevices) override
{
// Cribbed from MediaPermissionGonk.cpp
nsIID elementIID;
uint16_t elementType;
// Create array for nsIMediaDevice
nsTArray<nsCOMPtr<nsIMediaDevice>> devices;
// Contain the fumes
{
void* rawArray;
uint32_t arrayLen;
nsresult rv;
rv = aDevices->GetAsArray(&elementType, &elementIID, &arrayLen, &rawArray);
uint16_t vtype;
nsresult rv = aDevices->GetDataType(&vtype);
NS_ENSURE_SUCCESS(rv, rv);
if (vtype != nsIDataType::VTYPE_EMPTY_ARRAY) {
nsIID elementIID;
uint16_t elementType;
void* rawArray;
uint32_t arrayLen;
rv = aDevices->GetAsArray(&elementType, &elementIID, &arrayLen, &rawArray);
NS_ENSURE_SUCCESS(rv, rv);
if (elementType != nsIDataType::VTYPE_INTERFACE) {
free(rawArray);
return NS_ERROR_FAILURE;
}
if (elementType != nsIDataType::VTYPE_INTERFACE) {
free(rawArray);
return NS_ERROR_FAILURE;
nsISupports **supportsArray = reinterpret_cast<nsISupports **>(rawArray);
for (uint32_t i = 0; i < arrayLen; ++i) {
nsCOMPtr<nsIMediaDevice> device(do_QueryInterface(supportsArray[i]));
devices.AppendElement(device);
NS_IF_RELEASE(supportsArray[i]); // explicitly decrease refcount for rawptr
}
free(rawArray); // explicitly free memory from nsIVariant::GetAsArray
}
nsISupports **supportsArray = reinterpret_cast<nsISupports **>(rawArray);
for (uint32_t i = 0; i < arrayLen; ++i) {
nsCOMPtr<nsIMediaDevice> device(do_QueryInterface(supportsArray[i]));
devices.AppendElement(device);
NS_IF_RELEASE(supportsArray[i]); // explicitly decrease refcount for rawptr
}
free(rawArray); // explicitly free memory from nsIVariant::GetAsArray
}
nsTArray<nsRefPtr<MediaDeviceInfo>> infos;
for (auto& device : devices) {

View File

@ -21,10 +21,10 @@ function mustFailWith(msg, reason, f) {
e => is(e.name, reason, msg + " must fail: " + e.message));
}
var pushPrefs = dict => new Promise(res => SpecialPowers.pushPrefEnv(dict, res));
var pushPrefs = (...p) => new Promise(r => SpecialPowers.pushPrefEnv({set: p}, r));
runTest(() =>
pushPrefs({ set : [["media.navigator.streams.fake", true]] })
pushPrefs(["media.navigator.streams.fake", true])
.then(() => navigator.mediaDevices.enumerateDevices())
.then(devices => {
ok(devices.length > 0, "At least one device found");
@ -58,7 +58,12 @@ runTest(() =>
() => navigator.mediaDevices.getUserMedia({
audio: { deviceId: { exact: "unknown9qHr8B0JIbcHlbl9xR+jMbZZ8WyoPfpCXPfc=" } },
fake: true,
}))));
})))
// Check the special case of no devices found (these prefs override fake).
.then(() => pushPrefs(["media.audio_loopback_dev", "none"],
["media.video_loopback_dev", "none"]))
.then(() => navigator.mediaDevices.enumerateDevices())
.then(devices => ok(devices.length === 0, "No devices found")));
</script>
</pre>