Commit 76dc7b80 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Fix tests for Polymer2

Setting the plugin before attaching print-preview-app to the document
will no longer work in Polymer2. Add an interface for the plugin,
similar to the approach for the NativeLayer, and use this to stub out
checks for plugin compatibility and other plugin functions.

Bug: 738611
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I8428fba35ff5783e18679f99cc02f8d085f82a2e
Reviewed-on: https://chromium-review.googlesource.com/1097514
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567291}
parent 89102421
...@@ -235,6 +235,7 @@ js_library("preview_area") { ...@@ -235,6 +235,7 @@ js_library("preview_area") {
deps = [ deps = [
":margin_control_container", ":margin_control_container",
":model", ":model",
":plugin_proxy",
":settings_behavior", ":settings_behavior",
":state", ":state",
"..:native_layer", "..:native_layer",
...@@ -275,6 +276,12 @@ js_library("margin_control") { ...@@ -275,6 +276,12 @@ js_library("margin_control") {
] ]
} }
js_library("plugin_proxy") {
deps = [
"//ui/webui/resources/js:cr",
]
}
js_library("destination_dialog") { js_library("destination_dialog") {
deps = [ deps = [
":destination_list", ":destination_list",
......
<link rel="import" href="chrome://resources/html/cr.html">
<script src="plugin_proxy.js"></script>
<script src="../pdf/pdf_scripting_api.js"></script>
// 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.exportPath('print_preview_new');
/**
* @typedef {{accessibility: Function,
* documentLoadComplete: Function,
* getHeight: Function,
* getHorizontalScrollbarThickness: Function,
* getPageLocationNormalized: Function,
* getVerticalScrollbarThickness: Function,
* getWidth: Function,
* getZoomLevel: Function,
* goToPage: Function,
* grayscale: Function,
* loadPreviewPage: Function,
* onload: Function,
* onPluginSizeChanged: Function,
* onScroll: Function,
* pageXOffset: Function,
* pageYOffset: Function,
* reload: Function,
* resetPrintPreviewMode: Function,
* sendKeyEvent: Function,
* setPageNumbers: Function,
* setPageXOffset: Function,
* setPageYOffset: Function,
* setZoomLevel: Function,
* fitToHeight: Function,
* fitToWidth: Function,
* zoomIn: Function,
* zoomOut: Function}}
*/
print_preview_new.PDFPlugin;
cr.define('print_preview_new', function() {
'use strict';
/**
* An interface to the PDF plugin.
*/
class PluginProxy {
/**
* Creates a new PluginProxy if the current instance is not set.
* @return {!print_preview_new.PluginProxy} The singleton instance.
*/
static getInstance() {
if (instance == null)
instance = new PluginProxy();
return assert(instance);
}
/**
* @param {!print_preview_new.PluginProxy} newInstance The PluginProxy
* instance to set for print preview construction.
*/
static setInstance(newInstance) {
instance = newInstance;
}
constructor() {
/** @private {?print_preview_new.PDFPlugin} */
this.plugin_ = null;
}
/**
* @param {!Element} oopCompatObj The out of process compatibility element.
* @return {boolean} Whether the plugin exists and is compatible.
*/
checkPluginCompatibility(oopCompatObj) {
const isOOPCompatible = oopCompatObj.postMessage;
oopCompatObj.parentElement.removeChild(oopCompatObj);
return isOOPCompatible;
}
/** @return {boolean} Whether the plugin is ready. */
pluginReady() {
return !!this.plugin_;
}
/**
* Creates the PDF plugin.
* @param {number} previewUid The unique ID of the preview UI.
* @param {number} index The preview index to load.
* @return {!print_preview_new.PDFPlugin} The created plugin.
*/
createPlugin(previewUid, index) {
assert(!this.plugin_);
const srcUrl = this.getPreviewUrl_(previewUid, index);
this.plugin_ = /** @type {print_preview_new.PDFPlugin} */ (
PDFCreateOutOfProcessPlugin(srcUrl, 'chrome://print/pdf'));
this.plugin_.classList.add('preview-area-plugin');
this.plugin_.setAttribute('aria-live', 'polite');
this.plugin_.setAttribute('aria-atomic', 'true');
// NOTE: The plugin's 'id' field must be set to 'pdf-viewer' since
// chrome/renderer/printing/print_render_frame_helper.cc actually
// references it.
this.plugin_.setAttribute('id', 'pdf-viewer');
return this.plugin_;
}
/**
* Get the URL for the plugin.
* @param {number} previewUid Unique identifier of preview.
* @param {number} index Page index for plugin.
* @return {string} The URL
* @private
*/
getPreviewUrl_(previewUid, index) {
return `chrome://print/${previewUid}/${index}/print.pdf`;
}
/**
* @param {number} previewUid Unique identifier of preview.
* @param {number} index Page index for plugin.
* @param {boolean} color Whether the preview should be color.
* @param {!Array<number>} pages Page indices to preview.
* @param {boolean} modifiable Whether the document is modifiable.
*/
resetPrintPreviewMode(previewUid, index, color, pages, modifiable) {
this.plugin_.resetPrintPreviewMode(
this.getPreviewUrl_(previewUid, index), color, pages, modifiable);
}
/** @param {!KeyboardEvent} e Keyboard event to forward to the plugin. */
sendKeyEvent(e) {
this.plugin_.sendKeyEvent(e);
}
/**
* @param {boolean} eventsEnabled Whether pointer events should be captured
* by the plugin.
*/
setPointerEvents(eventsEnabled) {
this.plugin_.style.pointerEvents = eventsEnabled ? 'auto' : 'none';
}
/**
* @param {number} previewUid The unique ID of the preview UI.
* @param {number} pageIndex The page index to load.
* @param {number} index The preview index.
*/
loadPreviewPage(previewUid, pageIndex, index) {
this.plugin_.loadPreviewPage(
this.getPreviewUrl_(previewUid, pageIndex), index);
}
}
/** @type {?print_preview_new.PluginProxy} */
let instance = null;
// Export
return {PluginProxy: PluginProxy};
});
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<link rel="import" href="../data/size.html"> <link rel="import" href="../data/size.html">
<link rel="import" href="margin_control_container.html"> <link rel="import" href="margin_control_container.html">
<link rel="import" href="model.html"> <link rel="import" href="model.html">
<link rel="import" href="plugin_proxy.html">
<link rel="import" href="state.html"> <link rel="import" href="state.html">
<link rel="import" href="settings_behavior.html"> <link rel="import" href="settings_behavior.html">
<link rel="import" href="strings.html"> <link rel="import" href="strings.html">
...@@ -159,6 +160,4 @@ ...@@ -159,6 +160,4 @@
</print-preview-margin-control-container> </print-preview-margin-control-container>
</template> </template>
<script src="preview_area.js"></script> <script src="preview_area.js"></script>
<script src="../pdf/pdf_scripting_api.js">
</script>
</dom-module> </dom-module>
...@@ -3,36 +3,6 @@ ...@@ -3,36 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
cr.exportPath('print_preview_new'); cr.exportPath('print_preview_new');
/**
* @typedef {{accessibility: Function,
* documentLoadComplete: Function,
* getHeight: Function,
* getHorizontalScrollbarThickness: Function,
* getPageLocationNormalized: Function,
* getVerticalScrollbarThickness: Function,
* getWidth: Function,
* getZoomLevel: Function,
* goToPage: Function,
* grayscale: Function,
* loadPreviewPage: Function,
* onload: Function,
* onPluginSizeChanged: Function,
* onScroll: Function,
* pageXOffset: Function,
* pageYOffset: Function,
* reload: Function,
* resetPrintPreviewMode: Function,
* sendKeyEvent: Function,
* setPageNumbers: Function,
* setPageXOffset: Function,
* setPageYOffset: Function,
* setZoomLevel: Function,
* fitToHeight: Function,
* fitToWidth: Function,
* zoomIn: Function,
* zoomOut: Function}}
*/
print_preview_new.PDFPlugin;
/** /**
* @typedef {{ * @typedef {{
...@@ -138,8 +108,8 @@ Polymer({ ...@@ -138,8 +108,8 @@ Polymer({
/** @private {boolean} */ /** @private {boolean} */
requestPreviewWhenReady_: false, requestPreviewWhenReady_: false,
/** @private {HTMLEmbedElement|print_preview_new.PDFPlugin} */ /** @private {?print_preview_new.PluginProxy} */
plugin_: null, pluginProxy_: null,
/** @private {?function(!KeyboardEvent)} */ /** @private {?function(!KeyboardEvent)} */
keyEventCallback_: null, keyEventCallback_: null,
...@@ -154,22 +124,13 @@ Polymer({ ...@@ -154,22 +124,13 @@ Polymer({
this.addWebUIListener( this.addWebUIListener(
'page-preview-ready', this.onPagePreviewReady_.bind(this)); 'page-preview-ready', this.onPagePreviewReady_.bind(this));
if (!this.checkPluginCompatibility()) this.pluginProxy_ = print_preview_new.PluginProxy.getInstance();
if (!this.pluginProxy_.checkPluginCompatibility(assert(
this.$$('.preview-area-compatibility-object-out-of-process')))) {
this.previewState = print_preview_new.PreviewAreaState.NO_PLUGIN; this.previewState = print_preview_new.PreviewAreaState.NO_PLUGIN;
}
}, },
/**
* @return {boolean} Whether the plugin exists and is compatible. Overridden
* in tests.
*/
checkPluginCompatibility: function() {
const oopCompatObj =
this.$$('.preview-area-compatibility-object-out-of-process');
const isOOPCompatible = oopCompatObj.postMessage;
oopCompatObj.parentElement.removeChild(oopCompatObj);
return isOOPCompatible;
},
/** /**
* @return {boolean} Whether the preview is loaded. * @return {boolean} Whether the preview is loaded.
...@@ -379,12 +340,21 @@ Polymer({ ...@@ -379,12 +340,21 @@ Polymer({
* @private * @private
*/ */
onPreviewStart_: function(previewUid, index) { onPreviewStart_: function(previewUid, index) {
if (!this.plugin_) if (!this.pluginProxy_.pluginReady()) {
this.createPlugin_(previewUid, index); const plugin = this.pluginProxy_.createPlugin(previewUid, index);
plugin.setKeyEventCallback(this.keyEventCallback_);
this.$$('.preview-area-plugin-wrapper')
.appendChild(
/** @type {Node} */ (plugin));
plugin.setLoadCallback(this.onPluginLoad_.bind(this));
plugin.setViewportChangedCallback(
this.onPreviewVisualStateChange_.bind(this));
}
this.pluginLoaded_ = false; this.pluginLoaded_ = false;
this.plugin_.resetPrintPreviewMode( this.pluginProxy_.resetPrintPreviewMode(
this.getPreviewUrl_(previewUid, index), !this.getSettingValue('color'), previewUid, index, !this.getSettingValue('color'),
this.getSetting('pages').value, this.documentInfo.isModifiable); /** @type {!Array<number>} */ (this.getSetting('pages').value),
this.documentInfo.isModifiable);
}, },
/** /**
...@@ -478,17 +448,6 @@ Polymer({ ...@@ -478,17 +448,6 @@ Polymer({
new print_preview.Size(viewportWidth, viewportHeight)); new print_preview.Size(viewportWidth, viewportHeight));
}, },
/**
* Get the URL for the plugin.
* @param {number} previewUid Unique identifier of preview.
* @param {number} index Page index for plugin.
* @return {string} The URL
* @private
*/
getPreviewUrl_: function(previewUid, index) {
return `chrome://print/${previewUid}/${index}/print.pdf`;
},
/** /**
* Called when a page's preview has been generated. * Called when a page's preview has been generated.
* @param {number} pageIndex The index of the page whose preview is ready. * @param {number} pageIndex The index of the page whose preview is ready.
...@@ -504,10 +463,8 @@ Polymer({ ...@@ -504,10 +463,8 @@ Polymer({
const index = this.getSettingValue('pages').indexOf(pageNumber); const index = this.getSettingValue('pages').indexOf(pageNumber);
if (index == 0) if (index == 0)
this.onPreviewStart_(previewUid, pageIndex); this.onPreviewStart_(previewUid, pageIndex);
if (index != -1) { if (index != -1)
this.plugin_.loadPreviewPage( this.pluginProxy_.loadPreviewPage(previewUid, pageIndex, index);
this.getPreviewUrl_(previewUid, pageIndex), index);
}
}, },
/** /**
...@@ -519,7 +476,7 @@ Polymer({ ...@@ -519,7 +476,7 @@ Polymer({
// Make sure the PDF plugin is there. // Make sure the PDF plugin is there.
// We only care about: PageUp, PageDown, Left, Up, Right, Down. // We only care about: PageUp, PageDown, Left, Up, Right, Down.
// If the user is holding a modifier key, ignore. // If the user is holding a modifier key, ignore.
if (!this.plugin_ || if (!this.pluginProxy_.pluginReady() ||
!arrayContains( !arrayContains(
[ [
'PageUp', 'PageDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'PageUp', 'PageDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp',
...@@ -551,7 +508,7 @@ Polymer({ ...@@ -551,7 +508,7 @@ Polymer({
// No scroll bar anywhere, or the active element is something else, like a // No scroll bar anywhere, or the active element is something else, like a
// button. Note: buttons have a bigger scrollHeight than clientHeight. // button. Note: buttons have a bigger scrollHeight than clientHeight.
this.plugin_.sendKeyEvent(e); this.pluginProxy_.sendKeyEvent(e);
e.preventDefault(); e.preventDefault();
}, },
...@@ -565,47 +522,18 @@ Polymer({ ...@@ -565,47 +522,18 @@ Polymer({
this.keyEventCallback_ = callback; this.keyEventCallback_ = callback;
}, },
/**
* Creates a preview plugin and adds it to the DOM.
* @param {number} previewUid The unique ID of the preview. Used to determine
* the URL for the plugin.
* @param {number} index The index of the page to load. Used to determine the
* URL for the plugin.
* @private
*/
createPlugin_: function(previewUid, index) {
assert(!this.plugin_);
const srcUrl = this.getPreviewUrl_(previewUid, index);
this.plugin_ = /** @type {print_preview_new.PDFPlugin} */ (
PDFCreateOutOfProcessPlugin(srcUrl, 'chrome://print/pdf'));
this.plugin_.setKeyEventCallback(this.keyEventCallback_);
this.plugin_.classList.add('preview-area-plugin');
this.plugin_.setAttribute('aria-live', 'polite');
this.plugin_.setAttribute('aria-atomic', 'true');
// NOTE: The plugin's 'id' field must be set to 'pdf-viewer' since
// chrome/renderer/printing/print_render_frame_helper.cc actually
// references it.
this.plugin_.setAttribute('id', 'pdf-viewer');
this.$$('.preview-area-plugin-wrapper')
.appendChild(/** @type {Node} */ (this.plugin_));
this.plugin_.setLoadCallback(this.onPluginLoad_.bind(this));
this.plugin_.setViewportChangedCallback(
this.onPreviewVisualStateChange_.bind(this));
},
/** /**
* Called when dragging margins starts or stops. * Called when dragging margins starts or stops.
*/ */
onMarginDragChanged_: function(e) { onMarginDragChanged_: function(e) {
if (!this.plugin_) if (!this.pluginProxy_.pluginReady())
return; return;
// When hovering over the plugin (which may be in a separate iframe) // When hovering over the plugin (which may be in a separate iframe)
// pointer events will be sent to the frame. When dragging the margins, // pointer events will be sent to the frame. When dragging the margins,
// we don't want this to happen as it can cause the margin to stop // we don't want this to happen as it can cause the margin to stop
// being draggable. // being draggable.
this.plugin_.style.pointerEvents = e.detail ? 'none' : 'auto'; this.pluginProxy_.setPointerEvents(!e.detail);
}, },
/** /**
......
...@@ -157,6 +157,12 @@ ...@@ -157,6 +157,12 @@
file="new/preview_area.js" file="new/preview_area.js"
type="chrome_html" type="chrome_html"
preprocess="true" /> preprocess="true" />
<structure name="IDR_PRINT_PREVIEW_NEW_PLUGIN_PROXY_HTML"
file="new/plugin_proxy.html"
type="chrome_html" />
<structure name="IDR_PRINT_PREVIEW_NEW_PLUGIN_PROXY_JS"
file="new/plugin_proxy.js"
type="chrome_html" />
<structure name="IDR_PRINT_PREVIEW_NEW_HEADER_HTML" <structure name="IDR_PRINT_PREVIEW_NEW_HEADER_HTML"
file="new/header.html" file="new/header.html"
type="chrome_html" /> type="chrome_html" />
......
...@@ -54,8 +54,10 @@ cr.define('invalid_settings_browsertest', function() { ...@@ -54,8 +54,10 @@ cr.define('invalid_settings_browsertest', function() {
* given by |initialSettings| and |localDestinationInfos|. Also creates * given by |initialSettings| and |localDestinationInfos|. Also creates
* the fake plugin. Moved out of setup so tests can set those parameters * the fake plugin. Moved out of setup so tests can set those parameters
* differently. * differently.
* @param {boolean} pluginCompatible Whether the plugin should be set to
* appear compatible.
*/ */
function createPage() { function createPage(pluginCompatible) {
nativeLayer.setInitialSettings(initialSettings); nativeLayer.setInitialSettings(initialSettings);
nativeLayer.setLocalDestinations(localDestinationInfos); nativeLayer.setLocalDestinations(localDestinationInfos);
if (initialSettings.printerName) { if (initialSettings.printerName) {
...@@ -63,11 +65,14 @@ cr.define('invalid_settings_browsertest', function() { ...@@ -63,11 +65,14 @@ cr.define('invalid_settings_browsertest', function() {
print_preview_test_utils.getCddTemplate( print_preview_test_utils.getCddTemplate(
initialSettings.printerName)); initialSettings.printerName));
} }
const pluginProxy = new print_preview.PDFPluginStub();
pluginProxy.setPluginCompatible(pluginCompatible);
print_preview_new.PluginProxy.setInstance(pluginProxy);
page = document.createElement('print-preview-app'); page = document.createElement('print-preview-app');
const previewArea = page.$$('print-preview-preview-area'); document.body.appendChild(page);
previewArea.plugin_ = new print_preview.PDFPluginStub( const previewArea = page.$.previewArea;
previewArea.onPluginLoad_.bind(previewArea)); pluginProxy.setLoadCallback(previewArea.onPluginLoad_.bind(previewArea));
} }
/** /**
...@@ -88,9 +93,8 @@ cr.define('invalid_settings_browsertest', function() { ...@@ -88,9 +93,8 @@ cr.define('invalid_settings_browsertest', function() {
}); });
localDestinationInfos = []; localDestinationInfos = [];
createPage(); createPage(true);
document.body.appendChild(page);
page.userInfo_.setUsers('foo@chromium.org', ['foo@chromium.org']); page.userInfo_.setUsers('foo@chromium.org', ['foo@chromium.org']);
cr.webUIListenerCallback('use-cloud-print', 'cloudprint url', false); cr.webUIListenerCallback('use-cloud-print', 'cloudprint url', false);
printers.forEach(printer => { printers.forEach(printer => {
...@@ -99,13 +103,11 @@ cr.define('invalid_settings_browsertest', function() { ...@@ -99,13 +103,11 @@ cr.define('invalid_settings_browsertest', function() {
} }
// Test that error message is displayed when plugin doesn't exist. // Test that error message is displayed when plugin doesn't exist.
// TODO (rbpotter): Fix this test so that it works again with calling
// appendChild() before setting checkPluginCompatibility.
test(assert(TestNames.NoPDFPluginError), function() { test(assert(TestNames.NoPDFPluginError), function() {
createPage(); createPage(false);
const previewArea = page.$.previewArea; const previewArea = page.$.previewArea;
previewArea.checkPluginCompatibility = function() {
return false;
};
document.body.appendChild(page);
return nativeLayer.whenCalled('getInitialSettings').then(function() { return nativeLayer.whenCalled('getInitialSettings').then(function() {
const overlayEl = previewArea.$$('.preview-area-overlay-layer'); const overlayEl = previewArea.$$('.preview-area-overlay-layer');
...@@ -130,7 +132,7 @@ cr.define('invalid_settings_browsertest', function() { ...@@ -130,7 +132,7 @@ cr.define('invalid_settings_browsertest', function() {
// is disabled. Verifies that the user can recover from this error by // is disabled. Verifies that the user can recover from this error by
// selecting a different, valid printer. // selecting a different, valid printer.
test(assert(TestNames.InvalidSettingsError), function() { test(assert(TestNames.InvalidSettingsError), function() {
createPage(); createPage(true);
const barDevice = print_preview_test_utils.getCddTemplate('BarDevice'); const barDevice = print_preview_test_utils.getCddTemplate('BarDevice');
nativeLayer.setLocalDestinationCapabilities(barDevice); nativeLayer.setLocalDestinationCapabilities(barDevice);
...@@ -150,7 +152,6 @@ cr.define('invalid_settings_browsertest', function() { ...@@ -150,7 +152,6 @@ cr.define('invalid_settings_browsertest', function() {
const header = page.$$('print-preview-header'); const header = page.$$('print-preview-header');
const printButton = header.$$('.print'); const printButton = header.$$('.print');
document.body.appendChild(page);
return nativeLayer.whenCalled('getInitialSettings') return nativeLayer.whenCalled('getInitialSettings')
.then(function() { .then(function() {
page.destinationStore_.startLoadDestinations( page.destinationStore_.startLoadDestinations(
......
...@@ -4,36 +4,79 @@ ...@@ -4,36 +4,79 @@
cr.define('print_preview', function() { cr.define('print_preview', function() {
/** /**
* Test version of the print preview PDF plugin * Test version of the PluginProxy.
*/ */
class PDFPluginStub { class PDFPluginStub {
constructor() {
/** @type {?Function} The callback to call on load. */
this.loadCallback_ = null;
/** @type {boolean} Whether the plugin is compatible. */
this.compatible_ = true;
}
/** @param {boolean} Whether the PDF plugin should be compatible. */
setPluginCompatible(compatible) {
this.compatible_ = compatible;
}
/** /**
* @param {!Function} loadCallback The function to call when the plugin has * @param {!Function} loadCallback Callback to call when the preview
* loaded. * loads.
*/ */
constructor(loadCallback) { setLoadCallback(loadCallback) {
/**
* @private {!Function} The callback to run when the plugin has loaded.
*/
this.loadCallback_ = loadCallback; this.loadCallback_ = loadCallback;
} }
/** /**
* Stubbed out since some tests result in a call. * @param {!Element} oopCompatObj The out of process compatibility element.
* @param {string} url The url to initialize the plugin to. * @return {boolean} Whether the plugin exists and is compatible.
* @param {boolean} color Whether the preview should be in color. */
* @param {!Array<number>} pages The pages to preview. checkPluginCompatibility(oopCompatObj) {
* @param {boolean} modifiable Whether the source document is modifiable. return this.compatible_;
}
/** @return {boolean} Whether the plugin is ready. */
pluginReady() {
return true;
}
/**
* Sets the load callback to imitate the plugin.
* @param {number} previewUid The unique ID of the preview UI.
* @param {number} index The preview index to load.
* @return {?print_preview_new.PDFPlugin}
*/
createPlugin(previewUid, index) {
return null;
}
/**
* @param {number} previewUid Unique identifier of preview.
* @param {number} index Page index for plugin.
* @param {boolean} color Whether the preview should be color.
* @param {!Array<number>} pages Page indices to preview.
* @param {boolean} modifiable Whether the document is modifiable.
*/
resetPrintPreviewMode(previewUid, index, color, pages, modifiable) {}
/** @param {!KeyEvent} e Keyboard event to forward to the plugin. */
sendKeyEvent(e) {}
/**
* @param {boolean} eventsOn Whether pointer events should be captured by
* the plugin.
*/ */
resetPrintPreviewMode(url, color, pages, modifiable) {} setPointerEvents(eventsOn) {}
/** /**
* Called when the preview area wants the plugin to load a preview page. * Called when the preview area wants the plugin to load a preview page.
* Immediately calls loadCallback_(). * Immediately calls loadCallback_().
* @param {string} url The preview URL * @param {number} previewUid The unique ID of the preview UI.
* @param {number} index The index of the page number to load. * @param {number} pageIndex The page index to load.
* @param {number} index The preview index.
*/ */
loadPreviewPage(url, index) { loadPreviewPage(previewUid, pageIndex, index) {
if (this.loadCallback_) if (this.loadCallback_)
this.loadCallback_(); this.loadCallback_();
} }
......
...@@ -54,12 +54,14 @@ cr.define('preview_generation_test', function() { ...@@ -54,12 +54,14 @@ cr.define('preview_generation_test', function() {
nativeLayer.setLocalDestinationCapabilities( nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate(initialSettings.printerName)); print_preview_test_utils.getCddTemplate(initialSettings.printerName));
nativeLayer.setPageCount(3); nativeLayer.setPageCount(3);
const pluginProxy = new print_preview.PDFPluginStub();
print_preview_new.PluginProxy.setInstance(pluginProxy);
page = document.createElement('print-preview-app'); page = document.createElement('print-preview-app');
const previewArea = page.$$('print-preview-preview-area');
previewArea.plugin_ = new print_preview.PDFPluginStub(
previewArea.onPluginLoad_.bind(previewArea));
document.body.appendChild(page); document.body.appendChild(page);
const previewArea = page.$.previewArea;
pluginProxy.setLoadCallback(previewArea.onPluginLoad_.bind(previewArea));
return Promise return Promise
.all([ .all([
nativeLayer.whenCalled('getInitialSettings'), nativeLayer.whenCalled('getInitialSettings'),
......
...@@ -329,7 +329,8 @@ cr.define('print_preview_test', function() { ...@@ -329,7 +329,8 @@ cr.define('print_preview_test', function() {
print_preview.NativeLayer.setInstance(nativeLayer); print_preview.NativeLayer.setInstance(nativeLayer);
printPreview = new print_preview.PrintPreview(); printPreview = new print_preview.PrintPreview();
previewArea = printPreview.getPreviewArea(); previewArea = printPreview.getPreviewArea();
previewArea.plugin_ = new print_preview.PDFPluginStub( previewArea.plugin_ = new print_preview.PDFPluginStub();
previewArea.plugin_.setLoadCallback(
previewArea.onPluginLoad_.bind(previewArea)); previewArea.onPluginLoad_.bind(previewArea));
}); });
......
...@@ -73,12 +73,14 @@ cr.define('restore_state_test', function() { ...@@ -73,12 +73,14 @@ cr.define('restore_state_test', function() {
nativeLayer.setLocalDestinationCapabilities( nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplateWithAdvancedSettings( print_preview_test_utils.getCddTemplateWithAdvancedSettings(
2, initialSettings.printerName)); 2, initialSettings.printerName));
const pluginProxy = new print_preview.PDFPluginStub();
print_preview_new.PluginProxy.setInstance(pluginProxy);
page = document.createElement('print-preview-app'); page = document.createElement('print-preview-app');
const previewArea = page.$$('print-preview-preview-area');
previewArea.plugin_ = new print_preview.PDFPluginStub(
previewArea.onPluginLoad_.bind(previewArea));
document.body.appendChild(page); document.body.appendChild(page);
const previewArea = page.$.previewArea;
pluginProxy.setLoadCallback(previewArea.onPluginLoad_.bind(previewArea));
return nativeLayer.whenCalled('getInitialSettings') return nativeLayer.whenCalled('getInitialSettings')
.then(function() { .then(function() {
return nativeLayer.whenCalled('getPrinterCapabilities'); return nativeLayer.whenCalled('getPrinterCapabilities');
...@@ -246,10 +248,10 @@ cr.define('restore_state_test', function() { ...@@ -246,10 +248,10 @@ cr.define('restore_state_test', function() {
print_preview_test_utils.getCddTemplate(initialSettings.printerName)); print_preview_test_utils.getCddTemplate(initialSettings.printerName));
page = document.createElement('print-preview-app'); page = document.createElement('print-preview-app');
document.body.appendChild(page);
const previewArea = page.$$('print-preview-preview-area'); const previewArea = page.$$('print-preview-preview-area');
previewArea.plugin_ = new print_preview.PDFPluginStub( previewArea.plugin_ = new print_preview.PDFPluginStub(
previewArea.onPluginLoad_.bind(previewArea)); previewArea.onPluginLoad_.bind(previewArea));
document.body.appendChild(page);
return nativeLayer.whenCalled('getInitialSettings') return nativeLayer.whenCalled('getInitialSettings')
.then(function() { .then(function() {
......
...@@ -44,12 +44,14 @@ cr.define('settings_sections_tests', function() { ...@@ -44,12 +44,14 @@ cr.define('settings_sections_tests', function() {
print_preview_test_utils.getCddTemplate(initialSettings.printerName)); print_preview_test_utils.getCddTemplate(initialSettings.printerName));
nativeLayer.setPageCount(3); nativeLayer.setPageCount(3);
print_preview.NativeLayer.setInstance(nativeLayer); print_preview.NativeLayer.setInstance(nativeLayer);
const pluginProxy = new print_preview.PDFPluginStub();
print_preview_new.PluginProxy.setInstance(pluginProxy);
PolymerTest.clearBody(); PolymerTest.clearBody();
page = document.createElement('print-preview-app'); page = document.createElement('print-preview-app');
const previewArea = page.$$('print-preview-preview-area');
previewArea.plugin_ = new print_preview.PDFPluginStub(
previewArea.onPluginLoad_.bind(previewArea));
document.body.appendChild(page); document.body.appendChild(page);
const previewArea = page.$.previewArea;
pluginProxy.setLoadCallback(previewArea.onPluginLoad_.bind(previewArea));
// Wait for initialization to complete. // Wait for initialization to complete.
return Promise return Promise
......
...@@ -37,13 +37,14 @@ cr.define('system_dialog_browsertest', function() { ...@@ -37,13 +37,14 @@ cr.define('system_dialog_browsertest', function() {
nativeLayer.setInitialSettings(initialSettings); nativeLayer.setInitialSettings(initialSettings);
nativeLayer.setLocalDestinationCapabilities( nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate(initialSettings.printerName)); print_preview_test_utils.getCddTemplate(initialSettings.printerName));
const pluginProxy = new print_preview.PDFPluginStub();
print_preview_new.PluginProxy.setInstance(pluginProxy);
page = document.createElement('print-preview-app'); 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.onPluginLoad_.bind(previewArea));
document.body.appendChild(page); document.body.appendChild(page);
const previewArea = page.$.previewArea;
pluginProxy.setLoadCallback(previewArea.onPluginLoad_.bind(previewArea));
linkContainer = page.$$('print-preview-link-container');
return Promise return Promise
.all([ .all([
nativeLayer.whenCalled('getInitialSettings'), nativeLayer.whenCalled('getInitialSettings'),
......
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