OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 GEN('#include "base/feature_list.h"'); | 5 GEN('#include "base/feature_list.h"'); |
6 GEN('#include "chrome/common/chrome_features.h"'); | 6 GEN('#include "chrome/common/chrome_features.h"'); |
7 | 7 |
8 /** | 8 /** |
9 * Test fixture for print preview WebUI testing. | 9 * Test fixture for print preview WebUI testing. |
10 * @constructor | 10 * @constructor |
11 * @extends {testing.Test} | 11 * @extends {testing.Test} |
12 */ | 12 */ |
13 function PrintPreviewWebUITest() { | 13 function PrintPreviewWebUITest() { |
14 testing.Test.call(this); | 14 testing.Test.call(this); |
15 this.nativeLayer_ = null; | 15 this.nativeLayer_ = null; |
16 this.initialSettings_ = null; | 16 this.initialSettings_ = null; |
17 this.localDestinationInfos_ = null; | 17 this.localDestinationInfos_ = null; |
18 this.previewArea_ = null; | |
18 } | 19 } |
19 | 20 |
20 /** | 21 /** |
21 * Index of the "Save as PDF" printer. | 22 * Index of the "Save as PDF" printer. |
22 * @type {number} | 23 * @type {number} |
23 * @const | 24 * @const |
24 */ | 25 */ |
25 PrintPreviewWebUITest.PDF_INDEX = 0; | 26 PrintPreviewWebUITest.PDF_INDEX = 0; |
26 | 27 |
27 /** | 28 /** |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 /** | 76 /** |
76 * Stub out low-level functionality like the NativeLayer and | 77 * Stub out low-level functionality like the NativeLayer and |
77 * CloudPrintInterface. | 78 * CloudPrintInterface. |
78 * @this {PrintPreviewWebUITest} | 79 * @this {PrintPreviewWebUITest} |
79 * @override | 80 * @override |
80 */ | 81 */ |
81 preLoad: function() { | 82 preLoad: function() { |
82 window.addEventListener('DOMContentLoaded', function() { | 83 window.addEventListener('DOMContentLoaded', function() { |
83 function NativeLayerStub() { | 84 function NativeLayerStub() { |
84 cr.EventTarget.call(this); | 85 cr.EventTarget.call(this); |
86 this.printStarted_ = false; | |
85 } | 87 } |
86 NativeLayerStub.prototype = { | 88 NativeLayerStub.prototype = { |
87 __proto__: cr.EventTarget.prototype, | 89 __proto__: cr.EventTarget.prototype, |
90 isPrintStarted: function() { return this.printStarted_; }, | |
91 previewReadyForTest: function() {}, | |
88 startGetInitialSettings: function() {}, | 92 startGetInitialSettings: function() {}, |
89 startGetLocalDestinations: function() {}, | 93 startGetLocalDestinations: function() {}, |
90 startGetPrivetDestinations: function() {}, | 94 startGetPrivetDestinations: function() {}, |
91 startGetExtensionDestinations: function() {}, | 95 startGetExtensionDestinations: function() {}, |
92 startGetLocalDestinationCapabilities: function(destinationId) {}, | 96 startGetLocalDestinationCapabilities: function(destinationId) {}, |
93 startGetPreview: function() {}, | 97 startGetPreview: function() {}, |
98 startHideDialog: function () {}, | |
99 startPrint: function () { this.printStarted_ = true; } | |
94 }; | 100 }; |
95 var oldNativeLayerEventType = print_preview.NativeLayer.EventType; | 101 var oldNativeLayerEventType = print_preview.NativeLayer.EventType; |
96 var oldDuplexMode = print_preview.NativeLayer.DuplexMode; | 102 var oldDuplexMode = print_preview.NativeLayer.DuplexMode; |
97 print_preview.NativeLayer = NativeLayerStub; | 103 print_preview.NativeLayer = NativeLayerStub; |
98 print_preview.NativeLayer.EventType = oldNativeLayerEventType; | 104 print_preview.NativeLayer.EventType = oldNativeLayerEventType; |
99 print_preview.NativeLayer.DuplexMode = oldDuplexMode; | 105 print_preview.NativeLayer.DuplexMode = oldDuplexMode; |
100 | 106 |
101 function CloudPrintInterfaceStub() { | 107 function CloudPrintInterfaceStub() { |
102 cr.EventTarget.call(this); | 108 cr.EventTarget.call(this); |
103 } | 109 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 * @device - The device whose capabilities should be dispatched. | 150 * @device - The device whose capabilities should be dispatched. |
145 */ | 151 */ |
146 setCapabilities: function(device) { | 152 setCapabilities: function(device) { |
147 var capsSetEvent = | 153 var capsSetEvent = |
148 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 154 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
149 capsSetEvent.settingsInfo = device; | 155 capsSetEvent.settingsInfo = device; |
150 this.nativeLayer_.dispatchEvent(capsSetEvent); | 156 this.nativeLayer_.dispatchEvent(capsSetEvent); |
151 }, | 157 }, |
152 | 158 |
153 /** | 159 /** |
160 * Dispatch the PREVIEW_GENERATION_DONE event. This call is NOT async and | |
161 * will happen in the same thread. | |
162 */ | |
163 dispatchPreviewDone: function() { | |
164 var previewDoneEvent = | |
165 new Event(print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); | |
166 this.previewArea_.dispatchEvent(previewDoneEvent); | |
167 }, | |
168 | |
169 /** | |
170 * Dispatch the SETTINGS_INVALID event. This call is NOT async and will | |
171 * happen in the same thread. | |
172 */ | |
173 dispatchInvalidSettings: function() { | |
174 var invalidSettingsEvent = | |
175 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); | |
176 this.nativeLayer_.dispatchEvent(invalidSettingsEvent); | |
177 }, | |
178 | |
179 /** | |
180 * @return {boolean} Whether the UI has/has not "printed" (called startPrint | |
181 * on the native layer). | |
182 **/ | |
dpapad
2017/04/29 01:20:20
Extra asterisk.
*/
rbpotter
2017/04/29 01:32:47
Done.
| |
183 hasPrinted: function() { | |
184 return this.nativeLayer_.isPrintStarted(); | |
185 }, | |
186 | |
187 /** | |
154 * Even though animation duration and delay is set to zero, it is necessary to | 188 * Even though animation duration and delay is set to zero, it is necessary to |
155 * wait until the animation has finished. | 189 * wait until the animation has finished. |
156 */ | 190 */ |
157 waitForAnimationToEnd: function(elementId) { | 191 waitForAnimationToEnd: function(elementId) { |
158 // add a listener for the animation end event | 192 // add a listener for the animation end event |
159 document.addEventListener('animationend', function f(e) { | 193 document.addEventListener('animationend', function f(e) { |
160 if (e.target.id == elementId) { | 194 if (e.target.id == elementId) { |
161 document.removeEventListener(f, 'animationend'); | 195 document.removeEventListener(f, 'animationend'); |
162 testDone(); | 196 testDone(); |
163 } | 197 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 true /*documentHasSelection*/, | 250 true /*documentHasSelection*/, |
217 false /*selectionOnly*/, | 251 false /*selectionOnly*/, |
218 'FooDevice' /*systemDefaultDestinationId*/, | 252 'FooDevice' /*systemDefaultDestinationId*/, |
219 null /*serializedAppStateStr*/, | 253 null /*serializedAppStateStr*/, |
220 null /*serializedDefaultDestinationSelectionRulesStr*/); | 254 null /*serializedDefaultDestinationSelectionRulesStr*/); |
221 this.localDestinationInfos_ = [ | 255 this.localDestinationInfos_ = [ |
222 { printerName: 'FooName', deviceName: 'FooDevice' }, | 256 { printerName: 'FooName', deviceName: 'FooDevice' }, |
223 { printerName: 'BarName', deviceName: 'BarDevice' } | 257 { printerName: 'BarName', deviceName: 'BarDevice' } |
224 ]; | 258 ]; |
225 this.nativeLayer_ = printPreview.nativeLayer_; | 259 this.nativeLayer_ = printPreview.nativeLayer_; |
260 this.previewArea_ = printPreview.previewArea_; | |
226 | 261 |
227 testing.Test.disableAnimationsAndTransitions(); | 262 testing.Test.disableAnimationsAndTransitions(); |
228 | 263 |
229 // Enable when failure is resolved. | 264 // Enable when failure is resolved. |
230 // AX_TEXT_03: http://crbug.com/559209 | 265 // AX_TEXT_03: http://crbug.com/559209 |
231 this.accessibilityAuditConfig.ignoreSelectors( | 266 this.accessibilityAuditConfig.ignoreSelectors( |
232 'multipleLabelableElementsPerLabel', | 267 'multipleLabelableElementsPerLabel', |
233 '#page-settings > .right-column > *'); | 268 '#page-settings > .right-column > *'); |
234 } | 269 } |
235 }; | 270 }; |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1349 // increments by 1 for each startGetPreview call it makes. It should only | 1384 // increments by 1 for each startGetPreview call it makes. It should only |
1350 // make one such call during initialization or there will be a race; see | 1385 // make one such call during initialization or there will be a race; see |
1351 // crbug.com/666595 | 1386 // crbug.com/666595 |
1352 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, | 1387 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, |
1353 -1); | 1388 -1); |
1354 this.setInitialSettings(); | 1389 this.setInitialSettings(); |
1355 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, | 1390 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, |
1356 0); | 1391 0); |
1357 testDone(); | 1392 testDone(); |
1358 }); | 1393 }); |
1394 | |
1395 // Test that invalid settings errors disable the print preview and display | |
1396 // an error and that the preview dialog can be recovered by selecting a | |
1397 // new destination. | |
1398 TEST_F('PrintPreviewWebUITest', 'TestInvalidSettingsError', function() { | |
1399 // Setup | |
1400 this.setInitialSettings(); | |
1401 this.setLocalDestinations(); | |
1402 this.setCapabilities(getCddTemplate("FooDevice")); | |
1403 | |
1404 // Manually enable the print header. This is needed since there is no | |
1405 // plugin during test, so it will be set as disabled normally. | |
1406 printPreview.printHeader_.isEnabled = true; | |
1407 | |
1408 // There will be an error message in the preview area since the plugin is | |
1409 // not running. However, it should not be the invalid settings error. | |
1410 var previewAreaEl = $('preview-area'); | |
1411 var customMessageEl = | |
1412 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; | |
1413 expectFalse(customMessageEl.hidden); | |
1414 var expectedMessageStart = 'The selected printer is not available or not ' + | |
1415 'installed correctly.' | |
1416 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.
| |
1417 | |
1418 // Verify that the print button is enabled. | |
1419 var printHeader = $('print-header'); | |
1420 var printButton = printHeader.querySelector('button.print'); | |
1421 checkElementDisplayed(printButton, true); | |
1422 expectFalse(printButton.disabled); | |
1423 | |
1424 // Report invalid settings error. | |
1425 this.dispatchInvalidSettings(); | |
1426 | |
1427 // Should be in an error state, print button disabled, invalid custom error | |
1428 // message shown. | |
1429 expectFalse(customMessageEl.hidden); | |
1430 expectTrue(customMessageEl.textContent.search(expectedMessageStart) > -1); | |
1431 expectTrue(printButton.disabled); | |
1432 | |
1433 // Select a new destination | |
1434 var barDestination; | |
dpapad
2017/04/29 01:20:20
var barDestination = printPreview.destinationStore
rbpotter
2017/04/29 01:32:47
Done.
| |
1435 var destinations = printPreview.destinationStore_.destinations(); | |
1436 for (var destination, i = 0; destination = destinations[i]; i++) { | |
1437 if (destination.id == 'BarDevice') { | |
1438 barDestination = destination; | |
1439 break; | |
1440 } | |
1441 } | |
1442 printPreview.destinationStore_.selectDestination(barDestination); | |
1443 | |
1444 // Dispatch events indicating capabilities were fetched and new preview has | |
1445 // loaded | |
dpapad
2017/04/29 01:20:20
Per styleguide, full sentence comments should fini
rbpotter
2017/04/29 01:32:47
Done.
| |
1446 this.setCapabilities(getCddTemplate("BarDevice")); | |
1447 this.dispatchPreviewDone(); | |
1448 | |
1449 // Has active print button and successfully "prints", indicating recovery | |
1450 // from error state. | |
1451 expectFalse(printButton.disabled); | |
1452 expectFalse(this.hasPrinted()); | |
1453 printButton.click(); | |
1454 expectTrue(this.hasPrinted()); | |
1455 testDone(); | |
1456 }); | |
OLD | NEW |