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

Print Preview: Add closure compilation for more tests, update proxy

Make the PluginProxy follow the standard BrowserProxy pattern (i.e.
define an interface and implement separately), and use
addSingletonGetter(). This allows for better type coverage when using
the stub in tests.

Add closure compilation for:
header_test
invalid_settings_browsertest
test_plugin_proxy (renamed from plugin_stub)

Bug: 1000989
Change-Id: I6e0cf064a6789b2cdc87b617fd0fdd58d5039f48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317165
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarJohn Lee <johntlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792025}
parent 62b21452
......@@ -27,7 +27,7 @@ export {BackgroundGraphicsModeRestriction, CapabilitiesResponse, LocalDestinatio
export {getSelectDropdownBackground} from './print_preview_utils.js';
export {DEFAULT_MAX_COPIES} from './ui/copies_settings.js';
export {DestinationState} from './ui/destination_settings.js';
export {PluginProxy} from './ui/plugin_proxy.js';
export {PDFPlugin, PluginProxy, PluginProxyImpl} from './ui/plugin_proxy.js';
export {PreviewAreaState} from './ui/preview_area.js';
export {SelectBehavior} from './ui/select_behavior.js';
export {SelectOption} from './ui/settings_select.js';
......@@ -37,7 +37,6 @@ Polymer({
managed: Boolean,
/** @private {number} */
sheetCount: Number,
/** @private {?string} */
......
......@@ -3,6 +3,8 @@
// found in the LICENSE file.
import {assert} from 'chrome://resources/js/assert.m.js';
import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
import {PDFCreateOutOfProcessPlugin} from '../pdf/pdf_scripting_api.js';
/**
......@@ -20,36 +22,80 @@ export let PDFPlugin;
/**
* An interface to the PDF plugin.
* @interface
*/
export class PluginProxy {
/**
* Creates a new PluginProxy if the current instance is not set.
* @return {!PluginProxy} The singleton instance.
* @param {!Element} oopCompatObj The out of process compatibility element.
* @return {boolean} Whether the plugin exists and is compatible.
*/
static getInstance() {
if (instance === null) {
instance = new PluginProxy();
}
return assert(instance);
}
checkPluginCompatibility(oopCompatObj) {}
/** @return {boolean} Whether the plugin is ready. */
pluginReady() {}
/**
* @param {!PluginProxy} newInstance The PluginProxy
* instance to set for print preview construction.
* Creates the PDF plugin.
* @param {number} previewUid The unique ID of the preview UI.
* @param {number} index The preview index to load.
* @return {!PDFPlugin} The created plugin.
*/
static setInstance(newInstance) {
instance = newInstance;
}
createPlugin(previewUid, index) {}
/**
* @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 {number} scrollX The amount to horizontally scroll in pixels.
* @param {number} scrollY The amount to vertically scroll in pixels.
*/
scrollPosition(scrollX, scrollY) {}
/** @param {!KeyboardEvent} e Keyboard event to forward to the plugin. */
sendKeyEvent(e) {}
hideToolbars() {}
/**
* @param {boolean} eventsEnabled Whether pointer events should be captured
* by the plugin.
*/
setPointerEvents(eventsEnabled) {}
/**
* @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) {}
/** @param {?Function} keyEventCallback */
setKeyEventCallback(keyEventCallback) {}
/** @param {?Function} loadCompleteCallback */
setLoadCompleteCallback(loadCompleteCallback) {}
/** @param {?Function} viewportChangedCallback */
setViewportChangedCallback(viewportChangedCallback) {}
/** @param {boolean} darkMode Whether the page is in dark mode. */
darkModeChanged(darkMode) {}
}
/** @implements {PluginProxy} */
export class PluginProxyImpl {
constructor() {
/** @private {?PDFPlugin} */
this.plugin_ = null;
}
/**
* @param {!Element} oopCompatObj The out of process compatibility element.
* @return {boolean} Whether the plugin exists and is compatible.
*/
/** @override */
checkPluginCompatibility(oopCompatObj) {
const isOOPCompatible = oopCompatObj.postMessage;
oopCompatObj.parentElement.removeChild(oopCompatObj);
......@@ -57,17 +103,12 @@ export class PluginProxy {
return isOOPCompatible;
}
/** @return {boolean} Whether the plugin is ready. */
/** @override */
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 {!PDFPlugin} The created plugin.
*/
/** @override */
createPlugin(previewUid, index) {
assert(!this.plugin_);
const srcUrl = this.getPreviewUrl_(previewUid, index);
......@@ -94,73 +135,57 @@ export class PluginProxy {
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.
*/
/** @override */
resetPrintPreviewMode(previewUid, index, color, pages, modifiable) {
this.plugin_.resetPrintPreviewMode(
this.getPreviewUrl_(previewUid, index), color, pages, modifiable);
}
/**
* @param {number} scrollX The amount to horizontally scroll in pixels.
* @param {number} scrollY The amount to vertically scroll in pixels.
*/
/** @override */
scrollPosition(scrollX, scrollY) {
this.plugin_.scrollPosition(scrollX, scrollY);
}
/** @param {!KeyboardEvent} e Keyboard event to forward to the plugin. */
/** @override */
sendKeyEvent(e) {
this.plugin_.sendKeyEvent(e);
}
/** @override */
hideToolbars() {
this.plugin_.hideToolbars();
}
/**
* @param {boolean} eventsEnabled Whether pointer events should be captured
* by the plugin.
*/
/** @override */
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.
*/
/** @override */
loadPreviewPage(previewUid, pageIndex, index) {
this.plugin_.loadPreviewPage(
this.getPreviewUrl_(previewUid, pageIndex), index);
}
/** @param {?Function} keyEventCallback */
/** @override */
setKeyEventCallback(keyEventCallback) {
this.plugin_.setKeyEventCallback(keyEventCallback);
}
/** @param {?Function} loadCompleteCallback */
/** @override */
setLoadCompleteCallback(loadCompleteCallback) {
this.plugin_.setLoadCompleteCallback(loadCompleteCallback);
}
/** @param {?Function} viewportChangedCallback */
/** @override */
setViewportChangedCallback(viewportChangedCallback) {
this.plugin_.setViewportChangedCallback(viewportChangedCallback);
}
/** @param {boolean} darkMode Whether the page is in dark mode. */
/** @override */
darkModeChanged(darkMode) {
this.plugin_.darkModeChanged(darkMode);
}
}
/** @type {?PluginProxy} */
let instance = null;
addSingletonGetter(PluginProxyImpl);
......@@ -29,7 +29,7 @@ import {NativeLayer, NativeLayerImpl} from '../native_layer.js';
import {areRangesEqual} from '../print_preview_utils.js';
import {MARGIN_KEY_MAP} from './margin_control_container.js';
import {PluginProxy} from './plugin_proxy.js';
import {PluginProxy, PluginProxyImpl} from './plugin_proxy.js';
import {SettingsBehavior} from './settings_behavior.js';
/**
......@@ -153,7 +153,7 @@ Polymer({
/** @override */
created() {
this.pluginProxy_ = PluginProxy.getInstance();
this.pluginProxy_ = PluginProxyImpl.getInstance();
},
/**
......
......@@ -30,9 +30,9 @@ js_type_check("closure_compile") {
":destination_store_test",
":dpi_settings_test",
":duplex_settings_test",
":header_test",
":invalid_settings_browsertest",
#":header_test",
#":invalid_settings_browsertest",
#":key_event_test",
#":layout_settings_test",
#":link_container_test",
......@@ -50,7 +50,8 @@ js_type_check("closure_compile") {
#":pages_settings_test",
#":pdf_viewer_test",
#":pin_settings_test",
#":plugin_stub",
":test_plugin_proxy",
#":policy_test",
#":preview_area_test",
#":preview_generation_test",
......@@ -339,3 +340,39 @@ js_library("duplex_settings_test") {
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
js_library("header_test") {
deps = [
"..:chai_assert",
"..:test_plural_string_proxy",
"..:test_util.m",
"//chrome/browser/resources/print_preview:print_preview",
"//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:load_time_data.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
js_library("test_plugin_proxy") {
deps = [
"..:test_browser_proxy.m",
"//chrome/browser/resources/print_preview:print_preview",
"//ui/webui/resources/js:assert.m",
]
}
js_library("invalid_settings_browsertest") {
deps = [
":cloud_print_interface_stub",
":native_layer_stub",
":print_preview_test_utils",
":test_plugin_proxy",
"..:chai_assert",
"..:test_util.m",
"//chrome/browser/resources/print_preview:print_preview",
"//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:cr.m",
"//ui/webui/resources/js:load_time_data.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {Destination, DestinationStore, InvitationStore, LocalDestinationInfo, makeRecentDestination, NativeLayerImpl, PluginProxy, RecentDestination} from 'chrome://print/print_preview.js';
import {Destination, DestinationStore, InvitationStore, LocalDestinationInfo, makeRecentDestination, NativeLayerImpl, RecentDestination} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {keyEventOn} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
......@@ -12,7 +12,6 @@ import {eventToPromise} from '../test_util.m.js';
import {CloudPrintInterfaceStub} from './cloud_print_interface_stub.js';
import {NativeLayerStub} from './native_layer_stub.js';
import {PDFPluginStub} from './plugin_stub.js';
import {createDestinationStore, getDestinations, getGoogleDriveDestination, setupTestListenerElement} from './print_preview_test_utils.js';
window.destination_dialog_test = {};
......
......@@ -4,10 +4,13 @@
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, Error, PrintPreviewPluralStringProxyImpl, State} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {TestPluralStringProxy} from 'chrome://test/test_plural_string_proxy.js';
import {fakeDataBind} from 'chrome://test/test_util.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
import {TestPluralStringProxy} from '../test_plural_string_proxy.js';
import {fakeDataBind} from '../test_util.m.js';
window.header_test = {};
const header_test = window.header_test;
header_test.suiteName = 'HeaderTest';
/** @enum {string} */
header_test.TestNames = {
......@@ -17,24 +20,26 @@ header_test.TestNames = {
};
suite(header_test.suiteName, function() {
/** @type {?PrintPreviewHeaderElement} */
let header = null;
/** @type {!PrintPreviewHeaderElement} */
let header;
/** @type {TestPluralStringProxy} */
let pluralString = null;
/** @override */
setup(function() {
PolymerTest.clearBody();
document.body.innerHTML = '';
pluralString = new TestPluralStringProxy();
PrintPreviewPluralStringProxyImpl.instance_ = pluralString;
pluralString.text = '1 sheet of paper';
const model = document.createElement('print-preview-model');
const model = /** @type {!PrintPreviewModelElement} */ (
document.createElement('print-preview-model'));
document.body.appendChild(model);
header = document.createElement('print-preview-header');
header = /** @type {!PrintPreviewHeaderElement} */ (
document.createElement('print-preview-header'));
header.settings = model.settings;
model.set('settings.duplex.available', true);
model.set('settings.duplex.value', false);
......
......@@ -2,16 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {CloudPrintInterfaceEventType, CloudPrintInterfaceImpl, Destination, DestinationConnectionStatus, DestinationOrigin, DestinationStore, DestinationType, makeRecentDestination, NativeLayer, NativeLayerImpl, PluginProxy, ScalingType, State, whenReady} from 'chrome://print/print_preview.js';
import {CloudPrintInterfaceEventType, CloudPrintInterfaceImpl, Destination, DestinationConnectionStatus, DestinationOrigin, DestinationStore, DestinationType, LocalDestinationInfo, makeRecentDestination, MeasurementSystemUnitType, NativeInitialSettings, NativeLayer, NativeLayerImpl, PluginProxyImpl, ScalingType, State, whenReady} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {isWindows} from 'chrome://resources/js/cr.m.js';
import {CloudPrintInterfaceStub} from 'chrome://test/print_preview/cloud_print_interface_stub.js';
import {NativeLayerStub} from 'chrome://test/print_preview/native_layer_stub.js';
import {PDFPluginStub} from 'chrome://test/print_preview/plugin_stub.js';
import {createDestinationWithCertificateStatus, getCddTemplate, getDefaultMediaSize, getDefaultOrientation} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {eventToPromise, waitBeforeNextRender} from 'chrome://test/test_util.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
import {eventToPromise, waitBeforeNextRender} from '../test_util.m.js';
import {CloudPrintInterfaceStub} from './cloud_print_interface_stub.js';
import {NativeLayerStub} from './native_layer_stub.js';
import {createDestinationWithCertificateStatus, getCddTemplate, getDefaultMediaSize, getDefaultOrientation} from './print_preview_test_utils.js';
import {TestPluginProxy} from './test_plugin_proxy.js';
window.invalid_settings_browsertest = {};
const invalid_settings_browsertest = window.invalid_settings_browsertest;
invalid_settings_browsertest.suiteName = 'InvalidSettingsBrowserTest';
/** @enum {string} */
invalid_settings_browsertest.TestNames = {
......@@ -22,14 +27,14 @@ invalid_settings_browsertest.TestNames = {
};
suite(invalid_settings_browsertest.suiteName, function() {
/** @type {?PrintPreviewAppElement} */
let page = null;
/** @type {!PrintPreviewAppElement} */
let page;
/** @type {?NativeLayer} */
let nativeLayer = null;
/** @type {!NativeLayerStub} */
let nativeLayer;
/** @type {?CloudPrintInterface} */
let cloudPrintInterface = null;
/** @type {!CloudPrintInterfaceStub} */
let cloudPrintInterface;
/** @type {!NativeInitialSettings} */
const initialSettings = {
......@@ -37,12 +42,16 @@ suite(invalid_settings_browsertest.suiteName, function() {
isInAppKioskMode: false,
thousandsDelimiter: ',',
decimalDelimiter: '.',
unitType: 1,
unitType: MeasurementSystemUnitType.IMPERIAL,
previewIsPdf: false,
previewModifiable: true,
destinationsManaged: false,
previewIsFromArc: false,
syncAvailable: true,
documentTitle: 'title',
documentHasSelection: true,
shouldPrintSelectionOnly: false,
uiLocale: 'en-us',
printerName: 'FooDevice',
pdfPrinterDisabled: false,
serializedAppStateStr: null,
......@@ -79,14 +88,15 @@ suite(invalid_settings_browsertest.suiteName, function() {
nativeLayer.setLocalDestinationCapabilities(
getCddTemplate(initialSettings.printerName));
}
const pluginProxy = new PDFPluginStub();
const pluginProxy = new TestPluginProxy();
pluginProxy.setPluginCompatible(pluginCompatible);
PluginProxy.setInstance(pluginProxy);
PluginProxyImpl.instance_ = pluginProxy;
page = document.createElement('print-preview-app');
page = /** @type {!PrintPreviewAppElement} */ (
document.createElement('print-preview-app'));
document.body.appendChild(page);
page.$.documentInfo.init(true, false, false, 'title', false);
const previewArea = page.$.previewArea;
page.$$('#documentInfo').init(true, false, false, 'title', false);
const previewArea = page.$$('#previewArea');
}
/**
......@@ -122,7 +132,8 @@ suite(invalid_settings_browsertest.suiteName, function() {
assert(invalid_settings_browsertest.TestNames.NoPDFPluginError),
function() {
createPage(false);
const previewArea = page.$.previewArea;
const previewArea = /** @type {!PrintPreviewPreviewAreaElement} */ (
page.$$('#previewArea'));
return nativeLayer.whenCalled('getInitialSettings').then(function() {
const overlayEl = previewArea.$$('.preview-area-overlay-layer');
......@@ -165,13 +176,16 @@ suite(invalid_settings_browsertest.suiteName, function() {
'printer.';
// Get references to relevant elements.
const previewAreaEl = page.$.previewArea;
const previewAreaEl = /** @type {!PrintPreviewPreviewAreaElement} */ (
page.$$('#previewArea'));
const overlay = previewAreaEl.$$('.preview-area-overlay-layer');
const messageEl = previewAreaEl.$$('.preview-area-message');
const sidebar = page.$$('print-preview-sidebar');
const sidebar = /** @type {!PrintPreviewSidebarElement} */ (
page.$$('print-preview-sidebar'));
let printButton = null;
const destinationSettings =
sidebar.$$('print-preview-destination-settings');
/** @type {!PrintPreviewDestinationSettingsElement} */ (
sidebar.$$('print-preview-destination-settings'));
return waitBeforeNextRender(page)
.then(() => {
......@@ -184,7 +198,8 @@ suite(invalid_settings_browsertest.suiteName, function() {
]);
})
.then(function() {
destinationSettings.destinationStore_.startLoadAllDestinations();
destinationSettings.getDestinationStoreForTest()
.startLoadAllDestinations();
// Wait for the preview request.
return Promise.all([
nativeLayer.whenCalled('getPrinterCapabilities'),
......@@ -203,17 +218,19 @@ suite(invalid_settings_browsertest.suiteName, function() {
// Select should still be enabled so that the user can select a
// new printer.
assertFalse(destinationSettings.$.destinationSelect.disabled);
assertFalse(
destinationSettings.$$('#destinationSelect').disabled);
// Reset
nativeLayer.reset();
// Select a new destination
const barDestination =
destinationSettings.destinationStore_.destinations().find(
d => d.id === 'BarDevice');
destinationSettings.destinationStore_.selectDestination(
barDestination);
destinationSettings.getDestinationStoreForTest()
.destinations()
.find(d => d.id === 'BarDevice');
destinationSettings.getDestinationStoreForTest()
.selectDestination(assert(barDestination));
// Wait for the preview to be updated.
return nativeLayer.whenCalled('getPreview');
......@@ -275,17 +292,23 @@ suite(invalid_settings_browsertest.suiteName, function() {
'computer\'s system settings.';
// Get references to relevant elements.
const previewAreaEl = page.$.previewArea;
const previewAreaEl = /** @type {!PrintPreviewPreviewAreaElement} */ (
page.$$('#previewArea'));
const overlayEl = previewAreaEl.$$('.preview-area-overlay-layer');
const messageEl = previewAreaEl.$$('.preview-area-message');
const sidebar = page.$$('print-preview-sidebar');
const sidebar = /** @type {!PrintPreviewSidebarElement} */ (
page.$$('print-preview-sidebar'));
let printButton = null;
const destinationSettings =
sidebar.$$('print-preview-destination-settings');
/** @type {!PrintPreviewDestinationSettingsElement} */ (
sidebar.$$('print-preview-destination-settings'));
const scalingSettings =
/** @type {!PrintPreviewNumberSettingsSectionElement} */ (
sidebar.$$('print-preview-scaling-settings')
.$$('print-preview-number-settings-section');
const layoutSettings = sidebar.$$('print-preview-layout-settings');
.$$('print-preview-number-settings-section'));
const layoutSettings =
/** @type {!PrintPreviewLayoutSettingsElement} */ (
sidebar.$$('print-preview-layout-settings'));
return waitBeforeNextRender(page)
.then(() => {
......@@ -300,7 +323,7 @@ suite(invalid_settings_browsertest.suiteName, function() {
// Set this to enable the scaling input.
page.setSetting('scalingType', ScalingType.CUSTOM);
destinationSettings.destinationStore_
destinationSettings.getDestinationStoreForTest()
.startLoadCloudDestinations();
return eventToPromise(
......@@ -328,14 +351,15 @@ suite(invalid_settings_browsertest.suiteName, function() {
// The destination select dropdown should be enabled, so that the
// user can select a new printer.
assertFalse(destinationSettings.$.destinationSelect.disabled);
assertFalse(
destinationSettings.$$('#destinationSelect').disabled);
// Reset
nativeLayer.reset();
// Select a new, valid cloud destination.
destinationSettings.destinationStore_.selectDestination(
validPrinter);
destinationSettings.getDestinationStoreForTest()
.selectDestination(validPrinter);
return nativeLayer.whenCalled('getPreview');
})
......@@ -349,7 +373,8 @@ suite(invalid_settings_browsertest.suiteName, function() {
assertFalse(scalingSettings.$$('cr-input').disabled);
// The destination select dropdown should still be enabled.
assertFalse(destinationSettings.$.destinationSelect.disabled);
assertFalse(
destinationSettings.$$('#destinationSelect').disabled);
// Message text should have changed and overlay should be
// invisible.
......@@ -373,13 +398,16 @@ suite(invalid_settings_browsertest.suiteName, function() {
setupInvalidCertificateTest([validPrinter, invalidPrinter]);
// Get references to relevant elements.
const previewAreaEl = page.$.previewArea;
const previewAreaEl = /** @type {!PrintPreviewPreviewAreaElement} */ (
page.$$('#previewArea'));
const overlayEl = previewAreaEl.$$('.preview-area-overlay-layer');
const messageEl = previewAreaEl.$$('.preview-area-message');
const sidebar = page.$$('print-preview-sidebar');
const sidebar = /** @type {!PrintPreviewSidebarElement} */ (
page.$$('print-preview-sidebar'));
let printButton = null;
const destinationSettings =
sidebar.$$('print-preview-destination-settings');
/** @type {!PrintPreviewDestinationSettingsElement} */ (
sidebar.$$('print-preview-destination-settings'));
return waitBeforeNextRender(page)
.then(() => {
......@@ -393,7 +421,7 @@ suite(invalid_settings_browsertest.suiteName, function() {
.then(function() {
// Start loading cloud destinations so that the printer
// capabilities arrive.
destinationSettings.destinationStore_
destinationSettings.getDestinationStoreForTest()
.startLoadCloudDestinations();
return nativeLayer.whenCalled('getPreview');
})
......@@ -407,9 +435,9 @@ suite(invalid_settings_browsertest.suiteName, function() {
// Select the invalid destination and wait for the event.
const whenInvalid = eventToPromise(
DestinationStore.EventType.ERROR,
destinationSettings.destinationStore_);
destinationSettings.destinationStore_.selectDestination(
invalidPrinter);
destinationSettings.getDestinationStoreForTest());
destinationSettings.getDestinationStoreForTest()
.selectDestination(invalidPrinter);
return whenInvalid;
})
.then(function() {
......@@ -423,9 +451,9 @@ suite(invalid_settings_browsertest.suiteName, function() {
// Reselect the valid cloud destination.
const whenSelected = eventToPromise(
DestinationStore.EventType.DESTINATION_SELECT,
destinationSettings.destinationStore_);
destinationSettings.destinationStore_.selectDestination(
validPrinter);
destinationSettings.getDestinationStoreForTest());
destinationSettings.getDestinationStoreForTest()
.selectDestination(validPrinter);
return whenSelected;
})
.then(function() {
......
......@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {NativeLayer, NativeLayerImpl, PluginProxy} from 'chrome://print/print_preview.js';
import {NativeLayer, NativeLayerImpl, PluginProxyImpl} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {isChromeOS, isMac, isWindows} from 'chrome://resources/js/cr.m.js';
import {keyEventOn} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {NativeLayerStub} from 'chrome://test/print_preview/native_layer_stub.js';
import {PDFPluginStub} from 'chrome://test/print_preview/plugin_stub.js';
import {getCddTemplateWithAdvancedSettings, getDefaultInitialSettings} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {TestPluginProxy} from 'chrome://test/print_preview/test_plugin_proxy.js';
import {eventToPromise, flushTasks} from 'chrome://test/test_util.m.js';
window.key_event_test = {};
......@@ -44,8 +44,8 @@ suite(key_event_test.suiteName, function() {
getCddTemplateWithAdvancedSettings(1, initialSettings.printerName));
nativeLayer.setPageCount(3);
NativeLayerImpl.instance_ = nativeLayer;
const pluginProxy = new PDFPluginStub();
PluginProxy.setInstance(pluginProxy);
const pluginProxy = new TestPluginProxy();
PluginProxyImpl.instance_ = pluginProxy;
document.body.innerHTML = '';
page = document.createElement('print-preview-app');
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {BackgroundGraphicsModeRestriction, NativeLayer, NativeLayerImpl, PluginProxy, PrintPreviewPluralStringProxyImpl} from 'chrome://print/print_preview.js';
import {BackgroundGraphicsModeRestriction, NativeLayer, NativeLayerImpl, PluginProxyImpl, PrintPreviewPluralStringProxyImpl} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {NativeLayerStub} from 'chrome://test/print_preview/native_layer_stub.js';
import {PDFPluginStub} from 'chrome://test/print_preview/plugin_stub.js';
import {getCddTemplate, getDefaultInitialSettings} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {TestPluginProxy} from 'chrome://test/print_preview/test_plugin_proxy.js';
import {TestPluralStringProxy} from 'chrome://test/test_plural_string_proxy.js';
window.policy_tests = {};
......@@ -48,8 +48,8 @@ suite(policy_tests.suiteName, function() {
getCddTemplate(initialSettings.printerName));
nativeLayer.setPageCount(3);
NativeLayerImpl.instance_ = nativeLayer;
const pluginProxy = new PDFPluginStub();
PluginProxy.setInstance(pluginProxy);
const pluginProxy = new TestPluginProxy();
PluginProxyImpl.instance_ = pluginProxy;
page = document.createElement('print-preview-app');
document.body.appendChild(page);
......
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, Error, Margins, MeasurementSystem, MeasurementSystemUnitType, NativeLayer, NativeLayerImpl, PluginProxy, PreviewAreaState, Size, State} from 'chrome://print/print_preview.js';
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, Error, Margins, MeasurementSystem, MeasurementSystemUnitType, NativeLayer, NativeLayerImpl, PluginProxyImpl, PreviewAreaState, Size, State} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {NativeLayerStub} from 'chrome://test/print_preview/native_layer_stub.js';
import {PDFPluginStub} from 'chrome://test/print_preview/plugin_stub.js';
import {getCddTemplate} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {TestPluginProxy} from 'chrome://test/print_preview/test_plugin_proxy.js';
import {fakeDataBind} from 'chrome://test/test_util.m.js';
window.preview_area_test = {};
......@@ -31,8 +31,8 @@ suite(preview_area_test.suiteName, function() {
nativeLayer = new NativeLayerStub();
NativeLayerImpl.instance_ = nativeLayer;
nativeLayer.setPageCount(3);
pluginProxy = new PDFPluginStub();
PluginProxy.setInstance(pluginProxy);
pluginProxy = new TestPluginProxy();
PluginProxyImpl.instance_ = pluginProxy;
document.body.innerHTML = '';
const model = document.createElement('print-preview-model');
......
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {ColorMode, Destination, DestinationConnectionStatus, DestinationOrigin, DestinationState, DestinationType, Margins, MarginsType, NativeLayer, NativeLayerImpl, PluginProxy, ScalingType} from 'chrome://print/print_preview.js';
import {ColorMode, Destination, DestinationConnectionStatus, DestinationOrigin, DestinationState, DestinationType, Margins, MarginsType, NativeLayer, NativeLayerImpl, PluginProxyImpl, ScalingType} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {NativeLayerStub} from 'chrome://test/print_preview/native_layer_stub.js';
import {PDFPluginStub} from 'chrome://test/print_preview/plugin_stub.js';
import {getCddTemplate, getDefaultInitialSettings} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {TestPluginProxy} from 'chrome://test/print_preview/test_plugin_proxy.js';
window.preview_generation_test = {};
preview_generation_test.suiteName = 'PreviewGenerationTest';
......@@ -71,8 +71,8 @@ suite(preview_generation_test.suiteName, function() {
nativeLayer.setLocalDestinationCapabilities(
getCddTemplate(initialSettings.printerName));
nativeLayer.setPageCount(3);
const pluginProxy = new PDFPluginStub();
PluginProxy.setInstance(pluginProxy);
const pluginProxy = new TestPluginProxy();
PluginProxyImpl.instance_ = pluginProxy;
page = document.createElement('print-preview-app');
document.body.appendChild(page);
......
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {NativeLayer, NativeLayerImpl, PluginProxy} from 'chrome://print/print_preview.js';
import {NativeLayer, NativeLayerImpl, PluginProxyImpl} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {NativeLayerStub} from 'chrome://test/print_preview/native_layer_stub.js';
import {PDFPluginStub} from 'chrome://test/print_preview/plugin_stub.js';
import {getDefaultInitialSettings} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {TestPluginProxy} from 'chrome://test/print_preview/test_plugin_proxy.js';
window.print_button_test = {};
print_button_test.suiteName = 'PrintButtonTest';
......@@ -43,9 +43,9 @@ suite(print_button_test.suiteName, function() {
];
nativeLayer.setLocalDestinations(localDestinationInfos);
const pluginProxy = new PDFPluginStub();
const pluginProxy = new TestPluginProxy();
pluginProxy.setPluginCompatible(true);
PluginProxy.setInstance(pluginProxy);
PluginProxyImpl.instance_ = pluginProxy;
page = document.createElement('print-preview-app');
document.body.appendChild(page);
......
......@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {CloudPrintInterface, CloudPrintInterfaceImpl, Destination, DuplexMode, NativeLayer, NativeLayerImpl, PluginProxy} from 'chrome://print/print_preview.js';
import {CloudPrintInterface, CloudPrintInterfaceImpl, Destination, DuplexMode, NativeLayer, NativeLayerImpl, PluginProxyImpl} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {webUIListenerCallback} from 'chrome://resources/js/cr.m.js';
import {CloudPrintInterfaceStub} from 'chrome://test/print_preview/cloud_print_interface_stub.js';
import {NativeLayerStub} from 'chrome://test/print_preview/native_layer_stub.js';
import {PDFPluginStub} from 'chrome://test/print_preview/plugin_stub.js';
import {getCddTemplate, getGoogleDriveDestination} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {TestPluginProxy} from 'chrome://test/print_preview/test_plugin_proxy.js';
window.print_preview_app_test = {};
print_preview_app_test.suiteName = 'PrintPreviewAppTest';
......@@ -32,7 +32,7 @@ suite(print_preview_app_test.suiteName, function() {
/** @type {?CloudPrintInterface} */
let cloudPrintInterface = null;
/** @type {?PluginProxy} */
/** @type {?TestPluginProxy} */
let pluginProxy = null;
/** @type {!NativeInitialSettings} */
......@@ -78,8 +78,8 @@ suite(print_preview_app_test.suiteName, function() {
NativeLayerImpl.instance_ = nativeLayer;
cloudPrintInterface = new CloudPrintInterfaceStub();
CloudPrintInterfaceImpl.instance_ = cloudPrintInterface;
pluginProxy = new PDFPluginStub();
PluginProxy.setInstance(pluginProxy);
pluginProxy = new TestPluginProxy();
PluginProxyImpl.instance_ = pluginProxy;
});
// Regression test for https://crbug.com/936029
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {getInstance, MarginsType, NativeLayer, NativeLayerImpl, PluginProxy, ScalingType} from 'chrome://print/print_preview.js';
import {getInstance, MarginsType, NativeLayer, NativeLayerImpl, PluginProxyImpl, ScalingType} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {isChromeOS} from 'chrome://resources/js/cr.m.js';
import {NativeLayerStub} from 'chrome://test/print_preview/native_layer_stub.js';
import {PDFPluginStub} from 'chrome://test/print_preview/plugin_stub.js';
import {getCddTemplate, getCddTemplateWithAdvancedSettings, getDefaultInitialSettings} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {TestPluginProxy} from 'chrome://test/print_preview/test_plugin_proxy.js';
window.restore_state_test = {};
restore_state_test.suiteName = 'RestoreStateTest';
......@@ -81,8 +81,8 @@ suite(restore_state_test.suiteName, function() {
nativeLayer.setInitialSettings(initialSettings);
nativeLayer.setLocalDestinationCapabilities(
getCddTemplateWithAdvancedSettings(2, initialSettings.printerName));
const pluginProxy = new PDFPluginStub();
PluginProxy.setInstance(pluginProxy);
const pluginProxy = new TestPluginProxy();
PluginProxyImpl.instance_ = pluginProxy;
page = document.createElement('print-preview-app');
document.body.appendChild(page);
......@@ -304,11 +304,11 @@ suite(restore_state_test.suiteName, function() {
nativeLayer.setLocalDestinationCapabilities(
getCddTemplate(initialSettings.printerName));
const pluginProxy = new TestPluginProxy();
PluginProxyImpl.instance_ = pluginProxy;
page = document.createElement('print-preview-app');
document.body.appendChild(page);
const previewArea = page.$$('print-preview-preview-area');
previewArea.plugin_ =
new PDFPluginStub(previewArea.onPluginLoadComplete_.bind(previewArea));
return nativeLayer.whenCalled('getInitialSettings')
.then(function() {
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, NativeLayer, NativeLayerImpl, PluginProxy, whenReady} from 'chrome://print/print_preview.js';
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, NativeLayer, NativeLayerImpl, PluginProxyImpl, whenReady} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {isWindows} from 'chrome://resources/js/cr.m.js';
import {NativeLayerStub} from 'chrome://test/print_preview/native_layer_stub.js';
import {PDFPluginStub} from 'chrome://test/print_preview/plugin_stub.js';
import {getCddTemplate, getDefaultInitialSettings, selectOption} from 'chrome://test/print_preview/print_preview_test_utils.js';
import {TestPluginProxy} from 'chrome://test/print_preview/test_plugin_proxy.js';
import {eventToPromise, waitBeforeNextRender} from 'chrome://test/test_util.m.js';
window.system_dialog_browsertest = {};
......@@ -44,8 +44,8 @@ suite(system_dialog_browsertest.suiteName, function() {
nativeLayer.setInitialSettings(initialSettings);
nativeLayer.setLocalDestinationCapabilities(
getCddTemplate(initialSettings.printerName));
const pluginProxy = new PDFPluginStub();
PluginProxy.setInstance(pluginProxy);
const pluginProxy = new TestPluginProxy();
PluginProxyImpl.instance_ = pluginProxy;
const page = document.createElement('print-preview-app');
document.body.appendChild(page);
......
......@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {PDFPlugin, PluginProxy} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {TestBrowserProxy} from 'chrome://test/test_browser_proxy.m.js';
import {TestBrowserProxy} from '../test_browser_proxy.m.js';
/**
* Test version of the PluginProxy.
* @implements {PluginProxy}
*/
export class PDFPluginStub extends TestBrowserProxy {
export class TestPluginProxy extends TestBrowserProxy {
constructor() {
super(['loadPreviewPage']);
......@@ -28,99 +30,67 @@ export class PDFPluginStub extends TestBrowserProxy {
this.fakePlugin_ = null;
}
/** @param {boolean} Whether the PDF plugin should be compatible. */
/**
* @param {boolean} compatible Whether the PDF plugin should be compatible.
*/
setPluginCompatible(compatible) {
this.compatible_ = compatible;
}
/**
* @param {?Function} loadCompleteCallback Callback to call when the preview
* loads.
*/
/** @override */
setLoadCompleteCallback(loadCompleteCallback) {
assert(!this.loadCompleteCallback_);
this.loadCompleteCallback_ = loadCompleteCallback;
}
/**
* @param {?Function} preloadCallback Callback to call before the preview
* loads.
*/
/** @param {?Function} preloadCallback */
setPreloadCallback(preloadCallback) {
this.preloadCallback_ = preloadCallback;
}
/** @param {?Function} keyEventCallback */
/** @override */
setKeyEventCallback(keyEventCallback) {}
/** @param {?Function} viewportChangedCallback */
/** @override */
setViewportChangedCallback(viewportChangedCallback) {
this.viewportChangedCallback_ = viewportChangedCallback;
}
/**
* @param {!Element} oopCompatObj The out of process compatibility element.
* @return {boolean} Whether the plugin exists and is compatible.
*/
/** @override */
checkPluginCompatibility(oopCompatObj) {
return this.compatible_;
}
/** @return {boolean} Whether the plugin is ready. */
/** @override */
pluginReady() {
return !!this.fakePlugin_;
}
/**
* 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.PDFPlugin}
*/
/** @override */
createPlugin(previewUid, index) {
if (!this.compatible_) {
return null;
}
this.fakePlugin_ = document.createElement('div');
this.fakePlugin_ =
/** @type {!HTMLDivElement} */ (document.createElement('div'));
this.fakePlugin_.classList.add('preview-area-plugin');
this.fakePlugin_.id = 'pdf-viewer';
return this.fakePlugin_;
return /** @type {!PDFPlugin} */ (this.fakePlugin_);
}
/**
* @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.
*/
/** @override */
resetPrintPreviewMode(previewUid, index, color, pages, modifiable) {}
/**
* @param {number} scrollX The amount to horizontally scroll in pixels.
* @param {number} scrollY The amount to vertically scroll in pixels.
*/
/** @override */
scrollPosition(scrollX, scrollY) {}
/** @param {!KeyEvent} e Keyboard event to forward to the plugin. */
/** @override */
sendKeyEvent(e) {}
/** @override */
hideToolbars() {}
/**
* @param {boolean} eventsOn Whether pointer events should be captured by
* the plugin.
*/
/** @override */
setPointerEvents(eventsOn) {}
/**
* Called when the preview area wants the plugin to load a preview page.
* Immediately calls loadCompleteCallback_().
* @param {number} previewUid The unique ID of the preview UI.
* @param {number} pageIndex The page index to load.
* @param {number} index The preview index.
*/
/** @override */
loadPreviewPage(previewUid, pageIndex, index) {
this.methodCalled(
'loadPreviewPage',
......@@ -133,6 +103,7 @@ export class PDFPluginStub extends TestBrowserProxy {
}
}
/** @override */
darkModeChanged(darkMode) {}
/**
......@@ -142,7 +113,6 @@ export class PDFPluginStub extends TestBrowserProxy {
* @param {number} pageWidth The page width in pixels.
* @param {number} viewportWidth The viewport width in pixels.
* @param {number} viewportHeight The viewport height in pixels.
* @private
*/
triggerVisualStateChange(
pageX, pageY, pageWidth, viewportWidth, viewportHeight) {
......
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