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 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 * Stub out low-level functionality like the NativeLayer and | 77 * Stub out low-level functionality like the NativeLayer and |
78 * CloudPrintInterface. | 78 * CloudPrintInterface. |
79 * @this {PrintPreviewWebUITest} | 79 * @this {PrintPreviewWebUITest} |
80 * @override | 80 * @override |
81 */ | 81 */ |
82 preLoad: function() { | 82 preLoad: function() { |
83 window.addEventListener('DOMContentLoaded', function() { | 83 window.addEventListener('DOMContentLoaded', function() { |
84 function NativeLayerStub() { | 84 function NativeLayerStub() { |
85 cr.EventTarget.call(this); | 85 cr.EventTarget.call(this); |
86 this.printStarted_ = false; | 86 this.printStarted_ = false; |
87 this.generateDraft_ = false; | |
87 } | 88 } |
88 NativeLayerStub.prototype = { | 89 NativeLayerStub.prototype = { |
89 __proto__: cr.EventTarget.prototype, | 90 __proto__: cr.EventTarget.prototype, |
90 isPrintStarted: function() { return this.printStarted_; }, | 91 isPrintStarted: function() { return this.printStarted_; }, |
92 generateDraft: function() { return this.generateDraft_; }, | |
91 previewReadyForTest: function() {}, | 93 previewReadyForTest: function() {}, |
92 startGetInitialSettings: function() {}, | 94 startGetInitialSettings: function() {}, |
93 startGetLocalDestinations: function() {}, | 95 startGetLocalDestinations: function() {}, |
94 startGetPrivetDestinations: function() {}, | 96 startGetPrivetDestinations: function() {}, |
95 startGetExtensionDestinations: function() {}, | 97 startGetExtensionDestinations: function() {}, |
96 startGetLocalDestinationCapabilities: function(destinationId) {}, | 98 startGetLocalDestinationCapabilities: function(destinationId) {}, |
97 startGetPreview: function() {}, | 99 startGetPreview: function(destination, printTicketStore, documentInfo, |
100 generateDraft, requestId) { | |
101 this.generateDraft_ = generateDraft; | |
102 }, | |
98 startHideDialog: function () {}, | 103 startHideDialog: function () {}, |
99 startPrint: function () { this.printStarted_ = true; } | 104 startPrint: function () { this.printStarted_ = true; } |
100 }; | 105 }; |
101 var oldNativeLayerEventType = print_preview.NativeLayer.EventType; | 106 var oldNativeLayerEventType = print_preview.NativeLayer.EventType; |
102 var oldDuplexMode = print_preview.NativeLayer.DuplexMode; | 107 var oldDuplexMode = print_preview.NativeLayer.DuplexMode; |
103 print_preview.NativeLayer = NativeLayerStub; | 108 print_preview.NativeLayer = NativeLayerStub; |
104 print_preview.NativeLayer.EventType = oldNativeLayerEventType; | 109 print_preview.NativeLayer.EventType = oldNativeLayerEventType; |
105 print_preview.NativeLayer.DuplexMode = oldDuplexMode; | 110 print_preview.NativeLayer.DuplexMode = oldDuplexMode; |
106 | 111 |
107 function CloudPrintInterfaceStub() { | 112 function CloudPrintInterfaceStub() { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 * Dispatch the SETTINGS_INVALID event. This call is NOT async and will | 175 * Dispatch the SETTINGS_INVALID event. This call is NOT async and will |
171 * happen in the same thread. | 176 * happen in the same thread. |
172 */ | 177 */ |
173 dispatchInvalidSettings: function() { | 178 dispatchInvalidSettings: function() { |
174 var invalidSettingsEvent = | 179 var invalidSettingsEvent = |
175 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); | 180 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); |
176 this.nativeLayer_.dispatchEvent(invalidSettingsEvent); | 181 this.nativeLayer_.dispatchEvent(invalidSettingsEvent); |
177 }, | 182 }, |
178 | 183 |
179 /** | 184 /** |
180 * @return {boolean} Whether the UI has/has not "printed" (called startPrint | 185 * @return {boolean} Whether the UI has "printed" or not. (called startPrint |
181 * on the native layer). | 186 * on the native layer) |
182 */ | 187 */ |
183 hasPrinted: function() { | 188 hasPrinted: function() { |
184 return this.nativeLayer_.isPrintStarted(); | 189 return this.nativeLayer_.isPrintStarted(); |
185 }, | 190 }, |
186 | 191 |
187 /** | 192 /** |
193 * @return {boolean} Whether the UI is "generating draft" in the most recent | |
194 * preview. (checking the result of the startGetPreview call in the native | |
195 * layer) | |
196 */ | |
197 generateDraft: function() { | |
198 return this.nativeLayer_.generateDraft(); | |
199 }, | |
200 | |
201 /** | |
188 * Even though animation duration and delay is set to zero, it is necessary to | 202 * Even though animation duration and delay is set to zero, it is necessary to |
189 * wait until the animation has finished. | 203 * wait until the animation has finished. |
190 */ | 204 */ |
191 waitForAnimationToEnd: function(elementId) { | 205 waitForAnimationToEnd: function(elementId) { |
192 // add a listener for the animation end event | 206 // add a listener for the animation end event |
193 document.addEventListener('animationend', function f(e) { | 207 document.addEventListener('animationend', function f(e) { |
194 if (e.target.id == elementId) { | 208 if (e.target.id == elementId) { |
195 document.removeEventListener(f, 'animationend'); | 209 document.removeEventListener(f, 'animationend'); |
196 testDone(); | 210 testDone(); |
197 } | 211 } |
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1442 this.dispatchPreviewDone(); | 1456 this.dispatchPreviewDone(); |
1443 | 1457 |
1444 // Has active print button and successfully "prints", indicating recovery | 1458 // Has active print button and successfully "prints", indicating recovery |
1445 // from error state. | 1459 // from error state. |
1446 expectFalse(printButton.disabled); | 1460 expectFalse(printButton.disabled); |
1447 expectFalse(this.hasPrinted()); | 1461 expectFalse(this.hasPrinted()); |
1448 printButton.click(); | 1462 printButton.click(); |
1449 expectTrue(this.hasPrinted()); | 1463 expectTrue(this.hasPrinted()); |
1450 testDone(); | 1464 testDone(); |
1451 }); | 1465 }); |
1466 | |
1467 // Test the preview generator to make sure the generate draft parameter is set | |
1468 // correctly. It should be false if the only change is the page range. | |
1469 TEST_F('PrintPreviewWebUITest', 'TestGenerateDraft', function() { | |
1470 // Use a real preview generator. | |
1471 printPreview.previewArea_.previewGenerator_ = | |
1472 new print_preview.PreviewGenerator(printPreview.destinationStore_, | |
1473 printPreview.printTicketStore_, this.nativeLayer_, | |
1474 printPreview.documentInfo_); | |
1475 | |
1476 this.setInitialSettings(); | |
1477 this.setLocalDestinations(); | |
1478 this.setCapabilities(getCddTemplate("FooDevice")); | |
1479 | |
1480 // The first request should generate draft because there was no previous print | |
1481 // preview draft. | |
1482 expectTrue(this.generateDraft()); | |
1483 | |
1484 // Change the page range - no new draft needed. | |
1485 printPreview.printTicketStore_.pageRange.updateValue("2"); | |
1486 expectFalse(this.generateDraft()); | |
dpapad
2017/05/05 18:28:49
Thanks. This looks good for now. Eventually when w
| |
1487 | |
1488 // Change the margin type - need to regenerate again. | |
1489 printPreview.printTicketStore_.marginsType.updateValue( | |
1490 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); | |
1491 expectTrue(this.generateDraft()); | |
1492 | |
1493 testDone(); | |
1494 }); | |
OLD | NEW |