Commit b0c1909e authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview Componentization: Use destination updates

Listen for destination events and update UI when destination changes.

Bug: 773928
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I1c9aff4f5e6fd1d856727064ab76058c30b12125
Reviewed-on: https://chromium-review.googlesource.com/823579
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524473}
parent 249dc2fe
......@@ -26,24 +26,6 @@ print_preview.AppStateField = {
VENDOR_OPTIONS: 'vendorOptions'
};
/**
* Creates a |RecentDestination| to represent |destination| in the app
* state.
* @param {!print_preview.Destination} destination The destination to store.
* @return {!print_preview.RecentDestination}
*/
function makeRecentDestination(destination) {
return {
id: destination.id,
origin: destination.origin,
account: destination.account || '',
capabilities: destination.capabilities,
displayName: destination.displayName || '',
extensionId: destination.extensionId || '',
extensionName: destination.extensionName || '',
};
}
cr.define('print_preview', function() {
'use strict';
class AppState extends cr.EventTarget {
......@@ -221,7 +203,8 @@ cr.define('print_preview', function() {
// Determine if this destination is already in the recent destinations,
// and where in the array it is located.
const newDestination = makeRecentDestination(assert(destination));
const newDestination =
print_preview.makeRecentDestination(assert(destination));
let indexFound =
this.state_[print_preview.AppStateField.RECENT_DESTINATIONS]
.findIndex(function(recent) {
......
......@@ -108,9 +108,38 @@ print_preview.CddCapabilities;
*/
print_preview.Cdd;
/**
* @typedef {{id: string,
* origin: print_preview.DestinationOrigin,
* account: string,
* capabilities: ?print_preview.Cdd,
* displayName: string,
* extensionId: string,
* extensionName: string}}
*/
print_preview.RecentDestination;
cr.define('print_preview', function() {
'use strict';
/**
* Creates a |RecentDestination| to represent |destination| in the app
* state.
* @param {!print_preview.Destination} destination The destination to store.
* @return {!print_preview.RecentDestination}
*/
function makeRecentDestination(destination) {
return {
id: destination.id,
origin: destination.origin,
account: destination.account || '',
capabilities: destination.capabilities,
displayName: destination.displayName || '',
extensionId: destination.extensionId || '',
extensionName: destination.extensionName || '',
};
}
class Destination {
/**
* Print destination data object that holds data for both local and cloud
......@@ -599,5 +628,6 @@ cr.define('print_preview', function() {
// Export
return {
Destination: Destination,
makeRecentDestination: makeRecentDestination,
};
});
......@@ -4,17 +4,6 @@
cr.exportPath('print_preview');
/**
* @typedef {{id: string,
* origin: print_preview.DestinationOrigin,
* account: string,
* capabilities: ?print_preview.Cdd,
* displayName: string,
* extensionId: string,
* extensionName: string}}
*/
print_preview.RecentDestination;
/**
* Printer search statuses used by the destination store.
* @enum {string}
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="chrome://resources/html/event_tracker.html">
<link rel="import" href="chrome://resources/html/webui_listener_tracker.html">
<link rel="import" href="../native_layer.html">
<link rel="import" href="../data/destination.html">
......
......@@ -59,63 +59,6 @@ Polymer({
destination_: {
type: Object,
notify: true,
value: function() {
const dest = new print_preview.Destination(
'Foo Printer', print_preview.DestinationType.LOCAL,
print_preview.DestinationOrigin.LOCAL, 'Foo Printer', true,
print_preview.DestinationConnectionStatus.ONLINE,
{description: 'PrinterBrandAA 12345'});
dest.capabilities = {
version: '1.0',
printer: {
collate: {default: true},
color: {
option: [
{type: 'STANDARD_COLOR', is_default: true},
{type: 'STANDARD_MONOCHROME'}
]
},
copies: {default: 1, max: 1000},
dpi: {
option: [
{horizontal_dpi: 200, vertical_dpi: 200, is_default: true},
{horizontal_dpi: 100, vertical_dpi: 100},
]
},
duplex: {
option: [
{type: 'NO_DUPLEX', is_default: true}, {type: 'LONG_EDGE'},
{type: 'SHORT_EDGE'}
]
},
page_orientation: {
option: [
{type: 'PORTRAIT', is_default: true}, {type: 'LANDSCAPE'},
{type: 'AUTO'}
]
},
media_size: {
option: [
{
name: 'NA_LETTER',
width_microns: 215900,
height_microns: 279400,
is_default: true,
custom_display_name: 'Letter',
},
{
name: 'CUSTOM_SQUARE',
width_microns: 215900,
height_microns: 215900,
custom_display_name: 'CUSTOM_SQUARE',
}
]
},
vendor_capability: [],
}
};
return dest;
},
},
/** @private {!print_preview_new.State} */
......@@ -132,6 +75,16 @@ Polymer({
},
},
observers: [
'updateRecentDestinations_(destination_, destination_.capabilities)',
],
/**
* @private {number} Number of recent destinations to save.
* @const
*/
NUM_DESTINATIONS_: 3,
/** @private {?print_preview.NativeLayer} */
nativeLayer_: null,
......@@ -141,6 +94,12 @@ Polymer({
/** @private {?WebUIListenerTracker} */
listenerTracker_: null,
/** @private {?print_preview.DestinationStore} */
destinationStore_: null,
/** @private {!EventTracker} */
tracker_: new EventTracker(),
/** @type {!print_preview.MeasurementSystem} */
measurementSystem_: new print_preview.MeasurementSystem(
',', '.', print_preview.MeasurementSystemUnitType.IMPERIAL),
......@@ -156,6 +115,15 @@ Polymer({
this.listenerTracker_ = new WebUIListenerTracker();
this.destinationStore_ = new print_preview.DestinationStore(
this.userInfo_, this.listenerTracker_);
this.tracker_.add(
this.destinationStore_,
print_preview.DestinationStore.EventType.DESTINATION_SELECT,
this.onDestinationSelect_.bind(this));
this.tracker_.add(
this.destinationStore_,
print_preview.DestinationStore.EventType
.SELECTED_DESTINATION_CAPABILITIES_READY,
this.onDestinationUpdated_.bind(this));
this.nativeLayer_.getInitialSettings().then(
this.onInitialSettingsSet_.bind(this));
},
......@@ -163,6 +131,7 @@ Polymer({
/** @override */
detached: function() {
this.listenerTracker_.removeAll();
this.tracker_.removeAll();
},
/**
......@@ -193,6 +162,53 @@ Polymer({
this.recentDestinations_);
},
/** @private */
onDestinationSelect_: function() {
this.destination_ = this.destinationStore_.selectedDestination;
},
/** @private */
onDestinationUpdated_: function() {
this.set(
'destination_.capabilities',
this.destinationStore_.selectedDestination.capabilities);
},
/** @private */
updateRecentDestinations_: function() {
if (!this.destination_)
return;
// Determine if this destination is already in the recent destinations,
// and where in the array it is located.
const newDestination =
print_preview.makeRecentDestination(assert(this.destination_));
let indexFound = this.recentDestinations_.findIndex(function(recent) {
return (
newDestination.id == recent.id &&
newDestination.origin == recent.origin);
});
// No change
if (indexFound == 0 &&
this.recentDestinations_[0].capabilities ==
newDestination.capabilities) {
return;
}
// Shift the array so that the nth most recent destination is located at
// index n.
if (indexFound == -1 &&
this.recentDestinations_.length == this.NUM_DESTINATIONS_) {
indexFound = this.NUM_DESTINATIONS_ - 1;
}
if (indexFound != -1)
this.recentDestinations_.splice(indexFound, 1);
// Add the most recent destination
this.recentDestinations_.splice(0, 0, newDestination);
},
/**
* @param {?string} savedSettingsStr The sticky settings from native layer
* @private
......
......@@ -26,6 +26,8 @@
'../data/compiled_resources2.gyp:document_info',
'../data/compiled_resources2.gyp:measurement_system',
'../data/compiled_resources2.gyp:user_info',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:cr',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:event_tracker',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:webui_listener_tracker',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
......
......@@ -23,6 +23,7 @@
align-items: center;
display: flex;
min-height: 28px;
overflow: hidden;
}
.destination-icon {
......@@ -36,6 +37,7 @@
display: flex;
flex: 1;
flex-direction: column;
overflow: hidden;
width: 100%;
}
......
......@@ -175,6 +175,7 @@ Polymer({
'destination.id, destination.capabilities, ' +
'documentInfo.isModifiable, documentInfo.hasCssMediaStyles,' +
'documentInfo.hasSelection)'],
/**
* @private {!Array<string>} List of capability types considered color.
* @const
......
......@@ -12,13 +12,15 @@
::slotted([slot=controls]) {
flex: 1;
overflow: hidden;
}
::slotted([slot=title]) {
-webkit-padding-end: 20px;
color: #646464;
font-size: 1em;
width: 70px;
max-width: 70px;
min-width: 70px;
word-break: break-word;
}
......
......@@ -50,6 +50,7 @@ PrintPreviewSettingsSectionsTest = class extends NewPrintPreviewTest {
/** @override */
get extraLibraries() {
return super.extraLibraries.concat([
'print_preview_test_utils.js',
'settings_section_test.js',
]);
}
......@@ -103,7 +104,7 @@ PrintPreviewRestoreStateTest = class extends NewPrintPreviewTest {
return super.extraLibraries.concat([
'../test_browser_proxy.js',
'native_layer_stub.js',
'print_preview_tests.js',
'print_preview_test_utils.js',
'restore_state_test.js',
]);
}
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('print_preview_test_utils', function() {
/**
* @param {string} printerId
* @param {string=} opt_printerName Defaults to an empty string.
* @return {!print_preview.PrinterCapabilitiesResponse}
*/
function getCddTemplate(printerId, opt_printerName) {
return {
printer: {
deviceName: printerId,
printerName: opt_printerName || '',
},
capabilities: {
version: '1.0',
printer: {
supported_content_type: [{content_type: 'application/pdf'}],
collate: {default: true},
copies: {default: 1, max: 1000},
color: {
option: [
{type: 'STANDARD_COLOR', is_default: true},
{type: 'STANDARD_MONOCHROME'}
]
},
dpi: {
option: [
{horizontal_dpi: 200, vertical_dpi: 200, is_default: true},
{horizontal_dpi: 100, vertical_dpi: 100},
]
},
duplex: {
option: [
{type: 'NO_DUPLEX', is_default: true},
{type: 'LONG_EDGE'},
{type: 'SHORT_EDGE'}
]
},
page_orientation: {
option: [
{type: 'PORTRAIT', is_default: true},
{type: 'LANDSCAPE'},
{type: 'AUTO'}
]
},
media_size: {
option: [
{ name: 'NA_LETTER',
width_microns: 215900,
height_microns: 279400,
is_default: true,
custom_display_name: "Letter",
},
{
name: 'CUSTOM_SQUARE',
width_microns: 215900,
height_microns: 215900,
custom_display_name: "CUSTOM_SQUARE",
}
]
}
}
}
};
}
return {
getCddTemplate: getCddTemplate,
};
});
......@@ -59,7 +59,8 @@ cr.define('print_preview_test', function() {
function setupSettingsAndDestinationsWithCapabilities(opt_device) {
nativeLayer.setInitialSettings(initialSettings);
nativeLayer.setLocalDestinations(localDestinationInfos);
opt_device = opt_device || getCddTemplate('FooDevice', 'FooName');
opt_device = opt_device ||
print_preview_test_utils.getCddTemplate('FooDevice', 'FooName');
nativeLayer.setLocalDestinationCapabilities(opt_device);
printPreview.initialize();
......@@ -106,70 +107,6 @@ cr.define('print_preview_test', function() {
'element="' + el.id + '" of class "' + el.classList + '"');
}
/**
* @param {string} printerId
* @param {string=} opt_printerName Defaults to an empty string.
* @return {!print_preview.PrinterCapabilitiesResponse}
*/
function getCddTemplate(printerId, opt_printerName) {
return {
printer: {
deviceName: printerId,
printerName: opt_printerName || '',
},
capabilities: {
version: '1.0',
printer: {
supported_content_type: [{content_type: 'application/pdf'}],
collate: {},
color: {
option: [
{type: 'STANDARD_COLOR', is_default: true},
{type: 'STANDARD_MONOCHROME'}
]
},
copies: {},
dpi: {
option: [
{horizontal_dpi: 200, vertical_dpi: 200, is_default: true},
{horizontal_dpi: 100, vertical_dpi: 100},
]
},
duplex: {
option: [
{type: 'NO_DUPLEX', is_default: true},
{type: 'LONG_EDGE'},
{type: 'SHORT_EDGE'}
]
},
page_orientation: {
option: [
{type: 'PORTRAIT', is_default: true},
{type: 'LANDSCAPE'},
{type: 'AUTO'}
]
},
media_size: {
option: [
{ name: 'NA_LETTER',
width_microns: 215900,
height_microns: 279400,
is_default: true,
custom_display_name: "Letter",
},
{
name: 'CUSTOM_SQUARE',
width_microns: 215900,
height_microns: 215900,
custom_display_name: "CUSTOM_SQUARE",
}
]
}
}
}
};
}
/**
* @return {!print_preview.PrinterCapabilitiesResponse} The capabilities of
* the Save as PDF destination.
......@@ -214,7 +151,8 @@ cr.define('print_preview_test', function() {
*/
function getAppStateString() {
const origin = cr.isChromeOS ? 'chrome_os' : 'local';
const cdd = getCddTemplate('ID1', 'One').capabilities;
const cdd =
print_preview_test_utils.getCddTemplate('ID1', 'One').capabilities;
return JSON.stringify({
version: 2,
recentDestinations: [
......@@ -293,7 +231,7 @@ cr.define('print_preview_test', function() {
* @return {!Object}
*/
function getCddTemplateWithAdvancedSettings(printerId) {
const template = getCddTemplate(printerId);
const template = print_preview_test_utils.getCddTemplate(printerId);
template.capabilities.printer.vendor_capability = [{
display_name: 'Print Area',
id: 'Print Area',
......@@ -517,7 +455,8 @@ cr.define('print_preview_test', function() {
},
],
});
nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID'));
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate('ID'));
setInitialSettings();
return nativeLayer.whenCalled('getInitialSettings');
});
......@@ -536,7 +475,7 @@ cr.define('print_preview_test', function() {
// Set up capabilities for ID1. This should be the device that should hav
// its capabilities fetched, since it is the most recent. If another
// device is selected the native layer will reject the callback.
const device = getCddTemplate('ID1', 'One');
const device = print_preview_test_utils.getCddTemplate('ID1', 'One');
return setupSettingsAndDestinationsWithCapabilities(device).then(
function() {
......@@ -578,10 +517,12 @@ cr.define('print_preview_test', function() {
];
initialSettings.printerName = 'ID3';
const device = getCddTemplate('ID3', 'Three');
const device = print_preview_test_utils.getCddTemplate('ID3', 'Three');
nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID1', 'One'));
nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID2', 'Two'));
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate('ID1', 'One'));
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate('ID2', 'Two'));
return setupSettingsAndDestinationsWithCapabilities(device).then(
function() {
nativeLayer.reset();
......@@ -634,7 +575,7 @@ cr.define('print_preview_test', function() {
{ printerName: 'Two', deviceName: 'ID2' },
{ printerName: 'Three', deviceName: 'ID3' },
];
const device = getCddTemplate('ID1', 'One');
const device = print_preview_test_utils.getCddTemplate('ID1', 'One');
return Promise.all([
setupSettingsAndDestinationsWithCapabilities(device),
......@@ -689,7 +630,9 @@ cr.define('print_preview_test', function() {
initialSettings.serializedDefaultDestinationSelectionRulesStr =
JSON.stringify({namePattern: '.*Bar.*'});
return setupSettingsAndDestinationsWithCapabilities(
getCddTemplate('BarDevice', 'BarName')).then(function() {
print_preview_test_utils.getCddTemplate(
'BarDevice', 'BarName'))
.then(function() {
assertEquals('BarDevice',
printPreview.destinationStore_.selectedDestination.id);
});
......@@ -698,7 +641,8 @@ cr.define('print_preview_test', function() {
test('SystemDialogLinkIsHiddenInAppKioskMode', function() {
if (!cr.isChromeOS)
initialSettings.isInAppKioskMode = true;
nativeLayer.setLocalDestinationCapabilities(getCddTemplate('FooDevice'));
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate('FooDevice'));
setInitialSettings();
return nativeLayer.whenCalled('getInitialSettings').then(
function() {
......@@ -713,7 +657,7 @@ cr.define('print_preview_test', function() {
checkSectionVisible($('layout-settings'), false);
checkSectionVisible($('color-settings'), false);
checkSectionVisible($('copies-settings'), false);
const device = getCddTemplate('FooDevice');
const device = print_preview_test_utils.getCddTemplate('FooDevice');
device.capabilities.printer.color = {
option: [{is_default: true, type: 'STANDARD_COLOR'}]
};
......@@ -1041,7 +985,7 @@ cr.define('print_preview_test', function() {
// Check header footer availability with small (label) page size.
test('SmallPaperSizeHeaderFooter', function() {
const device = getCddTemplate('FooDevice');
const device = print_preview_test_utils.getCddTemplate('FooDevice');
device.capabilities.printer.media_size = {
'option': [
{'name': 'SmallLabel', 'width_microns': 38100,
......@@ -1083,7 +1027,7 @@ cr.define('print_preview_test', function() {
// Test that the color settings, one option, standard monochrome.
test('ColorSettingsMonochrome', function() {
// Only one option, standard monochrome.
const device = getCddTemplate('FooDevice');
const device = print_preview_test_utils.getCddTemplate('FooDevice');
device.capabilities.printer.color = {
'option': [
{'is_default': true, 'type': 'STANDARD_MONOCHROME'}
......@@ -1101,7 +1045,7 @@ cr.define('print_preview_test', function() {
// Test that the color settings, one option, custom monochrome.
test('ColorSettingsCustomMonochrome', function() {
// Only one option, standard monochrome.
const device = getCddTemplate('FooDevice');
const device = print_preview_test_utils.getCddTemplate('FooDevice');
device.capabilities.printer.color = {
'option': [
{'is_default': true, 'type': 'CUSTOM_MONOCHROME',
......@@ -1119,7 +1063,7 @@ cr.define('print_preview_test', function() {
// Test that the color settings, one option, standard color.
test('ColorSettingsColor', function() {
const device = getCddTemplate('FooDevice');
const device = print_preview_test_utils.getCddTemplate('FooDevice');
device.capabilities.printer.color = {
'option': [
{'is_default': true, 'type': 'STANDARD_COLOR'}
......@@ -1136,7 +1080,7 @@ cr.define('print_preview_test', function() {
// Test that the color settings, one option, custom color.
test('ColorSettingsCustomColor', function() {
const device = getCddTemplate('FooDevice');
const device = print_preview_test_utils.getCddTemplate('FooDevice');
device.capabilities.printer.color = {
'option': [
{'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '42'}
......@@ -1153,7 +1097,7 @@ cr.define('print_preview_test', function() {
// Test that the color settings, two options, both standard, defaults to
// color.
test('ColorSettingsBothStandardDefaultColor', function() {
const device = getCddTemplate('FooDevice');
const device = print_preview_test_utils.getCddTemplate('FooDevice');
device.capabilities.printer.color = {
'option': [
{'type': 'STANDARD_MONOCHROME'},
......@@ -1175,7 +1119,7 @@ cr.define('print_preview_test', function() {
// Test that the color settings, two options, both standard, defaults to
// monochrome.
test('ColorSettingsBothStandardDefaultMonochrome', function() {
const device = getCddTemplate('FooDevice');
const device = print_preview_test_utils.getCddTemplate('FooDevice');
device.capabilities.printer.color = {
'option': [
{'is_default': true, 'type': 'STANDARD_MONOCHROME'},
......@@ -1197,7 +1141,7 @@ cr.define('print_preview_test', function() {
// Test that the color settings, two options, both custom, defaults to
// color.
test('ColorSettingsBothCustomDefaultColor', function() {
const device = getCddTemplate('FooDevice');
const device = print_preview_test_utils.getCddTemplate('FooDevice');
device.capabilities.printer.color = {
'option': [
{'type': 'CUSTOM_MONOCHROME', 'vendor_id': '42'},
......@@ -1233,7 +1177,7 @@ cr.define('print_preview_test', function() {
// Test to verify that duplex settings are set according to the printer
// capabilities.
test('DuplexSettingsFalse', function() {
const device = getCddTemplate('FooDevice');
const device = print_preview_test_utils.getCddTemplate('FooDevice');
delete device.capabilities.printer.duplex;
return setupSettingsAndDestinationsWithCapabilities(device)
.then(function() {
......@@ -1263,7 +1207,7 @@ cr.define('print_preview_test', function() {
nativeLayer.reset();
// Setup capabilities for BarDevice.
const device = getCddTemplate('BarDevice');
const device = print_preview_test_utils.getCddTemplate('BarDevice');
device.capabilities.printer.color = {
'option': [
{'is_default': true, 'type': 'STANDARD_MONOCHROME'}
......@@ -1288,7 +1232,8 @@ cr.define('print_preview_test', function() {
previewArea.checkPluginCompatibility_ = function() {
return false;
};
nativeLayer.setLocalDestinationCapabilities(getCddTemplate('FooDevice'));
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate('FooDevice'));
setInitialSettings();
return nativeLayer.whenCalled('getInitialSettings').then(function() {
const previewAreaEl = $('preview-area');
......@@ -1319,7 +1264,7 @@ cr.define('print_preview_test', function() {
const customLocalizedMediaName = 'Vendor defined localized media name';
const customMediaName = 'Vendor defined media name';
const device = getCddTemplate('FooDevice');
const device = print_preview_test_utils.getCddTemplate('FooDevice');
device.capabilities.printer.media_size = {
option: [
{ name: 'CUSTOM',
......@@ -1412,17 +1357,24 @@ cr.define('print_preview_test', function() {
version: 2,
recentDestinations: [1, 2, 3].map(function(i) {
return {
id: 'ID' + i, origin: origin, account: '',
capabilities: getCddTemplate('ID' + i), displayName: '',
extensionId: '', extensionName: ''
id: 'ID' + i,
origin: origin,
account: '',
capabilities: print_preview_test_utils.getCddTemplate('ID' + i),
displayName: '',
extensionId: '',
extensionName: ''
};
}),
});
// Ensure all capabilities are available for fetch.
nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID1'));
nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID2'));
nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID3'));
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate('ID1'));
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate('ID2'));
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate('ID3'));
// For crbug.com/666595. If multiple destinations are fetched there may
// be multiple preview requests. This verifies the first fetch is for
......@@ -1447,7 +1399,7 @@ cr.define('print_preview_test', function() {
// an error and that the preview dialog can be recovered by selecting a
// new destination.
test('InvalidSettingsError', function() {
const barDevice = getCddTemplate('BarDevice');
const barDevice = print_preview_test_utils.getCddTemplate('BarDevice');
nativeLayer.setLocalDestinationCapabilities(barDevice);
// FooDevice is the default printer, so will be selected for the initial
......@@ -1572,7 +1524,7 @@ cr.define('print_preview_test', function() {
{ printerName: 'FooName', deviceName: 'FooDevice' }
];
nativeLayer.setLocalDestinationCapabilities(
getCddTemplate('ID1', 'One'));
print_preview_test_utils.getCddTemplate('ID1', 'One'));
return setupSettingsAndDestinationsWithCapabilities().then(function() {
// The system default destination should be used instead of the
......@@ -1712,6 +1664,5 @@ cr.define('print_preview_test', function() {
return {
suiteName: suiteName,
getCddTemplate: getCddTemplate,
};
});
......@@ -4,7 +4,7 @@
/** @fileoverview Runs the Print Preview tests. */
var ROOT_PATH = '../../../../../';
const ROOT_PATH = '../../../../../';
/**
* @constructor
......@@ -59,6 +59,7 @@ PrintPreviewUIBrowserTest.prototype = {
'print_preview_tests.js',
'native_layer_stub.js',
'plugin_stub.js',
'print_preview_test_utils.js',
],
};
......
......@@ -72,7 +72,7 @@ cr.define('restore_state_test', function() {
nativeLayer.setInitialSettings(initialSettings);
nativeLayer.setLocalDestinationCapabilities(
print_preview_test.getCddTemplate(initialSettings.printerName));
print_preview_test_utils.getCddTemplate(initialSettings.printerName));
page = document.createElement('print-preview-app');
document.body.appendChild(page);
......
......@@ -24,60 +24,16 @@ cr.define('settings_sections_tests', function() {
PolymerTest.clearBody();
page = document.createElement('print-preview-app');
document.body.appendChild(page);
});
/** @return {!print_preview.Cdd} */
function getCdd() {
return {
version: '1.0',
printer: {
collate: {default: true},
copies: {default: 1, max: 1000},
color: {
option: [
{type: 'STANDARD_COLOR', is_default: true},
{type: 'STANDARD_MONOCHROME'}
]
},
dpi: {
option: [
{horizontal_dpi: 200, vertical_dpi: 200, is_default: true},
{horizontal_dpi: 100, vertical_dpi: 100},
]
},
duplex: {
option: [
{type: 'NO_DUPLEX', is_default: true}, {type: 'LONG_EDGE'},
{type: 'SHORT_EDGE'}
]
},
page_orientation: {
option: [
{type: 'PORTRAIT', is_default: true}, {type: 'LANDSCAPE'},
{type: 'AUTO'}
]
},
media_size: {
option: [
{
name: 'NA_LETTER',
width_microns: 215900,
height_microns: 279400,
is_default: true,
custom_display_name: 'Letter',
},
{
name: 'CUSTOM_SQUARE',
width_microns: 215900,
height_microns: 215900,
custom_display_name: 'CUSTOM_SQUARE',
}
]
},
vendor_capability: [],
},
};
}
const fooDestination = new print_preview.Destination(
'FooPrinter', print_preview.DestinationType.LOCAL,
print_preview.DestinationOrigin.LOCAL, 'Foo Printer',
false /*isRecent*/, print_preview.DestinationConnectionStatus.ONLINE);
fooDestination.capabilities =
print_preview_test_utils.getCddTemplate(fooDestination.id)
.capabilities;
page.set('destination_', fooDestination);
});
/** @param {boolean} isPdf Whether the document should be a PDF. */
function setPdfDocument(isPdf) {
......@@ -93,7 +49,9 @@ cr.define('settings_sections_tests', function() {
print_preview.DestinationOrigin.LOCAL,
loadTimeData.getString('printToPDF'), false /*isRecent*/,
print_preview.DestinationConnectionStatus.ONLINE);
saveAsPdfDestination.capabilities = getCdd();
saveAsPdfDestination.capabilities =
print_preview_test_utils.getCddTemplate(saveAsPdfDestination.id)
.capabilities;
page.set('destination_', saveAsPdfDestination);
}
......@@ -102,7 +60,8 @@ cr.define('settings_sections_tests', function() {
expectEquals(false, copiesElement.hidden);
// Remove copies capability.
const capabilities = getCdd();
let capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
delete capabilities.printer.copies;
// Copies section should now be hidden.
......@@ -118,16 +77,16 @@ cr.define('settings_sections_tests', function() {
expectEquals(false, layoutElement.hidden);
// Remove layout capability.
let capabilities = getCdd();
let capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
delete capabilities.printer.page_orientation;
// Each of these settings should not show the capability.
[
null,
{option: [{ type: 'PORTRAIT', is_default: true }]},
{option: [{ type: 'LANDSCAPE', is_default: true}]},
[null, {option: [{type: 'PORTRAIT', is_default: true}]},
{option: [{type: 'LANDSCAPE', is_default: true}]},
].forEach(layoutCap => {
capabilities = getCdd();
capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
capabilities.printer.page_orientation = layoutCap;
// Layout section should now be hidden.
page.set('destination_.capabilities', capabilities);
......@@ -135,7 +94,8 @@ cr.define('settings_sections_tests', function() {
});
// Reset full capabilities
capabilities = getCdd();
capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
page.set('destination_.capabilities', capabilities);
expectEquals(false, layoutElement.hidden);
......@@ -149,20 +109,26 @@ cr.define('settings_sections_tests', function() {
expectEquals(false, colorElement.hidden);
// Remove color capability.
let capabilities = getCdd();
let capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
delete capabilities.printer.color;
// Each of these settings should not show the capability.
[
null,
{option: [{ type: 'STANDARD_COLOR', is_default: true }]},
{option: [{ type: 'STANDARD_COLOR', is_default: true },
{ type: 'CUSTOM_COLOR'}]},
{option: [{ type: 'STANDARD_MONOCHROME', is_default: true },
{ type: 'CUSTOM_MONOCHROME' }]},
{option: [{ type: 'STANDARD_MONOCHROME', is_default: true}]},
[null, {option: [{type: 'STANDARD_COLOR', is_default: true}]}, {
option: [
{type: 'STANDARD_COLOR', is_default: true}, {type: 'CUSTOM_COLOR'}
]
},
{
option: [
{type: 'STANDARD_MONOCHROME', is_default: true},
{type: 'CUSTOM_MONOCHROME'}
]
},
{option: [{type: 'STANDARD_MONOCHROME', is_default: true}]},
].forEach(colorCap => {
capabilities = getCdd();
capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
capabilities.printer.color = colorCap;
// Layout section should now be hidden.
page.set('destination_.capabilities', capabilities);
......@@ -170,7 +136,8 @@ cr.define('settings_sections_tests', function() {
});
// Custom color and monochrome options should make the section visible.
capabilities = getCdd();
capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
capabilities.printer.color =
{option: [{ type: 'CUSTOM_COLOR', is_default: true },
{ type: 'CUSTOM_MONOCHROME' }]};
......@@ -183,7 +150,8 @@ cr.define('settings_sections_tests', function() {
expectEquals(false, mediaSizeElement.hidden);
// Remove capability.
let capabilities = getCdd();
let capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
delete capabilities.printer.media_size;
// Section should now be hidden.
......@@ -191,7 +159,8 @@ cr.define('settings_sections_tests', function() {
expectEquals(true, mediaSizeElement.hidden);
// Reset
capabilities = getCdd();
capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
page.set('destination_.capabilities', capabilities);
// Set PDF document type.
......@@ -224,7 +193,8 @@ cr.define('settings_sections_tests', function() {
expectEquals(false, dpiElement.hidden);
// Remove capability.
let capabilities = getCdd();
let capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
delete capabilities.printer.dpi;
// Section should now be hidden.
......@@ -232,7 +202,8 @@ cr.define('settings_sections_tests', function() {
expectEquals(true, dpiElement.hidden);
// Does not show up for only 1 option.
capabilities = getCdd();
capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
capabilities.printer.dpi.option.pop();
page.set('destination_.capabilities', capabilities);
expectEquals(true, dpiElement.hidden);
......@@ -273,7 +244,8 @@ cr.define('settings_sections_tests', function() {
// Start with HTML + duplex capability.
setPdfDocument(false);
let capabilities = getCdd();
let capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
page.set('destination_.capabilities', capabilities);
expectEquals(false, optionsElement.hidden);
expectEquals(false, headerFooter.hidden);
......@@ -290,7 +262,8 @@ cr.define('settings_sections_tests', function() {
expectEquals(false, selectionOnly.hidden);
// Remove duplex capability.
capabilities = getCdd();
capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
delete capabilities.printer.duplex;
page.set('destination_.capabilities', capabilities);
expectEquals(false, optionsElement.hidden);
......@@ -313,7 +286,8 @@ cr.define('settings_sections_tests', function() {
expectEquals(true, selectionOnly.hidden);
// Add duplex.
capabilities = getCdd();
capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
page.set('destination_.capabilities', capabilities);
expectEquals(false, optionsElement.hidden);
expectEquals(false, duplex.hidden);
......
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