Commit 4f3c37cd authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Update print preview tests to work with PrinterStatus flag enabled

This change will prepare the tests to allow setting PrinterStatus flag
to enabled by default.

Update the script in PDFPluginNotKeyboardFocusable to focus the
destination_select element.

Make NativeLayerStub return an empty JSON for printer status when the
printer_id isn't found.

Set the flag to always disabled in
PrintPreviewDestinationSelectTestCrOS. The equivalent of these tests
will run in PrinterStatusTestCros with the flag enabled.

Bug: 1059607
Change-Id: I49e2f3d133434c4c5c1770971271074e9f45ab19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298030Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791239}
parent 38c8775d
......@@ -891,8 +891,7 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PDFPluginNotKeyboardFocusable) {
const select_tag = document.getElementsByTagName('print-preview-app')[0]
.$['sidebar']
.$['destinationSettings']
.$['destinationSelect']
.$$('select');
.$['destinationSelect'];
select_tag.addEventListener('focus', () => {
window.domAutomationController.send(true);
});
......
......@@ -162,4 +162,12 @@ Polymer({
this.i18n('noLongerSupportedFragment') :
this.destination.connectionStatusText;
},
/**
* Return the options currently visible to the user for testing purposes.
* @return {!NodeList<!Element>}
*/
getVisibleItemsForTest: function() {
return this.shadowRoot.querySelectorAll('option:not([hidden])');
}
});
......@@ -144,7 +144,11 @@ Polymer({
},
focus() {
this.$$('#dropdown').focus();
if (this.printerStatusFlagEnabled_) {
this.$$('#dropdown').$$('#destination-dropdown').focus();
return;
}
this.$$('.md-select').focus();
},
/** Sets the select to the current value of |destination|. */
......@@ -408,4 +412,15 @@ Polymer({
return this.destination &&
this.destination.origin === DestinationOrigin.CROS;
},
/**
* Return the options currently visible to the user for testing purposes.
* @return {!Array<!Element>}
*/
getVisibleItemsForTest: function() {
return this.printerStatusFlagEnabled_ ?
this.$$('#dropdown')
.shadowRoot.querySelectorAll('.list-item:not([hidden])') :
this.shadowRoot.querySelectorAll('option:not([hidden])');
}
});
......@@ -10,7 +10,7 @@ import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
import {waitBeforeNextRender} from '../test_util.m.js';
import {NativeLayerStub} from './native_layer_stub.js';
import {getGoogleDriveDestination, selectOption} from './print_preview_test_utils.js';
import {getGoogleDriveDestination, getSaveAsPdfDestination, selectOption} from './print_preview_test_utils.js';
window.printer_status_test_cros = {};
const printer_status_test_cros = window.printer_status_test_cros;
......@@ -20,6 +20,7 @@ printer_status_test_cros.TestNames = {
PrinterStatusUpdatesColor: 'printer status updates color',
SendStatusRequestOnce: 'send status request once',
HiddenStatusText: 'hidden status text',
ChangeIcon: 'change icon',
};
suite(printer_status_test_cros.suiteName, function() {
......@@ -255,22 +256,66 @@ suite(printer_status_test_cros.suiteName, function() {
// trigger the error text being populated.
const destinationWithErrorStatus =
createDestination('ID4', 'Four', DestinationOrigin.CROS);
const cloudPrintDestination = new Destination(
'ID2', DestinationType.GOOGLE, DestinationOrigin.COOKIES, 'Two',
DestinationConnectionStatus.OFFLINE, {account: account});
destinationSelect.recentDestinationList = [
destinationWithoutErrorStatus,
destinationWithErrorStatus,
cloudPrintDestination,
];
const destinationStatus =
destinationSelect.$$('.destination-additional-info');
const destinationEulaWrapper =
destinationSelect.$$('#destinationEulaWrapper');
destinationSelect.destination = cloudPrintDestination;
assertFalse(destinationStatus.hidden);
assertTrue(destinationEulaWrapper.hidden);
destinationSelect.destination = destinationWithoutErrorStatus;
assertTrue(destinationSelect.$$('.destination-additional-info').hidden);
assertTrue(destinationStatus.hidden);
assertTrue(destinationEulaWrapper.hidden);
destinationSelect.set('destination.eulaUrl', 'chrome://os-credits/eula');
assertFalse(destinationEulaWrapper.hidden);
destinationSelect.destination = destinationWithErrorStatus;
return nativeLayer.whenCalled('requestPrinterStatusUpdate').then(() => {
assertFalse(
destinationSelect.$$('.destination-additional-info').hidden);
assertFalse(destinationStatus.hidden);
});
});
});
test(assert(printer_status_test_cros.TestNames.ChangeIcon), function() {
return waitBeforeNextRender(destinationSelect).then(() => {
const localCrosPrinter =
createDestination('ID1', 'One', DestinationOrigin.CROS);
const saveToDrive = getGoogleDriveDestination('account');
const saveAsPdf = getSaveAsPdfDestination();
destinationSelect.recentDestinationList = [
localCrosPrinter,
saveToDrive,
saveAsPdf,
];
const dropdown = destinationSelect.$$('#dropdown');
destinationSelect.destination = localCrosPrinter;
destinationSelect.updateDestination();
assertEquals('print-preview:print', dropdown.destinationIcon);
destinationSelect.destination = saveToDrive;
destinationSelect.updateDestination();
assertEquals('print-preview:save-to-drive', dropdown.destinationIcon);
destinationSelect.destination = saveAsPdf;
destinationSelect.updateDestination();
assertEquals('cr:insert-drive-file', dropdown.destinationIcon);
});
});
});
window.destination_select_test_cros = {};
......
......@@ -218,8 +218,8 @@ suite(destination_settings_test.suiteName, function() {
* destinations in the dropdown.
*/
function assertDropdownItems(expectedDestinations) {
const options = destinationSettings.$$('#destinationSelect')
.shadowRoot.querySelectorAll('option:not([hidden])');
const options =
destinationSettings.$$('#destinationSelect').getVisibleItemsForTest();
assertEquals(expectedDestinations.length + 1, options.length);
expectedDestinations.forEach((expectedValue, index) => {
assertEquals(expectedValue, options[index].value);
......
......@@ -374,7 +374,7 @@ export class NativeLayerStub extends TestBrowserProxy {
}
}
return Promise.resolve(this.printerStatusMap_.get(printerId));
return Promise.resolve(this.printerStatusMap_.get(printerId) || {});
}
/**
......
......@@ -1069,6 +1069,16 @@ var PrintPreviewDestinationSelectTestCrOS = class extends PrintPreviewTest {
get suiteName() {
return destination_select_test_cros.suiteName;
}
/** @override */
get featureList() {
const kPrinterStatus = ['chromeos::features::kPrinterStatus'];
const featureList = super.featureList;
featureList.disabled = featureList.disabled ?
featureList.disabled.concat(kPrinterStatus) :
kPrinterStatus;
return featureList;
}
};
TEST_F('PrintPreviewDestinationSelectTestCrOS', 'UpdateStatus', function() {
......@@ -1123,6 +1133,10 @@ TEST_F('PrintPreviewPrinterStatusTestCros', 'HiddenStatusText', function() {
this.runMochaTest(printer_status_test_cros.TestNames.HiddenStatusText);
});
TEST_F('PrintPreviewPrinterStatusTestCros', 'ChangeIcon', function() {
this.runMochaTest(printer_status_test_cros.TestNames.ChangeIcon);
});
// eslint-disable-next-line no-var
var PrintPreviewDestinationDropdownCrosTest = class extends PrintPreviewTest {
/** @override */
......
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