Chromium Code Reviews| Index: chrome/test/data/webui/print_preview.js |
| diff --git a/chrome/test/data/webui/print_preview.js b/chrome/test/data/webui/print_preview.js |
| index 2743ce8ed98a97ae60ecaf0cfe1a9bf0ed4786c0..0f79a7572bb145516b7677b37abab9b0963250f7 100644 |
| --- a/chrome/test/data/webui/print_preview.js |
| +++ b/chrome/test/data/webui/print_preview.js |
| @@ -15,6 +15,7 @@ function PrintPreviewWebUITest() { |
| this.nativeLayer_ = null; |
| this.initialSettings_ = null; |
| this.localDestinationInfos_ = null; |
| + this.previewArea_ = null; |
| } |
| /** |
| @@ -82,15 +83,20 @@ PrintPreviewWebUITest.prototype = { |
| window.addEventListener('DOMContentLoaded', function() { |
| function NativeLayerStub() { |
| cr.EventTarget.call(this); |
| + this.printStarted_ = false; |
| } |
| NativeLayerStub.prototype = { |
| __proto__: cr.EventTarget.prototype, |
| + isPrintStarted: function() { return this.printStarted_; }, |
| + previewReadyForTest: function() {}, |
| startGetInitialSettings: function() {}, |
| startGetLocalDestinations: function() {}, |
| startGetPrivetDestinations: function() {}, |
| startGetExtensionDestinations: function() {}, |
| startGetLocalDestinationCapabilities: function(destinationId) {}, |
| startGetPreview: function() {}, |
| + startHideDialog: function () {}, |
| + startPrint: function () { this.printStarted_ = true; } |
| }; |
| var oldNativeLayerEventType = print_preview.NativeLayer.EventType; |
| var oldDuplexMode = print_preview.NativeLayer.DuplexMode; |
| @@ -151,6 +157,34 @@ PrintPreviewWebUITest.prototype = { |
| }, |
| /** |
| + * Dispatch the PREVIEW_GENERATION_DONE event. This call is NOT async and |
| + * will happen in the same thread. |
| + */ |
| + dispatchPreviewDone: function() { |
| + var previewDoneEvent = |
| + new Event(print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); |
| + this.previewArea_.dispatchEvent(previewDoneEvent); |
| + }, |
| + |
| + /** |
| + * Dispatch the SETTINGS_INVALID event. This call is NOT async and will |
| + * happen in the same thread. |
| + */ |
| + dispatchInvalidSettings: function() { |
| + var invalidSettingsEvent = |
| + new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); |
| + this.nativeLayer_.dispatchEvent(invalidSettingsEvent); |
| + }, |
| + |
| + /** |
| + * @return {boolean} Whether the UI has/has not "printed" (called startPrint |
| + * on the native layer). |
| + **/ |
|
dpapad
2017/04/29 01:20:20
Extra asterisk.
*/
rbpotter
2017/04/29 01:32:47
Done.
|
| + hasPrinted: function() { |
| + return this.nativeLayer_.isPrintStarted(); |
| + }, |
| + |
| + /** |
| * Even though animation duration and delay is set to zero, it is necessary to |
| * wait until the animation has finished. |
| */ |
| @@ -223,6 +257,7 @@ PrintPreviewWebUITest.prototype = { |
| { printerName: 'BarName', deviceName: 'BarDevice' } |
| ]; |
| this.nativeLayer_ = printPreview.nativeLayer_; |
| + this.previewArea_ = printPreview.previewArea_; |
| testing.Test.disableAnimationsAndTransitions(); |
| @@ -1356,3 +1391,66 @@ TEST_F('PrintPreviewWebUITest', 'TestInitIssuesOneRequest', function() { |
| 0); |
| testDone(); |
| }); |
| + |
| +// Test that invalid settings errors disable the print preview and display |
| +// an error and that the preview dialog can be recovered by selecting a |
| +// new destination. |
| +TEST_F('PrintPreviewWebUITest', 'TestInvalidSettingsError', function() { |
| + // Setup |
| + this.setInitialSettings(); |
| + this.setLocalDestinations(); |
| + this.setCapabilities(getCddTemplate("FooDevice")); |
| + |
| + // Manually enable the print header. This is needed since there is no |
| + // plugin during test, so it will be set as disabled normally. |
| + printPreview.printHeader_.isEnabled = true; |
| + |
| + // There will be an error message in the preview area since the plugin is |
| + // not running. However, it should not be the invalid settings error. |
| + var previewAreaEl = $('preview-area'); |
| + var customMessageEl = |
| + previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; |
| + expectFalse(customMessageEl.hidden); |
| + var expectedMessageStart = 'The selected printer is not available or not ' + |
| + 'installed correctly.' |
| + expectEquals(-1, customMessageEl.textContent.search(expectedMessageStart)); |
|
dpapad
2017/04/29 01:20:20
Nit: Use includes() instead, https://developer.moz
rbpotter
2017/04/29 01:32:47
Done.
|
| + |
| + // Verify that the print button is enabled. |
| + var printHeader = $('print-header'); |
| + var printButton = printHeader.querySelector('button.print'); |
| + checkElementDisplayed(printButton, true); |
| + expectFalse(printButton.disabled); |
| + |
| + // Report invalid settings error. |
| + this.dispatchInvalidSettings(); |
| + |
| + // Should be in an error state, print button disabled, invalid custom error |
| + // message shown. |
| + expectFalse(customMessageEl.hidden); |
| + expectTrue(customMessageEl.textContent.search(expectedMessageStart) > -1); |
| + expectTrue(printButton.disabled); |
| + |
| + // Select a new destination |
| + var barDestination; |
|
dpapad
2017/04/29 01:20:20
var barDestination = printPreview.destinationStore
rbpotter
2017/04/29 01:32:47
Done.
|
| + var destinations = printPreview.destinationStore_.destinations(); |
| + for (var destination, i = 0; destination = destinations[i]; i++) { |
| + if (destination.id == 'BarDevice') { |
| + barDestination = destination; |
| + break; |
| + } |
| + } |
| + printPreview.destinationStore_.selectDestination(barDestination); |
| + |
| + // Dispatch events indicating capabilities were fetched and new preview has |
| + // loaded |
|
dpapad
2017/04/29 01:20:20
Per styleguide, full sentence comments should fini
rbpotter
2017/04/29 01:32:47
Done.
|
| + this.setCapabilities(getCddTemplate("BarDevice")); |
| + this.dispatchPreviewDone(); |
| + |
| + // Has active print button and successfully "prints", indicating recovery |
| + // from error state. |
| + expectFalse(printButton.disabled); |
| + expectFalse(this.hasPrinted()); |
| + printButton.click(); |
| + expectTrue(this.hasPrinted()); |
| + testDone(); |
| +}); |