Commit 77a25e91 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Add destination store load/select test

Add a test for destination store that loads all destinations and
selects one.

Bug: 998103
Change-Id: I4de8fe6f2d8ad1fc0878962fd17fb392e474996a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1776780Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691915}
parent c906513f
......@@ -16,6 +16,7 @@ cr.define('destination_store_test', function() {
UnreachableRecentCloudPrinter: 'unreachable recent cloud printer',
RecentSaveAsPdf: 'recent save as pdf',
MultipleRecentDestinationsAccounts: 'multiple recent destinations accounts',
LoadAndSelectDestination: 'select loaded destination',
};
const suiteName = 'DestinationStoreTest';
......@@ -402,6 +403,65 @@ cr.define('destination_store_test', function() {
loadedPrintersAccount2[0].id);
});
});
/**
* Tests that if the user has a single valid recent destination the
* destination is automatically reselected.
*/
test(assert(TestNames.LoadAndSelectDestination), function() {
destinations = print_preview_test_utils.getDestinations(
nativeLayer, localDestinations);
initialSettings.printerName = '';
const id1 = 'ID1';
const name1 = 'One';
let destination = null;
return setInitialSettings()
.then(function(args) {
assertEquals(
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
args.destinationId);
assertEquals(print_preview.PrinterType.LOCAL, args.type);
assertEquals(
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF,
destinationStore.selectedDestination.id);
// Update destination with ID 1 so that it has policies.
const localDestinationInfo = {deviceName: id1, printerName: name1};
if (cr.isChromeOS) {
localDestinationInfo.policies = {
allowedColorModes: 0x1,
defaultColorMode: 0x1
};
}
nativeLayer.setLocalDestinationCapabilities({
printer: localDestinationInfo,
capabilities: print_preview_test_utils.getCddTemplate(id1, name1),
});
destinationStore.startLoadAllDestinations();
return nativeLayer.whenCalled('getPrinters');
})
.then(() => {
destination =
destinationStore.destinations().find(d => d.id === id1);
// No capabilities or policies yet.
assertFalse(!!destination.capabilities);
if (cr.isChromeOS) {
assertEquals(null, destination.policies);
}
destinationStore.selectDestination(destination);
return nativeLayer.whenCalled('getPrinterCapabilities');
})
.then(() => {
assertEquals(destination, destinationStore.selectedDestination);
// Capabilities are updated.
assertTrue(!!destination.capabilities);
// TODO (https://crbug.com/998103): Ensure that the destination
// policies are actually set.
if (cr.isChromeOS) {
assertEquals(null, destination.policies);
}
});
});
});
return {
......
......@@ -246,18 +246,24 @@ cr.define('print_preview_test_utils', function() {
const origin = cr.isChromeOS ? print_preview.DestinationOrigin.CROS :
print_preview.DestinationOrigin.LOCAL;
// Five destinations. FooDevice is the system default.
[{id: 'ID1', name: 'One'}, {id: 'ID2', name: 'Two'},
{id: 'ID3', name: 'Three'}, {id: 'ID4', name: 'Four'},
{id: 'FooDevice', name: 'FooName'}]
[{deviceName: 'ID1', printerName: 'One'},
{deviceName: 'ID2', printerName: 'Two'},
{deviceName: 'ID3', printerName: 'Three'},
{deviceName: 'ID4', printerName: 'Four'},
{deviceName: 'FooDevice', printerName: 'FooName'}]
.forEach((info, index) => {
const destination = new print_preview.Destination(
info.id, print_preview.DestinationType.LOCAL, origin, info.name,
info.deviceName, print_preview.DestinationType.LOCAL, origin,
info.printerName,
print_preview.DestinationConnectionStatus.ONLINE);
if (nativeLayer) {
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate(info.id, info.name));
nativeLayer.setLocalDestinationCapabilities({
printer: info,
capabilities: print_preview_test_utils.getCddTemplate(
info.deviceName, info.printerName),
});
}
localDestinations.push({printerName: info.name, deviceName: info.id});
localDestinations.push(info);
destinations.push(destination);
});
return destinations;
......
......@@ -697,6 +697,12 @@ TEST_F(
destination_store_test.TestNames.KioskModeSelectsFirstPrinter);
});
TEST_F(
'PrintPreviewDestinationStoreTest', 'LoadAndSelectDestination', function() {
this.runMochaTest(
destination_store_test.TestNames.LoadAndSelectDestination);
});
GEN('#if defined(OS_CHROMEOS)');
TEST_F('PrintPreviewDestinationStoreTest', 'NoPrintersShowsError', function() {
this.runMochaTest(destination_store_test.TestNames.NoPrintersShowsError);
......
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