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,19 +109,20 @@ suite('Bluetooth', function() { ...@@ -109,19 +109,20 @@ suite('Bluetooth', function() {
}); });
} }
setup(function() { setup(async function() {
bluetoothApi_.setEnabled(true); bluetoothApi_.setEnabled(true);
Polymer.dom.flush(); Polymer.dom.flush();
const div = bluetoothPage.$$('div.settings-box'); const div = bluetoothPage.$$('div.settings-box');
div.click(); div.click();
return flushAsync().then(() => {
subpage = bluetoothPage.$$('settings-bluetooth-subpage'); await flushAsync();
subpage.listUpdateFrequencyMs = 0;
assertTrue(!!subpage); subpage = bluetoothPage.$$('settings-bluetooth-subpage');
assertTrue(subpage.bluetoothToggleState); subpage.listUpdateFrequencyMs = 0;
assertFalse(subpage.stateChangeInProgress); assertTrue(!!subpage);
assertEquals(0, subpage.listUpdateFrequencyMs); assertTrue(subpage.bluetoothToggleState);
}); assertFalse(subpage.stateChangeInProgress);
assertEquals(0, subpage.listUpdateFrequencyMs);
}); });
test('toggle', function() { test('toggle', function() {
...@@ -147,85 +148,86 @@ suite('Bluetooth', function() { ...@@ -147,85 +148,86 @@ suite('Bluetooth', function() {
}); });
} }
test('paired device list', function() { test('paired device list', async function() {
const pairedContainer = subpage.$.pairedContainer; const pairedContainer = subpage.$.pairedContainer;
assertTrue(!!pairedContainer); assertTrue(!!pairedContainer);
assertTrue(pairedContainer.hidden); assertTrue(pairedContainer.hidden);
assertFalse(subpage.$.noPairedDevices.hidden); assertFalse(subpage.$.noPairedDevices.hidden);
bluetoothApi_.setDevicesForTest(fakeDevices_); bluetoothApi_.setDevicesForTest(fakeDevices_);
return waitForListUpdateTimeout().then(function() {
Polymer.dom.flush(); await waitForListUpdateTimeout();
assertEquals(4, subpage.deviceList_.length);
assertEquals(2, subpage.pairedDeviceList_.length); Polymer.dom.flush();
assertTrue(subpage.$.noPairedDevices.hidden); assertEquals(4, subpage.deviceList_.length);
assertEquals(2, subpage.pairedDeviceList_.length);
const ironList = subpage.$.pairedDevices; assertTrue(subpage.$.noPairedDevices.hidden);
assertTrue(!!ironList);
ironList.notifyResize(); const ironList = subpage.$.pairedDevices;
Polymer.dom.flush(); assertTrue(!!ironList);
const devices = ironList.querySelectorAll('bluetooth-device-list-item'); ironList.notifyResize();
assertEquals(2, devices.length); Polymer.dom.flush();
assertTrue(devices[0].device.connected); const devices = ironList.querySelectorAll('bluetooth-device-list-item');
assertFalse(devices[1].device.connected); assertEquals(2, devices.length);
}); 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; const unpairedContainer = subpage.$.unpairedContainer;
assertTrue(!!unpairedContainer); assertTrue(!!unpairedContainer);
assertTrue(unpairedContainer.hidden); assertTrue(unpairedContainer.hidden);
assertFalse(subpage.$.noUnpairedDevices.hidden); assertFalse(subpage.$.noUnpairedDevices.hidden);
bluetoothApi_.setDevicesForTest(fakeDevices_); bluetoothApi_.setDevicesForTest(fakeDevices_);
return waitForListUpdateTimeout().then(function() { await waitForListUpdateTimeout();
Polymer.dom.flush();
assertEquals(4, subpage.deviceList_.length); Polymer.dom.flush();
assertEquals(2, subpage.unpairedDeviceList_.length); assertEquals(4, subpage.deviceList_.length);
assertTrue(subpage.$.noUnpairedDevices.hidden); assertEquals(2, subpage.unpairedDeviceList_.length);
assertTrue(subpage.$.noUnpairedDevices.hidden);
const ironList = subpage.$.unpairedDevices;
assertTrue(!!ironList); const ironList = subpage.$.unpairedDevices;
ironList.notifyResize(); assertTrue(!!ironList);
Polymer.dom.flush(); ironList.notifyResize();
const devices = ironList.querySelectorAll('bluetooth-device-list-item'); Polymer.dom.flush();
assertEquals(2, devices.length); const devices = ironList.querySelectorAll('bluetooth-device-list-item');
assertFalse(devices[0].device.paired); assertEquals(2, devices.length);
assertFalse(devices[1].device.paired); assertFalse(devices[0].device.paired);
}); assertFalse(devices[1].device.paired);
}); });
test('pair device', function(done) { test('pair device', async function() {
bluetoothApi_.setDevicesForTest(fakeDevices_); bluetoothApi_.setDevicesForTest(fakeDevices_);
return waitForListUpdateTimeout().then(function() { await waitForListUpdateTimeout();
Polymer.dom.flush();
assertEquals(4, subpage.deviceList_.length); Polymer.dom.flush();
assertEquals(2, subpage.pairedDeviceList_.length); assertEquals(4, subpage.deviceList_.length);
assertEquals(2, subpage.unpairedDeviceList_.length); assertEquals(2, subpage.pairedDeviceList_.length);
assertEquals(2, subpage.unpairedDeviceList_.length);
const address = subpage.unpairedDeviceList_[0].address;
bluetoothPrivateApi_.connect(address, function() { const address = subpage.unpairedDeviceList_[0].address;
Polymer.dom.flush(); await new Promise(
assertEquals(3, subpage.pairedDeviceList_.length); resolve => bluetoothPrivateApi_.connect(address, resolve));
assertEquals(1, subpage.unpairedDeviceList_.length);
done(); Polymer.dom.flush();
}); assertEquals(3, subpage.pairedDeviceList_.length);
}); assertEquals(1, subpage.unpairedDeviceList_.length);
}); });
test('pair dialog', function() { test('pair dialog', async function() {
bluetoothApi_.setDevicesForTest(fakeDevices_); bluetoothApi_.setDevicesForTest(fakeDevices_);
return waitForListUpdateTimeout().then(function() { await waitForListUpdateTimeout();
Polymer.dom.flush();
const dialog = subpage.$.deviceDialog; Polymer.dom.flush();
assertTrue(!!dialog); const dialog = subpage.$.deviceDialog;
assertFalse(dialog.$.dialog.open); assertTrue(!!dialog);
assertFalse(dialog.$.dialog.open);
// Simulate selecting an unpaired device; should show the pair dialog.
subpage.connectDevice_(subpage.unpairedDeviceList_[0]); // Simulate selecting an unpaired device; should show the pair dialog.
Polymer.dom.flush(); subpage.connectDevice_(subpage.unpairedDeviceList_[0]);
assertTrue(dialog.$.dialog.open); 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