зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1482150 - Create a unit test to verify all corner cases of the helper method. r=padenot
Quering the stored devices list for an ID was not always correct. The stored devices list is expected to be empty before an enumeration takes place or after a collection change notification. In those cases, the method will fail to find an existing ID. The method has been updated to address these cases in previous patch. Here I have implemented a unit test to verify the case. Currently, the method is not being used. Differential Revision: https://phabricator.services.mozilla.com/D9380 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
ba88363c9c
Коммит
ae8562694f
|
@ -620,5 +620,45 @@ TEST(CubebDeviceEnumerator, ForceNullCubebContext)
|
|||
nsTArray<RefPtr<AudioDeviceInfo>> outputDevices;
|
||||
enumerator->EnumerateAudioOutputDevices(outputDevices);
|
||||
EXPECT_EQ(outputDevices.Length(), 0u) << "Enumeration must fail, output device list must be empty.";
|
||||
|
||||
// Shutdown to clean up the null context effect
|
||||
CubebDeviceEnumerator::Shutdown();
|
||||
}
|
||||
|
||||
TEST(CubebDeviceEnumerator, DeviceInfoFromId)
|
||||
{
|
||||
MockCubeb* mock = new MockCubeb();
|
||||
mozilla::CubebUtils::ForceSetCubebContext(mock->AsCubebContext());
|
||||
|
||||
uint32_t device_count = 4;
|
||||
cubeb_device_type deviceTypes[2] = {CUBEB_DEVICE_TYPE_INPUT,
|
||||
CUBEB_DEVICE_TYPE_OUTPUT};
|
||||
|
||||
bool supportsDeviceChangeCallback[2] = { true, false };
|
||||
for (bool supports : supportsDeviceChangeCallback) {
|
||||
// Shutdown for `supports` to take effect
|
||||
CubebDeviceEnumerator::Shutdown();
|
||||
mock->SetSupportDeviceChangeCallback(supports);
|
||||
for (cubeb_device_type& deviceType : deviceTypes) {
|
||||
AddDevices(mock, device_count, deviceType);
|
||||
|
||||
cubeb_devid id_1 = reinterpret_cast<cubeb_devid>(1);
|
||||
RefPtr<CubebDeviceEnumerator> enumerator = CubebDeviceEnumerator::GetInstance();
|
||||
RefPtr<AudioDeviceInfo> devInfo = enumerator->DeviceInfoFromID(id_1);
|
||||
EXPECT_TRUE(devInfo) << "the device exist";
|
||||
EXPECT_EQ(devInfo->DeviceID(), id_1) << "verify the device";
|
||||
|
||||
mock->RemoveDevice(id_1);
|
||||
devInfo = enumerator->DeviceInfoFromID(id_1);
|
||||
EXPECT_FALSE(devInfo) << "the device does not exist any more";
|
||||
|
||||
cubeb_devid id_5 = reinterpret_cast<cubeb_devid>(5);
|
||||
mock->AddDevice(DeviceTemplate(id_5, deviceType));
|
||||
devInfo = enumerator->DeviceInfoFromID(id_5);
|
||||
EXPECT_TRUE(devInfo) << "newly added device must exist";
|
||||
EXPECT_EQ(devInfo->DeviceID(), id_5) << "verify the device";
|
||||
}
|
||||
}
|
||||
// Shutdown for `supports` to take effect
|
||||
CubebDeviceEnumerator::Shutdown();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче