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:
Alex Chronopoulos 2018-11-08 12:33:41 +00:00
Родитель ba88363c9c
Коммит ae8562694f
1 изменённых файлов: 40 добавлений и 0 удалений

Просмотреть файл

@ -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();
}