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() { ...@@ -1302,10 +1302,15 @@ cr.define('print_preview', function() {
if (this.autoSelectMatchingDestination_ && if (this.autoSelectMatchingDestination_ &&
this.autoSelectMatchingDestination_.matchIdAndOrigin( this.autoSelectMatchingDestination_.matchIdAndOrigin(
eventDetail.destinationId, eventDetail.origin)) { eventDetail.destinationId, eventDetail.origin)) {
console.error( console.warn(
'Failed to fetch last used printer caps: ' + 'Failed to fetch last used printer caps: ' +
eventDetail.destinationId); eventDetail.destinationId);
this.selectDefaultDestination_(); 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({ ...@@ -392,14 +392,18 @@ Polymer({
assert(this.cloudPrintInterface_).getEventTarget(), assert(this.cloudPrintInterface_).getEventTarget(),
cloudprint.CloudPrintInterfaceEventType.SUBMIT_DONE, cloudprint.CloudPrintInterfaceEventType.SUBMIT_DONE,
this.close_.bind(this)); this.close_.bind(this));
[cloudprint.CloudPrintInterfaceEventType.SEARCH_FAILED, [cloudprint.CloudPrintInterfaceEventType.SEARCH_FAILED,
cloudprint.CloudPrintInterfaceEventType.SUBMIT_FAILED,
cloudprint.CloudPrintInterfaceEventType.PRINTER_FAILED, cloudprint.CloudPrintInterfaceEventType.PRINTER_FAILED,
].forEach(eventType => { ].forEach(eventType => {
this.tracker_.add( this.tracker_.add(
assert(this.cloudPrintInterface_).getEventTarget(), eventType, 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.destinationStore_.setCloudPrintInterface(this.cloudPrintInterface_);
this.invitationStore_.setCloudPrintInterface(this.cloudPrintInterface_); this.invitationStore_.setCloudPrintInterface(this.cloudPrintInterface_);
...@@ -606,6 +610,24 @@ Polymer({ ...@@ -606,6 +610,24 @@ Polymer({
} }
}, },
/**
* 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
*/
checkCloudPrintStatus_: function(event) {
if (event.detail.status != 403 || this.isInAppKioskMode_) {
return;
}
// 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;
console.warn('Google Cloud Print Error: HTTP status 403');
},
/** /**
* Called when there was an error communicating with Google Cloud print. * Called when there was an error communicating with Google Cloud print.
* Displays an error message in the print header. * Displays an error message in the print header.
...@@ -613,18 +635,13 @@ Polymer({ ...@@ -613,18 +635,13 @@ Polymer({
* @private * @private
*/ */
onCloudPrintError_: function(event) { onCloudPrintError_: function(event) {
if (event.detail.status == 0) { this.checkCloudPrintStatus_(event);
return; // Ignore, the system does not have internet connectivity. if (event.detail.status == 0 ||
} (event.detail.status == 403 && !this.isInAppKioskMode_)) {
if (event.detail.status == 403 && !this.isInAppKioskMode_) { return; // No internet connectivity or handled by checkCloudPrintStatus_.
// 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 {
this.errorMessage_ = event.detail.message;
this.$.state.transitTo(print_preview_new.State.FATAL_ERROR);
} }
this.errorMessage_ = event.detail.message;
this.$.state.transitTo(print_preview_new.State.FATAL_ERROR);
if (event.detail.status == 200) { if (event.detail.status == 200) {
console.error( console.error(
'Google Cloud Print Error: ' + 'Google Cloud Print Error: ' +
......
...@@ -78,6 +78,16 @@ cr.define('print_preview', function() { ...@@ -78,6 +78,16 @@ cr.define('print_preview', function() {
this.eventTarget_.dispatchEvent(new CustomEvent( this.eventTarget_.dispatchEvent(new CustomEvent(
cloudprint.CloudPrintInterfaceEventType.PRINTER_DONE, cloudprint.CloudPrintInterfaceEventType.PRINTER_DONE,
{detail: printer})); {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() { ...@@ -13,6 +13,7 @@ cr.define('destination_select_test', function() {
SystemDefaultPrinterPolicy: 'system default printer policy', SystemDefaultPrinterPolicy: 'system default printer policy',
KioskModeSelectsFirstPrinter: 'kiosk mode selects first printer', KioskModeSelectsFirstPrinter: 'kiosk mode selects first printer',
NoPrintersShowsError: 'no printers shows error', NoPrintersShowsError: 'no printers shows error',
UnreachableRecentCloudPrinter: 'unreachable recent cloud printer',
}; };
const suiteName = 'DestinationSelectTests'; const suiteName = 'DestinationSelectTests';
...@@ -56,9 +57,12 @@ cr.define('destination_select_test', function() { ...@@ -56,9 +57,12 @@ cr.define('destination_select_test', function() {
nativeLayer.setInitialSettings(initialSettings); nativeLayer.setInitialSettings(initialSettings);
nativeLayer.setLocalDestinations(localDestinations); nativeLayer.setLocalDestinations(localDestinations);
print_preview.NativeLayer.setInstance(nativeLayer); print_preview.NativeLayer.setInstance(nativeLayer);
const cloudPrintInterface = new print_preview.CloudPrintInterfaceStub();
cloudprint.setCloudPrintInterfaceForTesting(cloudPrintInterface);
PolymerTest.clearBody(); PolymerTest.clearBody();
page = document.createElement('print-preview-app'); page = document.createElement('print-preview-app');
document.body.appendChild(page); document.body.appendChild(page);
cr.webUIListenerCallback('use-cloud-print', 'cloudprint url', false);
return nativeLayer.whenCalled('getInitialSettings').then(() => { return nativeLayer.whenCalled('getInitialSettings').then(() => {
page.destinationStore_.addEventListener( page.destinationStore_.addEventListener(
...@@ -87,6 +91,7 @@ cr.define('destination_select_test', function() { ...@@ -87,6 +91,7 @@ cr.define('destination_select_test', function() {
// Check that the throbber is hidden and the dropdown is shown. // Check that the throbber is hidden and the dropdown is shown.
assertTrue(destinationSettings.$$('.throbber-container').hidden); assertTrue(destinationSettings.$$('.throbber-container').hidden);
assertFalse(destinationSelect.hidden); assertFalse(destinationSelect.hidden);
assertFalse(destinationSelect.disabled);
const options = destinationSelect.shadowRoot.querySelectorAll('option'); const options = destinationSelect.shadowRoot.querySelectorAll('option');
const selectedOption = const selectedOption =
...@@ -304,6 +309,30 @@ cr.define('destination_select_test', function() { ...@@ -304,6 +309,30 @@ cr.define('destination_select_test', function() {
assertEquals('noDestinations', selected.value); 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 { return {
......
...@@ -592,6 +592,7 @@ PrintPreviewDestinationSelectTest = class extends NewPrintPreviewTest { ...@@ -592,6 +592,7 @@ PrintPreviewDestinationSelectTest = class extends NewPrintPreviewTest {
return super.extraLibraries.concat([ return super.extraLibraries.concat([
'../settings/test_util.js', '../settings/test_util.js',
'../test_browser_proxy.js', '../test_browser_proxy.js',
'cloud_print_interface_stub.js',
'native_layer_stub.js', 'native_layer_stub.js',
'print_preview_test_utils.js', 'print_preview_test_utils.js',
'destination_select_test.js', 'destination_select_test.js',
...@@ -654,6 +655,13 @@ TEST_F('PrintPreviewDestinationSelectTest', 'NoPrintersShowsError', function() { ...@@ -654,6 +655,13 @@ TEST_F('PrintPreviewDestinationSelectTest', 'NoPrintersShowsError', function() {
}); });
GEN('#endif'); GEN('#endif');
TEST_F(
'PrintPreviewDestinationSelectTest', 'UnreachableRecentCloudPrinter',
function() {
this.runMochaTest(
destination_select_test.TestNames.UnreachableRecentCloudPrinter);
});
PrintPreviewDestinationDialogTest = class extends NewPrintPreviewTest { PrintPreviewDestinationDialogTest = class extends NewPrintPreviewTest {
/** @override */ /** @override */
get browsePreload() { 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