Commit 60c1e1fe authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

bluetooth: use async/await in bluetooth tests

No behavioural change; just refactor the code to use async/await.

Bug: 908288
Change-Id: I533c05538e25fa5e4176a7373706dd479c6009b1
Reviewed-on: https://chromium-review.googlesource.com/c/1379594
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626908}
parent 582e1eba
......@@ -109,12 +109,14 @@ suite('Bluetooth', function() {
});
}
setup(function() {
setup(async function() {
bluetoothApi_.setEnabled(true);
Polymer.dom.flush();
const div = bluetoothPage.$$('div.settings-box');
div.click();
return flushAsync().then(() => {
await flushAsync();
subpage = bluetoothPage.$$('settings-bluetooth-subpage');
subpage.listUpdateFrequencyMs = 0;
assertTrue(!!subpage);
......@@ -122,7 +124,6 @@ suite('Bluetooth', function() {
assertFalse(subpage.stateChangeInProgress);
assertEquals(0, subpage.listUpdateFrequencyMs);
});
});
test('toggle', function() {
assertTrue(subpage.bluetoothToggleState);
......@@ -147,14 +148,16 @@ suite('Bluetooth', function() {
});
}
test('paired device list', function() {
test('paired device list', async function() {
const pairedContainer = subpage.$.pairedContainer;
assertTrue(!!pairedContainer);
assertTrue(pairedContainer.hidden);
assertFalse(subpage.$.noPairedDevices.hidden);
bluetoothApi_.setDevicesForTest(fakeDevices_);
return waitForListUpdateTimeout().then(function() {
await waitForListUpdateTimeout();
Polymer.dom.flush();
assertEquals(4, subpage.deviceList_.length);
assertEquals(2, subpage.pairedDeviceList_.length);
......@@ -169,16 +172,16 @@ suite('Bluetooth', function() {
assertTrue(devices[0].device.connected);
assertFalse(devices[1].device.connected);
});
});
test('unpaired device list', function() {
test('unpaired device list', async function() {
const unpairedContainer = subpage.$.unpairedContainer;
assertTrue(!!unpairedContainer);
assertTrue(unpairedContainer.hidden);
assertFalse(subpage.$.noUnpairedDevices.hidden);
bluetoothApi_.setDevicesForTest(fakeDevices_);
return waitForListUpdateTimeout().then(function() {
await waitForListUpdateTimeout();
Polymer.dom.flush();
assertEquals(4, subpage.deviceList_.length);
assertEquals(2, subpage.unpairedDeviceList_.length);
......@@ -193,29 +196,29 @@ suite('Bluetooth', function() {
assertFalse(devices[0].device.paired);
assertFalse(devices[1].device.paired);
});
});
test('pair device', function(done) {
test('pair device', async function() {
bluetoothApi_.setDevicesForTest(fakeDevices_);
return waitForListUpdateTimeout().then(function() {
await waitForListUpdateTimeout();
Polymer.dom.flush();
assertEquals(4, subpage.deviceList_.length);
assertEquals(2, subpage.pairedDeviceList_.length);
assertEquals(2, subpage.unpairedDeviceList_.length);
const address = subpage.unpairedDeviceList_[0].address;
bluetoothPrivateApi_.connect(address, function() {
await new Promise(
resolve => bluetoothPrivateApi_.connect(address, resolve));
Polymer.dom.flush();
assertEquals(3, subpage.pairedDeviceList_.length);
assertEquals(1, subpage.unpairedDeviceList_.length);
done();
});
});
});
test('pair dialog', function() {
test('pair dialog', async function() {
bluetoothApi_.setDevicesForTest(fakeDevices_);
return waitForListUpdateTimeout().then(function() {
await waitForListUpdateTimeout();
Polymer.dom.flush();
const dialog = subpage.$.deviceDialog;
assertTrue(!!dialog);
......@@ -226,7 +229,6 @@ suite('Bluetooth', function() {
Polymer.dom.flush();
assertTrue(dialog.$.dialog.open);
});
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment