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

Print Preview: Add test for hiding preview behavior

Test that the preview hides when the user clicks print before the
preview has loaded if the printer is local, and that the preview
remains open until the preview loads if printing to PDF.

Bug: 865544
Change-Id: I1fd89a565f65f4aa0c8115facc8817478896b141
Reviewed-on: https://chromium-review.googlesource.com/1153621
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579209}
parent 0e9a499d
......@@ -884,3 +884,34 @@ TEST_F('PrintPreviewDestinationListTest', 'FireDestinationSelected',
function() {
this.runMochaTest(destination_list_test.TestNames.FireDestinationSelected);
});
PrintPreviewPrintButtonTest = class extends NewPrintPreviewTest {
/** @override */
get browsePreload() {
return 'chrome://print/new/app.html';
}
/** @override */
get extraLibraries() {
return super.extraLibraries.concat([
'../test_browser_proxy.js',
'native_layer_stub.js',
'plugin_stub.js',
'print_preview_test_utils.js',
'print_button_test.js',
]);
}
/** @override */
get suiteName() {
return print_button_test.suiteName;
}
};
TEST_F('PrintPreviewPrintButtonTest', 'LocalPrintHidePreview', function() {
this.runMochaTest(print_button_test.TestNames.LocalPrintHidePreview);
});
TEST_F('PrintPreviewPrintButtonTest', 'PDFPrintVisiblePreview', function() {
this.runMochaTest(print_button_test.TestNames.PDFPrintVisiblePreview);
});
// 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('print_button_test', function() {
/** @enum {string} */
const TestNames = {
LocalPrintHidePreview: 'local print hide preview',
PDFPrintVisiblePreview: 'pdf print visible preview',
};
const suiteName = 'PrintButtonTest';
suite(suiteName, function() {
/** @type {?PrintPreviewAppElement} */
let page = null;
/** @type {?print_preview.NativeLayer} */
let nativeLayer = null;
/** @type {boolean} */
let printBeforePreviewReady = false;
/** @type {boolean} */
let previewHidden = false;
/** @type {!print_preview.NativeInitialSettings} */
const initialSettings =
print_preview_test_utils.getDefaultInitialSettings();
/** @override */
setup(function() {
nativeLayer = new print_preview.NativeLayerStub();
print_preview.NativeLayer.setInstance(nativeLayer);
PolymerTest.clearBody();
nativeLayer.setInitialSettings(initialSettings);
let localDestinationInfos = [
{printerName: 'FooName', deviceName: 'FooDevice'},
];
nativeLayer.setLocalDestinations(localDestinationInfos);
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getCddTemplate(
initialSettings.printerName));
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getPdfPrinter());
const pluginProxy = new print_preview.PDFPluginStub();
pluginProxy.setPluginCompatible(true);
print_preview_new.PluginProxy.setInstance(pluginProxy);
page = document.createElement('print-preview-app');
document.body.appendChild(page);
pluginProxy.setLoadCallback(() => {
// Print before calling previewArea.onPluginLoad_. This simulates the
// user clicking the print button while the preview is still loading,
// since previewArea.onPluginLoad_() indicates to the UI that the
// preview is ready.
if (printBeforePreviewReady) {
const header = page.$$('print-preview-header');
const printButton = header.$$('.print');
assertFalse(printButton.disabled);
printButton.click();
}
const previewArea = page.$.previewArea;
previewArea.onPluginLoad_(true);
});
previewHidden = false;
nativeLayer.whenCalled('hidePreview').then(() => {
previewHidden = true;
});
});
function waitForInitialPreview() {
return nativeLayer.whenCalled('getInitialSettings')
.then(function() {
page.destinationStore_.startLoadDestinations(
print_preview.PrinterType.LOCAL_PRINTER);
// Wait for the preview request.
return Promise.all([
nativeLayer.whenCalled('getPrinterCapabilities'),
nativeLayer.whenCalled('getPreview')
]);
});
}
// Tests that hidePreview() is called before print() if a local printer is
// selected and the user clicks print while the preview is loading.
test(assert(TestNames.LocalPrintHidePreview), function() {
printBeforePreviewReady = true;
return waitForInitialPreview().then(function() {
// Wait for the print request.
return nativeLayer.whenCalled('print');
}).then(function(printTicket) {
assertTrue(previewHidden);
// Verify that the printer name is correct.
assertEquals('FooDevice', JSON.parse(printTicket).deviceName);
return nativeLayer.whenCalled('dialogClose');
});
});
// Tests that hidePreview() is not called if Save as PDF is selected and
// the user clicks print while the preview is loading.
test(assert(TestNames.PDFPrintVisiblePreview), function() {
printBeforePreviewReady = false;
return waitForInitialPreview().then(function() {
// Setup to print before the preview loads.
printBeforePreviewReady = true;
// Select Save as PDF destination
const pdfDestination = page.destinationStore_.destinations().find(
d => d.id == 'Save as PDF');
assertTrue(!!pdfDestination);
page.destinationStore_.selectDestination(pdfDestination);
// Reload preview and wait for print.
return Promise.all([
nativeLayer.whenCalled('getPrinterCapabilities'),
nativeLayer.whenCalled('getPreview'),
nativeLayer.whenCalled('print')
]);
}).then(function(args) {
assertFalse(previewHidden);
const printTicket = args[2];
// Verify that the printer name is correct.
assertEquals('Save as PDF', JSON.parse(printTicket).deviceName);
return nativeLayer.whenCalled('dialogClose');
});
});
});
return {
suiteName: suiteName,
TestNames: TestNames,
};
});
......@@ -166,6 +166,38 @@ cr.define('print_preview_test_utils', function() {
return dest;
}
/**
* @return {!print_preview.PrinterCapabilitiesResponse} The capabilities of
* the Save as PDF destination.
*/
function getPdfPrinter() {
return {
printer: {
deviceName: 'Save as PDF',
},
capabilities: {
version: '1.0',
printer: {
page_orientation: {
option: [
{type: 'AUTO', is_default: true}, {type: 'PORTRAIT'},
{type: 'LANDSCAPE'}
]
},
color: {option: [{type: 'STANDARD_COLOR', is_default: true}]},
media_size: {
option: [{
name: 'NA_LETTER',
width_microns: 0,
height_microns: 0,
is_default: true
}]
}
}
}
};
}
/**
* Get the default media size for |device|.
* @param {!print_preview.PrinterCapabilitiesResponse} device
......@@ -259,5 +291,6 @@ cr.define('print_preview_test_utils', function() {
getDestinations: getDestinations,
getMediaSizeCapabilityWithCustomNames:
getMediaSizeCapabilityWithCustomNames,
getPdfPrinter: getPdfPrinter,
};
});
......@@ -107,38 +107,6 @@ cr.define('print_preview_test', function() {
'element="' + el.id + '" of class "' + el.classList + '"');
}
/**
* @return {!print_preview.PrinterCapabilitiesResponse} The capabilities of
* the Save as PDF destination.
*/
function getPdfPrinter() {
return {
printer: {
deviceName: 'Save as PDF',
},
capabilities: {
version: '1.0',
printer: {
page_orientation: {
option: [
{type: 'AUTO', is_default: true}, {type: 'PORTRAIT'},
{type: 'LANDSCAPE'}
]
},
color: {option: [{type: 'STANDARD_COLOR', is_default: true}]},
media_size: {
option: [{
name: 'NA_LETTER',
width_microns: 0,
height_microns: 0,
is_default: true
}]
}
}
}
};
}
/**
* Gets a serialized app state string with some non-default values.
* @return {string}
......@@ -618,7 +586,8 @@ cr.define('print_preview_test', function() {
initialSettings.printerName = 'Save as PDF';
// Set PDF printer
nativeLayer.setLocalDestinationCapabilities(getPdfPrinter());
nativeLayer.setLocalDestinationCapabilities(
print_preview_test_utils.getPdfPrinter());
setInitialSettings();
return nativeLayer.whenCalled('getInitialSettings')
......@@ -1661,7 +1630,7 @@ cr.define('print_preview_test', function() {
// Test that Mac "Open PDF in Preview" link is treated correctly as a
// local printer. See crbug.com/741341 and crbug.com/741528
test('MacOpenPDFInPreview', function() {
const device = getPdfPrinter();
const device = print_preview_test_utils.getPdfPrinter();
initialSettings.printerName = device.printer.deviceName;
return setupSettingsAndDestinationsWithCapabilities(device)
.then(function() {
......@@ -1691,7 +1660,7 @@ cr.define('print_preview_test', function() {
// Test that the OpenPDFInPreview link is correctly disabled when the
// print ticket is invalid.
test('MacOpenPDFInPreviewBadPrintTicket', function() {
const device = getPdfPrinter();
const device = print_preview_test_utils.getPdfPrinter();
initialSettings.printerName = device.printer.deviceName;
const openPdfPreviewLink = $('open-pdf-in-preview-link');
return Promise
......
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