Commit 6fbd33d2 authored by Julian Watson's avatar Julian Watson Committed by Commit Bot

crostini: use async in page tests

Bug: None
Change-Id: I2ffbdec3ccf5fc94118e2080df159bc78869c711
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2084034
Commit-Queue: Julian Watson <juwa@google.com>
Auto-Submit: Julian Watson <juwa@google.com>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746232}
parent a6ba460f
...@@ -69,24 +69,20 @@ suite('CrostiniPageTests', function() { ...@@ -69,24 +69,20 @@ suite('CrostiniPageTests', function() {
assertTrue(!!crostiniPage.$$('.subpage-arrow')); assertTrue(!!crostiniPage.$$('.subpage-arrow'));
}); });
test('ButtonDisabledDuringInstall', function() { test('ButtonDisabledDuringInstall', async function() {
const button = crostiniPage.$$('#enable'); const button = crostiniPage.$$('#enable');
assertTrue(!!button); assertTrue(!!button);
return flushAsync()
.then(() => { await flushAsync();
assertFalse(button.disabled); assertFalse(button.disabled);
cr.webUIListenerCallback('crostini-installer-status-changed', true); cr.webUIListenerCallback('crostini-installer-status-changed', true);
return flushAsync();
}) await flushAsync();
.then(() => { assertTrue(button.disabled);
assertTrue(button.disabled); cr.webUIListenerCallback('crostini-installer-status-changed', false);
cr.webUIListenerCallback(
'crostini-installer-status-changed', false); await flushAsync();
return flushAsync(); assertFalse(button.disabled);
})
.then(() => {
assertFalse(button.disabled);
});
}); });
}); });
...@@ -94,7 +90,7 @@ suite('CrostiniPageTests', function() { ...@@ -94,7 +90,7 @@ suite('CrostiniPageTests', function() {
/** @type {?SettingsCrostiniSubPageElement} */ /** @type {?SettingsCrostiniSubPageElement} */
let subpage; let subpage;
setup(function() { setup(async function() {
setCrostiniPrefs(true); setCrostiniPrefs(true);
loadTimeData.overrideValues({ loadTimeData.overrideValues({
showCrostiniExportImport: true, showCrostiniExportImport: true,
...@@ -118,7 +114,7 @@ suite('CrostiniPageTests', function() { ...@@ -118,7 +114,7 @@ suite('CrostiniPageTests', function() {
assertTrue(!!subpage); assertTrue(!!subpage);
}); });
return Promise.all([pageLoadPromise, eventPromise]); await Promise.all([pageLoadPromise, eventPromise]);
}); });
test('Sanity', function() { test('Sanity', function() {
...@@ -130,13 +126,13 @@ suite('CrostiniPageTests', function() { ...@@ -130,13 +126,13 @@ suite('CrostiniPageTests', function() {
assertTrue(!!subpage.$$('#crostini-port-forwarding')); assertTrue(!!subpage.$$('#crostini-port-forwarding'));
}); });
test('SharedPaths', function() { test('SharedPaths', async function() {
assertTrue(!!subpage.$$('#crostini-shared-paths')); assertTrue(!!subpage.$$('#crostini-shared-paths'));
subpage.$$('#crostini-shared-paths').click(); subpage.$$('#crostini-shared-paths').click();
return flushAsync().then(() => {
subpage = crostiniPage.$$('settings-crostini-shared-paths'); await flushAsync();
assertTrue(!!subpage); subpage = crostiniPage.$$('settings-crostini-shared-paths');
}); assertTrue(!!subpage);
}); });
test('ContainerUpgrade', function() { test('ContainerUpgrade', function() {
...@@ -148,133 +144,117 @@ suite('CrostiniPageTests', function() { ...@@ -148,133 +144,117 @@ suite('CrostiniPageTests', function() {
'requestCrostiniContainerUpgradeView')); 'requestCrostiniContainerUpgradeView'));
}); });
test('ContainerUpgradeButtonDisabledOnUpgradeDialog', function() { test('ContainerUpgradeButtonDisabledOnUpgradeDialog', async function() {
const button = subpage.$$('#container-upgrade cr-button'); const button = subpage.$$('#container-upgrade cr-button');
assertTrue(!!button); assertTrue(!!button);
return flushAsync()
.then(() => { await flushAsync();
assertFalse(button.disabled); assertFalse(button.disabled);
cr.webUIListenerCallback('crostini-upgrader-status-changed', true); cr.webUIListenerCallback('crostini-upgrader-status-changed', true);
return flushAsync();
}) await flushAsync();
.then(() => { assertTrue(button.disabled);
assertTrue(button.disabled); cr.webUIListenerCallback('crostini-upgrader-status-changed', false);
cr.webUIListenerCallback('crostini-upgrader-status-changed', false);
return flushAsync(); await flushAsync();
}) assertFalse(button.disabled);
.then(() => {
assertFalse(button.disabled);
});
}); });
test('ContainerUpgradeButtonDisabledOnInstall', function() { test('ContainerUpgradeButtonDisabledOnInstall', async function() {
const button = subpage.$$('#container-upgrade cr-button'); const button = subpage.$$('#container-upgrade cr-button');
assertTrue(!!button); assertTrue(!!button);
return flushAsync()
.then(() => {
assertFalse(button.disabled);
cr.webUIListenerCallback('crostini-installer-status-changed', true);
return flushAsync();
})
.then(() => {
assertTrue(button.disabled);
cr.webUIListenerCallback(
'crostini-installer-status-changed', false);
return flushAsync();
})
.then(() => {
assertFalse(button.disabled);
});
});
test('Export', function() { await flushAsync();
assertTrue(!!subpage.$$('#crostini-export-import')); assertFalse(button.disabled);
subpage.$$('#crostini-export-import').click(); cr.webUIListenerCallback('crostini-installer-status-changed', true);
return flushAsync().then(() => {
subpage = crostiniPage.$$('settings-crostini-export-import'); await flushAsync();
assertTrue(!!subpage.$$('#export cr-button')); assertTrue(button.disabled);
subpage.$$('#export cr-button').click(); cr.webUIListenerCallback('crostini-installer-status-changed', false);
assertEquals(
1, crostiniBrowserProxy.getCallCount('exportCrostiniContainer')); await flushAsync();
}); assertFalse(button.disabled);
}); });
test('Import', function() { test('Export', async function() {
assertTrue(!!subpage.$$('#crostini-export-import')); assertTrue(!!subpage.$$('#crostini-export-import'));
subpage.$$('#crostini-export-import').click(); subpage.$$('#crostini-export-import').click();
return flushAsync()
.then(() => { await flushAsync();
subpage = crostiniPage.$$('settings-crostini-export-import'); subpage = crostiniPage.$$('settings-crostini-export-import');
subpage.$$('#import cr-button').click(); assertTrue(!!subpage.$$('#export cr-button'));
return flushAsync(); subpage.$$('#export cr-button').click();
}) assertEquals(
.then(() => { 1, crostiniBrowserProxy.getCallCount('exportCrostiniContainer'));
subpage =
subpage.$$('settings-crostini-import-confirmation-dialog');
subpage.$$('cr-dialog cr-button[id="continue"]').click();
assertEquals(
1,
crostiniBrowserProxy.getCallCount('importCrostiniContainer'));
});
}); });
test('ExportImportButtonsGetDisabledOnOperationStatus', function() { test('Import', async function() {
assertTrue(!!subpage.$$('#crostini-export-import')); assertTrue(!!subpage.$$('#crostini-export-import'));
subpage.$$('#crostini-export-import').click(); subpage.$$('#crostini-export-import').click();
return flushAsync()
.then(() => { await flushAsync();
subpage = crostiniPage.$$('settings-crostini-export-import'); subpage = crostiniPage.$$('settings-crostini-export-import');
assertFalse(subpage.$$('#export cr-button').disabled); subpage.$$('#import cr-button').click();
assertFalse(subpage.$$('#import cr-button').disabled);
cr.webUIListenerCallback( await flushAsync();
'crostini-export-import-operation-status-changed', true); subpage = subpage.$$('settings-crostini-import-confirmation-dialog');
return flushAsync(); subpage.$$('cr-dialog cr-button[id="continue"]').click();
}) assertEquals(
.then(() => { 1, crostiniBrowserProxy.getCallCount('importCrostiniContainer'));
subpage = crostiniPage.$$('settings-crostini-export-import');
assertTrue(subpage.$$('#export cr-button').disabled);
assertTrue(subpage.$$('#import cr-button').disabled);
cr.webUIListenerCallback(
'crostini-export-import-operation-status-changed', false);
return flushAsync();
})
.then(() => {
subpage = crostiniPage.$$('settings-crostini-export-import');
assertFalse(subpage.$$('#export cr-button').disabled);
assertFalse(subpage.$$('#import cr-button').disabled);
});
}); });
test('ExportImportButtonsDisabledOnWhenInstallingCrostini', function() { test('ExportImportButtonsGetDisabledOnOperationStatus', async function() {
assertTrue(!!subpage.$$('#crostini-export-import')); assertTrue(!!subpage.$$('#crostini-export-import'));
subpage.$$('#crostini-export-import').click(); subpage.$$('#crostini-export-import').click();
return flushAsync()
.then(() => { await flushAsync();
subpage = crostiniPage.$$('settings-crostini-export-import'); subpage = crostiniPage.$$('settings-crostini-export-import');
assertFalse(subpage.$$('#export cr-button').disabled); assertFalse(subpage.$$('#export cr-button').disabled);
assertFalse(subpage.$$('#import cr-button').disabled); assertFalse(subpage.$$('#import cr-button').disabled);
cr.webUIListenerCallback('crostini-installer-status-changed', true); cr.webUIListenerCallback(
return flushAsync(); 'crostini-export-import-operation-status-changed', true);
})
.then(() => { await flushAsync();
subpage = crostiniPage.$$('settings-crostini-export-import'); subpage = crostiniPage.$$('settings-crostini-export-import');
assertTrue(subpage.$$('#export cr-button').disabled); assertTrue(subpage.$$('#export cr-button').disabled);
assertTrue(subpage.$$('#import cr-button').disabled); assertTrue(subpage.$$('#import cr-button').disabled);
cr.webUIListenerCallback( cr.webUIListenerCallback(
'crostini-installer-status-changed', false); 'crostini-export-import-operation-status-changed', false);
return flushAsync();
}) await flushAsync();
.then(() => { subpage = crostiniPage.$$('settings-crostini-export-import');
subpage = crostiniPage.$$('settings-crostini-export-import'); assertFalse(subpage.$$('#export cr-button').disabled);
assertFalse(subpage.$$('#export cr-button').disabled); assertFalse(subpage.$$('#import cr-button').disabled);
assertFalse(subpage.$$('#import cr-button').disabled);
});
}); });
test(
'ExportImportButtonsDisabledOnWhenInstallingCrostini',
async function() {
assertTrue(!!subpage.$$('#crostini-export-import'));
subpage.$$('#crostini-export-import').click();
await flushAsync();
subpage = crostiniPage.$$('settings-crostini-export-import');
assertFalse(subpage.$$('#export cr-button').disabled);
assertFalse(subpage.$$('#import cr-button').disabled);
cr.webUIListenerCallback('crostini-installer-status-changed', true);
await flushAsync();
subpage = crostiniPage.$$('settings-crostini-export-import');
assertTrue(subpage.$$('#export cr-button').disabled);
assertTrue(subpage.$$('#import cr-button').disabled);
cr.webUIListenerCallback('crostini-installer-status-changed', false);
await flushAsync();
subpage = crostiniPage.$$('settings-crostini-export-import');
assertFalse(subpage.$$('#export cr-button').disabled);
assertFalse(subpage.$$('#import cr-button').disabled);
});
suite('SubPagePortForwarding', function() { suite('SubPagePortForwarding', function() {
/** @type {?SettingsCrostiniPortForwarding} */ /** @type {?SettingsCrostiniPortForwarding} */
let subpage; let subpage;
setup(function() { setup(async function() {
setCrostiniPrefs(true, { setCrostiniPrefs(true, {
forwardedPorts: [ forwardedPorts: [
{ {
...@@ -292,16 +272,13 @@ suite('CrostiniPageTests', function() { ...@@ -292,16 +272,13 @@ suite('CrostiniPageTests', function() {
] ]
}); });
return flushAsync() await flushAsync();
.then(() => { settings.Router.getInstance().navigateTo(
settings.Router.getInstance().navigateTo( settings.routes.CROSTINI_PORT_FORWARDING);
settings.routes.CROSTINI_PORT_FORWARDING);
return flushAsync(); await flushAsync();
}) subpage = crostiniPage.$$('settings-crostini-port-forwarding');
.then(() => { assertTrue(!!subpage);
subpage = crostiniPage.$$('settings-crostini-port-forwarding');
assertTrue(!!subpage);
});
}); });
test('Forwarded ports are shown', function() { test('Forwarded ports are shown', function() {
...@@ -310,140 +287,120 @@ suite('CrostiniPageTests', function() { ...@@ -310,140 +287,120 @@ suite('CrostiniPageTests', function() {
3, subpage.shadowRoot.querySelectorAll('.list-item').length); 3, subpage.shadowRoot.querySelectorAll('.list-item').length);
}); });
test('AddPortSuccess', function() { test('AddPortSuccess', async function() {
return flushAsync() await flushAsync();
.then(() => { subpage = crostiniPage.$$('settings-crostini-port-forwarding');
subpage = crostiniPage.$$('settings-crostini-port-forwarding'); subpage.$$('#addPort cr-button').click();
subpage.$$('#addPort cr-button').click();
return flushAsync(); await flushAsync();
}) subpage = subpage.$$('settings-crostini-add-port-dialog');
.then(() => { const portNumberInput = subpage.$$('#portNumberInput');
subpage = subpage.$$('settings-crostini-add-port-dialog'); portNumberInput.value = '5000';
const portNumberInput = subpage.$$('#portNumberInput'); const portLabelInput = subpage.$$('#portLabelInput');
portNumberInput.value = '5000'; portLabelInput.value = 'Some Label';
const portLabelInput = subpage.$$('#portLabelInput'); subpage.$$('cr-dialog cr-button[id="continue"]').click();
portLabelInput.value = 'Some Label'; assertEquals(
subpage.$$('cr-dialog cr-button[id="continue"]').click(); 1, crostiniBrowserProxy.getCallCount('addCrostiniPortForward'));
assertEquals(
1,
crostiniBrowserProxy.getCallCount('addCrostiniPortForward'));
});
}); });
test('AddPortFail', function() { test('AddPortFail', async function() {
return flushAsync() await flushAsync();
.then(() => { subpage = crostiniPage.$$('settings-crostini-port-forwarding');
subpage = crostiniPage.$$('settings-crostini-port-forwarding'); subpage.$$('#addPort cr-button').click();
subpage.$$('#addPort cr-button').click();
return flushAsync(); await flushAsync();
}) subpage = subpage.$$('settings-crostini-add-port-dialog');
.then(() => { const portNumberInput = subpage.$$('#portNumberInput');
subpage = subpage.$$('settings-crostini-add-port-dialog'); portNumberInput.value = 'INVALID_PORT_NUMBER';
const portNumberInput = subpage.$$('#portNumberInput'); const portLabelInput = subpage.$$('#portLabelInput');
portNumberInput.value = 'INVALID_PORT_NUMBER'; portLabelInput.value = 'Some Label';
const portLabelInput = subpage.$$('#portLabelInput'); subpage.$$('cr-dialog cr-button[id="continue"]').click();
portLabelInput.value = 'Some Label'; assertEquals(
subpage.$$('cr-dialog cr-button[id="continue"]').click(); 0, crostiniBrowserProxy.getCallCount('addCrostiniPortForward'));
assertEquals( portNumberInput.value = '65536';
0, subpage.$$('cr-dialog cr-button[id="continue"]').click();
crostiniBrowserProxy.getCallCount('addCrostiniPortForward')); assertEquals(
portNumberInput.value = '65536'; 0, crostiniBrowserProxy.getCallCount('addCrostiniPortForward'));
subpage.$$('cr-dialog cr-button[id="continue"]').click(); portNumberInput.value = '65535';
assertEquals( subpage.$$('cr-dialog cr-button[id="continue"]').click();
0, assertEquals(
crostiniBrowserProxy.getCallCount('addCrostiniPortForward')); 1, crostiniBrowserProxy.getCallCount('addCrostiniPortForward'));
portNumberInput.value = '65535';
subpage.$$('cr-dialog cr-button[id="continue"]').click();
assertEquals(
1,
crostiniBrowserProxy.getCallCount('addCrostiniPortForward'));
});
}); });
test('AddPortCancel', function() { test('AddPortCancel', async function() {
return flushAsync() await flushAsync();
.then(() => { subpage = crostiniPage.$$('settings-crostini-port-forwarding');
subpage = crostiniPage.$$('settings-crostini-port-forwarding'); subpage.$$('#addPort cr-button').click();
subpage.$$('#addPort cr-button').click();
return flushAsync(); await flushAsync();
}) subpage = subpage.$$('settings-crostini-add-port-dialog');
.then(() => { subpage.$$('cr-dialog cr-button[id="cancel"]').click();
subpage = subpage.$$('settings-crostini-add-port-dialog');
subpage.$$('cr-dialog cr-button[id="cancel"]').click();
return flushAsync(); await flushAsync();
}) subpage = crostiniPage.$$('settings-crostini-port-forwarding');
.then(() => { assertTrue(!!subpage);
subpage = crostiniPage.$$('settings-crostini-port-forwarding');
assertTrue(!!subpage);
});
}); });
}); });
test('Remove', function() { test('Remove', async function() {
assertTrue(!!subpage.$$('#remove cr-button')); assertTrue(!!subpage.$$('#remove cr-button'));
subpage.$$('#remove cr-button').click(); subpage.$$('#remove cr-button').click();
assertEquals( assertEquals(
1, crostiniBrowserProxy.getCallCount('requestRemoveCrostini')); 1, crostiniBrowserProxy.getCallCount('requestRemoveCrostini'));
setCrostiniPrefs(false); setCrostiniPrefs(false);
return test_util.eventToPromise('popstate', window).then(function() {
assertEquals( await test_util.eventToPromise('popstate', window);
settings.Router.getInstance().getCurrentRoute(), assertEquals(
settings.routes.CROSTINI); settings.Router.getInstance().getCurrentRoute(),
assertTrue(!!crostiniPage.$$('#enable')); settings.routes.CROSTINI);
}); assertTrue(!!crostiniPage.$$('#enable'));
}); });
test('RemoveHidden', function() { test('RemoveHidden', async function() {
// Elements are not destroyed when a dom-if stops being shown, but we can // Elements are not destroyed when a dom-if stops being shown, but we
// check if their rendered width is non-zero. This should be resilient // can check if their rendered width is non-zero. This should be
// against most formatting changes, since we're not relying on them having // resilient against most formatting changes, since we're not relying on
// any exact size, or on Polymer using any particular means of hiding // them having any exact size, or on Polymer using any particular means
// elements. // of hiding elements.
assertTrue(!!subpage.shadowRoot.querySelector('#remove').clientWidth); assertTrue(!!subpage.shadowRoot.querySelector('#remove').clientWidth);
cr.webUIListenerCallback('crostini-installer-status-changed', true); cr.webUIListenerCallback('crostini-installer-status-changed', true);
return flushAsync()
.then(() => { await flushAsync();
assertFalse( assertFalse(!!subpage.shadowRoot.querySelector('#remove').clientWidth);
!!subpage.shadowRoot.querySelector('#remove').clientWidth); cr.webUIListenerCallback('crostini-installer-status-changed', false);
cr.webUIListenerCallback(
'crostini-installer-status-changed', false); await flushAsync();
return flushAsync(); assertTrue(!!subpage.shadowRoot.querySelector('#remove').clientWidth);
})
.then(() => {
assertTrue(
!!subpage.shadowRoot.querySelector('#remove').clientWidth);
});
}); });
test('HideOnDisable', function() { test('HideOnDisable', async function() {
assertEquals( assertEquals(
settings.Router.getInstance().getCurrentRoute(), settings.Router.getInstance().getCurrentRoute(),
settings.routes.CROSTINI_DETAILS); settings.routes.CROSTINI_DETAILS);
setCrostiniPrefs(false); setCrostiniPrefs(false);
return test_util.eventToPromise('popstate', window).then(function() {
assertEquals( await test_util.eventToPromise('popstate', window);
settings.Router.getInstance().getCurrentRoute(), assertEquals(
settings.routes.CROSTINI); settings.Router.getInstance().getCurrentRoute(),
}); settings.routes.CROSTINI);
}); });
}); });
suite('SubPageSharedPaths', function() { suite('SubPageSharedPaths', function() {
let subpage; let subpage;
setup(function() { setup(async function() {
setCrostiniPrefs( setCrostiniPrefs(
true, {sharedPaths: {path1: ['termina'], path2: ['termina']}}); true, {sharedPaths: {path1: ['termina'], path2: ['termina']}});
return flushAsync()
.then(() => { await flushAsync();
settings.Router.getInstance().navigateTo( settings.Router.getInstance().navigateTo(
settings.routes.CROSTINI_SHARED_PATHS); settings.routes.CROSTINI_SHARED_PATHS);
return flushAsync();
}) await flushAsync();
.then(() => { subpage = crostiniPage.$$('settings-crostini-shared-paths');
subpage = crostiniPage.$$('settings-crostini-shared-paths'); assertTrue(!!subpage);
assertTrue(!!subpage);
});
}); });
test('Sanity', function() { test('Sanity', function() {
...@@ -452,76 +409,72 @@ suite('CrostiniPageTests', function() { ...@@ -452,76 +409,72 @@ suite('CrostiniPageTests', function() {
assertEquals(2, subpage.shadowRoot.querySelectorAll('.list-item').length); assertEquals(2, subpage.shadowRoot.querySelectorAll('.list-item').length);
}); });
test('Remove', function() { test('Remove', async function() {
assertFalse(subpage.$.crostiniInstructionsRemove.hidden); assertFalse(subpage.$.crostiniInstructionsRemove.hidden);
assertFalse(subpage.$.crostiniList.hidden); assertFalse(subpage.$.crostiniList.hidden);
assertTrue(subpage.$.crostiniListEmpty.hidden); assertTrue(subpage.$.crostiniListEmpty.hidden);
assertTrue(!!subpage.$$('.list-item cr-icon-button')); assertTrue(!!subpage.$$('.list-item cr-icon-button'));
// Remove first shared path, still one left.
subpage.$$('.list-item cr-icon-button').click(); {
return crostiniBrowserProxy.whenCalled('removeCrostiniSharedPath') // Remove first shared path, still one left.
.then(([vmName, path]) => { subpage.$$('.list-item cr-icon-button').click();
assertEquals('termina', vmName); const [vmName, path] =
assertEquals('path1', path); await crostiniBrowserProxy.whenCalled('removeCrostiniSharedPath');
setCrostiniPrefs(true, {sharedPaths: {path2: ['termina']}}); assertEquals('termina', vmName);
return flushAsync(); assertEquals('path1', path);
}) setCrostiniPrefs(true, {sharedPaths: {path2: ['termina']}});
.then(() => { }
Polymer.dom.flush();
assertEquals( await flushAsync();
1, subpage.shadowRoot.querySelectorAll('.list-item').length); Polymer.dom.flush();
assertFalse(subpage.$.crostiniInstructionsRemove.hidden); assertEquals(1, subpage.shadowRoot.querySelectorAll('.list-item').length);
assertFalse(subpage.$.crostiniInstructionsRemove.hidden);
// Remove remaining shared path, none left.
crostiniBrowserProxy.resetResolver('removeCrostiniSharedPath'); {
subpage.$$('.list-item cr-icon-button').click(); // Remove remaining shared path, none left.
return crostiniBrowserProxy.whenCalled('removeCrostiniSharedPath'); crostiniBrowserProxy.resetResolver('removeCrostiniSharedPath');
}) subpage.$$('.list-item cr-icon-button').click();
.then(([vmName, path]) => { const [vmName, path] =
assertEquals('termina', vmName); await crostiniBrowserProxy.whenCalled('removeCrostiniSharedPath');
assertEquals('path2', path); assertEquals('termina', vmName);
setCrostiniPrefs(true, {sharedPaths: {}}); assertEquals('path2', path);
return flushAsync(); setCrostiniPrefs(true, {sharedPaths: {}});
}) }
.then(() => {
Polymer.dom.flush(); await flushAsync();
assertEquals( Polymer.dom.flush();
0, subpage.shadowRoot.querySelectorAll('.list-item').length); assertEquals(0, subpage.shadowRoot.querySelectorAll('.list-item').length);
// Verify remove instructions are hidden, and empty list message // Verify remove instructions are hidden, and empty list message
// is shown. // is shown.
assertTrue(subpage.$.crostiniInstructionsRemove.hidden); assertTrue(subpage.$.crostiniInstructionsRemove.hidden);
assertTrue(subpage.$.crostiniList.hidden); assertTrue(subpage.$.crostiniList.hidden);
assertFalse(subpage.$.crostiniListEmpty.hidden); assertFalse(subpage.$.crostiniListEmpty.hidden);
});
}); });
test('RemoveFailedRetry', function() { test('RemoveFailedRetry', async function() {
// Remove shared path fails. // Remove shared path fails.
crostiniBrowserProxy.removeSharedPathResult = false; crostiniBrowserProxy.removeSharedPathResult = false;
subpage.$$('.list-item cr-icon-button').click(); subpage.$$('.list-item cr-icon-button').click();
return crostiniBrowserProxy.whenCalled('removeCrostiniSharedPath')
.then(() => { await crostiniBrowserProxy.whenCalled('removeCrostiniSharedPath');
Polymer.dom.flush(); Polymer.dom.flush();
assertTrue(subpage.$$('#removeSharedPathFailedDialog').open); assertTrue(subpage.$$('#removeSharedPathFailedDialog').open);
// Click retry and make sure 'removeCrostiniSharedPath' is called // Click retry and make sure 'removeCrostiniSharedPath' is called
// and dialog is closed/removed. // and dialog is closed/removed.
crostiniBrowserProxy.removeSharedPathResult = true; crostiniBrowserProxy.removeSharedPathResult = true;
subpage.$$('#removeSharedPathFailedDialog') subpage.$$('#removeSharedPathFailedDialog')
.querySelector('.action-button') .querySelector('.action-button')
.click(); .click();
return crostiniBrowserProxy.whenCalled('removeCrostiniSharedPath'); await crostiniBrowserProxy.whenCalled('removeCrostiniSharedPath');
}) assertFalse(!!subpage.$$('#removeSharedPathFailedDialog'));
.then(() => {
assertFalse(!!subpage.$$('#removeSharedPathFailedDialog'));
});
}); });
}); });
suite('SubPageSharedUsbDevices', function() { suite('SubPageSharedUsbDevices', function() {
let subpage; let subpage;
setup(function() { setup(async function() {
setCrostiniPrefs(true, { setCrostiniPrefs(true, {
sharedUsbDevices: [ sharedUsbDevices: [
{shared: true, guid: '0001', name: 'usb_dev1'}, {shared: true, guid: '0001', name: 'usb_dev1'},
...@@ -530,43 +483,37 @@ suite('CrostiniPageTests', function() { ...@@ -530,43 +483,37 @@ suite('CrostiniPageTests', function() {
] ]
}); });
return flushAsync() await flushAsync();
.then(() => { settings.Router.getInstance().navigateTo(
settings.Router.getInstance().navigateTo( settings.routes.CROSTINI_SHARED_USB_DEVICES);
settings.routes.CROSTINI_SHARED_USB_DEVICES);
return flushAsync(); await flushAsync();
}) subpage = crostiniPage.$$('settings-crostini-shared-usb-devices');
.then(() => { assertTrue(!!subpage);
subpage = crostiniPage.$$('settings-crostini-shared-usb-devices');
assertTrue(!!subpage);
});
}); });
test('USB devices are shown', function() { test('USB devices are shown', function() {
assertEquals(3, subpage.shadowRoot.querySelectorAll('.toggle').length); assertEquals(3, subpage.shadowRoot.querySelectorAll('.toggle').length);
}); });
test('USB shared state is updated by toggling', function() { test('USB shared state is updated by toggling', async function() {
assertTrue(!!subpage.$$('.toggle')); assertTrue(!!subpage.$$('.toggle'));
subpage.$$('.toggle').click(); subpage.$$('.toggle').click();
return flushAsync()
.then(() => { await flushAsync();
Polymer.dom.flush(); Polymer.dom.flush();
return crostiniBrowserProxy.whenCalled(
'setCrostiniUsbDeviceShared'); const args =
}) await crostiniBrowserProxy.whenCalled('setCrostiniUsbDeviceShared');
.then(args => { assertEquals('0001', args[0]);
assertEquals('0001', args[0]); assertEquals(false, args[1]);
assertEquals(false, args[1]);
// Simulate a change in the underlying model.
// Simulate a change in the underlying model. cr.webUIListenerCallback('crostini-shared-usb-devices-changed', [
cr.webUIListenerCallback('crostini-shared-usb-devices-changed', [ {shared: true, guid: '0001', name: 'usb_dev1'},
{shared: true, guid: '0001', name: 'usb_dev1'}, ]);
]); Polymer.dom.flush();
Polymer.dom.flush(); assertEquals(1, subpage.shadowRoot.querySelectorAll('.toggle').length);
assertEquals(
1, subpage.shadowRoot.querySelectorAll('.toggle').length);
});
}); });
}); });
}); });
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