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 */ |
| 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 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 this.setLocalDestinations(); | 1130 this.setLocalDestinations(); |
1096 this.setCapabilities(getCddTemplate("FooDevice")); | 1131 this.setCapabilities(getCddTemplate("FooDevice")); |
1097 | 1132 |
1098 var previewGenerator = mock(print_preview.PreviewGenerator); | 1133 var previewGenerator = mock(print_preview.PreviewGenerator); |
1099 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy(); | 1134 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy(); |
1100 | 1135 |
1101 // The number of settings that can change due to a change in the destination | 1136 // The number of settings that can change due to a change in the destination |
1102 // that will therefore dispatch ticket item change events. | 1137 // that will therefore dispatch ticket item change events. |
1103 previewGenerator.expects(exactly(9)).requestPreview(); | 1138 previewGenerator.expects(exactly(9)).requestPreview(); |
1104 | 1139 |
1105 var barDestination; | 1140 var barDestination = |
1106 var destinations = printPreview.destinationStore_.destinations(); | 1141 printPreview.destinationStore_.destinations().find(function(d) { |
1107 for (var destination, i = 0; destination = destinations[i]; i++) { | 1142 return d.id == 'BarDevice'; |
1108 if (destination.id == 'BarDevice') { | 1143 }); |
1109 barDestination = destination; | |
1110 break; | |
1111 } | |
1112 } | |
1113 | 1144 |
1114 printPreview.destinationStore_.selectDestination(barDestination); | 1145 printPreview.destinationStore_.selectDestination(barDestination); |
1115 | 1146 |
1116 var device = getCddTemplate("BarDevice"); | 1147 var device = getCddTemplate("BarDevice"); |
1117 device.capabilities.printer.color = { | 1148 device.capabilities.printer.color = { |
1118 "option": [ | 1149 "option": [ |
1119 {"is_default": true, "type": "STANDARD_MONOCHROME"} | 1150 {"is_default": true, "type": "STANDARD_MONOCHROME"} |
1120 ] | 1151 ] |
1121 }; | 1152 }; |
1122 this.setCapabilities(device); | 1153 this.setCapabilities(device); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 // increments by 1 for each startGetPreview call it makes. It should only | 1380 // 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 | 1381 // make one such call during initialization or there will be a race; see |
1351 // crbug.com/666595 | 1382 // crbug.com/666595 |
1352 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, | 1383 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, |
1353 -1); | 1384 -1); |
1354 this.setInitialSettings(); | 1385 this.setInitialSettings(); |
1355 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, | 1386 expectEquals(printPreview.previewArea_.previewGenerator_.inFlightRequestId_, |
1356 0); | 1387 0); |
1357 testDone(); | 1388 testDone(); |
1358 }); | 1389 }); |
| 1390 |
| 1391 // Test that invalid settings errors disable the print preview and display |
| 1392 // an error and that the preview dialog can be recovered by selecting a |
| 1393 // new destination. |
| 1394 TEST_F('PrintPreviewWebUITest', 'TestInvalidSettingsError', function() { |
| 1395 // Setup |
| 1396 this.setInitialSettings(); |
| 1397 this.setLocalDestinations(); |
| 1398 this.setCapabilities(getCddTemplate("FooDevice")); |
| 1399 |
| 1400 // Manually enable the print header. This is needed since there is no |
| 1401 // plugin during test, so it will be set as disabled normally. |
| 1402 printPreview.printHeader_.isEnabled = true; |
| 1403 |
| 1404 // There will be an error message in the preview area since the plugin is |
| 1405 // not running. However, it should not be the invalid settings error. |
| 1406 var previewAreaEl = $('preview-area'); |
| 1407 var customMessageEl = |
| 1408 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; |
| 1409 expectFalse(customMessageEl.hidden); |
| 1410 var expectedMessageStart = 'The selected printer is not available or not ' + |
| 1411 'installed correctly.' |
| 1412 expectFalse(customMessageEl.textContent.includes(expectedMessageStart)); |
| 1413 |
| 1414 // Verify that the print button is enabled. |
| 1415 var printHeader = $('print-header'); |
| 1416 var printButton = printHeader.querySelector('button.print'); |
| 1417 checkElementDisplayed(printButton, true); |
| 1418 expectFalse(printButton.disabled); |
| 1419 |
| 1420 // Report invalid settings error. |
| 1421 this.dispatchInvalidSettings(); |
| 1422 |
| 1423 // Should be in an error state, print button disabled, invalid custom error |
| 1424 // message shown. |
| 1425 expectFalse(customMessageEl.hidden); |
| 1426 expectTrue(customMessageEl.textContent.includes(expectedMessageStart)); |
| 1427 expectTrue(printButton.disabled); |
| 1428 |
| 1429 // Select a new destination |
| 1430 var barDestination = |
| 1431 printPreview.destinationStore_.destinations().find(function(d) { |
| 1432 return d.id == 'BarDevice'; |
| 1433 }); |
| 1434 |
| 1435 printPreview.destinationStore_.selectDestination(barDestination); |
| 1436 |
| 1437 // Dispatch events indicating capabilities were fetched and new preview has |
| 1438 // loaded. |
| 1439 this.setCapabilities(getCddTemplate("BarDevice")); |
| 1440 this.dispatchPreviewDone(); |
| 1441 |
| 1442 // Has active print button and successfully "prints", indicating recovery |
| 1443 // from error state. |
| 1444 expectFalse(printButton.disabled); |
| 1445 expectFalse(this.hasPrinted()); |
| 1446 printButton.click(); |
| 1447 expectTrue(this.hasPrinted()); |
| 1448 testDone(); |
| 1449 }); |
OLD | NEW |