Commit 1a6a1f02 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Add tests for "Open PDF in Preview" and System Dialog

Add tests to verify print preview behaves as expected when the "Open
PDF in Preview" link is clicked on MacOS, and when "Print with System
Dialog" is clicked on Windows.

Bug: 741341, 741528
Change-Id: I1174ec935eeea1b90e7853eb1e13d1fe3c596809
Reviewed-on: https://chromium-review.googlesource.com/570831
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486754}
parent 648712d3
...@@ -17,7 +17,8 @@ cr.define('print_preview', function() { ...@@ -17,7 +17,8 @@ cr.define('print_preview', function() {
'getPrivetPrinters', 'getPrivetPrinters',
'getPrinterCapabilities', 'getPrinterCapabilities',
'print', 'print',
'setupPrinter' 'setupPrinter',
'startHideDialog'
]); ]);
/** /**
...@@ -130,12 +131,15 @@ cr.define('print_preview', function() { ...@@ -130,12 +131,15 @@ cr.define('print_preview', function() {
/** @override */ /** @override */
print: function( print: function(
destination, printTicketStore, cloudPrintInterface, documentInfo) { destination, printTicketStore, cloudPrintInterface, documentInfo,
opt_isOpenPdfInPreview, opt_showSystemDialog) {
this.methodCalled('print', { this.methodCalled('print', {
destination: destination, destination: destination,
printTicketStore: printTicketStore, printTicketStore: printTicketStore,
cloudPrintInterface: cloudPrintInterface, cloudPrintInterface: cloudPrintInterface,
documentInfo: documentInfo, documentInfo: documentInfo,
openPdfInPreview: opt_isOpenPdfInPreview || false,
showSystemDialog: opt_showSystemDialog || false,
}); });
return Promise.resolve(); return Promise.resolve();
}, },
...@@ -148,8 +152,10 @@ cr.define('print_preview', function() { ...@@ -148,8 +152,10 @@ cr.define('print_preview', function() {
Promise.resolve(this.setupPrinterResponse_); Promise.resolve(this.setupPrinterResponse_);
}, },
/** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ /** @override */
startHideDialog: function () {}, startHideDialog: function () {
this.methodCalled('startHideDialog');
},
/** /**
* @param {!print_preview.NativeInitialSettings} settings The settings * @param {!print_preview.NativeInitialSettings} settings The settings
......
...@@ -144,6 +144,42 @@ cr.define('print_preview_test', function() { ...@@ -144,6 +144,42 @@ cr.define('print_preview_test', function() {
}; };
} }
/**
* @return {!print_preview.PrinterCapabilitiesResponse} The capabilities of
* the Save as PDF destination.
*/
function getPdfPrinter() {
return {
printerId: '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|. * Get the default media size for |device|.
* @param {!print_preview.PrinterCapabilitiesResponse} device * @param {!print_preview.PrinterCapabilitiesResponse} device
...@@ -533,36 +569,7 @@ cr.define('print_preview_test', function() { ...@@ -533,36 +569,7 @@ cr.define('print_preview_test', function() {
initialSettings.systemDefaultDestinationId_ = 'Save as PDF'; initialSettings.systemDefaultDestinationId_ = 'Save as PDF';
// Set PDF printer // Set PDF printer
var device = { nativeLayer.setLocalDestinationCapabilities(getPdfPrinter());
printerId: '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
}
]
}
}
}
};
nativeLayer.setLocalDestinationCapabilities(device);
setInitialSettings(); setInitialSettings();
return nativeLayer.whenCalled('getInitialSettings').then(function() { return nativeLayer.whenCalled('getInitialSettings').then(function() {
...@@ -1318,7 +1325,9 @@ cr.define('print_preview_test', function() { ...@@ -1318,7 +1325,9 @@ cr.define('print_preview_test', function() {
* printTicketStore: !print_preview.PrintTicketStore, * printTicketStore: !print_preview.PrintTicketStore,
* cloudPrintInterface: print_preview * cloudPrintInterface: print_preview
* .CloudPrintInterface, * .CloudPrintInterface,
* documentInfo: print_preview.DocumentInfo}} args * documentInfo: print_preview.DocumentInfo,
* openPdfInPreview: boolean,
* showSystemDialog: boolean}} args
* The arguments that print() was called with. * The arguments that print() was called with.
*/ */
function(args) { function(args) {
...@@ -1336,6 +1345,7 @@ cr.define('print_preview_test', function() { ...@@ -1336,6 +1345,7 @@ cr.define('print_preview_test', function() {
expectEquals( expectEquals(
mediaDefault.height_microns, mediaDefault.height_microns,
printTicketStore.mediaSize.getValue().height_microns); printTicketStore.mediaSize.getValue().height_microns);
return nativeLayer.whenCalled('startHideDialog');
}); });
}); });
...@@ -1405,5 +1415,74 @@ cr.define('print_preview_test', function() { ...@@ -1405,5 +1415,74 @@ cr.define('print_preview_test', function() {
printPreview.destinationStore_.selectedDestination.id); printPreview.destinationStore_.selectedDestination.id);
}); });
}); });
// Test that Mac "Open PDF in Preview" link is treated correctly as a
// local printer. See crbug.com/741341 and crbug.com/741528
if (cr.isMac) {
test('MacOpenPDFInPreview', function() {
var device = getPdfPrinter();
initialSettings.systemDefaultDestinationId_ = device.printerId;
return setupSettingsAndDestinationsWithCapabilities(device).
then(function() {
assertEquals(
device.printerId,
printPreview.destinationStore_.selectedDestination.id);
return nativeLayer.whenCalled('getPreview');
}).then(function() {
var openPdfPreviewLink = $('open-pdf-in-preview-link');
checkElementDisplayed(openPdfPreviewLink, true);
openPdfPreviewLink.click();
// Should result in a print call and dialog should hide
return nativeLayer.whenCalled('print');
}).then(
/**
* @param {{destination: !print_preview.Destination,
* printTicketStore: !print_preview.PrintTicketStore,
* cloudPrintInterface: print_preview
* .CloudPrintInterface,
* documentInfo: print_preview.DocumentInfo,
* openPdfInPreview: boolean
* showSystemDialog: boolean}} args
* The arguments that print() was called with.
*/
function(args) {
expectTrue(args.openPdfInPreview);
return nativeLayer.whenCalled('startHideDialog');
});
});
}
// Test that the system dialog link works correctly on Windows
if (cr.isWindows) {
test('WinSystemDialogLink', function() {
return setupSettingsAndDestinationsWithCapabilities().
then(function() {
assertEquals(
'FooDevice',
printPreview.destinationStore_.selectedDestination.id);
return nativeLayer.whenCalled('getPreview');
}).then(function() {
var systemDialogLink = $('system-dialog-link');
checkElementDisplayed(systemDialogLink, true);
systemDialogLink.click();
// Should result in a print call and dialog should hide
return nativeLayer.whenCalled('print');
}).then(
/**
* @param {{destination: !print_preview.Destination,
* printTicketStore: !print_preview.PrintTicketStore,
* cloudPrintInterface: print_preview
* .CloudPrintInterface,
* documentInfo: print_preview.DocumentInfo,
* openPdfInPreview: boolean
* showSystemDialog: boolean}} args
* The arguments that print() was called with.
*/
function(args) {
expectTrue(args.showSystemDialog);
return nativeLayer.whenCalled('startHideDialog');
});
});
}
}); });
}); });
...@@ -104,7 +104,6 @@ PrintPreviewUIBrowserTest.prototype = { ...@@ -104,7 +104,6 @@ PrintPreviewUIBrowserTest.prototype = {
}); });
}); });
// Disable accessibility errors for some tests. // Disable accessibility errors for some tests.
[ [
'AdvancedSettings1Option', 'AdvancedSettings1Option',
...@@ -122,3 +121,15 @@ TEST_F('PrintPreviewUIBrowserTest', 'SystemDefaultPrinterPolicy', function() { ...@@ -122,3 +121,15 @@ TEST_F('PrintPreviewUIBrowserTest', 'SystemDefaultPrinterPolicy', function() {
mocha.grep(new RegExp('SystemDefaultPrinterPolicy' + '\\b')).run(); mocha.grep(new RegExp('SystemDefaultPrinterPolicy' + '\\b')).run();
}); });
GEN('#endif'); GEN('#endif');
GEN('#if defined(OS_MACOSX)');
TEST_F('PrintPreviewUIBrowserTest', 'MacOpenPDFInPreview', function() {
mocha.grep(new RegExp('MacOpenPDFInPreview' + '\\b')).run();
});
GEN('#endif');
GEN('#if defined(OS_WIN)');
TEST_F('PrintPreviewUIBrowserTest', 'WinSystemDialogLink', function() {
mocha.grep(new RegExp('WinSystemDialogLink' + '\\b')).run();
});
GEN('#endif');
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