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

Print Preview Componentization: Add system dialog links

Bug: 773928, 812099
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I861a40dff62c4a4fd2929ff5644a23ebad0334b7
Reviewed-on: https://chromium-review.googlesource.com/971467
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547092}
parent 695ca6da
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
<link rel="import" href="scaling_settings.html"> <link rel="import" href="scaling_settings.html">
<link rel="import" href="other_options_settings.html"> <link rel="import" href="other_options_settings.html">
<link rel="import" href="advanced_options_settings.html"> <link rel="import" href="advanced_options_settings.html">
<if expr="not chromeos">
<link rel="import" href="link_container.html">
</if>
<dom-module id="print-preview-app"> <dom-module id="print-preview-app">
<template> <template>
<style> <style>
...@@ -119,6 +121,16 @@ ...@@ -119,6 +121,16 @@
destination="[[destination_]]" disabled="[[controlsDisabled_]]" destination="[[destination_]]" disabled="[[controlsDisabled_]]"
hidden$="[[!settings.vendorItems.available]]"> hidden$="[[!settings.vendorItems.available]]">
</print-preview-advanced-options-settings> </print-preview-advanced-options-settings>
<if expr="not chromeos">
<print-preview-link-container destination="[[destination_]]"
app-kiosk-mode="[[isInAppKioskMode_]]"
disabled="[[controlsDisabled_]]"
<if expr="is_macosx">
on-open-pdf-in-preview="onOpenPdfInPreview_"
</if>
on-print-with-system-dialog="onPrintWithSystemDialog_">
</print-preview-link-container>
</if>
</div> </div>
</div> </div>
<div id="preview-area-container"> <div id="preview-area-container">
......
...@@ -75,6 +75,13 @@ Polymer({ ...@@ -75,6 +75,13 @@ Polymer({
notify: true, notify: true,
value: null, value: null,
}, },
/** @private {boolean} */
isInAppKioskMode_: {
type: Boolean,
notify: true,
value: false,
},
}, },
/** @private {?WebUIListenerTracker} */ /** @private {?WebUIListenerTracker} */
...@@ -93,7 +100,10 @@ Polymer({ ...@@ -93,7 +100,10 @@ Polymer({
cancelled_: false, cancelled_: false,
/** @private {boolean} */ /** @private {boolean} */
isInAppKioskMode_: false, showSystemDialogBeforePrint_: false,
/** @private {boolean} */
openPdfInPreview_: false,
/** @override */ /** @override */
attached: function() { attached: function() {
...@@ -153,6 +163,7 @@ Polymer({ ...@@ -153,6 +163,7 @@ Polymer({
settings.isInAppKioskMode, settings.printerName, settings.isInAppKioskMode, settings.printerName,
settings.serializedDefaultDestinationSelectionRulesStr, settings.serializedDefaultDestinationSelectionRulesStr,
this.recentDestinations_); this.recentDestinations_);
this.isInAppKioskMode_ = settings.isInAppKioskMode;
}, },
/** /**
...@@ -222,7 +233,9 @@ Polymer({ ...@@ -222,7 +233,9 @@ Polymer({
} else if (this.state == print_preview_new.State.PRINTING) { } else if (this.state == print_preview_new.State.PRINTING) {
const destination = assert(this.destinationStore_.selectedDestination); const destination = assert(this.destinationStore_.selectedDestination);
const whenPrintDone = const whenPrintDone =
this.nativeLayer_.print(this.$.model.createPrintTicket(destination)); this.nativeLayer_.print(this.$.model.createPrintTicket(
destination, this.openPdfInPreview_,
this.showSystemDialogBeforePrint_));
if (destination.isLocal) { if (destination.isLocal) {
const onError = destination.id == const onError = destination.id ==
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ? print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ?
...@@ -289,6 +302,29 @@ Polymer({ ...@@ -289,6 +302,29 @@ Polymer({
assert(this.documentInfo_), data); assert(this.documentInfo_), data);
}, },
// <if expr="not chromeos">
/** @private */
onPrintWithSystemDialog_: function() {
assert(!cr.isChromeOS);
if (cr.isWindows) {
this.showSystemDialogBeforePrint_ = true;
this.onPrintRequested_();
return;
}
this.nativeLayer_.showSystemDialog();
this.$.state.transitTo(print_preview_new.State.SYSTEM_DIALOG);
},
// </if>
// <if expr="is_macosx">
/** @private */
onOpenPdfInPreview_: function() {
this.openPdfInPreview_ = true;
this.$.previewArea.setOpeningPdfInPreview();
this.onPrintRequested_();
},
// </if>
/** /**
* Called when printing to a privet, cloud, or extension printer fails. * Called when printing to a privet, cloud, or extension printer fails.
* @param {*} httpError The HTTP error code, or -1 or a string describing * @param {*} httpError The HTTP error code, or -1 or a string describing
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
'scaling_settings', 'scaling_settings',
'other_options_settings', 'other_options_settings',
'advanced_options_settings', 'advanced_options_settings',
'link_container',
'preview_area', 'preview_area',
'model', 'model',
'state', 'state',
...@@ -170,6 +171,15 @@ ...@@ -170,6 +171,15 @@
], ],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'], 'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
}, },
{
'target_name': 'link_container',
'dependencies': [
'../data/compiled_resources2.gyp:destination',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:assert',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:cr',
],
'includes': ['../../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{ {
'target_name': 'preview_area', 'target_name': 'preview_area',
'dependencies': [ 'dependencies': [
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/hidden_style_css.html">
<link rel="import" href="chrome://resources/html/action_link_css.html">
<link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="../data/destination.html">
<link rel="import" href="print_preview_shared_css.html">
<link rel="import" href="throbber_css.html">
<dom-module id="print-preview-link-container">
<template>
<style include="print-preview-shared throbber action-link cr-hidden-style">
:host {
margin: 7px 0;
}
:host > div {
display: flex;
}
:host > div > .throbber {
margin: 8px;
min-height: 16px;
min-width: 16px;
}
:host > div > a {
margin: 8px 20px;
}
</style>
<div>
<a is="action-link" id="systemDialogLink" disabled="[[disabled]]"
hidden$="[[!shouldShowSystemDialogLink_]]"
on-click="onSystemDialogClick_">
$i18n{systemDialogOption}
</a>
<div id="systemDialogThrobber" hidden class="throbber"></div>
</div>
<if expr="is_macosx">
<div>
<a is="action-link" id="openPdfInPreviewLink" disabled="[[disabled]]"
on-click="onOpenInPreviewClick_">
$i18n{openPdfInPreviewOption}
</a>
<div id="openPdfInPreviewThrobber" hidden class="throbber"></div>
</div>
</if>
</template>
<script src="link_container.js"></script>
</dom-module>
// Copyright 2018 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.
Polymer({
is: 'print-preview-link-container',
properties: {
appKioskMode: Boolean,
/** @type {?print_preview.Destination} */
destination: Object,
disabled: Boolean,
/** @private {boolean} */
shouldShowSystemDialogLink_: {
type: Boolean,
computed: 'computeShouldShowSystemDialogLink_(appKioskMode, destination)',
},
},
/**
* @return {boolean} Whether the system dialog link should be visible.
* @private
*/
computeShouldShowSystemDialogLink_: function() {
if (this.appKioskMode)
return false;
if (!cr.isWindows)
return true;
return !!this.destination &&
this.destination.origin == print_preview.DestinationOrigin.LOCAL &&
this.destination.id !=
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
},
/** @private */
onSystemDialogClick_: function() {
if (!this.shouldShowSystemDialogLink_)
return;
// <if expr="not is_win">
this.$.systemDialogThrobber.removeAttribute('hidden');
// </if>
this.fire('print-with-system-dialog');
},
// <if expr="is_macosx">
/** @private */
onOpenInPreviewClick_: function() {
this.$.openPdfInPreviewThrobber.removeAttribute('hidden');
this.fire('open-pdf-in-preview');
},
// </if>
});
...@@ -499,9 +499,13 @@ Polymer({ ...@@ -499,9 +499,13 @@ Polymer({
/** /**
* Creates a string that represents a print ticket. * Creates a string that represents a print ticket.
* @param {!print_preview.Destination} destination Destination to print to. * @param {!print_preview.Destination} destination Destination to print to.
* @param {boolean} openPdfInPreview Whether this print request is to open
* the PDF in Preview app (Mac only).
* @param {boolean} showSystemDialog Whether this print request is to show
* the system dialog.
* @return {string} Serialized print ticket. * @return {string} Serialized print ticket.
*/ */
createPrintTicket: function(destination) { createPrintTicket: function(destination, openPdfInPreview, showSystemDialog) {
const dpi = /** @type {{horizontal_dpi: (number | undefined), const dpi = /** @type {{horizontal_dpi: (number | undefined),
vertical_dpi: (number | undefined), vertical_dpi: (number | undefined),
vendor_id: (number | undefined)}} */ ( vendor_id: (number | undefined)}} */ (
...@@ -536,7 +540,7 @@ Polymer({ ...@@ -536,7 +540,7 @@ Polymer({
fitToPageEnabled: this.getSettingValue('fitToPage'), fitToPageEnabled: this.getSettingValue('fitToPage'),
pageWidth: this.documentInfo.pageSize.width, pageWidth: this.documentInfo.pageSize.width,
pageHeight: this.documentInfo.pageSize.height, pageHeight: this.documentInfo.pageSize.height,
showSystemDialog: false, showSystemDialog: showSystemDialog,
}; };
// Set 'cloudPrintID' only if the destination is not local. // Set 'cloudPrintID' only if the destination is not local.
...@@ -561,6 +565,10 @@ Polymer({ ...@@ -561,6 +565,10 @@ Polymer({
ticket.ticket = this.createCloudJobTicket(destination); ticket.ticket = this.createCloudJobTicket(destination);
ticket.capabilities = JSON.stringify(destination.capabilities); ticket.capabilities = JSON.stringify(destination.capabilities);
} }
if (openPdfInPreview)
ticket.OpenPDFInPreview = true;
return JSON.stringify(ticket); return JSON.stringify(ticket);
}, },
......
...@@ -67,6 +67,18 @@ Polymer({ ...@@ -67,6 +67,18 @@ Polymer({
/** @type {?print_preview.MeasurementSystem} */ /** @type {?print_preview.MeasurementSystem} */
measurementSystem: Object, measurementSystem: Object,
/** @private {boolean} Whether the plugin is loaded */
pluginLoaded_: {
type: Boolean,
value: false,
},
/** @private {boolean} Whether the document is ready */
documentReady_: {
type: Boolean,
value: false,
},
/** @private {string} */ /** @private {string} */
previewState_: { previewState_: {
type: String, type: String,
...@@ -78,7 +90,8 @@ Polymer({ ...@@ -78,7 +90,8 @@ Polymer({
previewLoaded_: { previewLoaded_: {
type: Boolean, type: Boolean,
notify: true, notify: true,
computed: 'computePreviewLoaded_(previewState_)', computed: 'computePreviewLoaded_(' +
'previewState_, pluginLoaded_, documentReady_)',
}, },
}, },
...@@ -108,12 +121,6 @@ Polymer({ ...@@ -108,12 +121,6 @@ Polymer({
/** @private {HTMLEmbedElement|print_preview_new.PDFPlugin} */ /** @private {HTMLEmbedElement|print_preview_new.PDFPlugin} */
plugin_: null, plugin_: null,
/** @private {boolean} Whether the plugin is loaded */
pluginLoaded_: false,
/** @private {boolean} Whether the document is ready */
documentReady_: false,
/** @override */ /** @override */
attached: function() { attached: function() {
this.nativeLayer_ = print_preview.NativeLayer.getInstance(); this.nativeLayer_ = print_preview.NativeLayer.getInstance();
...@@ -139,7 +146,9 @@ Polymer({ ...@@ -139,7 +146,9 @@ Polymer({
* @private * @private
*/ */
computePreviewLoaded_: function() { computePreviewLoaded_: function() {
return this.previewState_ == PreviewAreaState_.DISPLAY_PREVIEW; return this.previewState_ == PreviewAreaState_.DISPLAY_PREVIEW ||
(this.documentReady_ && this.pluginLoaded_ &&
this.previewState_ == PreviewAreaState_.OPEN_IN_PREVIEW);
}, },
/** @return {boolean} Whether the preview is loaded. */ /** @return {boolean} Whether the preview is loaded. */
...@@ -237,7 +246,7 @@ Polymer({ ...@@ -237,7 +246,7 @@ Polymer({
if (this.previewState_ == PreviewAreaState_.LOADING) if (this.previewState_ == PreviewAreaState_.LOADING)
return this.i18n('loading'); return this.i18n('loading');
if (this.previewState_ == PreviewAreaState_.OPEN_IN_PREVIEW) if (this.previewState_ == PreviewAreaState_.OPEN_IN_PREVIEW)
return this.i18n('openPdfInPreview'); return this.i18n('openingPDFInPreview');
if (this.previewState_ == PreviewAreaState_.INVALID_SETTINGS) if (this.previewState_ == PreviewAreaState_.INVALID_SETTINGS)
return this.i18n('invalidSettings'); return this.i18n('invalidSettings');
if (this.previewState_ == PreviewAreaState_.PREVIEW_FAILED) if (this.previewState_ == PreviewAreaState_.PREVIEW_FAILED)
...@@ -255,7 +264,8 @@ Polymer({ ...@@ -255,7 +264,8 @@ Polymer({
this.onPreviewStart_(previewUid, -1); this.onPreviewStart_(previewUid, -1);
this.documentReady_ = true; this.documentReady_ = true;
if (this.pluginLoaded_) { if (this.pluginLoaded_) {
this.previewState_ = PreviewAreaState_.DISPLAY_PREVIEW; if (this.previewState_ != PreviewAreaState_.OPEN_IN_PREVIEW)
this.previewState_ = PreviewAreaState_.DISPLAY_PREVIEW;
this.fire('preview-loaded'); this.fire('preview-loaded');
} }
}, },
...@@ -291,6 +301,14 @@ Polymer({ ...@@ -291,6 +301,14 @@ Polymer({
} }
}, },
// <if expr="macosx">
/** Set the preview state to display the "opening in preview" message. */
setOpeningPdfInPreview: function() {
assert(cr.isMac);
this.previewState_ = PreviewAreaState_.OPEN_IN_PREVIEW;
},
// </if>
/** /**
* @param {number} previewUid The unique identifier of the preview. * @param {number} previewUid The unique identifier of the preview.
* @param {number} index The index of the page to preview. * @param {number} index The index of the page to preview.
...@@ -375,7 +393,8 @@ Polymer({ ...@@ -375,7 +393,8 @@ Polymer({
onPluginLoad_: function() { onPluginLoad_: function() {
this.pluginLoaded_ = true; this.pluginLoaded_ = true;
if (this.documentReady_) { if (this.documentReady_) {
this.previewState_ = PreviewAreaState_.DISPLAY_PREVIEW; if (this.previewState_ != PreviewAreaState_.OPEN_IN_PREVIEW)
this.previewState_ = PreviewAreaState_.DISPLAY_PREVIEW;
this.fire('preview-loaded'); this.fire('preview-loaded');
} }
}, },
......
...@@ -10,10 +10,11 @@ print_preview_new.State = { ...@@ -10,10 +10,11 @@ print_preview_new.State = {
READY: 1, READY: 1,
HIDDEN: 2, HIDDEN: 2,
PRINTING: 3, PRINTING: 3,
INVALID_TICKET: 4, SYSTEM_DIALOG: 4,
INVALID_PRINTER: 5, INVALID_TICKET: 5,
FATAL_ERROR: 6, INVALID_PRINTER: 6,
CLOSING: 7, FATAL_ERROR: 7,
CLOSING: 8,
}; };
Polymer({ Polymer({
...@@ -51,6 +52,9 @@ Polymer({ ...@@ -51,6 +52,9 @@ Polymer({
this.state == print_preview_new.State.READY || this.state == print_preview_new.State.READY ||
this.state == print_preview_new.State.HIDDEN); this.state == print_preview_new.State.HIDDEN);
break; break;
case (print_preview_new.State.SYSTEM_DIALOG):
assert(this.state == print_preview_new.State.READY);
break;
case (print_preview_new.State.INVALID_TICKET): case (print_preview_new.State.INVALID_TICKET):
assert(this.state == print_preview_new.State.READY); assert(this.state == print_preview_new.State.READY);
break; break;
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
type="chrome_html" /> type="chrome_html" />
<structure name="IDR_PRINT_PREVIEW_NEW_APP_HTML" <structure name="IDR_PRINT_PREVIEW_NEW_APP_HTML"
file="new/app.html" file="new/app.html"
type="chrome_html" /> type="chrome_html"
preprocess="true" />
<structure name="IDR_PRINT_PREVIEW_NEW_APP_JS" <structure name="IDR_PRINT_PREVIEW_NEW_APP_JS"
file="new/app.js" file="new/app.js"
type="chrome_html" /> type="chrome_html" />
...@@ -269,6 +270,16 @@ ...@@ -269,6 +270,16 @@
<structure name="IDR_PRINT_PREVIEW_NEW_NUMBER_SETTINGS_SECTION_JS" <structure name="IDR_PRINT_PREVIEW_NEW_NUMBER_SETTINGS_SECTION_JS"
file="new/number_settings_section.js" file="new/number_settings_section.js"
type="chrome_html" /> type="chrome_html" />
<if expr="not chromeos">
<structure name="IDR_PRINT_PREVIEW_NEW_LINK_CONTAINER_HTML"
file="new/link_container.html"
type="chrome_html"
preprocess="true" />
<structure name="IDR_PRINT_PREVIEW_NEW_LINK_CONTAINER_JS"
file="new/link_container.js"
type="chrome_html"
preprocess="true" />
</if>
<structure name="IDR_PRINT_PREVIEW_NEW_DESTINATION_DIALOG_HTML" <structure name="IDR_PRINT_PREVIEW_NEW_DESTINATION_DIALOG_HTML"
file="new/destination_dialog.html" file="new/destination_dialog.html"
type="chrome_html" /> type="chrome_html" />
......
// Copyright 2018 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('link_container_test', function() {
/** @enum {string} */
const TestNames = {
HideInAppKioskMode: 'hide in app kiosk mode',
SystemDialogLinkClick: 'system dialog link click',
OpenInPreviewLinkClick: 'open in preview link click',
};
const suiteName = 'LinkContainerTest';
suite(suiteName, function() {
/** @type {?PrintPreviewLinkContainerElement} */
let linkContainer = null;
/** @override */
setup(function() {
PolymerTest.clearBody();
linkContainer = document.createElement('print-preview-link-container');
document.body.appendChild(linkContainer);
/** Set inputs to some defaults. */
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;
linkContainer.destination = fooDestination;
linkContainer.appKioskMode = false;
linkContainer.disabled = false;
});
/** Tests that the system dialog link is hidden in App Kiosk mode. */
test(assert(TestNames.HideInAppKioskMode), function() {
const systemDialogLink = linkContainer.$.systemDialogLink;
assertFalse(systemDialogLink.hidden);
linkContainer.set('appKioskMode', true);
assertTrue(systemDialogLink.hidden);
});
/**
* Test that clicking the system dialog link click results in an event
* firing, and the throbber appears on non-Windows.
*/
test(assert(TestNames.SystemDialogLinkClick), function() {
const promise =
test_util.eventToPromise('print-with-system-dialog', linkContainer);
const throbber = linkContainer.$.systemDialogThrobber;
assertTrue(throbber.hidden);
linkContainer.$.systemDialogLink.click();
return promise.then(function() {
assertEquals(cr.isWindows, throbber.hidden);
});
});
/**
* Test that clicking the open in preview link correctly results in a
* property change and that the throbber appears. Mac only.
*/
test(assert(TestNames.OpenInPreviewLinkClick), function() {
const throbber = linkContainer.$.openPdfInPreviewThrobber;
assertTrue(throbber.hidden);
const promise =
test_util.eventToPromise('open-pdf-in-preview', linkContainer);
linkContainer.$.openPdfInPreviewLink.click();
return promise.then(function() {
assertFalse(throbber.hidden);
});
});
});
return {
suiteName: suiteName,
TestNames: TestNames,
};
});
...@@ -264,3 +264,77 @@ GEN('#endif'); ...@@ -264,3 +264,77 @@ GEN('#endif');
TEST_F('PrintPreviewPreviewGenerationTest', 'Destination', function() { TEST_F('PrintPreviewPreviewGenerationTest', 'Destination', function() {
this.runMochaTest(preview_generation_test.TestNames.Destination); this.runMochaTest(preview_generation_test.TestNames.Destination);
}); });
GEN('#if !defined(OS_CHROMEOS)');
PrintPreviewLinkContainerTest = class extends NewPrintPreviewTest {
/** @override */
get browsePreload() {
return 'chrome://print/new/link_container.html';
}
/** @override */
get extraLibraries() {
return super.extraLibraries.concat([
'../settings/test_util.js',
'print_preview_test_utils.js',
'link_container_test.js',
]);
}
/** @override */
get suiteName() {
return link_container_test.suiteName;
}
};
TEST_F('PrintPreviewLinkContainerTest', 'HideInAppKioskMode', function() {
this.runMochaTest(link_container_test.TestNames.HideInAppKioskMode);
});
TEST_F('PrintPreviewLinkContainerTest', 'SystemDialogLinkClick', function() {
this.runMochaTest(link_container_test.TestNames.SystemDialogLinkClick);
});
GEN('#endif'); // !defined(OS_CHROMEOS)
GEN('#if defined(OS_MACOSX)');
TEST_F('PrintPreviewLinkContainerTest', 'OpenInPreviewLinkClick', function() {
this.runMochaTest(link_container_test.TestNames.OpenInPreviewLinkClick);
});
GEN('#endif'); // defined(OS_MACOSX)
GEN('#if defined(OS_WIN) || defined(OS_MACOSX)');
PrintPreviewSystemDialogBrowserTest = class extends NewPrintPreviewTest {
/** @override */
get browsePreload() {
return 'chrome://print/new/app.html';
}
/** @override */
get extraLibraries() {
return super.extraLibraries.concat([
ROOT_PATH + 'chrome/test/data/webui/settings/test_util.js',
'../test_browser_proxy.js',
'native_layer_stub.js',
'plugin_stub.js',
'print_preview_test_utils.js',
'system_dialog_browsertest.js',
]);
}
/** @override */
get suiteName() {
return system_dialog_browsertest.suiteName;
}
};
TEST_F('PrintPreviewSystemDialogBrowserTest', 'LinkTriggersLocalPrint',
function() {
this.runMochaTest(system_dialog_browsertest.TestNames.LinkTriggersLocalPrint);
});
TEST_F('PrintPreviewSystemDialogBrowserTest', 'InvalidSettingsDisableLink',
function() {
this.runMochaTest(
system_dialog_browsertest.TestNames.InvalidSettingsDisableLink);
});
GEN('#endif'); // defined(OS_WIN) || defined(OS_MACOSX)
// Copyright 2018 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('system_dialog_browsertest', function() {
/** @enum {string} */
const TestNames = {
LinkTriggersLocalPrint: 'link triggers local print',
InvalidSettingsDisableLink: 'invalid settings disable link',
};
const suiteName = 'SystemDialogBrowserTest';
suite(suiteName, function() {
/** @type {?PrintPreviewAppElement} */
let page = null;
/** @type {?print_preview.NativeLayer} */
let nativeLayer = null;
/** @type {?PrintPreviewLinkContainerElement} */
let linkContainer = null;
/** @type {?HTMLElement} */
let link = null;
/** @type {string} */
let printTicketKey = '';
/** @override */
setup(function() {
nativeLayer = new print_preview.NativeLayerStub();
print_preview.NativeLayer.setInstance(nativeLayer);
PolymerTest.clearBody();
const initialSettings = {
isInKioskAutoPrintMode: false,
isInAppKioskMode: false,
thousandsDelimeter: ',',
decimalDelimeter: '.',
unitType: 1,
previewModifiable: true,
documentTitle: 'title',
documentHasSelection: true,
shouldPrintSelectionOnly: false,
printerName: 'FooDevice',
serializedAppStateStr: null,
serializedDefaultDestinationSelectionRulesStr: null
};
nativeLayer.setInitialSettings(initialSettings);
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate(initialSettings.printerName));
page = document.createElement('print-preview-app');
linkContainer = page.$$('print-preview-link-container');
const previewArea = page.$$('print-preview-preview-area');
previewArea.plugin_ = new print_preview.PDFPluginStub(previewArea);
previewArea.plugin_.setLoadCallback(
previewArea.onPluginLoad_.bind(previewArea));
document.body.appendChild(page);
return Promise.all([
nativeLayer.whenCalled('getInitialSettings'),
nativeLayer.whenCalled('getPrinterCapabilities'),
]).then(function() {
return nativeLayer.whenCalled('getPreview');
}).then(function() {
assertEquals('FooDevice', page.destination_.id);
link = cr.isWindows ?
linkContainer.$.systemDialogLink :
linkContainer.$.openPdfInPreviewLink;
printTicketKey = cr.isWindows ? 'showSystemDialog' : 'OpenPDFInPreview';
});
});
test(assert(TestNames.LinkTriggersLocalPrint), function() {
assertFalse(linkContainer.disabled);
assertFalse(link.hidden);
link.click();
// Should result in a print call and dialog should close.
return nativeLayer.whenCalled('print').then(function(printTicket) {
expectTrue(JSON.parse(printTicket)[printTicketKey]);
return nativeLayer.whenCalled('dialogClose');
});
});
test(assert(TestNames.InvalidSettingsDisableLink), function() {
assertFalse(linkContainer.disabled);
assertFalse(link.hidden);
const pageSettings = page.$$('print-preview-pages-settings');
assertFalse(pageSettings.hidden);
nativeLayer.resetResolver('getPreview');
// Set page settings to a bad value
pageSettings.$$('#custom-radio-button').checked = true;
pageSettings.$$('#all-radio-button').dispatchEvent(
new CustomEvent('change'));
const pageSettingsInput = pageSettings.$$('.user-value');
pageSettingsInput.value = 'abc';
pageSettingsInput.dispatchEvent(new CustomEvent('input'));
// No new preview
nativeLayer.whenCalled('getPreview').then(function() {
assertTrue(false);
});
return test_util.eventToPromise('input-change', pageSettings).then(
function() {
// Expect disabled print button and Pdf in preview link
const header = page.$$('print-preview-header');
const printButton = header.$$('.print');
assertTrue(printButton.disabled);
assertTrue(linkContainer.disabled);
assertFalse(link.hidden);
assertTrue(link.disabled);
});
});
});
return {
suiteName: suiteName,
TestNames: TestNames,
};
});
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