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 var ROOT_PATH = '../../../../'; |
| 6 |
5 /** | 7 /** |
6 * Test fixture for print preview WebUI testing. | 8 * Test fixture for print preview WebUI testing. |
7 * @constructor | 9 * @constructor |
8 * @extends {testing.Test} | 10 * @extends {testing.Test} |
9 */ | 11 */ |
10 function PrintPreviewWebUITest() { | 12 function PrintPreviewWebUITest() { |
11 testing.Test.call(this); | 13 testing.Test.call(this); |
| 14 this.printPreview_ = null; |
12 this.nativeLayer_ = null; | 15 this.nativeLayer_ = null; |
13 this.initialSettings_ = null; | 16 this.initialSettings_ = null; |
14 this.localDestinationInfos_ = null; | 17 this.localDestinationInfos_ = null; |
15 this.previewArea_ = null; | 18 this.previewArea_ = null; |
16 } | 19 } |
17 | 20 |
18 /** | 21 /** |
19 * Index of the "Save as PDF" printer. | 22 * Index of the "Save as PDF" printer. |
20 * @type {number} | 23 * @type {number} |
21 * @const | 24 * @const |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 /** @override */ | 58 /** @override */ |
56 isAsync: true, | 59 isAsync: true, |
57 | 60 |
58 /** | 61 /** |
59 * Stub out low-level functionality like the NativeLayer and | 62 * Stub out low-level functionality like the NativeLayer and |
60 * CloudPrintInterface. | 63 * CloudPrintInterface. |
61 * @this {PrintPreviewWebUITest} | 64 * @this {PrintPreviewWebUITest} |
62 * @override | 65 * @override |
63 */ | 66 */ |
64 preLoad: function() { | 67 preLoad: function() { |
| 68 window.isTest = true; |
65 window.addEventListener('DOMContentLoaded', function() { | 69 window.addEventListener('DOMContentLoaded', function() { |
| 70 /** |
| 71 * Test version of the native layer. |
| 72 * @constructor |
| 73 * @extends {settings.TestBrowserProxy} |
| 74 */ |
66 function NativeLayerStub() { | 75 function NativeLayerStub() { |
67 cr.EventTarget.call(this); | 76 settings.TestBrowserProxy.call(this, [ 'getInitialSettings' ]); |
| 77 this.eventTarget_ = new cr.EventTarget(); |
68 this.printStarted_ = false; | 78 this.printStarted_ = false; |
69 this.generateDraft_ = false; | 79 this.generateDraft_ = false; |
| 80 this.initialSettings_ = null; |
70 } | 81 } |
71 NativeLayerStub.prototype = { | 82 NativeLayerStub.prototype = { |
72 __proto__: cr.EventTarget.prototype, | 83 __proto__: settings.TestBrowserProxy.prototype, |
| 84 getEventTarget: function() { return this.eventTarget_; }, |
73 isPrintStarted: function() { return this.printStarted_; }, | 85 isPrintStarted: function() { return this.printStarted_; }, |
74 generateDraft: function() { return this.generateDraft_; }, | 86 generateDraft: function() { return this.generateDraft_; }, |
| 87 getInitialSettings: function() { |
| 88 this.methodCalled('getInitialSettings'); |
| 89 return Promise.resolve(this.initialSettings_); |
| 90 }, |
75 previewReadyForTest: function() {}, | 91 previewReadyForTest: function() {}, |
76 startGetInitialSettings: function() {}, | |
77 startGetLocalDestinations: function() {}, | 92 startGetLocalDestinations: function() {}, |
78 startGetPrivetDestinations: function() {}, | 93 startGetPrivetDestinations: function() {}, |
79 startGetExtensionDestinations: function() {}, | 94 startGetExtensionDestinations: function() {}, |
80 startGetLocalDestinationCapabilities: function(destinationId) {}, | 95 startGetLocalDestinationCapabilities: function(destinationId) {}, |
81 startGetPreview: function(destination, printTicketStore, documentInfo, | 96 startGetPreview: function(destination, printTicketStore, documentInfo, |
82 generateDraft, requestId) { | 97 generateDraft, requestId) { |
83 this.generateDraft_ = generateDraft; | 98 this.generateDraft_ = generateDraft; |
84 }, | 99 }, |
85 startHideDialog: function () {}, | 100 startHideDialog: function () {}, |
86 startPrint: function () { this.printStarted_ = true; } | 101 startPrint: function () { this.printStarted_ = true; } |
(...skipping 15 matching lines...) Expand all Loading... |
102 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub; | 117 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub; |
103 cloudprint.CloudPrintInterfaceEventType = oldCpInterfaceEventType; | 118 cloudprint.CloudPrintInterfaceEventType = oldCpInterfaceEventType; |
104 | 119 |
105 print_preview.PreviewArea.prototype.checkPluginCompatibility_ = | 120 print_preview.PreviewArea.prototype.checkPluginCompatibility_ = |
106 function() { | 121 function() { |
107 return false; | 122 return false; |
108 }; | 123 }; |
109 }.bind(this)); | 124 }.bind(this)); |
110 }, | 125 }, |
111 | 126 |
| 127 extraLibraries: [ |
| 128 ROOT_PATH + 'ui/webui/resources/js/cr.js', |
| 129 ROOT_PATH + 'ui/webui/resources/js/promise_resolver.js', |
| 130 ROOT_PATH + 'ui/webui/resources/js/util.js', |
| 131 ROOT_PATH + 'chrome/test/data/webui/settings/test_browser_proxy.js', |
| 132 ], |
| 133 |
112 /** | 134 /** |
113 * Dispatch the INITIAL_SETTINGS_SET event. This call is NOT async and will | 135 * Creates an instance of print_preview.PrintPreview and initializes the |
114 * happen in the same thread. | 136 * |nativeLayer_| and |previewArea_|. |
115 */ | 137 */ |
116 setInitialSettings: function() { | 138 createPrintPreview: function() { |
117 var initialSettingsSetEvent = | 139 this.printPreview_ = new print_preview.PrintPreview(); |
118 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 140 this.nativeLayer_ = this.printPreview_.nativeLayer_; |
119 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 141 this.previewArea_ = this.printPreview_.previewArea_; |
120 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
121 }, | 142 }, |
122 | 143 |
123 /** | 144 /** |
| 145 * Initialize print preview with the initial settings currently stored in |
| 146 * |this.initialSettings_|. Creates |this.printPreview_| if it does not |
| 147 * already exist. |
| 148 */ |
| 149 setInitialSettings: function() { |
| 150 if (!this.printPreview_) { |
| 151 this.printPreview_ = new print_preview.PrintPreview(); |
| 152 this.nativeLayer_ = this.printPreview_.nativeLayer_; |
| 153 this.previewArea_ = this.printPreview_.previewArea_; |
| 154 } |
| 155 this.nativeLayer_.initialSettings_ = this.initialSettings_; |
| 156 this.printPreview_.initialize(); |
| 157 testing.Test.disableAnimationsAndTransitions(); |
| 158 // Enable when failure is resolved. |
| 159 // AX_TEXT_03: http://crbug.com/559209 |
| 160 this.accessibilityAuditConfig.ignoreSelectors( |
| 161 'multipleLabelableElementsPerLabel', |
| 162 '#page-settings > .right-column > *'); |
| 163 }, |
| 164 |
| 165 /** |
124 * Dispatch the LOCAL_DESTINATIONS_SET event. This call is NOT async and will | 166 * Dispatch the LOCAL_DESTINATIONS_SET event. This call is NOT async and will |
125 * happen in the same thread. | 167 * happen in the same thread. |
126 */ | 168 */ |
127 setLocalDestinations: function() { | 169 setLocalDestinations: function() { |
128 var localDestsSetEvent = | 170 var localDestsSetEvent = |
129 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | 171 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
130 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | 172 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
131 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | 173 this.nativeLayer_.getEventTarget().dispatchEvent(localDestsSetEvent); |
132 }, | 174 }, |
133 | 175 |
134 /** | 176 /** |
135 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will | 177 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will |
136 * happen in the same thread. | 178 * happen in the same thread. |
137 * @device - The device whose capabilities should be dispatched. | 179 * @device - The device whose capabilities should be dispatched. |
138 */ | 180 */ |
139 setCapabilities: function(device) { | 181 setCapabilities: function(device) { |
140 var capsSetEvent = | 182 var capsSetEvent = |
141 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 183 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
142 capsSetEvent.settingsInfo = device; | 184 capsSetEvent.settingsInfo = device; |
143 this.nativeLayer_.dispatchEvent(capsSetEvent); | 185 this.nativeLayer_.getEventTarget().dispatchEvent(capsSetEvent); |
144 }, | 186 }, |
145 | 187 |
146 /** | 188 /** |
147 * Dispatch the PREVIEW_GENERATION_DONE event. This call is NOT async and | 189 * Dispatch the PREVIEW_GENERATION_DONE event. This call is NOT async and |
148 * will happen in the same thread. | 190 * will happen in the same thread. |
149 */ | 191 */ |
150 dispatchPreviewDone: function() { | 192 dispatchPreviewDone: function() { |
151 var previewDoneEvent = | 193 var previewDoneEvent = |
152 new Event(print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); | 194 new Event(print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); |
153 this.previewArea_.dispatchEvent(previewDoneEvent); | 195 this.previewArea_.dispatchEvent(previewDoneEvent); |
154 }, | 196 }, |
155 | 197 |
156 /** | 198 /** |
157 * Dispatch the SETTINGS_INVALID event. This call is NOT async and will | 199 * Dispatch the SETTINGS_INVALID event. This call is NOT async and will |
158 * happen in the same thread. | 200 * happen in the same thread. |
159 */ | 201 */ |
160 dispatchInvalidSettings: function() { | 202 dispatchInvalidSettings: function() { |
161 var invalidSettingsEvent = | 203 var invalidSettingsEvent = |
162 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); | 204 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); |
163 this.nativeLayer_.dispatchEvent(invalidSettingsEvent); | 205 this.nativeLayer_.getEventTarget().dispatchEvent(invalidSettingsEvent); |
164 }, | 206 }, |
165 | 207 |
166 /** | 208 /** |
167 * @return {boolean} Whether the UI has "printed" or not. (called startPrint | 209 * @return {boolean} Whether the UI has "printed" or not. (called startPrint |
168 * on the native layer) | 210 * on the native layer) |
169 */ | 211 */ |
170 hasPrinted: function() { | 212 hasPrinted: function() { |
171 return this.nativeLayer_.isPrintStarted(); | 213 return this.nativeLayer_.isPrintStarted(); |
172 }, | 214 }, |
173 | 215 |
(...skipping 29 matching lines...) Expand all Loading... |
203 moreSettings.click(); | 245 moreSettings.click(); |
204 }, | 246 }, |
205 | 247 |
206 /** | 248 /** |
207 * Repeated setup steps for the advanced settings tests. | 249 * Repeated setup steps for the advanced settings tests. |
208 * Disables accessiblity errors, sets initial settings, and verifies | 250 * Disables accessiblity errors, sets initial settings, and verifies |
209 * advanced options section is visible after expanding more settings. | 251 * advanced options section is visible after expanding more settings. |
210 */ | 252 */ |
211 setupAdvancedSettingsTest: function(device) { | 253 setupAdvancedSettingsTest: function(device) { |
212 // Need to disable this since overlay animation will not fully complete. | 254 // Need to disable this since overlay animation will not fully complete. |
213 this.accessibilityIssuesAreErrors = false; | |
214 this.setInitialSettings(); | |
215 this.setLocalDestinations(); | 255 this.setLocalDestinations(); |
216 this.setCapabilities(device); | 256 this.setCapabilities(device); |
217 this.expandMoreSettings(); | 257 this.expandMoreSettings(); |
218 | 258 |
219 // Check that the advanced options settings section is visible. | 259 // Check that the advanced options settings section is visible. |
220 checkSectionVisible($('advanced-options-settings'), true); | 260 checkSectionVisible($('advanced-options-settings'), true); |
221 }, | 261 }, |
222 | 262 |
223 /** | 263 /** |
224 * @this {PrintPreviewWebUITest} | 264 * @this {PrintPreviewWebUITest} |
(...skipping 13 matching lines...) Expand all Loading... |
238 'title' /*documentTitle*/, | 278 'title' /*documentTitle*/, |
239 true /*documentHasSelection*/, | 279 true /*documentHasSelection*/, |
240 false /*selectionOnly*/, | 280 false /*selectionOnly*/, |
241 'FooDevice' /*systemDefaultDestinationId*/, | 281 'FooDevice' /*systemDefaultDestinationId*/, |
242 null /*serializedAppStateStr*/, | 282 null /*serializedAppStateStr*/, |
243 null /*serializedDefaultDestinationSelectionRulesStr*/); | 283 null /*serializedDefaultDestinationSelectionRulesStr*/); |
244 this.localDestinationInfos_ = [ | 284 this.localDestinationInfos_ = [ |
245 { printerName: 'FooName', deviceName: 'FooDevice' }, | 285 { printerName: 'FooName', deviceName: 'FooDevice' }, |
246 { printerName: 'BarName', deviceName: 'BarDevice' } | 286 { printerName: 'BarName', deviceName: 'BarDevice' } |
247 ]; | 287 ]; |
248 this.nativeLayer_ = printPreview.nativeLayer_; | 288 }, |
249 this.previewArea_ = printPreview.previewArea_; | |
250 | |
251 testing.Test.disableAnimationsAndTransitions(); | |
252 | |
253 // Enable when failure is resolved. | |
254 // AX_TEXT_03: http://crbug.com/559209 | |
255 this.accessibilityAuditConfig.ignoreSelectors( | |
256 'multipleLabelableElementsPerLabel', | |
257 '#page-settings > .right-column > *'); | |
258 } | |
259 }; | 289 }; |
260 | 290 |
261 // Test some basic assumptions about the print preview WebUI. | 291 // Test some basic assumptions about the print preview WebUI. |
262 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { | 292 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { |
263 this.setInitialSettings(); | 293 this.setInitialSettings(); |
264 this.setLocalDestinations(); | 294 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
265 | 295 function() { |
266 var recentList = $('destination-search').querySelector('.recent-list ul'); | 296 this.setLocalDestinations(); |
267 var localList = $('destination-search').querySelector('.local-list ul'); | 297 var recentList = |
268 assertNotEquals(null, recentList); | 298 $('destination-search').querySelector('.recent-list ul'); |
269 assertEquals(1, recentList.childNodes.length); | 299 var localList = |
270 assertEquals('FooName', | 300 $('destination-search').querySelector('.local-list ul'); |
271 recentList.childNodes.item(0).querySelector( | 301 assertNotEquals(null, recentList); |
272 '.destination-list-item-name').textContent); | 302 assertEquals(1, recentList.childNodes.length); |
273 | 303 assertEquals('FooName', |
274 assertNotEquals(null, localList); | 304 recentList.childNodes.item(0).querySelector( |
275 assertEquals(3, localList.childNodes.length); | 305 '.destination-list-item-name').textContent); |
276 assertEquals('Save as PDF', | 306 assertNotEquals(null, localList); |
277 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). | 307 assertEquals(3, localList.childNodes.length); |
278 querySelector('.destination-list-item-name').textContent); | 308 assertEquals('Save as PDF', |
279 assertEquals('FooName', | 309 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). |
280 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). | 310 querySelector('.destination-list-item-name').textContent); |
281 querySelector('.destination-list-item-name').textContent); | 311 assertEquals('FooName', |
282 assertEquals('BarName', | 312 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). |
283 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). | 313 querySelector('.destination-list-item-name').textContent); |
284 querySelector('.destination-list-item-name').textContent); | 314 assertEquals('BarName', |
285 | 315 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). |
286 testDone(); | 316 querySelector('.destination-list-item-name').textContent); |
| 317 testDone(); |
| 318 }.bind(this)); |
287 }); | 319 }); |
288 | 320 |
289 // Test that the printer list is structured correctly after calling | 321 // Test that the printer list is structured correctly after calling |
290 // addCloudPrinters with an empty list. | 322 // addCloudPrinters with an empty list. |
291 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { | 323 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { |
292 this.setInitialSettings(); | 324 this.setInitialSettings(); |
293 this.setLocalDestinations(); | |
294 | 325 |
295 var cloudPrintEnableEvent = | 326 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
296 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); | 327 function() { |
297 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; | 328 this.setLocalDestinations(); |
298 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent); | |
299 | 329 |
300 var searchDoneEvent = | 330 var cloudPrintEnableEvent = |
301 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE); | 331 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); |
302 searchDoneEvent.printers = []; | 332 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; |
303 searchDoneEvent.isRecent = true; | 333 this.nativeLayer_.getEventTarget().dispatchEvent( |
304 searchDoneEvent.email = 'foo@chromium.org'; | 334 cloudPrintEnableEvent); |
305 printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent); | |
306 | 335 |
307 var recentList = $('destination-search').querySelector('.recent-list ul'); | 336 var searchDoneEvent = |
308 var localList = $('destination-search').querySelector('.local-list ul'); | 337 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE); |
309 var cloudList = $('destination-search').querySelector('.cloud-list ul'); | 338 searchDoneEvent.printers = []; |
| 339 searchDoneEvent.isRecent = true; |
| 340 searchDoneEvent.email = 'foo@chromium.org'; |
| 341 this.printPreview_.cloudPrintInterface_.dispatchEvent(searchDoneEvent); |
310 | 342 |
311 assertNotEquals(null, recentList); | 343 var recentList = |
312 assertEquals(1, recentList.childNodes.length); | 344 $('destination-search').querySelector('.recent-list ul'); |
313 assertEquals('FooName', | 345 var localList = |
314 recentList.childNodes.item(0).querySelector( | 346 $('destination-search').querySelector('.local-list ul'); |
315 '.destination-list-item-name').textContent); | 347 var cloudList = |
| 348 $('destination-search').querySelector('.cloud-list ul'); |
316 | 349 |
317 assertNotEquals(null, localList); | 350 assertNotEquals(null, recentList); |
318 assertEquals(3, localList.childNodes.length); | 351 assertEquals(1, recentList.childNodes.length); |
319 assertEquals('Save as PDF', | 352 assertEquals('FooName', |
320 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). | 353 recentList.childNodes.item(0). |
321 querySelector('.destination-list-item-name').textContent); | 354 querySelector('.destination-list-item-name'). |
322 assertEquals('FooName', | 355 textContent); |
323 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). | |
324 querySelector('.destination-list-item-name').textContent); | |
325 assertEquals('BarName', | |
326 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). | |
327 querySelector('.destination-list-item-name').textContent); | |
328 | 356 |
329 assertNotEquals(null, cloudList); | 357 assertNotEquals(null, localList); |
330 assertEquals(0, cloudList.childNodes.length); | 358 assertEquals(3, localList.childNodes.length); |
| 359 assertEquals('Save as PDF', |
| 360 localList.childNodes.item( |
| 361 PrintPreviewWebUITest.PDF_INDEX). |
| 362 querySelector('.destination-list-item-name'). |
| 363 textContent); |
| 364 assertEquals('FooName', |
| 365 localList.childNodes. |
| 366 item(PrintPreviewWebUITest.FOO_INDEX). |
| 367 querySelector('.destination-list-item-name'). |
| 368 textContent); |
| 369 assertEquals('BarName', |
| 370 localList.childNodes. |
| 371 item(PrintPreviewWebUITest.BAR_INDEX). |
| 372 querySelector('.destination-list-item-name'). |
| 373 textContent); |
331 | 374 |
332 testDone(); | 375 assertNotEquals(null, cloudList); |
| 376 assertEquals(0, cloudList.childNodes.length); |
| 377 |
| 378 testDone(); |
| 379 }.bind(this)); |
333 }); | 380 }); |
334 | 381 |
335 /** | 382 /** |
336 * Verify that |section| visibility matches |visible|. | 383 * Verify that |section| visibility matches |visible|. |
337 * @param {HTMLDivElement} section The section to check. | 384 * @param {HTMLDivElement} section The section to check. |
338 * @param {boolean} visible The expected state of visibility. | 385 * @param {boolean} visible The expected state of visibility. |
339 */ | 386 */ |
340 function checkSectionVisible(section, visible) { | 387 function checkSectionVisible(section, visible) { |
341 assertNotEquals(null, section); | 388 assertNotEquals(null, section); |
342 expectEquals( | 389 expectEquals( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 loadTimeData.getBoolean('printPdfAsImageEnabled')); | 446 loadTimeData.getBoolean('printPdfAsImageEnabled')); |
400 } | 447 } |
401 | 448 |
402 // Test restore settings with one destination. | 449 // Test restore settings with one destination. |
403 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreLocalDestination', | 450 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreLocalDestination', |
404 function() { | 451 function() { |
405 this.initialSettings_.serializedAppStateStr_ = | 452 this.initialSettings_.serializedAppStateStr_ = |
406 '{"version":2,"recentDestinations":[{"id":"ID", "origin":"local",' + | 453 '{"version":2,"recentDestinations":[{"id":"ID", "origin":"local",' + |
407 '"account":"", "capabilities":0, "name":"", "extensionId":"",' + | 454 '"account":"", "capabilities":0, "name":"", "extensionId":"",' + |
408 '"extensionName":""}]}'; | 455 '"extensionName":""}]}'; |
| 456 |
409 this.setInitialSettings(); | 457 this.setInitialSettings(); |
410 | 458 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
411 testDone(); | 459 function() { |
| 460 testDone(); |
| 461 }); |
412 }); | 462 }); |
413 | 463 |
414 // Test with multiple destinations | 464 // Test with multiple destinations |
415 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreMultipleDestinations', | 465 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreMultipleDestinations', |
416 function() { | 466 function() { |
417 var origin = cr.isChromeOS ? "chrome_os" : "local"; | 467 var origin = cr.isChromeOS ? "chrome_os" : "local"; |
418 | 468 |
419 var appState = { | 469 var appState = { |
420 'version': 2, | 470 'version': 2, |
421 'recentDestinations': [ | 471 'recentDestinations': [ |
(...skipping 21 matching lines...) Expand all Loading... |
443 'account': '', | 493 'account': '', |
444 'capabilities': 0, | 494 'capabilities': 0, |
445 'name': '', | 495 'name': '', |
446 'extensionId': '', | 496 'extensionId': '', |
447 'extensionName': '' | 497 'extensionName': '' |
448 } | 498 } |
449 ] | 499 ] |
450 }; | 500 }; |
451 | 501 |
452 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(appState); | 502 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(appState); |
453 | |
454 this.setInitialSettings(); | 503 this.setInitialSettings(); |
455 | 504 |
456 // Set capabilities for the three recently used destinations + 1 more | 505 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
457 this.setCapabilities(getCddTemplate('ID1')); | 506 function() { |
458 this.setCapabilities(getCddTemplate('ID2')); | 507 // Set capabilities for the three recently used destinations + 1 more |
459 this.setCapabilities(getCddTemplate('ID3')); | 508 this.setCapabilities(getCddTemplate('ID1')); |
460 this.setCapabilities(getCddTemplate('ID4')); | 509 this.setCapabilities(getCddTemplate('ID2')); |
| 510 this.setCapabilities(getCddTemplate('ID3')); |
| 511 this.setCapabilities(getCddTemplate('ID4')); |
461 | 512 |
462 // The most recently used destination should be the currently selected one. | 513 // The most recently used destination should be the currently selected |
463 // This is ID1. | 514 // one. This is ID1. |
464 assertEquals( | 515 assertEquals( |
465 'ID1', printPreview.destinationStore_.selectedDestination.id); | 516 'ID1', this.printPreview_.destinationStore_.selectedDestination.id); |
466 | 517 |
467 // Look through the destinations. ID1, ID2, and ID3 should all be recent. | 518 // Look through the destinations. ID1, ID2, and ID3 should all be |
468 var destinations = printPreview.destinationStore_.destinations_; | 519 // recent. |
469 var idsFound = []; | 520 var destinations = this.printPreview_.destinationStore_.destinations_; |
| 521 var idsFound = []; |
470 | 522 |
471 for (var i = 0; i < destinations.length; i++) { | 523 for (var i = 0; i < destinations.length; i++) { |
472 if (!destinations[i]) | 524 if (!destinations[i]) |
473 continue; | 525 continue; |
474 if (destinations[i].isRecent) | 526 if (destinations[i].isRecent) |
475 idsFound.push(destinations[i].id); | 527 idsFound.push(destinations[i].id); |
476 } | 528 } |
477 | 529 |
478 // Make sure there were 3 recent destinations and that they are the correct | 530 // Make sure there were 3 recent destinations and that they are the |
479 // IDs. | 531 // correct IDs. |
480 assertEquals(3, idsFound.length); | 532 assertEquals(3, idsFound.length); |
481 assertNotEquals(-1, idsFound.indexOf("ID1")); | 533 assertNotEquals(-1, idsFound.indexOf("ID1")); |
482 assertNotEquals(-1, idsFound.indexOf("ID2")); | 534 assertNotEquals(-1, idsFound.indexOf("ID2")); |
483 assertNotEquals(-1, idsFound.indexOf("ID3")); | 535 assertNotEquals(-1, idsFound.indexOf("ID3")); |
484 | 536 |
485 testDone(); | 537 testDone(); |
| 538 }.bind(this)); |
486 }); | 539 }); |
487 | 540 |
488 TEST_F('PrintPreviewWebUITest', | 541 TEST_F('PrintPreviewWebUITest', |
489 'TestPrintPreviewDefaultDestinationSelectionRules', function() { | 542 'TestPrintPreviewDefaultDestinationSelectionRules', function() { |
490 // It also makes sure these rules do override system default destination. | 543 // It also makes sure these rules do override system default destination. |
491 this.initialSettings_.serializedDefaultDestinationSelectionRulesStr_ = | 544 this.initialSettings_.serializedDefaultDestinationSelectionRulesStr_ = |
492 '{"namePattern":".*Bar.*"}'; | 545 '{"namePattern":".*Bar.*"}'; |
493 this.setInitialSettings(); | 546 this.setInitialSettings(); |
494 this.setLocalDestinations(); | 547 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
| 548 function() { |
| 549 this.setLocalDestinations(); |
495 | 550 |
496 assertEquals( | 551 assertEquals( |
497 'BarDevice', printPreview.destinationStore_.selectedDestination.id); | 552 'BarDevice', |
| 553 this.printPreview_.destinationStore_.selectedDestination.id); |
498 | 554 |
499 testDone(); | 555 testDone(); |
| 556 }.bind(this)); |
500 }); | 557 }); |
501 | 558 |
502 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode', | 559 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode', |
503 function() { | 560 function() { |
504 if (cr.isChromeOS) { | 561 if (!cr.isChromeOS) |
505 assertEquals(null, $('system-dialog-link')); | |
506 } else { | |
507 this.initialSettings_.isInAppKioskMode_ = true; | 562 this.initialSettings_.isInAppKioskMode_ = true; |
508 this.setInitialSettings(); | |
509 | 563 |
510 checkElementDisplayed($('system-dialog-link'), false); | 564 this.setInitialSettings(); |
511 } | 565 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
512 | 566 function() { |
513 testDone(); | 567 if (cr.isChromeOS) |
| 568 assertEquals(null, $('system-dialog-link')); |
| 569 else |
| 570 checkElementDisplayed($('system-dialog-link'), false); |
| 571 testDone(); |
| 572 }); |
514 }); | 573 }); |
515 | 574 |
516 // Test that disabled settings hide the disabled sections. | 575 // Test that disabled settings hide the disabled sections. |
517 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { | 576 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { |
| 577 this.createPrintPreview(); |
518 checkSectionVisible($('layout-settings'), false); | 578 checkSectionVisible($('layout-settings'), false); |
519 checkSectionVisible($('color-settings'), false); | 579 checkSectionVisible($('color-settings'), false); |
520 checkSectionVisible($('copies-settings'), false); | 580 checkSectionVisible($('copies-settings'), false); |
521 | 581 |
522 this.setInitialSettings(); | 582 this.setInitialSettings(); |
523 this.setLocalDestinations(); | 583 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
524 var device = getCddTemplate("FooDevice"); | 584 function() { |
525 device.capabilities.printer.color = { | 585 this.setLocalDestinations(); |
526 "option": [ | 586 var device = getCddTemplate("FooDevice"); |
527 {"is_default": true, "type": "STANDARD_COLOR"} | 587 device.capabilities.printer.color = { |
528 ] | 588 "option": [ |
529 }; | 589 {"is_default": true, "type": "STANDARD_COLOR"} |
530 delete device.capabilities.printer.copies; | 590 ] |
531 this.setCapabilities(device); | 591 }; |
| 592 delete device.capabilities.printer.copies; |
| 593 this.setCapabilities(device); |
532 | 594 |
533 checkSectionVisible($('layout-settings'), true); | 595 checkSectionVisible($('layout-settings'), true); |
534 checkSectionVisible($('color-settings'), false); | 596 checkSectionVisible($('color-settings'), false); |
535 checkSectionVisible($('copies-settings'), false); | 597 checkSectionVisible($('copies-settings'), false); |
536 | 598 |
537 this.waitForAnimationToEnd('other-options-collapsible'); | 599 this.waitForAnimationToEnd('other-options-collapsible'); |
| 600 }.bind(this)); |
538 }); | 601 }); |
539 | 602 |
540 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the | 603 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the |
541 // fit to page option. | 604 // fit to page option. |
542 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() { | 605 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() { |
543 // Add PDF printer. | 606 // Add PDF printer. |
544 this.initialSettings_.isDocumentModifiable_ = false; | 607 this.initialSettings_.isDocumentModifiable_ = false; |
545 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF'; | 608 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF'; |
546 this.setInitialSettings(); | 609 this.setInitialSettings(); |
547 | 610 |
548 var device = { | 611 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
549 printerId: 'Save as PDF', | 612 function() { |
550 capabilities: { | 613 var device = { |
551 version: '1.0', | 614 printerId: 'Save as PDF', |
552 printer: { | 615 capabilities: { |
553 page_orientation: { | 616 version: '1.0', |
554 option: [ | 617 printer: { |
555 {type: 'AUTO', is_default: true}, | 618 page_orientation: { |
556 {type: 'PORTRAIT'}, | 619 option: [ |
557 {type: 'LANDSCAPE'} | 620 {type: 'AUTO', is_default: true}, |
558 ] | 621 {type: 'PORTRAIT'}, |
559 }, | 622 {type: 'LANDSCAPE'} |
560 color: { | 623 ] |
561 option: [ | 624 }, |
562 {type: 'STANDARD_COLOR', is_default: true} | 625 color: { |
563 ] | 626 option: [ |
564 }, | 627 {type: 'STANDARD_COLOR', is_default: true} |
565 media_size: { | 628 ] |
566 option: [ | 629 }, |
567 { name: 'NA_LETTER', | 630 media_size: { |
568 width_microns: 0, | 631 option: [ |
569 height_microns: 0, | 632 { name: 'NA_LETTER', |
570 is_default: true | 633 width_microns: 0, |
| 634 height_microns: 0, |
| 635 is_default: true |
| 636 } |
| 637 ] |
| 638 } |
571 } | 639 } |
572 ] | 640 } |
| 641 }; |
| 642 this.setCapabilities(device); |
| 643 |
| 644 var otherOptions = $('other-options-settings'); |
| 645 // If rasterization is an option, other options should be visible. If |
| 646 // not, there should be no available other options. |
| 647 checkSectionVisible(otherOptions, isPrintAsImageEnabled()); |
| 648 if (isPrintAsImageEnabled()) { |
| 649 checkElementDisplayed( |
| 650 otherOptions.querySelector('#fit-to-page-container'), false); |
| 651 checkElementDisplayed( |
| 652 otherOptions.querySelector('#rasterize-container'), true); |
573 } | 653 } |
574 } | 654 checkSectionVisible($('media-size-settings'), false); |
575 } | 655 checkSectionVisible($('scaling-settings'), false); |
576 }; | |
577 this.setCapabilities(device); | |
578 | 656 |
579 var otherOptions = $('other-options-settings'); | 657 testDone(); |
580 // If rasterization is an option, other options should be visible. If not, | 658 }.bind(this)); |
581 // there should be no available other options. | |
582 checkSectionVisible(otherOptions, isPrintAsImageEnabled()); | |
583 if (isPrintAsImageEnabled()) { | |
584 checkElementDisplayed( | |
585 otherOptions.querySelector('#fit-to-page-container'), false); | |
586 checkElementDisplayed( | |
587 otherOptions.querySelector('#rasterize-container'), true); | |
588 } | |
589 checkSectionVisible($('media-size-settings'), false); | |
590 checkSectionVisible($('scaling-settings'), false); | |
591 | |
592 testDone(); | |
593 }); | 659 }); |
594 | 660 |
595 // When the source is 'HTML', we always hide the fit to page option and show | 661 // When the source is 'HTML', we always hide the fit to page option and show |
596 // media size option. | 662 // media size option. |
597 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() { | 663 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() { |
598 this.setInitialSettings(); | 664 this.setInitialSettings(); |
599 this.setLocalDestinations(); | 665 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
600 this.setCapabilities(getCddTemplate("FooDevice")); | 666 function() { |
| 667 this.setLocalDestinations(); |
| 668 this.setCapabilities(getCddTemplate("FooDevice")); |
601 | 669 |
602 var otherOptions = $('other-options-settings'); | 670 var otherOptions = $('other-options-settings'); |
603 var fitToPage = otherOptions.querySelector('#fit-to-page-container'); | 671 var fitToPage = otherOptions.querySelector('#fit-to-page-container'); |
604 var rasterize; | 672 var rasterize; |
605 if (isPrintAsImageEnabled()) | 673 if (isPrintAsImageEnabled()) |
606 rasterize = otherOptions.querySelector('#rasterize-container'); | 674 rasterize = otherOptions.querySelector('#rasterize-container'); |
607 var mediaSize = $('media-size-settings'); | 675 var mediaSize = $('media-size-settings'); |
608 var scalingSettings = $('scaling-settings'); | 676 var scalingSettings = $('scaling-settings'); |
609 | 677 |
610 // Check that options are collapsed (section is visible, because duplex is | 678 // Check that options are collapsed (section is visible, because duplex |
611 // available). | 679 // is available). |
612 checkSectionVisible(otherOptions, true); | 680 checkSectionVisible(otherOptions, true); |
613 checkElementDisplayed(fitToPage, false); | 681 checkElementDisplayed(fitToPage, false); |
614 if (isPrintAsImageEnabled()) | 682 if (isPrintAsImageEnabled()) |
615 checkElementDisplayed(rasterize, false); | 683 checkElementDisplayed(rasterize, false); |
616 checkSectionVisible(mediaSize, false); | 684 checkSectionVisible(mediaSize, false); |
617 checkSectionVisible(scalingSettings, false); | 685 checkSectionVisible(scalingSettings, false); |
618 | 686 |
619 this.expandMoreSettings(); | 687 this.expandMoreSettings(); |
620 | 688 |
621 checkElementDisplayed(fitToPage, false); | 689 checkElementDisplayed(fitToPage, false); |
622 if (isPrintAsImageEnabled()) | 690 if (isPrintAsImageEnabled()) |
623 checkElementDisplayed(rasterize, false); | 691 checkElementDisplayed(rasterize, false); |
624 checkSectionVisible(mediaSize, true); | 692 checkSectionVisible(mediaSize, true); |
625 checkSectionVisible(scalingSettings, true); | 693 checkSectionVisible(scalingSettings, true); |
626 | 694 |
627 this.waitForAnimationToEnd('more-settings'); | 695 this.waitForAnimationToEnd('more-settings'); |
| 696 }.bind(this)); |
628 }); | 697 }); |
629 | 698 |
630 // When the source is "PDF", depending on the selected destination printer, we | 699 // When the source is "PDF", depending on the selected destination printer, we |
631 // show/hide the fit to page option and hide media size selection. | 700 // show/hide the fit to page option and hide media size selection. |
632 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() { | 701 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() { |
633 this.initialSettings_.isDocumentModifiable_ = false; | 702 this.initialSettings_.isDocumentModifiable_ = false; |
634 this.setInitialSettings(); | 703 this.setInitialSettings(); |
635 this.setLocalDestinations(); | 704 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
636 this.setCapabilities(getCddTemplate("FooDevice")); | 705 function() { |
| 706 this.setLocalDestinations(); |
| 707 this.setCapabilities(getCddTemplate("FooDevice")); |
637 | 708 |
638 var otherOptions = $('other-options-settings'); | 709 var otherOptions = $('other-options-settings'); |
639 var scalingSettings = $('scaling-settings'); | 710 var scalingSettings = $('scaling-settings'); |
640 var fitToPageContainer = | 711 var fitToPageContainer = |
641 otherOptions.querySelector('#fit-to-page-container'); | 712 otherOptions.querySelector('#fit-to-page-container'); |
642 var rasterizeContainer; | 713 var rasterizeContainer; |
643 if (isPrintAsImageEnabled()) { | 714 if (isPrintAsImageEnabled()) { |
644 rasterizeContainer = | 715 rasterizeContainer = |
645 otherOptions.querySelector('#rasterize-container'); | 716 otherOptions.querySelector('#rasterize-container'); |
646 } | 717 } |
647 | 718 |
648 checkSectionVisible(otherOptions, true); | 719 checkSectionVisible(otherOptions, true); |
649 checkElementDisplayed(fitToPageContainer, true); | 720 checkElementDisplayed(fitToPageContainer, true); |
650 if (isPrintAsImageEnabled()) | 721 if (isPrintAsImageEnabled()) |
651 checkElementDisplayed(rasterizeContainer, false); | 722 checkElementDisplayed(rasterizeContainer, false); |
652 expectTrue( | 723 expectTrue( |
653 fitToPageContainer.querySelector('.checkbox').checked); | 724 fitToPageContainer.querySelector('.checkbox').checked); |
654 this.expandMoreSettings(); | 725 this.expandMoreSettings(); |
655 if (isPrintAsImageEnabled()) { | 726 if (isPrintAsImageEnabled()) { |
656 checkElementDisplayed(rasterizeContainer, true); | 727 checkElementDisplayed(rasterizeContainer, true); |
657 expectFalse( | 728 expectFalse( |
658 rasterizeContainer.querySelector('.checkbox').checked); | 729 rasterizeContainer.querySelector('.checkbox').checked); |
659 } | 730 } |
660 checkSectionVisible($('media-size-settings'), true); | 731 checkSectionVisible($('media-size-settings'), true); |
661 checkSectionVisible(scalingSettings, true); | 732 checkSectionVisible(scalingSettings, true); |
662 | 733 |
663 this.waitForAnimationToEnd('other-options-collapsible'); | 734 this.waitForAnimationToEnd('other-options-collapsible'); |
| 735 }.bind(this)); |
664 }); | 736 }); |
665 | 737 |
666 // When the source is "PDF", depending on the selected destination printer, we | 738 // When the source is "PDF", depending on the selected destination printer, we |
667 // show/hide the fit to page option and hide media size selection. | 739 // show/hide the fit to page option and hide media size selection. |
668 TEST_F('PrintPreviewWebUITest', 'ScalingUnchecksFitToPage', function() { | 740 TEST_F('PrintPreviewWebUITest', 'ScalingUnchecksFitToPage', function() { |
669 this.initialSettings_.isDocumentModifiable_ = false; | 741 this.initialSettings_.isDocumentModifiable_ = false; |
670 this.setInitialSettings(); | 742 this.setInitialSettings(); |
671 this.setLocalDestinations(); | 743 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
672 this.setCapabilities(getCddTemplate("FooDevice")); | 744 function() { |
| 745 this.setLocalDestinations(); |
| 746 this.setCapabilities(getCddTemplate("FooDevice")); |
673 | 747 |
674 var otherOptions = $('other-options-settings'); | 748 var otherOptions = $('other-options-settings'); |
675 var scalingSettings = $('scaling-settings'); | 749 var scalingSettings = $('scaling-settings'); |
676 | 750 |
677 checkSectionVisible(otherOptions, true); | 751 checkSectionVisible(otherOptions, true); |
678 var fitToPageContainer = | 752 var fitToPageContainer = |
679 otherOptions.querySelector('#fit-to-page-container'); | 753 otherOptions.querySelector('#fit-to-page-container'); |
680 checkElementDisplayed(fitToPageContainer, true); | 754 checkElementDisplayed(fitToPageContainer, true); |
681 expectTrue( | 755 expectTrue( |
682 fitToPageContainer.querySelector('.checkbox').checked); | 756 fitToPageContainer.querySelector('.checkbox').checked); |
683 this.expandMoreSettings(); | 757 this.expandMoreSettings(); |
684 checkSectionVisible($('media-size-settings'), true); | 758 checkSectionVisible($('media-size-settings'), true); |
685 checkSectionVisible(scalingSettings, true); | 759 checkSectionVisible(scalingSettings, true); |
686 | 760 |
687 // Change scaling input | 761 // Change scaling input |
688 var scalingInput = scalingSettings.querySelector('.user-value'); | 762 var scalingInput = scalingSettings.querySelector('.user-value'); |
689 expectEquals('100', scalingInput.value); | 763 expectEquals('100', scalingInput.value); |
690 scalingInput.stepUp(5); | 764 scalingInput.stepUp(5); |
691 expectEquals('105', scalingInput.value); | 765 expectEquals('105', scalingInput.value); |
692 | 766 |
693 // Trigger the event | 767 // Trigger the event |
694 var enterEvent = document.createEvent('Event'); | 768 var enterEvent = document.createEvent('Event'); |
695 enterEvent.initEvent('keydown'); | 769 enterEvent.initEvent('keydown'); |
696 enterEvent.keyCode = 'Enter'; | 770 enterEvent.keyCode = 'Enter'; |
697 scalingInput.dispatchEvent(enterEvent); | 771 scalingInput.dispatchEvent(enterEvent); |
698 expectFalse( | 772 expectFalse( |
699 fitToPageContainer.querySelector('.checkbox').checked); | 773 fitToPageContainer.querySelector('.checkbox').checked); |
700 | 774 |
701 this.waitForAnimationToEnd('other-options-collapsible'); | 775 this.waitForAnimationToEnd('other-options-collapsible'); |
| 776 }.bind(this)); |
702 }); | 777 }); |
703 | 778 |
704 // When the number of copies print preset is set for source 'PDF', we update | 779 // When the number of copies print preset is set for source 'PDF', we update |
705 // the copies value if capability is supported by printer. | 780 // the copies value if capability is supported by printer. |
706 TEST_F('PrintPreviewWebUITest', 'CheckNumCopiesPrintPreset', function() { | 781 TEST_F('PrintPreviewWebUITest', 'CheckNumCopiesPrintPreset', function() { |
707 this.initialSettings_.isDocumentModifiable_ = false; | 782 this.initialSettings_.isDocumentModifiable_ = false; |
708 this.setInitialSettings(); | 783 this.setInitialSettings(); |
709 this.setLocalDestinations(); | 784 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
710 this.setCapabilities(getCddTemplate("FooDevice")); | 785 function() { |
| 786 this.setLocalDestinations(); |
| 787 this.setCapabilities(getCddTemplate("FooDevice")); |
711 | 788 |
712 // Indicate that the number of copies print preset is set for source PDF. | 789 // Indicate that the number of copies print preset is set for source |
713 var printPresetOptions = { | 790 // PDF. |
714 disableScaling: true, | 791 var printPresetOptions = { |
715 copies: 2 | 792 disableScaling: true, |
716 }; | 793 copies: 2 |
717 var printPresetOptionsEvent = new Event( | 794 }; |
718 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); | 795 var printPresetOptionsEvent = new Event( |
719 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; | 796 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
720 this.nativeLayer_.dispatchEvent(printPresetOptionsEvent); | 797 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; |
| 798 this.nativeLayer_.getEventTarget(). |
| 799 dispatchEvent(printPresetOptionsEvent); |
721 | 800 |
722 checkSectionVisible($('copies-settings'), true); | 801 checkSectionVisible($('copies-settings'), true); |
723 expectEquals( | 802 expectEquals( |
724 printPresetOptions.copies, | 803 printPresetOptions.copies, |
725 parseInt($('copies-settings').querySelector('.user-value').value)); | 804 parseInt($('copies-settings').querySelector('.user-value').value)); |
726 | 805 |
727 this.waitForAnimationToEnd('other-options-collapsible'); | 806 this.waitForAnimationToEnd('other-options-collapsible'); |
| 807 }.bind(this)); |
728 }); | 808 }); |
729 | 809 |
730 // When the duplex print preset is set for source 'PDF', we update the | 810 // When the duplex print preset is set for source 'PDF', we update the |
731 // duplex setting if capability is supported by printer. | 811 // duplex setting if capability is supported by printer. |
732 TEST_F('PrintPreviewWebUITest', 'CheckDuplexPrintPreset', function() { | 812 TEST_F('PrintPreviewWebUITest', 'CheckDuplexPrintPreset', function() { |
733 this.initialSettings_.isDocumentModifiable_ = false; | 813 this.initialSettings_.isDocumentModifiable_ = false; |
734 this.setInitialSettings(); | 814 this.setInitialSettings(); |
735 this.setLocalDestinations(); | |
736 this.setCapabilities(getCddTemplate("FooDevice")); | |
737 | 815 |
738 // Indicate that the duplex print preset is set to "long edge" for source PDF. | 816 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
739 var printPresetOptions = { | 817 function() { |
740 duplex: 1 | 818 this.setLocalDestinations(); |
741 }; | 819 this.setCapabilities(getCddTemplate("FooDevice")); |
742 var printPresetOptionsEvent = new Event( | |
743 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); | |
744 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; | |
745 this.nativeLayer_.dispatchEvent(printPresetOptionsEvent); | |
746 | 820 |
747 var otherOptions = $('other-options-settings'); | 821 // Indicate that the duplex print preset is set to "long edge" for |
748 checkSectionVisible(otherOptions, true); | 822 // source PDF. |
749 var duplexContainer = otherOptions.querySelector('#duplex-container'); | 823 var printPresetOptions = { |
750 checkElementDisplayed(duplexContainer, true); | 824 duplex: 1 |
751 expectTrue(duplexContainer.querySelector('.checkbox').checked); | 825 }; |
| 826 var printPresetOptionsEvent = new Event( |
| 827 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| 828 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; |
| 829 this.nativeLayer_.getEventTarget(). |
| 830 dispatchEvent(printPresetOptionsEvent); |
752 | 831 |
753 this.waitForAnimationToEnd('other-options-collapsible'); | 832 var otherOptions = $('other-options-settings'); |
| 833 checkSectionVisible(otherOptions, true); |
| 834 var duplexContainer = otherOptions.querySelector('#duplex-container'); |
| 835 checkElementDisplayed(duplexContainer, true); |
| 836 expectTrue(duplexContainer.querySelector('.checkbox').checked); |
| 837 |
| 838 this.waitForAnimationToEnd('other-options-collapsible'); |
| 839 }.bind(this)); |
754 }); | 840 }); |
755 | 841 |
756 // Make sure that custom margins controls are properly set up. | 842 // Make sure that custom margins controls are properly set up. |
757 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() { | 843 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() { |
758 this.setInitialSettings(); | 844 this.setInitialSettings(); |
759 this.setLocalDestinations(); | 845 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
760 this.setCapabilities(getCddTemplate("FooDevice")); | 846 function() { |
| 847 this.setLocalDestinations(); |
| 848 this.setCapabilities(getCddTemplate("FooDevice")); |
761 | 849 |
762 printPreview.printTicketStore_.marginsType.updateValue( | 850 this.printPreview_.printTicketStore_.marginsType.updateValue( |
763 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 851 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
764 | 852 |
765 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { | 853 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { |
766 var control = $('preview-area').querySelector('.margin-control-' + margin); | 854 var control = |
767 assertNotEquals(null, control); | 855 $('preview-area').querySelector('.margin-control-' + margin); |
768 var input = control.querySelector('.margin-control-textbox'); | 856 assertNotEquals(null, control); |
769 assertTrue(input.hasAttribute('aria-label')); | 857 var input = control.querySelector('.margin-control-textbox'); |
770 assertNotEquals('undefined', input.getAttribute('aria-label')); | 858 assertTrue(input.hasAttribute('aria-label')); |
771 }); | 859 assertNotEquals('undefined', input.getAttribute('aria-label')); |
772 this.waitForAnimationToEnd('more-settings'); | 860 }); |
| 861 this.waitForAnimationToEnd('more-settings'); |
| 862 }.bind(this)); |
773 }); | 863 }); |
774 | 864 |
775 // Page layout has zero margins. Hide header and footer option. | 865 // Page layout has zero margins. Hide header and footer option. |
776 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter', | 866 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter', |
777 function() { | 867 function() { |
778 this.setInitialSettings(); | 868 this.setInitialSettings(); |
779 this.setLocalDestinations(); | 869 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
780 this.setCapabilities(getCddTemplate("FooDevice")); | 870 function() { |
| 871 this.setLocalDestinations(); |
| 872 this.setCapabilities(getCddTemplate("FooDevice")); |
781 | 873 |
782 var otherOptions = $('other-options-settings'); | 874 var otherOptions = $('other-options-settings'); |
783 var headerFooter = otherOptions.querySelector('#header-footer-container'); | 875 var headerFooter = |
| 876 otherOptions.querySelector('#header-footer-container'); |
784 | 877 |
785 // Check that options are collapsed (section is visible, because duplex is | 878 // Check that options are collapsed (section is visible, because duplex |
786 // available). | 879 // is available). |
787 checkSectionVisible(otherOptions, true); | 880 checkSectionVisible(otherOptions, true); |
788 checkElementDisplayed(headerFooter, false); | 881 checkElementDisplayed(headerFooter, false); |
789 | 882 |
790 this.expandMoreSettings(); | 883 this.expandMoreSettings(); |
791 | 884 |
792 checkElementDisplayed(headerFooter, true); | 885 checkElementDisplayed(headerFooter, true); |
793 | 886 |
794 printPreview.printTicketStore_.marginsType.updateValue( | 887 this.printPreview_.printTicketStore_.marginsType.updateValue( |
795 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 888 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
796 printPreview.printTicketStore_.customMargins.updateValue( | 889 this.printPreview_.printTicketStore_.customMargins.updateValue( |
797 new print_preview.Margins(0, 0, 0, 0)); | 890 new print_preview.Margins(0, 0, 0, 0)); |
798 | 891 |
799 checkElementDisplayed(headerFooter, false); | 892 checkElementDisplayed(headerFooter, false); |
800 | 893 |
801 this.waitForAnimationToEnd('more-settings'); | 894 this.waitForAnimationToEnd('more-settings'); |
| 895 }.bind(this)); |
802 }); | 896 }); |
803 | 897 |
804 // Page layout has half-inch margins. Show header and footer option. | 898 // Page layout has half-inch margins. Show header and footer option. |
805 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter', | 899 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter', |
806 function() { | 900 function() { |
807 this.setInitialSettings(); | 901 this.setInitialSettings(); |
808 this.setLocalDestinations(); | 902 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
809 this.setCapabilities(getCddTemplate("FooDevice")); | 903 function() { |
| 904 this.setLocalDestinations(); |
| 905 this.setCapabilities(getCddTemplate("FooDevice")); |
810 | 906 |
811 var otherOptions = $('other-options-settings'); | 907 var otherOptions = $('other-options-settings'); |
812 var headerFooter = otherOptions.querySelector('#header-footer-container'); | 908 var headerFooter = |
| 909 otherOptions.querySelector('#header-footer-container'); |
813 | 910 |
814 // Check that options are collapsed (section is visible, because duplex is | 911 // Check that options are collapsed (section is visible, because duplex |
815 // available). | 912 // is available). |
816 checkSectionVisible(otherOptions, true); | 913 checkSectionVisible(otherOptions, true); |
817 checkElementDisplayed(headerFooter, false); | 914 checkElementDisplayed(headerFooter, false); |
818 | 915 |
819 this.expandMoreSettings(); | 916 this.expandMoreSettings(); |
820 | 917 |
821 checkElementDisplayed(headerFooter, true); | 918 checkElementDisplayed(headerFooter, true); |
822 | 919 |
823 printPreview.printTicketStore_.marginsType.updateValue( | 920 this.printPreview_.printTicketStore_.marginsType.updateValue( |
824 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 921 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
825 printPreview.printTicketStore_.customMargins.updateValue( | 922 this.printPreview_.printTicketStore_.customMargins.updateValue( |
826 new print_preview.Margins(36, 36, 36, 36)); | 923 new print_preview.Margins(36, 36, 36, 36)); |
827 | 924 |
828 checkElementDisplayed(headerFooter, true); | 925 checkElementDisplayed(headerFooter, true); |
829 | 926 |
830 this.waitForAnimationToEnd('more-settings'); | 927 this.waitForAnimationToEnd('more-settings'); |
| 928 }.bind(this)); |
831 }); | 929 }); |
832 | 930 |
833 // Page layout has zero top and bottom margins. Hide header and footer option. | 931 // Page layout has zero top and bottom margins. Hide header and footer option. |
834 TEST_F('PrintPreviewWebUITest', | 932 TEST_F('PrintPreviewWebUITest', |
835 'ZeroTopAndBottomMarginsHideHeaderFooter', | 933 'ZeroTopAndBottomMarginsHideHeaderFooter', |
836 function() { | 934 function() { |
837 this.setInitialSettings(); | 935 this.setInitialSettings(); |
838 this.setLocalDestinations(); | 936 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
839 this.setCapabilities(getCddTemplate("FooDevice")); | 937 function() { |
| 938 this.setLocalDestinations(); |
| 939 this.setCapabilities(getCddTemplate("FooDevice")); |
840 | 940 |
841 var otherOptions = $('other-options-settings'); | 941 var otherOptions = $('other-options-settings'); |
842 var headerFooter = otherOptions.querySelector('#header-footer-container'); | 942 var headerFooter = |
| 943 otherOptions.querySelector('#header-footer-container'); |
843 | 944 |
844 // Check that options are collapsed (section is visible, because duplex is | 945 // Check that options are collapsed (section is visible, because duplex |
845 // available). | 946 // is available). |
846 checkSectionVisible(otherOptions, true); | 947 checkSectionVisible(otherOptions, true); |
847 checkElementDisplayed(headerFooter, false); | 948 checkElementDisplayed(headerFooter, false); |
848 | 949 |
849 this.expandMoreSettings(); | 950 this.expandMoreSettings(); |
850 | 951 |
851 checkElementDisplayed(headerFooter, true); | 952 checkElementDisplayed(headerFooter, true); |
852 | 953 |
853 printPreview.printTicketStore_.marginsType.updateValue( | 954 this.printPreview_.printTicketStore_.marginsType.updateValue( |
854 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 955 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
855 printPreview.printTicketStore_.customMargins.updateValue( | 956 this.printPreview_.printTicketStore_.customMargins.updateValue( |
856 new print_preview.Margins(0, 36, 0, 36)); | 957 new print_preview.Margins(0, 36, 0, 36)); |
857 | 958 |
858 checkElementDisplayed(headerFooter, false); | 959 checkElementDisplayed(headerFooter, false); |
859 | 960 |
860 this.waitForAnimationToEnd('more-settings'); | 961 this.waitForAnimationToEnd('more-settings'); |
| 962 }.bind(this)); |
861 }); | 963 }); |
862 | 964 |
863 // Page layout has zero top and half-inch bottom margin. Show header and footer | 965 // Page layout has zero top and half-inch bottom margin. Show header and footer |
864 // option. | 966 // option. |
865 TEST_F('PrintPreviewWebUITest', | 967 TEST_F('PrintPreviewWebUITest', |
866 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter', | 968 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter', |
867 function() { | 969 function() { |
868 this.setInitialSettings(); | 970 this.setInitialSettings(); |
869 this.setLocalDestinations(); | 971 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
870 this.setCapabilities(getCddTemplate("FooDevice")); | 972 function() { |
| 973 this.setLocalDestinations(); |
| 974 this.setCapabilities(getCddTemplate("FooDevice")); |
871 | 975 |
872 var otherOptions = $('other-options-settings'); | 976 var otherOptions = $('other-options-settings'); |
873 var headerFooter = otherOptions.querySelector('#header-footer-container'); | 977 var headerFooter = |
| 978 otherOptions.querySelector('#header-footer-container'); |
874 | 979 |
875 // Check that options are collapsed (section is visible, because duplex is | 980 // Check that options are collapsed (section is visible, because duplex |
876 // available). | 981 // is available). |
877 checkSectionVisible(otherOptions, true); | 982 checkSectionVisible(otherOptions, true); |
878 checkElementDisplayed(headerFooter, false); | 983 checkElementDisplayed(headerFooter, false); |
879 | 984 |
880 this.expandMoreSettings(); | 985 this.expandMoreSettings(); |
881 | 986 |
882 checkElementDisplayed(headerFooter, true); | 987 checkElementDisplayed(headerFooter, true); |
883 | 988 |
884 printPreview.printTicketStore_.marginsType.updateValue( | 989 this.printPreview_.printTicketStore_.marginsType.updateValue( |
885 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 990 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
886 printPreview.printTicketStore_.customMargins.updateValue( | 991 this.printPreview_.printTicketStore_.customMargins.updateValue( |
887 new print_preview.Margins(0, 36, 36, 36)); | 992 new print_preview.Margins(0, 36, 36, 36)); |
888 | 993 |
889 checkElementDisplayed(headerFooter, true); | 994 checkElementDisplayed(headerFooter, true); |
890 | 995 |
891 this.waitForAnimationToEnd('more-settings'); | 996 this.waitForAnimationToEnd('more-settings'); |
| 997 }.bind(this)); |
892 }); | 998 }); |
893 | 999 |
894 // Check header footer availability with small (label) page size. | 1000 // Check header footer availability with small (label) page size. |
895 TEST_F('PrintPreviewWebUITest', 'SmallPaperSizeHeaderFooter', function() { | 1001 TEST_F('PrintPreviewWebUITest', 'SmallPaperSizeHeaderFooter', function() { |
896 this.setInitialSettings(); | 1002 this.setInitialSettings(); |
897 this.setLocalDestinations(); | 1003 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
898 var device = getCddTemplate("FooDevice"); | 1004 function() { |
899 device.capabilities.printer.media_size = { | 1005 this.setLocalDestinations(); |
900 "option": [ | 1006 var device = getCddTemplate("FooDevice"); |
901 {"name": "SmallLabel", "width_microns": 38100, "height_microns": 12700, | 1007 device.capabilities.printer.media_size = { |
902 "is_default": false}, | 1008 "option": [ |
903 {"name": "BigLabel", "width_microns": 50800, "height_microns": 76200, | 1009 {"name": "SmallLabel", "width_microns": 38100, |
904 "is_default": true} | 1010 "height_microns": 12700, "is_default": false}, |
905 ] | 1011 {"name": "BigLabel", "width_microns": 50800, |
906 }; | 1012 "height_microns": 76200, "is_default": true} |
907 this.setCapabilities(device); | 1013 ] |
| 1014 }; |
| 1015 this.setCapabilities(device); |
908 | 1016 |
909 var otherOptions = $('other-options-settings'); | 1017 var otherOptions = $('other-options-settings'); |
910 var headerFooter = otherOptions.querySelector('#header-footer-container'); | 1018 var headerFooter = |
| 1019 otherOptions.querySelector('#header-footer-container'); |
911 | 1020 |
912 // Check that options are collapsed (section is visible, because duplex is | 1021 // Check that options are collapsed (section is visible, because duplex |
913 // available). | 1022 // is available). |
914 checkSectionVisible(otherOptions, true); | 1023 checkSectionVisible(otherOptions, true); |
915 checkElementDisplayed(headerFooter, false); | 1024 checkElementDisplayed(headerFooter, false); |
916 | 1025 |
917 this.expandMoreSettings(); | 1026 this.expandMoreSettings(); |
918 | 1027 |
919 // Big label should have header/footer | 1028 // Big label should have header/footer |
920 checkElementDisplayed(headerFooter, true); | 1029 checkElementDisplayed(headerFooter, true); |
921 | 1030 |
922 // Small label should not | 1031 // Small label should not |
923 printPreview.printTicketStore_.mediaSize.updateValue( | 1032 this.printPreview_.printTicketStore_.mediaSize.updateValue( |
924 device.capabilities.printer.media_size.option[0]); | 1033 device.capabilities.printer.media_size.option[0]); |
925 checkElementDisplayed(headerFooter, false); | 1034 checkElementDisplayed(headerFooter, false); |
926 | 1035 |
927 // Oriented in landscape, there should be enough space for header/footer. | 1036 // Oriented in landscape, there should be enough space for |
928 printPreview.printTicketStore_.landscape.updateValue(true); | 1037 // header/footer. |
929 checkElementDisplayed(headerFooter, true); | 1038 this.printPreview_.printTicketStore_.landscape.updateValue(true); |
| 1039 checkElementDisplayed(headerFooter, true); |
930 | 1040 |
931 this.waitForAnimationToEnd('more-settings'); | 1041 this.waitForAnimationToEnd('more-settings'); |
| 1042 }.bind(this)); |
932 }); | 1043 }); |
933 | 1044 |
934 // Test that the color settings, one option, standard monochrome. | 1045 // Test that the color settings, one option, standard monochrome. |
935 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() { | 1046 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() { |
936 this.setInitialSettings(); | 1047 this.setInitialSettings(); |
937 this.setLocalDestinations(); | 1048 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
| 1049 function() { |
| 1050 this.setLocalDestinations(); |
938 | 1051 |
939 // Only one option, standard monochrome. | 1052 // Only one option, standard monochrome. |
940 var device = getCddTemplate("FooDevice"); | 1053 var device = getCddTemplate("FooDevice"); |
941 device.capabilities.printer.color = { | 1054 device.capabilities.printer.color = { |
942 "option": [ | 1055 "option": [ |
943 {"is_default": true, "type": "STANDARD_MONOCHROME"} | 1056 {"is_default": true, "type": "STANDARD_MONOCHROME"} |
944 ] | 1057 ] |
945 }; | 1058 }; |
946 this.setCapabilities(device); | 1059 this.setCapabilities(device); |
947 | 1060 |
948 checkSectionVisible($('color-settings'), false); | 1061 checkSectionVisible($('color-settings'), false); |
949 | 1062 |
950 this.waitForAnimationToEnd('more-settings'); | 1063 this.waitForAnimationToEnd('more-settings'); |
| 1064 }.bind(this)); |
951 }); | 1065 }); |
952 | 1066 |
953 // Test that the color settings, one option, custom monochrome. | 1067 // Test that the color settings, one option, custom monochrome. |
954 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome', | 1068 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome', |
955 function() { | 1069 function() { |
956 this.setInitialSettings(); | 1070 this.setInitialSettings(); |
957 this.setLocalDestinations(); | 1071 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
| 1072 function() { |
| 1073 this.setLocalDestinations(); |
958 | 1074 |
959 // Only one option, standard monochrome. | 1075 // Only one option, standard monochrome. |
960 var device = getCddTemplate("FooDevice"); | 1076 var device = getCddTemplate("FooDevice"); |
961 device.capabilities.printer.color = { | 1077 device.capabilities.printer.color = { |
962 "option": [ | 1078 "option": [ |
963 {"is_default": true, "type": "CUSTOM_MONOCHROME", "vendor_id": "42"} | 1079 {"is_default": true, "type": "CUSTOM_MONOCHROME", |
964 ] | 1080 "vendor_id": "42"} |
965 }; | 1081 ] |
966 this.setCapabilities(device); | 1082 }; |
| 1083 this.setCapabilities(device); |
967 | 1084 |
968 checkSectionVisible($('color-settings'), false); | 1085 checkSectionVisible($('color-settings'), false); |
969 | 1086 |
970 this.waitForAnimationToEnd('more-settings'); | 1087 this.waitForAnimationToEnd('more-settings'); |
| 1088 }.bind(this)); |
971 }); | 1089 }); |
972 | 1090 |
973 // Test that the color settings, one option, standard color. | 1091 // Test that the color settings, one option, standard color. |
974 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() { | 1092 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() { |
975 this.setInitialSettings(); | 1093 this.setInitialSettings(); |
976 this.setLocalDestinations(); | 1094 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
| 1095 function() { |
| 1096 this.setLocalDestinations(); |
977 | 1097 |
978 var device = getCddTemplate("FooDevice"); | 1098 var device = getCddTemplate("FooDevice"); |
979 device.capabilities.printer.color = { | 1099 device.capabilities.printer.color = { |
980 "option": [ | 1100 "option": [ |
981 {"is_default": true, "type": "STANDARD_COLOR"} | 1101 {"is_default": true, "type": "STANDARD_COLOR"} |
982 ] | 1102 ] |
983 }; | 1103 }; |
984 this.setCapabilities(device); | 1104 this.setCapabilities(device); |
985 | 1105 |
986 checkSectionVisible($('color-settings'), false); | 1106 checkSectionVisible($('color-settings'), false); |
987 | 1107 |
988 this.waitForAnimationToEnd('more-settings'); | 1108 this.waitForAnimationToEnd('more-settings'); |
| 1109 }.bind(this)); |
989 }); | 1110 }); |
990 | 1111 |
991 // Test that the color settings, one option, custom color. | 1112 // Test that the color settings, one option, custom color. |
992 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() { | 1113 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() { |
993 this.setInitialSettings(); | 1114 this.setInitialSettings(); |
994 this.setLocalDestinations(); | 1115 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
| 1116 function() { |
| 1117 this.setLocalDestinations(); |
995 | 1118 |
996 var device = getCddTemplate("FooDevice"); | 1119 var device = getCddTemplate("FooDevice"); |
997 device.capabilities.printer.color = { | 1120 device.capabilities.printer.color = { |
998 "option": [ | 1121 "option": [ |
999 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"} | 1122 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"} |
1000 ] | 1123 ] |
1001 }; | 1124 }; |
1002 this.setCapabilities(device); | 1125 this.setCapabilities(device); |
1003 | 1126 |
1004 checkSectionVisible($('color-settings'), false); | 1127 checkSectionVisible($('color-settings'), false); |
1005 | 1128 |
1006 this.waitForAnimationToEnd('more-settings'); | 1129 this.waitForAnimationToEnd('more-settings'); |
| 1130 }.bind(this)); |
1007 }); | 1131 }); |
1008 | 1132 |
1009 // Test that the color settings, two options, both standard, defaults to color. | 1133 // Test that the color settings, two options, both standard, defaults to color. |
1010 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor', | 1134 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor', |
1011 function() { | 1135 function() { |
1012 this.setInitialSettings(); | 1136 this.setInitialSettings(); |
1013 this.setLocalDestinations(); | 1137 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
| 1138 function() { |
| 1139 this.setLocalDestinations(); |
1014 | 1140 |
1015 var device = getCddTemplate("FooDevice"); | 1141 var device = getCddTemplate("FooDevice"); |
1016 device.capabilities.printer.color = { | 1142 device.capabilities.printer.color = { |
1017 "option": [ | 1143 "option": [ |
1018 {"type": "STANDARD_MONOCHROME"}, | 1144 {"type": "STANDARD_MONOCHROME"}, |
1019 {"is_default": true, "type": "STANDARD_COLOR"} | 1145 {"is_default": true, "type": "STANDARD_COLOR"} |
1020 ] | 1146 ] |
1021 }; | 1147 }; |
1022 this.setCapabilities(device); | 1148 this.setCapabilities(device); |
1023 | 1149 |
1024 checkSectionVisible($('color-settings'), true); | 1150 checkSectionVisible($('color-settings'), true); |
1025 expectEquals( | 1151 expectEquals( |
1026 'color', | 1152 'color', |
1027 $('color-settings').querySelector('.color-settings-select').value); | 1153 $('color-settings').querySelector('.color-settings-select').value); |
1028 | 1154 |
1029 this.waitForAnimationToEnd('more-settings'); | 1155 this.waitForAnimationToEnd('more-settings'); |
| 1156 }.bind(this)); |
1030 }); | 1157 }); |
1031 | 1158 |
1032 // Test that the color settings, two options, both standard, defaults to | 1159 // Test that the color settings, two options, both standard, defaults to |
1033 // monochrome. | 1160 // monochrome. |
1034 TEST_F('PrintPreviewWebUITest', | 1161 TEST_F('PrintPreviewWebUITest', |
1035 'TestColorSettingsBothStandardDefaultMonochrome', function() { | 1162 'TestColorSettingsBothStandardDefaultMonochrome', function() { |
1036 this.setInitialSettings(); | 1163 this.setInitialSettings(); |
1037 this.setLocalDestinations(); | 1164 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
1038 | 1165 function() { |
1039 var device = getCddTemplate("FooDevice"); | 1166 this.setLocalDestinations(); |
1040 device.capabilities.printer.color = { | 1167 |
1041 "option": [ | 1168 var device = getCddTemplate("FooDevice"); |
1042 {"is_default": true, "type": "STANDARD_MONOCHROME"}, | 1169 device.capabilities.printer.color = { |
1043 {"type": "STANDARD_COLOR"} | 1170 "option": [ |
1044 ] | 1171 {"is_default": true, "type": "STANDARD_MONOCHROME"}, |
1045 }; | 1172 {"type": "STANDARD_COLOR"} |
1046 this.setCapabilities(device); | 1173 ] |
1047 | 1174 }; |
1048 checkSectionVisible($('color-settings'), true); | 1175 this.setCapabilities(device); |
1049 expectEquals( | 1176 |
1050 'bw', $('color-settings').querySelector('.color-settings-select').value); | 1177 checkSectionVisible($('color-settings'), true); |
1051 | 1178 expectEquals( |
1052 this.waitForAnimationToEnd('more-settings'); | 1179 'bw', |
| 1180 $('color-settings').querySelector('.color-settings-select').value); |
| 1181 |
| 1182 this.waitForAnimationToEnd('more-settings'); |
| 1183 }.bind(this)); |
1053 }); | 1184 }); |
1054 | 1185 |
1055 // Test that the color settings, two options, both custom, defaults to color. | 1186 // Test that the color settings, two options, both custom, defaults to color. |
1056 TEST_F('PrintPreviewWebUITest', | 1187 TEST_F('PrintPreviewWebUITest', |
1057 'TestColorSettingsBothCustomDefaultColor', function() { | 1188 'TestColorSettingsBothCustomDefaultColor', function() { |
1058 this.setInitialSettings(); | 1189 this.setInitialSettings(); |
1059 this.setLocalDestinations(); | 1190 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
1060 | 1191 function() { |
1061 var device = getCddTemplate("FooDevice"); | 1192 this.setLocalDestinations(); |
1062 device.capabilities.printer.color = { | 1193 |
1063 "option": [ | 1194 var device = getCddTemplate("FooDevice"); |
1064 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"}, | 1195 device.capabilities.printer.color = { |
1065 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"} | 1196 "option": [ |
1066 ] | 1197 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"}, |
1067 }; | 1198 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"} |
1068 this.setCapabilities(device); | 1199 ] |
1069 | 1200 }; |
1070 checkSectionVisible($('color-settings'), true); | 1201 this.setCapabilities(device); |
1071 expectEquals( | 1202 |
1072 'color', | 1203 checkSectionVisible($('color-settings'), true); |
1073 $('color-settings').querySelector('.color-settings-select').value); | 1204 expectEquals( |
1074 | 1205 'color', |
1075 this.waitForAnimationToEnd('more-settings'); | 1206 $('color-settings').querySelector('.color-settings-select').value); |
| 1207 |
| 1208 this.waitForAnimationToEnd('more-settings'); |
| 1209 }.bind(this)); |
1076 }); | 1210 }); |
1077 | 1211 |
1078 // Test to verify that duplex settings are set according to the printer | 1212 // Test to verify that duplex settings are set according to the printer |
1079 // capabilities. | 1213 // capabilities. |
1080 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() { | 1214 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() { |
1081 this.setInitialSettings(); | 1215 this.setInitialSettings(); |
1082 this.setLocalDestinations(); | 1216 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
1083 this.setCapabilities(getCddTemplate("FooDevice")); | 1217 function() { |
1084 | 1218 this.setLocalDestinations(); |
1085 var otherOptions = $('other-options-settings'); | 1219 this.setCapabilities(getCddTemplate("FooDevice")); |
1086 checkSectionVisible(otherOptions, true); | 1220 |
1087 duplexContainer = otherOptions.querySelector('#duplex-container'); | 1221 var otherOptions = $('other-options-settings'); |
1088 expectFalse(duplexContainer.hidden); | 1222 checkSectionVisible(otherOptions, true); |
1089 expectFalse(duplexContainer.querySelector('.checkbox').checked); | 1223 duplexContainer = otherOptions.querySelector('#duplex-container'); |
1090 | 1224 expectFalse(duplexContainer.hidden); |
1091 this.waitForAnimationToEnd('more-settings'); | 1225 expectFalse(duplexContainer.querySelector('.checkbox').checked); |
| 1226 |
| 1227 this.waitForAnimationToEnd('more-settings'); |
| 1228 }.bind(this)); |
1092 }); | 1229 }); |
1093 | 1230 |
1094 // Test to verify that duplex settings are set according to the printer | 1231 // Test to verify that duplex settings are set according to the printer |
1095 // capabilities. | 1232 // capabilities. |
1096 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() { | 1233 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() { |
1097 this.setInitialSettings(); | 1234 this.setInitialSettings(); |
1098 this.setLocalDestinations(); | 1235 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
1099 var device = getCddTemplate("FooDevice"); | 1236 function() { |
1100 delete device.capabilities.printer.duplex; | 1237 this.setLocalDestinations(); |
1101 this.setCapabilities(device); | 1238 var device = getCddTemplate("FooDevice"); |
1102 | 1239 delete device.capabilities.printer.duplex; |
1103 // Check that it is collapsed. | 1240 this.setCapabilities(device); |
1104 var otherOptions = $('other-options-settings'); | 1241 |
1105 checkSectionVisible(otherOptions, false); | 1242 // Check that it is collapsed. |
1106 | 1243 var otherOptions = $('other-options-settings'); |
1107 this.expandMoreSettings(); | 1244 checkSectionVisible(otherOptions, false); |
1108 | 1245 |
1109 // Now it should be visible. | 1246 this.expandMoreSettings(); |
1110 checkSectionVisible(otherOptions, true); | 1247 |
1111 expectTrue(otherOptions.querySelector('#duplex-container').hidden); | 1248 // Now it should be visible. |
1112 | 1249 checkSectionVisible(otherOptions, true); |
1113 this.waitForAnimationToEnd('more-settings'); | 1250 expectTrue(otherOptions.querySelector('#duplex-container').hidden); |
| 1251 |
| 1252 this.waitForAnimationToEnd('more-settings'); |
| 1253 }.bind(this)); |
1114 }); | 1254 }); |
1115 | 1255 |
1116 // Test that changing the selected printer updates the preview. | 1256 // Test that changing the selected printer updates the preview. |
1117 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { | 1257 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { |
1118 this.setInitialSettings(); | 1258 this.setInitialSettings(); |
1119 this.setLocalDestinations(); | 1259 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
1120 this.setCapabilities(getCddTemplate("FooDevice")); | 1260 function() { |
1121 | 1261 this.setLocalDestinations(); |
1122 var previewGenerator = mock(print_preview.PreviewGenerator); | 1262 this.setCapabilities(getCddTemplate("FooDevice")); |
1123 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy(); | 1263 |
1124 | 1264 var previewGenerator = mock(print_preview.PreviewGenerator); |
1125 // The number of settings that can change due to a change in the destination | 1265 this.printPreview_.previewArea_.previewGenerator_ = |
1126 // that will therefore dispatch ticket item change events. | 1266 previewGenerator.proxy(); |
1127 previewGenerator.expects(exactly(9)).requestPreview(); | 1267 |
1128 | 1268 // The number of settings that can change due to a change in the |
1129 var barDestination = | 1269 // destination that will therefore dispatch ticket item change events. |
1130 printPreview.destinationStore_.destinations().find(function(d) { | 1270 previewGenerator.expects(exactly(9)).requestPreview(); |
1131 return d.id == 'BarDevice'; | 1271 |
1132 }); | 1272 var barDestination = |
1133 | 1273 this.printPreview_.destinationStore_.destinations().find( |
1134 printPreview.destinationStore_.selectDestination(barDestination); | 1274 function(d) { |
1135 | 1275 return d.id == 'BarDevice'; |
1136 var device = getCddTemplate("BarDevice"); | 1276 }); |
1137 device.capabilities.printer.color = { | 1277 |
1138 "option": [ | 1278 this.printPreview_.destinationStore_.selectDestination(barDestination); |
1139 {"is_default": true, "type": "STANDARD_MONOCHROME"} | 1279 |
1140 ] | 1280 var device = getCddTemplate("BarDevice"); |
1141 }; | 1281 device.capabilities.printer.color = { |
1142 this.setCapabilities(device); | 1282 "option": [ |
1143 | 1283 {"is_default": true, "type": "STANDARD_MONOCHROME"} |
1144 this.waitForAnimationToEnd('more-settings'); | 1284 ] |
| 1285 }; |
| 1286 this.setCapabilities(device); |
| 1287 |
| 1288 this.waitForAnimationToEnd('more-settings'); |
| 1289 }.bind(this)); |
1145 }); | 1290 }); |
1146 | 1291 |
1147 // Test that error message is displayed when plugin doesn't exist. | 1292 // Test that error message is displayed when plugin doesn't exist. |
1148 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() { | 1293 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() { |
1149 var previewAreaEl = $('preview-area'); | 1294 this.setInitialSettings(); |
1150 | 1295 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
1151 var loadingMessageEl = | 1296 function() { |
1152 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0]; | 1297 var previewAreaEl = $('preview-area'); |
1153 expectTrue(loadingMessageEl.hidden); | 1298 |
1154 | 1299 var loadingMessageEl = |
1155 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( | 1300 previewAreaEl. |
1156 'preview-area-preview-failed-message')[0]; | 1301 getElementsByClassName('preview-area-loading-message')[0]; |
1157 expectTrue(previewFailedMessageEl.hidden); | 1302 expectTrue(loadingMessageEl.hidden); |
1158 | 1303 |
1159 var printFailedMessageEl = | 1304 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( |
1160 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0]; | 1305 'preview-area-preview-failed-message')[0]; |
1161 expectTrue(printFailedMessageEl.hidden); | 1306 expectTrue(previewFailedMessageEl.hidden); |
1162 | 1307 |
1163 var customMessageEl = | 1308 var printFailedMessageEl = |
1164 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; | 1309 previewAreaEl. |
1165 expectFalse(customMessageEl.hidden); | 1310 getElementsByClassName('preview-area-print-failed')[0]; |
1166 | 1311 expectTrue(printFailedMessageEl.hidden); |
1167 testDone(); | 1312 |
| 1313 var customMessageEl = |
| 1314 previewAreaEl. |
| 1315 getElementsByClassName('preview-area-custom-message')[0]; |
| 1316 expectFalse(customMessageEl.hidden); |
| 1317 |
| 1318 testDone(); |
| 1319 }); |
1168 }); | 1320 }); |
1169 | 1321 |
1170 // Test custom localized paper names. | 1322 // Test custom localized paper names. |
1171 TEST_F('PrintPreviewWebUITest', 'TestCustomPaperNames', function() { | 1323 TEST_F('PrintPreviewWebUITest', 'TestCustomPaperNames', function() { |
1172 this.setInitialSettings(); | 1324 this.setInitialSettings(); |
1173 this.setLocalDestinations(); | 1325 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
1174 | 1326 function() { |
1175 var customLocalizedMediaName = 'Vendor defined localized media name'; | 1327 this.setLocalDestinations(); |
1176 var customMediaName = 'Vendor defined media name'; | 1328 |
1177 | 1329 var customLocalizedMediaName = 'Vendor defined localized media name'; |
1178 var device = getCddTemplate("FooDevice"); | 1330 var customMediaName = 'Vendor defined media name'; |
1179 device.capabilities.printer.media_size = { | 1331 |
1180 option: [ | 1332 var device = getCddTemplate("FooDevice"); |
1181 { name: 'CUSTOM', | 1333 device.capabilities.printer.media_size = { |
1182 width_microns: 15900, | 1334 option: [ |
1183 height_microns: 79400, | 1335 { name: 'CUSTOM', |
1184 is_default: true, | 1336 width_microns: 15900, |
1185 custom_display_name_localized: [ | 1337 height_microns: 79400, |
1186 { locale: navigator.language, | 1338 is_default: true, |
1187 value: customLocalizedMediaName | 1339 custom_display_name_localized: [ |
1188 } | 1340 { locale: navigator.language, |
1189 ] | 1341 value: customLocalizedMediaName |
1190 }, | 1342 } |
1191 { name: 'CUSTOM', | 1343 ] |
1192 width_microns: 15900, | 1344 }, |
1193 height_microns: 79400, | 1345 { name: 'CUSTOM', |
1194 custom_display_name: customMediaName | 1346 width_microns: 15900, |
1195 } | 1347 height_microns: 79400, |
1196 ] | 1348 custom_display_name: customMediaName |
1197 }; | 1349 } |
1198 | 1350 ] |
1199 this.setCapabilities(device); | 1351 }; |
1200 | 1352 |
1201 this.expandMoreSettings(); | 1353 this.setCapabilities(device); |
1202 | 1354 |
1203 checkSectionVisible($('media-size-settings'), true); | 1355 this.expandMoreSettings(); |
1204 var mediaSelect = $('media-size-settings').querySelector('.settings-select'); | 1356 |
1205 // Check the default media item. | 1357 checkSectionVisible($('media-size-settings'), true); |
1206 expectEquals( | 1358 var mediaSelect = |
1207 customLocalizedMediaName, | 1359 $('media-size-settings').querySelector('.settings-select'); |
1208 mediaSelect.options[mediaSelect.selectedIndex].text); | 1360 // Check the default media item. |
1209 // Check the other media item. | 1361 expectEquals( |
1210 expectEquals( | 1362 customLocalizedMediaName, |
1211 customMediaName, | 1363 mediaSelect.options[mediaSelect.selectedIndex].text); |
1212 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text); | 1364 // Check the other media item. |
1213 | 1365 expectEquals( |
1214 this.waitForAnimationToEnd('more-settings'); | 1366 customMediaName, |
| 1367 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text); |
| 1368 |
| 1369 this.waitForAnimationToEnd('more-settings'); |
| 1370 }.bind(this)); |
1215 }); | 1371 }); |
1216 | 1372 |
1217 function getCddTemplateWithAdvancedSettings(printerId) { | 1373 function getCddTemplateWithAdvancedSettings(printerId) { |
1218 return { | 1374 return { |
1219 printerId: printerId, | 1375 printerId: printerId, |
1220 capabilities: { | 1376 capabilities: { |
1221 version: '1.0', | 1377 version: '1.0', |
1222 printer: { | 1378 printer: { |
1223 supported_content_type: [{content_type: 'application/pdf'}], | 1379 supported_content_type: [{content_type: 'application/pdf'}], |
1224 vendor_capability: | 1380 vendor_capability: |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 // testPluginCompatibility() being set to always return false. Enable button | 1439 // testPluginCompatibility() being set to always return false. Enable button |
1284 // to send click event. | 1440 // to send click event. |
1285 advancedOptionsSettingsButton.disabled = false; | 1441 advancedOptionsSettingsButton.disabled = false; |
1286 advancedOptionsSettingsButton.click(); | 1442 advancedOptionsSettingsButton.click(); |
1287 } | 1443 } |
1288 | 1444 |
1289 // Test advanced settings with 1 capability (should not display settings search | 1445 // Test advanced settings with 1 capability (should not display settings search |
1290 // box). | 1446 // box). |
1291 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings1Option', function() { | 1447 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings1Option', function() { |
1292 var device = getCddTemplateWithAdvancedSettings("FooDevice"); | 1448 var device = getCddTemplateWithAdvancedSettings("FooDevice"); |
1293 this.setupAdvancedSettingsTest(device); | 1449 this.accessibilityIssuesAreErrors = false; |
| 1450 this.setInitialSettings(); |
| 1451 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
| 1452 function() { |
| 1453 this.setupAdvancedSettingsTest(device); |
1294 | 1454 |
1295 // Open the advanced settings overlay. | 1455 // Open the advanced settings overlay. |
1296 openAdvancedSettings(); | 1456 openAdvancedSettings(); |
1297 | 1457 |
1298 // Check that advanced settings close button is now visible, | 1458 // Check that advanced settings close button is now visible, |
1299 // but not the search box (only 1 capability). | 1459 // but not the search box (only 1 capability). |
1300 var advancedSettingsCloseButton = $('advanced-settings'). | 1460 var advancedSettingsCloseButton = $('advanced-settings'). |
1301 querySelector('.close-button'); | 1461 querySelector('.close-button'); |
1302 checkElementDisplayed(advancedSettingsCloseButton, true); | 1462 checkElementDisplayed(advancedSettingsCloseButton, true); |
1303 checkElementDisplayed($('advanced-settings'). | 1463 checkElementDisplayed($('advanced-settings'). |
1304 querySelector('.search-box-area'), false); | 1464 querySelector('.search-box-area'), false); |
1305 | 1465 |
1306 this.waitForAnimationToEnd('more-settings'); | 1466 this.waitForAnimationToEnd('more-settings'); |
| 1467 }.bind(this)); |
1307 }); | 1468 }); |
1308 | 1469 |
1309 | 1470 |
1310 // Test advanced settings with 2 capabilities (should have settings search box). | 1471 // Test advanced settings with 2 capabilities (should have settings search box). |
1311 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings2Options', function() { | 1472 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings2Options', function() { |
1312 var device = getCddTemplateWithAdvancedSettings("FooDevice"); | 1473 var device = getCddTemplateWithAdvancedSettings("FooDevice"); |
1313 // Add new capability. | 1474 // Add new capability. |
1314 device.capabilities.printer.vendor_capability.push({ | 1475 device.capabilities.printer.vendor_capability.push({ |
1315 display_name: 'Paper Type', | 1476 display_name: 'Paper Type', |
1316 id: 'Paper Type', | 1477 id: 'Paper Type', |
1317 type: 'SELECT', | 1478 type: 'SELECT', |
1318 select_cap: { | 1479 select_cap: { |
1319 option: [ | 1480 option: [ |
1320 {display_name: 'Standard', value: 0, is_default: true}, | 1481 {display_name: 'Standard', value: 0, is_default: true}, |
1321 {display_name: 'Recycled', value: 1}, | 1482 {display_name: 'Recycled', value: 1}, |
1322 {display_name: 'Special', value: 2} | 1483 {display_name: 'Special', value: 2} |
1323 ] | 1484 ] |
1324 } | 1485 } |
1325 }); | 1486 }); |
1326 this.setupAdvancedSettingsTest(device); | 1487 this.accessibilityIssuesAreErrors = false; |
| 1488 this.setInitialSettings(); |
| 1489 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
| 1490 function() { |
| 1491 this.setupAdvancedSettingsTest(device); |
1327 | 1492 |
1328 // Open the advanced settings overlay. | 1493 // Open the advanced settings overlay. |
1329 openAdvancedSettings(); | 1494 openAdvancedSettings(); |
1330 | 1495 |
1331 // Check advanced settings is visible and that the search box now | 1496 // Check advanced settings is visible and that the search box now |
1332 // appears. | 1497 // appears. |
1333 var advancedSettingsCloseButton = $('advanced-settings'). | 1498 var advancedSettingsCloseButton = $('advanced-settings'). |
1334 querySelector('.close-button'); | 1499 querySelector('.close-button'); |
1335 checkElementDisplayed(advancedSettingsCloseButton, true); | 1500 checkElementDisplayed(advancedSettingsCloseButton, true); |
1336 checkElementDisplayed($('advanced-settings'). | 1501 checkElementDisplayed($('advanced-settings'). |
1337 querySelector('.search-box-area'), true); | 1502 querySelector('.search-box-area'), true); |
1338 | 1503 |
1339 this.waitForAnimationToEnd('more-settings'); | 1504 this.waitForAnimationToEnd('more-settings'); |
| 1505 }.bind(this)); |
1340 }); | 1506 }); |
1341 | 1507 |
1342 // Test that initialization with saved destination only issues one call | 1508 // Test that initialization with saved destination only issues one call |
1343 // to startPreview. | 1509 // to startPreview. |
1344 TEST_F('PrintPreviewWebUITest', 'TestInitIssuesOneRequest', function() { | 1510 TEST_F('PrintPreviewWebUITest', 'TestInitIssuesOneRequest', function() { |
| 1511 this.createPrintPreview(); |
1345 // Load in a bunch of recent destinations with non null capabilities. | 1512 // Load in a bunch of recent destinations with non null capabilities. |
1346 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; | 1513 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; |
1347 var initSettings = { | 1514 var initSettings = { |
1348 version: 2, | 1515 version: 2, |
1349 recentDestinations: [1, 2, 3].map(function(i) { | 1516 recentDestinations: [1, 2, 3].map(function(i) { |
1350 return { | 1517 return { |
1351 id: 'ID' + i, origin: origin, account: '', | 1518 id: 'ID' + i, origin: origin, account: '', |
1352 capabilities: getCddTemplate('ID' + i), name: '', | 1519 capabilities: getCddTemplate('ID' + i), name: '', |
1353 extensionId: '', extensionName: '' | 1520 extensionId: '', extensionName: '' |
1354 }; | 1521 }; |
1355 }), | 1522 }), |
1356 }; | 1523 }; |
1357 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(initSettings); | 1524 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(initSettings); |
1358 this.setCapabilities(getCddTemplate('ID1')); | 1525 this.setCapabilities(getCddTemplate('ID1')); |
1359 this.setCapabilities(getCddTemplate('ID2')); | 1526 this.setCapabilities(getCddTemplate('ID2')); |
1360 this.setCapabilities(getCddTemplate('ID3')); | 1527 this.setCapabilities(getCddTemplate('ID3')); |
1361 | 1528 |
1362 // Use a real preview generator. | 1529 // Use a real preview generator. |
1363 printPreview.previewArea_.previewGenerator_ = | 1530 this.printPreview_.previewArea_.previewGenerator_ = |
1364 new print_preview.PreviewGenerator(printPreview.destinationStore_, | 1531 new print_preview.PreviewGenerator(this.printPreview_.destinationStore_, |
1365 printPreview.printTicketStore_, this.nativeLayer_, | 1532 this.printPreview_.printTicketStore_, this.nativeLayer_, |
1366 printPreview.documentInfo_); | 1533 this.printPreview_.documentInfo_); |
1367 | 1534 |
1368 // Preview generator starts out with inFlightRequestId_ == -1. The id | 1535 // Preview generator starts out with inFlightRequestId_ == -1. The id |
1369 // increments by 1 for each startGetPreview call it makes. It should only | 1536 // increments by 1 for each startGetPreview call it makes. It should only |
1370 // make one such call during initialization or there will be a race; see | 1537 // make one such call during initialization or there will be a race; see |
1371 // crbug.com/666595 | 1538 // crbug.com/666595 |
1372 expectEquals( | 1539 expectEquals( |
1373 -1, | 1540 -1, |
1374 printPreview.previewArea_.previewGenerator_.inFlightRequestId_); | 1541 this.printPreview_.previewArea_.previewGenerator_.inFlightRequestId_); |
1375 this.setInitialSettings(); | 1542 this.setInitialSettings(); |
1376 expectEquals( | 1543 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
1377 0, | 1544 function() { |
1378 printPreview.previewArea_.previewGenerator_.inFlightRequestId_); | 1545 expectEquals( |
1379 testDone(); | 1546 0, |
| 1547 this.printPreview_.previewArea_.previewGenerator_. |
| 1548 inFlightRequestId_); |
| 1549 testDone(); |
| 1550 }.bind(this)); |
1380 }); | 1551 }); |
1381 | 1552 |
1382 // Test that invalid settings errors disable the print preview and display | 1553 // Test that invalid settings errors disable the print preview and display |
1383 // an error and that the preview dialog can be recovered by selecting a | 1554 // an error and that the preview dialog can be recovered by selecting a |
1384 // new destination. | 1555 // new destination. |
1385 TEST_F('PrintPreviewWebUITest', 'TestInvalidSettingsError', function() { | 1556 TEST_F('PrintPreviewWebUITest', 'TestInvalidSettingsError', function() { |
1386 // Setup | 1557 // Setup |
1387 this.setInitialSettings(); | 1558 this.setInitialSettings(); |
1388 this.setLocalDestinations(); | 1559 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
1389 this.setCapabilities(getCddTemplate("FooDevice")); | 1560 function() { |
| 1561 this.setLocalDestinations(); |
| 1562 this.setCapabilities(getCddTemplate("FooDevice")); |
1390 | 1563 |
1391 // Manually enable the print header. This is needed since there is no | 1564 // Manually enable the print header. This is needed since there is no |
1392 // plugin during test, so it will be set as disabled normally. | 1565 // plugin during test, so it will be set as disabled normally. |
1393 printPreview.printHeader_.isEnabled = true; | 1566 this.printPreview_.printHeader_.isEnabled = true; |
1394 | 1567 |
1395 // There will be an error message in the preview area since the plugin is | 1568 // There will be an error message in the preview area since the plugin |
1396 // not running. However, it should not be the invalid settings error. | 1569 // is not running. However, it should not be the invalid settings error. |
1397 var previewAreaEl = $('preview-area'); | 1570 var previewAreaEl = $('preview-area'); |
1398 var customMessageEl = | 1571 var customMessageEl = |
1399 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; | 1572 previewAreaEl. |
1400 expectFalse(customMessageEl.hidden); | 1573 getElementsByClassName('preview-area-custom-message')[0]; |
1401 var expectedMessageStart = 'The selected printer is not available or not ' + | 1574 expectFalse(customMessageEl.hidden); |
1402 'installed correctly.' | 1575 var expectedMessageStart = 'The selected printer is not available or ' |
1403 expectFalse(customMessageEl.textContent.includes(expectedMessageStart)); | 1576 + 'not installed correctly.' |
| 1577 expectFalse(customMessageEl.textContent.includes(expectedMessageStart)); |
1404 | 1578 |
1405 // Verify that the print button is enabled. | 1579 // Verify that the print button is enabled. |
1406 var printHeader = $('print-header'); | 1580 var printHeader = $('print-header'); |
1407 var printButton = printHeader.querySelector('button.print'); | 1581 var printButton = printHeader.querySelector('button.print'); |
1408 checkElementDisplayed(printButton, true); | 1582 checkElementDisplayed(printButton, true); |
1409 expectFalse(printButton.disabled); | 1583 expectFalse(printButton.disabled); |
1410 | 1584 |
1411 // Report invalid settings error. | 1585 // Report invalid settings error. |
1412 this.dispatchInvalidSettings(); | 1586 this.dispatchInvalidSettings(); |
1413 | 1587 |
1414 // Should be in an error state, print button disabled, invalid custom error | 1588 // Should be in an error state, print button disabled, invalid custom |
1415 // message shown. | 1589 // error message shown. |
1416 expectFalse(customMessageEl.hidden); | 1590 expectFalse(customMessageEl.hidden); |
1417 expectTrue(customMessageEl.textContent.includes(expectedMessageStart)); | 1591 expectTrue(customMessageEl.textContent.includes(expectedMessageStart)); |
1418 expectTrue(printButton.disabled); | 1592 expectTrue(printButton.disabled); |
1419 | 1593 |
1420 // Select a new destination | 1594 // Select a new destination |
1421 var barDestination = | 1595 var barDestination = |
1422 printPreview.destinationStore_.destinations().find(function(d) { | 1596 this.printPreview_.destinationStore_.destinations().find( |
1423 return d.id == 'BarDevice'; | 1597 function(d) { |
1424 }); | 1598 return d.id == 'BarDevice'; |
| 1599 }); |
1425 | 1600 |
1426 printPreview.destinationStore_.selectDestination(barDestination); | 1601 this.printPreview_.destinationStore_.selectDestination(barDestination); |
1427 | 1602 |
1428 // Dispatch events indicating capabilities were fetched and new preview has | 1603 // Dispatch events indicating capabilities were fetched and new preview |
1429 // loaded. | 1604 // has loaded. |
1430 this.setCapabilities(getCddTemplate("BarDevice")); | 1605 this.setCapabilities(getCddTemplate("BarDevice")); |
1431 this.dispatchPreviewDone(); | 1606 this.dispatchPreviewDone(); |
1432 | 1607 |
1433 // Has active print button and successfully "prints", indicating recovery | 1608 // Has active print button and successfully "prints", indicating |
1434 // from error state. | 1609 // recovery from error state. |
1435 expectFalse(printButton.disabled); | 1610 expectFalse(printButton.disabled); |
1436 expectFalse(this.hasPrinted()); | 1611 expectFalse(this.hasPrinted()); |
1437 printButton.click(); | 1612 printButton.click(); |
1438 expectTrue(this.hasPrinted()); | 1613 expectTrue(this.hasPrinted()); |
1439 testDone(); | 1614 testDone(); |
| 1615 }.bind(this)); |
1440 }); | 1616 }); |
1441 | 1617 |
1442 // Test the preview generator to make sure the generate draft parameter is set | 1618 // Test the preview generator to make sure the generate draft parameter is set |
1443 // correctly. It should be false if the only change is the page range. | 1619 // correctly. It should be false if the only change is the page range. |
1444 TEST_F('PrintPreviewWebUITest', 'TestGenerateDraft', function() { | 1620 TEST_F('PrintPreviewWebUITest', 'TestGenerateDraft', function() { |
| 1621 this.createPrintPreview(); |
| 1622 |
1445 // Use a real preview generator. | 1623 // Use a real preview generator. |
1446 printPreview.previewArea_.previewGenerator_ = | 1624 this.printPreview_.previewArea_.previewGenerator_ = |
1447 new print_preview.PreviewGenerator(printPreview.destinationStore_, | 1625 new print_preview.PreviewGenerator(this.printPreview_.destinationStore_, |
1448 printPreview.printTicketStore_, this.nativeLayer_, | 1626 this.printPreview_.printTicketStore_, this.nativeLayer_, |
1449 printPreview.documentInfo_); | 1627 this.printPreview_.documentInfo_); |
1450 | 1628 |
1451 this.setInitialSettings(); | 1629 this.setInitialSettings(); |
1452 this.setLocalDestinations(); | 1630 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then( |
1453 this.setCapabilities(getCddTemplate("FooDevice")); | 1631 function() { |
| 1632 this.setLocalDestinations(); |
| 1633 this.setCapabilities(getCddTemplate("FooDevice")); |
1454 | 1634 |
1455 // The first request should generate draft because there was no previous print | 1635 // The first request should generate draft because there was no |
1456 // preview draft. | 1636 // previous print preview draft. |
1457 expectTrue(this.generateDraft()); | 1637 expectTrue(this.generateDraft()); |
1458 | 1638 |
1459 // Change the page range - no new draft needed. | 1639 // Change the page range - no new draft needed. |
1460 printPreview.printTicketStore_.pageRange.updateValue("2"); | 1640 this.printPreview_.printTicketStore_.pageRange.updateValue("2"); |
1461 expectFalse(this.generateDraft()); | 1641 expectFalse(this.generateDraft()); |
1462 | 1642 |
1463 // Change the margin type - need to regenerate again. | 1643 // Change the margin type - need to regenerate again. |
1464 printPreview.printTicketStore_.marginsType.updateValue( | 1644 this.printPreview_.printTicketStore_.marginsType.updateValue( |
1465 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); | 1645 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); |
1466 expectTrue(this.generateDraft()); | 1646 expectTrue(this.generateDraft()); |
1467 | 1647 |
1468 testDone(); | 1648 testDone(); |
| 1649 }.bind(this)); |
1469 }); | 1650 }); |
OLD | NEW |