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

Print Preview: Do not disable for cloud printer fetch failure

It does not make sense to disable the entire preview for a printer
fetch failure. Update the cloud print state if there is a 403 error,
and otherwise ignore these failures in app.js and let DestinationStore
handle them.

Bug: 923914
Change-Id: Ie0dc8596c30397ad531354a4a80345a4299c64f8
Reviewed-on: https://chromium-review.googlesource.com/c/1428059
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625412}
parent 54862d1e
......@@ -1302,10 +1302,15 @@ cr.define('print_preview', function() {
if (this.autoSelectMatchingDestination_ &&
this.autoSelectMatchingDestination_.matchIdAndOrigin(
eventDetail.destinationId, eventDetail.origin)) {
console.error(
console.warn(
'Failed to fetch last used printer caps: ' +
eventDetail.destinationId);
this.selectDefaultDestination_();
} else {
// Log the failure
console.warn(
'Failed to fetch printer capabilities for ' +
eventDetail.destinationId + ' with origin ' + eventDetail.origin);
}
}
......
......@@ -392,14 +392,18 @@ Polymer({
assert(this.cloudPrintInterface_).getEventTarget(),
cloudprint.CloudPrintInterfaceEventType.SUBMIT_DONE,
this.close_.bind(this));
[cloudprint.CloudPrintInterfaceEventType.SEARCH_FAILED,
cloudprint.CloudPrintInterfaceEventType.SUBMIT_FAILED,
cloudprint.CloudPrintInterfaceEventType.PRINTER_FAILED,
].forEach(eventType => {
this.tracker_.add(
assert(this.cloudPrintInterface_).getEventTarget(), eventType,
this.onCloudPrintError_.bind(this));
this.checkCloudPrintStatus_.bind(this));
});
this.tracker_.add(
assert(this.cloudPrintInterface_).getEventTarget(),
cloudprint.CloudPrintInterfaceEventType.SUBMIT_FAILED,
this.onCloudPrintError_.bind(this));
this.destinationStore_.setCloudPrintInterface(this.cloudPrintInterface_);
this.invitationStore_.setCloudPrintInterface(this.cloudPrintInterface_);
......@@ -607,24 +611,37 @@ Polymer({
},
/**
* Called when there was an error communicating with Google Cloud print.
* Displays an error message in the print header.
* @param {!CustomEvent} event Contains the error message.
* Updates the cloud print status to NOT_SIGNED_IN if there is an
* authentication error.
* @param {!CustomEvent<{status: number}>} event Contains the error status
* @private
*/
onCloudPrintError_: function(event) {
if (event.detail.status == 0) {
return; // Ignore, the system does not have internet connectivity.
checkCloudPrintStatus_: function(event) {
if (event.detail.status != 403 || this.isInAppKioskMode_) {
return;
}
if (event.detail.status == 403 && !this.isInAppKioskMode_) {
// Should not have sent a message to Cloud Print if cloud print is
// disabled.
assert(this.cloudPrintState_ !== print_preview.CloudPrintState.DISABLED);
this.cloudPrintState_ = print_preview.CloudPrintState.NOT_SIGNED_IN;
} else {
console.warn('Google Cloud Print Error: HTTP status 403');
},
/**
* Called when there was an error communicating with Google Cloud print.
* Displays an error message in the print header.
* @param {!CustomEvent} event Contains the error message.
* @private
*/
onCloudPrintError_: function(event) {
this.checkCloudPrintStatus_(event);
if (event.detail.status == 0 ||
(event.detail.status == 403 && !this.isInAppKioskMode_)) {
return; // No internet connectivity or handled by checkCloudPrintStatus_.
}
this.errorMessage_ = event.detail.message;
this.$.state.transitTo(print_preview_new.State.FATAL_ERROR);
}
if (event.detail.status == 200) {
console.error(
'Google Cloud Print Error: ' +
......
......@@ -78,6 +78,16 @@ cr.define('print_preview', function() {
this.eventTarget_.dispatchEvent(new CustomEvent(
cloudprint.CloudPrintInterfaceEventType.PRINTER_DONE,
{detail: printer}));
} else {
this.eventTarget_.dispatchEvent(new CustomEvent(
cloudprint.CloudPrintInterfaceEventType.PRINTER_FAILED, {
detail: {
origin: origin,
destinationId: printerId,
status: 200,
message: 'Unknown printer',
},
}));
}
}
}
......
......@@ -13,6 +13,7 @@ cr.define('destination_select_test', function() {
SystemDefaultPrinterPolicy: 'system default printer policy',
KioskModeSelectsFirstPrinter: 'kiosk mode selects first printer',
NoPrintersShowsError: 'no printers shows error',
UnreachableRecentCloudPrinter: 'unreachable recent cloud printer',
};
const suiteName = 'DestinationSelectTests';
......@@ -56,9 +57,12 @@ cr.define('destination_select_test', function() {
nativeLayer.setInitialSettings(initialSettings);
nativeLayer.setLocalDestinations(localDestinations);
print_preview.NativeLayer.setInstance(nativeLayer);
const cloudPrintInterface = new print_preview.CloudPrintInterfaceStub();
cloudprint.setCloudPrintInterfaceForTesting(cloudPrintInterface);
PolymerTest.clearBody();
page = document.createElement('print-preview-app');
document.body.appendChild(page);
cr.webUIListenerCallback('use-cloud-print', 'cloudprint url', false);
return nativeLayer.whenCalled('getInitialSettings').then(() => {
page.destinationStore_.addEventListener(
......@@ -87,6 +91,7 @@ cr.define('destination_select_test', function() {
// Check that the throbber is hidden and the dropdown is shown.
assertTrue(destinationSettings.$$('.throbber-container').hidden);
assertFalse(destinationSelect.hidden);
assertFalse(destinationSelect.disabled);
const options = destinationSelect.shadowRoot.querySelectorAll('option');
const selectedOption =
......@@ -304,6 +309,30 @@ cr.define('destination_select_test', function() {
assertEquals('noDestinations', selected.value);
});
});
/**
* Tests that if the user has a recent destination that triggers a cloud
* print error this does not disable the dialog.
*/
test(assert(TestNames.UnreachableRecentCloudPrinter), function() {
const cloudPrinter =
print_preview_test_utils.createDestinationWithCertificateStatus(
'BarDevice', 'BarName', false);
const recentDestination =
print_preview.makeRecentDestination(cloudPrinter);
initialSettings.serializedAppStateStr = JSON.stringify({
version: 2,
recentDestinations: [recentDestination],
});
return setInitialSettings().then(function(args) {
assertEquals(print_preview_new.State.READY, page.state);
assertEquals('FooDevice', args.destinationId);
assertEquals(print_preview.PrinterType.LOCAL, args.type);
assertEquals('FooDevice', page.destination_.id);
return assertPrinterDisplay('FooName');
});
});
});
return {
......
......@@ -592,6 +592,7 @@ PrintPreviewDestinationSelectTest = class extends NewPrintPreviewTest {
return super.extraLibraries.concat([
'../settings/test_util.js',
'../test_browser_proxy.js',
'cloud_print_interface_stub.js',
'native_layer_stub.js',
'print_preview_test_utils.js',
'destination_select_test.js',
......@@ -654,6 +655,13 @@ TEST_F('PrintPreviewDestinationSelectTest', 'NoPrintersShowsError', function() {
});
GEN('#endif');
TEST_F(
'PrintPreviewDestinationSelectTest', 'UnreachableRecentCloudPrinter',
function() {
this.runMochaTest(
destination_select_test.TestNames.UnreachableRecentCloudPrinter);
});
PrintPreviewDestinationDialogTest = class extends NewPrintPreviewTest {
/** @override */
get browsePreload() {
......
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