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

Print Preview Componentization: Add listeners for failed and presets

Add listeners for the print-failed and print-preset-options Web UI
events in the new UI, and migrate the behaviors of calling
onPrintFailed_() for print-failed and setting the copies and duplex
setting values based on the presets when they are received.

Also migrate the tests used to verify that presets work.

Bug: 773928
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I6cb17b5a189c8d138647a82cf845a47b51d91bdf
Reviewed-on: https://chromium-review.googlesource.com/1038660Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555989}
parent d83b571d
...@@ -156,6 +156,9 @@ Polymer({ ...@@ -156,6 +156,9 @@ Polymer({
this.listenerTracker_ = new WebUIListenerTracker(); this.listenerTracker_ = new WebUIListenerTracker();
this.listenerTracker_.add( this.listenerTracker_.add(
'use-cloud-print', this.onCloudPrintEnable_.bind(this)); 'use-cloud-print', this.onCloudPrintEnable_.bind(this));
this.listenerTracker_.add('print-failed', this.onPrintFailed_.bind(this));
this.listenerTracker_.add(
'print-preset-options', this.onPrintPresetOptions_.bind(this));
this.destinationStore_ = new print_preview.DestinationStore( this.destinationStore_ = new print_preview.DestinationStore(
this.userInfo_, this.listenerTracker_); this.userInfo_, this.listenerTracker_);
this.invitationStore_ = new print_preview.InvitationStore(this.userInfo_); this.invitationStore_ = new print_preview.InvitationStore(this.userInfo_);
...@@ -496,6 +499,24 @@ Polymer({ ...@@ -496,6 +499,24 @@ Polymer({
} }
}, },
/**
* Updates printing options according to source document presets.
* @param {boolean} disableScaling Whether the document disables scaling.
* @param {number} copies The default number of copies from the document.
* @param {number} duplex The default duplex setting from the document.
* @private
*/
onPrintPresetOptions_: function(disableScaling, copies, duplex) {
if (disableScaling)
this.documentInfo_.updateIsScalingDisabled(true);
if (copies > 0 && this.getSetting('copies').available)
this.setSetting('copies', copies);
if (duplex >= 0 && this.getSetting('duplex').available)
this.setSetting('duplex', duplex);
},
/** /**
* @return {boolean} Whether to show the "More settings" link. * @return {boolean} Whether to show the "More settings" link.
* @private * @private
......
...@@ -17,22 +17,16 @@ Polymer({ ...@@ -17,22 +17,16 @@ Polymer({
disabled: Boolean, disabled: Boolean,
}, },
/** @private {boolean} */
isInitialized_: false,
observers: [ observers: [
'onInputChanged_(currentValue_, inputValid_)', 'onInputChanged_(currentValue_, inputValid_)',
'onInitialized_(settings.copies.value, settings.collate.value)' 'onSettingsChanged_(settings.copies.value, settings.collate.value)'
], ],
/** /**
* Updates the input string when the setting has been initialized. * Updates the input string when the setting has been initialized.
* @private * @private
*/ */
onInitialized_: function() { onSettingsChanged_: function() {
if (this.isInitialized_)
return;
this.isInitialized_ = true;
const copies = this.getSetting('copies'); const copies = this.getSetting('copies');
this.currentValue_ = /** @type {string} */ (copies.value.toString()); this.currentValue_ = /** @type {string} */ (copies.value.toString());
const collate = this.getSetting('collate'); const collate = this.getSetting('collate');
......
...@@ -141,6 +141,14 @@ TEST_F('PrintPreviewSettingsSectionsTest', 'SetOther', function() { ...@@ -141,6 +141,14 @@ TEST_F('PrintPreviewSettingsSectionsTest', 'SetOther', function() {
this.runMochaTest(settings_sections_tests.TestNames.SetOther); this.runMochaTest(settings_sections_tests.TestNames.SetOther);
}); });
TEST_F('PrintPreviewSettingsSectionsTest', 'PresetCopies', function() {
this.runMochaTest(settings_sections_tests.TestNames.PresetCopies);
});
TEST_F('PrintPreviewSettingsSectionsTest', 'PresetDuplex', function() {
this.runMochaTest(settings_sections_tests.TestNames.PresetDuplex);
});
PrintPreviewSettingsSelectTest = class extends NewPrintPreviewTest { PrintPreviewSettingsSelectTest = class extends NewPrintPreviewTest {
/** @override */ /** @override */
get browsePreload() { get browsePreload() {
......
...@@ -24,6 +24,8 @@ cr.define('settings_sections_tests', function() { ...@@ -24,6 +24,8 @@ cr.define('settings_sections_tests', function() {
SetMargins: 'set margins', SetMargins: 'set margins',
SetScaling: 'set scaling', SetScaling: 'set scaling',
SetOther: 'set other', SetOther: 'set other',
PresetCopies: 'preset copies',
PresetDuplex: 'preset duplex',
}; };
const suiteName = 'SettingsSectionsTests'; const suiteName = 'SettingsSectionsTests';
...@@ -826,6 +828,43 @@ cr.define('settings_sections_tests', function() { ...@@ -826,6 +828,43 @@ cr.define('settings_sections_tests', function() {
optionsElement.$$('#rasterize'), false, page.settings.rasterize); optionsElement.$$('#rasterize'), false, page.settings.rasterize);
} }
}); });
test(assert(TestNames.PresetCopies), function() {
const copiesElement = page.$$('print-preview-copies-settings');
assertFalse(copiesElement.hidden);
// Default value is 1
const copiesInput =
copiesElement.$$('print-preview-number-settings-section')
.$$('.user-value');
expectEquals('1', copiesInput.value);
expectEquals(1, page.settings.copies.value);
// Send a preset value of 2
const copies = 2;
cr.webUIListenerCallback('print-preset-options', true, copies);
assertEquals(copies, page.settings.copies.value);
assertEquals(copies.toString(), copiesInput.value);
});
test(assert(TestNames.PresetDuplex), function() {
toggleMoreSettings();
const optionsElement = page.$$('print-preview-other-options-settings');
assertFalse(optionsElement.hidden);
// Default value is on, so turn it off
page.setSetting('duplex', print_preview_new.DuplexMode.SIMPLEX);
const checkbox = optionsElement.$$('#duplex');
assertFalse(checkbox.checked);
assertEquals(print_preview_new.DuplexMode.SIMPLEX,
page.settings.duplex.value);
// Send a preset value of LONG_EDGE
const duplex = print_preview_new.DuplexMode.LONG_EDGE;
cr.webUIListenerCallback('print-preset-options', false, 1, duplex);
assertEquals(duplex, page.settings.duplex.value);
assertTrue(checkbox.checked);
});
}); });
return { return {
......
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