| 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 /** | 5 /** |
| 6 * Test fixture for print preview WebUI testing. | 6 * Test fixture for print preview WebUI testing. |
| 7 * @constructor | 7 * @constructor |
| 8 * @extends {testing.Test} | 8 * @extends {testing.Test} |
| 9 */ | 9 */ |
| 10 function PrintPreviewWebUITest() { | 10 function PrintPreviewWebUITest() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 PrintPreviewWebUITest.prototype = { | 38 PrintPreviewWebUITest.prototype = { |
| 39 __proto__: testing.Test.prototype, | 39 __proto__: testing.Test.prototype, |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * Browse to the sample page, cause print preview & call preLoad(). | 42 * Browse to the sample page, cause print preview & call preLoad(). |
| 43 * @type {string} | 43 * @type {string} |
| 44 * @override | 44 * @override |
| 45 */ | 45 */ |
| 46 browsePrintPreload: 'print_preview_hello_world_test.html', | 46 browsePrintPreload: 'print_preview_hello_world_test.html', |
| 47 | 47 |
| 48 /** @override */ |
| 49 runAccessibilityChecks: true, |
| 50 |
| 51 /** @override */ |
| 52 accessibilityIssuesAreErrors: true, |
| 53 |
| 54 /** @override */ |
| 55 isAsync: true, |
| 56 |
| 48 /** | 57 /** |
| 49 * Stub out low-level functionality like the NativeLayer and | 58 * Stub out low-level functionality like the NativeLayer and |
| 50 * CloudPrintInterface. | 59 * CloudPrintInterface. |
| 51 * @this {PrintPreviewWebUITest} | 60 * @this {PrintPreviewWebUITest} |
| 52 * @override | 61 * @override |
| 53 */ | 62 */ |
| 54 preLoad: function() { | 63 preLoad: function() { |
| 55 window.addEventListener('DOMContentLoaded', function() { | 64 window.addEventListener('DOMContentLoaded', function() { |
| 56 function NativeLayerStub() { | 65 function NativeLayerStub() { |
| 57 cr.EventTarget.call(this); | 66 cr.EventTarget.call(this); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 80 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub; | 89 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub; |
| 81 cloudprint.CloudPrintInterface.EventType = oldCpInterfaceEventType; | 90 cloudprint.CloudPrintInterface.EventType = oldCpInterfaceEventType; |
| 82 | 91 |
| 83 print_preview.PreviewArea.prototype.getPluginType_ = | 92 print_preview.PreviewArea.prototype.getPluginType_ = |
| 84 function() { | 93 function() { |
| 85 return print_preview.PreviewArea.PluginType_.NONE; | 94 return print_preview.PreviewArea.PluginType_.NONE; |
| 86 }; | 95 }; |
| 87 }.bind(this)); | 96 }.bind(this)); |
| 88 }, | 97 }, |
| 89 | 98 |
| 90 setUpPreview: function() { | 99 /** |
| 100 * Dispatch the INITIAL_SETTINGS_SET event. This call is NOT async and will |
| 101 * happen in the same thread. |
| 102 */ |
| 103 setInitialSettings: function() { |
| 91 var initialSettingsSetEvent = | 104 var initialSettingsSetEvent = |
| 92 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 105 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
| 93 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 106 initialSettingsSetEvent.initialSettings = this.initialSettings_; |
| 94 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | 107 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
| 108 }, |
| 95 | 109 |
| 110 /** |
| 111 * Dispatch the LOCAL_DESTINATIONS_SET event. This call is NOT async and will |
| 112 * happen in the same thread. |
| 113 */ |
| 114 setLocalDestinations: function() { |
| 96 var localDestsSetEvent = | 115 var localDestsSetEvent = |
| 97 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | 116 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
| 98 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | 117 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
| 99 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | 118 this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
| 100 }, | 119 }, |
| 101 | 120 |
| 102 /** | 121 /** |
| 122 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will |
| 123 * happen in the same thread. |
| 124 * @device - The device whose capabilities should be dispatched. |
| 125 */ |
| 126 setCapabilities: function(device) { |
| 127 var capsSetEvent = |
| 128 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
| 129 capsSetEvent.settingsInfo = device; |
| 130 this.nativeLayer_.dispatchEvent(capsSetEvent); |
| 131 }, |
| 132 |
| 133 /** |
| 134 * Even though animation duration and delay is set to zero, it is necessary to |
| 135 * wait until the animation has finished. |
| 136 */ |
| 137 waitForAnimationToEnd: function(elementId) { |
| 138 // add a listener for the animation end event |
| 139 document.addEventListener('webkitAnimationEnd', function f(e) { |
| 140 if (e.target.id == elementId) { |
| 141 document.removeEventListener(f, 'webkitAnimationEnd'); |
| 142 testDone(); |
| 143 } |
| 144 }); |
| 145 }, |
| 146 |
| 147 /** |
| 148 * Expand the 'More Settings' div to expose all options. |
| 149 */ |
| 150 expandMoreSettings: function() { |
| 151 var moreSettings = $('more-settings'); |
| 152 checkSectionVisible(moreSettings, true); |
| 153 moreSettings.click(); |
| 154 }, |
| 155 |
| 156 /** |
| 103 * Generate a real C++ class; don't typedef. | 157 * Generate a real C++ class; don't typedef. |
| 104 * @type {?string} | 158 * @type {?string} |
| 105 * @override | 159 * @override |
| 106 */ | 160 */ |
| 107 typedefCppFixture: null, | 161 typedefCppFixture: null, |
| 108 | 162 |
| 109 /** | 163 /** |
| 110 * @this {PrintPreviewWebUITest} | 164 * @this {PrintPreviewWebUITest} |
| 111 * @override | 165 * @override |
| 112 */ | 166 */ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 125 true /*documentHasSelection*/, | 179 true /*documentHasSelection*/, |
| 126 false /*selectionOnly*/, | 180 false /*selectionOnly*/, |
| 127 'FooDevice' /*systemDefaultDestinationId*/, | 181 'FooDevice' /*systemDefaultDestinationId*/, |
| 128 null /*serializedAppStateStr*/, | 182 null /*serializedAppStateStr*/, |
| 129 false /*documentHasSelection*/); | 183 false /*documentHasSelection*/); |
| 130 this.localDestinationInfos_ = [ | 184 this.localDestinationInfos_ = [ |
| 131 { printerName: 'FooName', deviceName: 'FooDevice' }, | 185 { printerName: 'FooName', deviceName: 'FooDevice' }, |
| 132 { printerName: 'BarName', deviceName: 'BarDevice' } | 186 { printerName: 'BarName', deviceName: 'BarDevice' } |
| 133 ]; | 187 ]; |
| 134 this.nativeLayer_ = printPreview.nativeLayer_; | 188 this.nativeLayer_ = printPreview.nativeLayer_; |
| 189 |
| 190 // Make all transitions and animations take 0ms for testing purposes. |
| 191 // Animations still happen and must be waited on. |
| 192 var noAnimationStyle = document.createElement('style'); |
| 193 noAnimationStyle.textContent = |
| 194 '* {' + |
| 195 ' -webkit-transition-duration: 0s !important;' + |
| 196 ' -webkit-transition-delay: 0s !important;' + |
| 197 ' -webkit-animation-duration: 0s !important;' + |
| 198 ' -webkit-animation-delay: 0s !important;' + |
| 199 '}'; |
| 200 document.querySelector('head').appendChild(noAnimationStyle); |
| 135 } | 201 } |
| 136 }; | 202 }; |
| 137 | 203 |
| 138 GEN('#include "chrome/test/data/webui/print_preview.h"'); | 204 GEN('#include "chrome/test/data/webui/print_preview.h"'); |
| 139 | 205 |
| 140 // Test some basic assumptions about the print preview WebUI. | 206 // Test some basic assumptions about the print preview WebUI. |
| 141 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { | 207 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { |
| 142 var initialSettingsSetEvent = | 208 this.setInitialSettings(); |
| 143 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 209 this.setLocalDestinations(); |
| 144 initialSettingsSetEvent.initialSettings = this.initialSettings_; | |
| 145 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
| 146 | |
| 147 var localDestsSetEvent = | |
| 148 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
| 149 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 150 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 151 | 210 |
| 152 var recentList = $('destination-search').querySelector('.recent-list ul'); | 211 var recentList = $('destination-search').querySelector('.recent-list ul'); |
| 153 var localList = $('destination-search').querySelector('.local-list ul'); | 212 var localList = $('destination-search').querySelector('.local-list ul'); |
| 154 assertNotEquals(null, recentList); | 213 assertNotEquals(null, recentList); |
| 155 assertEquals(1, recentList.childNodes.length); | 214 assertEquals(1, recentList.childNodes.length); |
| 156 assertEquals('FooName', | 215 assertEquals('FooName', |
| 157 recentList.childNodes.item(0).querySelector( | 216 recentList.childNodes.item(0).querySelector( |
| 158 '.destination-list-item-name').textContent); | 217 '.destination-list-item-name').textContent); |
| 159 | 218 |
| 160 assertNotEquals(null, localList); | 219 assertNotEquals(null, localList); |
| 161 assertEquals(3, localList.childNodes.length); | 220 assertEquals(3, localList.childNodes.length); |
| 162 assertEquals('Save as PDF', | 221 assertEquals('Save as PDF', |
| 163 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). | 222 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). |
| 164 querySelector('.destination-list-item-name').textContent); | 223 querySelector('.destination-list-item-name').textContent); |
| 165 assertEquals('FooName', | 224 assertEquals('FooName', |
| 166 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). | 225 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). |
| 167 querySelector('.destination-list-item-name').textContent); | 226 querySelector('.destination-list-item-name').textContent); |
| 168 assertEquals('BarName', | 227 assertEquals('BarName', |
| 169 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). | 228 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). |
| 170 querySelector('.destination-list-item-name').textContent); | 229 querySelector('.destination-list-item-name').textContent); |
| 230 |
| 231 testDone(); |
| 171 }); | 232 }); |
| 172 | 233 |
| 173 // Test that the printer list is structured correctly after calling | 234 // Test that the printer list is structured correctly after calling |
| 174 // addCloudPrinters with an empty list. | 235 // addCloudPrinters with an empty list. |
| 175 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { | 236 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { |
| 176 var initialSettingsSetEvent = | 237 this.setInitialSettings(); |
| 177 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 238 this.setLocalDestinations(); |
| 178 initialSettingsSetEvent.initialSettings = this.initialSettings_; | |
| 179 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
| 180 | |
| 181 var localDestsSetEvent = | |
| 182 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
| 183 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 184 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 185 | 239 |
| 186 var cloudPrintEnableEvent = | 240 var cloudPrintEnableEvent = |
| 187 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); | 241 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); |
| 188 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; | 242 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; |
| 189 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent); | 243 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent); |
| 190 | 244 |
| 191 var searchDoneEvent = | 245 var searchDoneEvent = |
| 192 new Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE); | 246 new Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE); |
| 193 searchDoneEvent.printers = []; | 247 searchDoneEvent.printers = []; |
| 194 searchDoneEvent.isRecent = true; | 248 searchDoneEvent.isRecent = true; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 212 querySelector('.destination-list-item-name').textContent); | 266 querySelector('.destination-list-item-name').textContent); |
| 213 assertEquals('FooName', | 267 assertEquals('FooName', |
| 214 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). | 268 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). |
| 215 querySelector('.destination-list-item-name').textContent); | 269 querySelector('.destination-list-item-name').textContent); |
| 216 assertEquals('BarName', | 270 assertEquals('BarName', |
| 217 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). | 271 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). |
| 218 querySelector('.destination-list-item-name').textContent); | 272 querySelector('.destination-list-item-name').textContent); |
| 219 | 273 |
| 220 assertNotEquals(null, cloudList); | 274 assertNotEquals(null, cloudList); |
| 221 assertEquals(0, cloudList.childNodes.length); | 275 assertEquals(0, cloudList.childNodes.length); |
| 276 |
| 277 testDone(); |
| 222 }); | 278 }); |
| 223 | 279 |
| 224 /** | 280 /** |
| 225 * Verify that |section| visibility matches |visible|. | 281 * Verify that |section| visibility matches |visible|. |
| 226 * @param {HTMLDivElement} section The section to check. | 282 * @param {HTMLDivElement} section The section to check. |
| 227 * @param {boolean} visible The expected state of visibility. | 283 * @param {boolean} visible The expected state of visibility. |
| 228 */ | 284 */ |
| 229 function checkSectionVisible(section, visible) { | 285 function checkSectionVisible(section, visible) { |
| 230 assertNotEquals(null, section); | 286 assertNotEquals(null, section); |
| 231 expectEquals( | 287 expectEquals( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 336 } |
| 281 } | 337 } |
| 282 }; | 338 }; |
| 283 } | 339 } |
| 284 | 340 |
| 285 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode', | 341 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode', |
| 286 function() { | 342 function() { |
| 287 if (cr.isChromeOS) { | 343 if (cr.isChromeOS) { |
| 288 assertEquals(null, $('system-dialog-link')); | 344 assertEquals(null, $('system-dialog-link')); |
| 289 } else { | 345 } else { |
| 290 var initialSettingsSetEvent = | 346 this.initialSettings_.isInAppKioskMode_ = true; |
| 291 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 347 this.setInitialSettings(); |
| 292 initialSettingsSetEvent.initialSettings = this.initialSettings_; | |
| 293 initialSettingsSetEvent.initialSettings.isInAppKioskMode_ = true; | |
| 294 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
| 295 | 348 |
| 296 checkElementDisplayed($('system-dialog-link'), false); | 349 checkElementDisplayed($('system-dialog-link'), false); |
| 297 } | 350 } |
| 351 |
| 352 testDone(); |
| 298 }); | 353 }); |
| 299 | 354 |
| 300 // Test that disabled settings hide the disabled sections. | 355 // Test that disabled settings hide the disabled sections. |
| 301 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { | 356 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { |
| 302 checkSectionVisible($('layout-settings'), false); | 357 checkSectionVisible($('layout-settings'), false); |
| 303 checkSectionVisible($('color-settings'), false); | 358 checkSectionVisible($('color-settings'), false); |
| 304 checkSectionVisible($('copies-settings'), false); | 359 checkSectionVisible($('copies-settings'), false); |
| 305 | 360 |
| 306 var initialSettingsSetEvent = | 361 this.setInitialSettings(); |
| 307 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 362 this.setLocalDestinations(); |
| 308 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 363 var device = getCddTemplate("FooDevice"); |
| 309 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | 364 device.capabilities.printer.color = { |
| 310 | |
| 311 var localDestsSetEvent = | |
| 312 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
| 313 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 314 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 315 | |
| 316 var capsSetEvent = | |
| 317 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 318 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 319 capsSetEvent.settingsInfo.capabilities.printer.color = { | |
| 320 "option": [ | 365 "option": [ |
| 321 {"is_default": true, "type": "STANDARD_COLOR"} | 366 {"is_default": true, "type": "STANDARD_COLOR"} |
| 322 ] | 367 ] |
| 323 }; | 368 }; |
| 324 delete capsSetEvent.settingsInfo.capabilities.printer.copies; | 369 delete device.capabilities.printer.copies; |
| 325 this.nativeLayer_.dispatchEvent(capsSetEvent); | 370 this.setCapabilities(device); |
| 326 | 371 |
| 327 checkSectionVisible($('layout-settings'), true); | 372 checkSectionVisible($('layout-settings'), true); |
| 328 checkSectionVisible($('color-settings'), false); | 373 checkSectionVisible($('color-settings'), false); |
| 329 checkSectionVisible($('copies-settings'), false); | 374 checkSectionVisible($('copies-settings'), false); |
| 375 |
| 376 this.waitForAnimationToEnd('other-options-collapsible'); |
| 330 }); | 377 }); |
| 331 | 378 |
| 332 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the | 379 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the |
| 333 // fit to page option. | 380 // fit to page option. |
| 334 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() { | 381 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() { |
| 335 // Add PDF printer. | 382 // Add PDF printer. |
| 336 this.initialSettings_.isDocumentModifiable_ = false; | 383 this.initialSettings_.isDocumentModifiable_ = false; |
| 337 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF'; | 384 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF'; |
| 385 this.setInitialSettings(); |
| 338 | 386 |
| 339 var initialSettingsSetEvent = | 387 var device = { |
| 340 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | |
| 341 initialSettingsSetEvent.initialSettings = this.initialSettings_; | |
| 342 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
| 343 | |
| 344 var capsSetEvent = | |
| 345 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 346 capsSetEvent.settingsInfo = { | |
| 347 printerId: 'Save as PDF', | 388 printerId: 'Save as PDF', |
| 348 capabilities: { | 389 capabilities: { |
| 349 version: '1.0', | 390 version: '1.0', |
| 350 printer: { | 391 printer: { |
| 351 page_orientation: { | 392 page_orientation: { |
| 352 option: [ | 393 option: [ |
| 353 {type: 'AUTO', is_default: true}, | 394 {type: 'AUTO', is_default: true}, |
| 354 {type: 'PORTRAIT'}, | 395 {type: 'PORTRAIT'}, |
| 355 {type: 'LANDSCAPE'} | 396 {type: 'LANDSCAPE'} |
| 356 ] | 397 ] |
| 357 }, | 398 }, |
| 358 color: { | 399 color: { |
| 359 option: [ | 400 option: [ |
| 360 {type: 'STANDARD_COLOR', is_default: true} | 401 {type: 'STANDARD_COLOR', is_default: true} |
| 361 ] | 402 ] |
| 362 }, | 403 }, |
| 363 media_size: { | 404 media_size: { |
| 364 option: [ | 405 option: [ |
| 365 { name: 'NA_LETTER', | 406 { name: 'NA_LETTER', |
| 366 width_microns: 0, | 407 width_microns: 0, |
| 367 height_microns: 0, | 408 height_microns: 0, |
| 368 is_default: true | 409 is_default: true |
| 369 } | 410 } |
| 370 ] | 411 ] |
| 371 } | 412 } |
| 372 } | 413 } |
| 373 } | 414 } |
| 374 }; | 415 }; |
| 375 this.nativeLayer_.dispatchEvent(capsSetEvent); | 416 this.setCapabilities(device); |
| 376 | 417 |
| 377 checkSectionVisible($('other-options-settings'), false); | 418 checkSectionVisible($('other-options-settings'), false); |
| 378 checkSectionVisible($('media-size-settings'), false); | 419 checkSectionVisible($('media-size-settings'), false); |
| 420 |
| 421 testDone(); |
| 379 }); | 422 }); |
| 380 | 423 |
| 381 // When the source is 'HTML', we always hide the fit to page option and show | 424 // When the source is 'HTML', we always hide the fit to page option and show |
| 382 // media size option. | 425 // media size option. |
| 383 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() { | 426 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() { |
| 384 var initialSettingsSetEvent = | 427 this.setInitialSettings(); |
| 385 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 428 this.setLocalDestinations(); |
| 386 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 429 this.setCapabilities(getCddTemplate("FooDevice")); |
| 387 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
| 388 | 430 |
| 389 var localDestsSetEvent = | 431 var otherOptions = $('other-options-settings'); |
| 390 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | 432 var fitToPage = otherOptions.querySelector('.fit-to-page-container'); |
| 391 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | 433 var mediaSize = $('media-size-settings'); |
| 392 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 393 | |
| 394 var capsSetEvent = | |
| 395 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 396 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 397 this.nativeLayer_.dispatchEvent(capsSetEvent); | |
| 398 | |
| 399 var moreSettingsDiv = $('more-settings'); | |
| 400 var mediaSizeDiv = $('media-size-settings'); | |
| 401 var otherOptionsDiv = $('other-options-settings'); | |
| 402 var fitToPageEl = otherOptionsDiv.querySelector('.fit-to-page-container'); | |
| 403 | 434 |
| 404 // Check that options are collapsed (section is visible, because duplex is | 435 // Check that options are collapsed (section is visible, because duplex is |
| 405 // available). | 436 // available). |
| 406 checkSectionVisible(otherOptionsDiv, true); | 437 checkSectionVisible(otherOptions, true); |
| 407 checkElementDisplayed(fitToPageEl, false); | 438 checkElementDisplayed(fitToPage, false); |
| 408 checkSectionVisible(mediaSizeDiv, false); | 439 checkSectionVisible(mediaSize, false); |
| 409 // Expand it. | |
| 410 checkSectionVisible(moreSettingsDiv, true); | |
| 411 moreSettingsDiv.click(); | |
| 412 | 440 |
| 413 checkElementDisplayed(fitToPageEl, false); | 441 this.expandMoreSettings(); |
| 414 checkSectionVisible(mediaSizeDiv, true); | 442 |
| 443 checkElementDisplayed(fitToPage, false); |
| 444 checkSectionVisible(mediaSize, true); |
| 445 |
| 446 this.waitForAnimationToEnd('more-settings'); |
| 415 }); | 447 }); |
| 416 | 448 |
| 417 // When the source is "PDF", depending on the selected destination printer, we | 449 // When the source is "PDF", depending on the selected destination printer, we |
| 418 // show/hide the fit to page option and hide media size selection. | 450 // show/hide the fit to page option and hide media size selection. |
| 419 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() { | 451 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() { |
| 420 this.initialSettings_.isDocumentModifiable_ = false; | 452 this.initialSettings_.isDocumentModifiable_ = false; |
| 453 this.setInitialSettings(); |
| 454 this.setLocalDestinations(); |
| 455 this.setCapabilities(getCddTemplate("FooDevice")); |
| 421 | 456 |
| 422 var initialSettingsSetEvent = | 457 var otherOptions = $('other-options-settings'); |
| 423 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 458 checkSectionVisible(otherOptions, true); |
| 424 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 459 checkElementDisplayed( |
| 425 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | 460 otherOptions.querySelector('.fit-to-page-container'), true); |
| 461 expectTrue( |
| 462 otherOptions.querySelector('.fit-to-page-checkbox').checked); |
| 463 checkSectionVisible($('media-size-settings'), true); |
| 426 | 464 |
| 427 var localDestsSetEvent = | 465 this.waitForAnimationToEnd('other-options-collapsible'); |
| 428 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
| 429 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 430 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 431 | |
| 432 var capsSetEvent = | |
| 433 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 434 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 435 this.nativeLayer_.dispatchEvent(capsSetEvent); | |
| 436 | |
| 437 var otherOptionsDiv = $('other-options-settings'); | |
| 438 | |
| 439 checkSectionVisible(otherOptionsDiv, true); | |
| 440 checkElementDisplayed( | |
| 441 otherOptionsDiv.querySelector('.fit-to-page-container'), true); | |
| 442 expectTrue( | |
| 443 otherOptionsDiv.querySelector('.fit-to-page-checkbox').checked); | |
| 444 checkSectionVisible($('media-size-settings'), true); | |
| 445 }); | 466 }); |
| 446 | 467 |
| 447 // When the print scaling is disabled for the source "PDF", we show the fit | 468 // When the print scaling is disabled for the source "PDF", we show the fit |
| 448 // to page option but the state is unchecked by default. | 469 // to page option but the state is unchecked by default. |
| 449 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() { | 470 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() { |
| 450 this.initialSettings_.isDocumentModifiable_ = false; | 471 this.initialSettings_.isDocumentModifiable_ = false; |
| 451 | 472 this.setInitialSettings(); |
| 452 var initialSettingsSetEvent = | 473 this.setLocalDestinations(); |
| 453 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 474 this.setCapabilities(getCddTemplate("FooDevice")); |
| 454 initialSettingsSetEvent.initialSettings = this.initialSettings_; | |
| 455 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
| 456 | |
| 457 var localDestsSetEvent = | |
| 458 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
| 459 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 460 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 461 | |
| 462 var capsSetEvent = | |
| 463 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 464 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 465 this.nativeLayer_.dispatchEvent(capsSetEvent); | |
| 466 | 475 |
| 467 // Indicate that the PDF does not support scaling by default. | 476 // Indicate that the PDF does not support scaling by default. |
| 468 cr.dispatchSimpleEvent( | 477 cr.dispatchSimpleEvent( |
| 469 this.nativeLayer_, print_preview.NativeLayer.EventType.DISABLE_SCALING); | 478 this.nativeLayer_, print_preview.NativeLayer.EventType.DISABLE_SCALING); |
| 470 | 479 |
| 471 var otherOptionsDiv = $('other-options-settings'); | 480 var otherOptions = $('other-options-settings'); |
| 481 checkSectionVisible(otherOptions, true); |
| 482 checkElementDisplayed( |
| 483 otherOptions.querySelector('.fit-to-page-container'), true); |
| 484 expectFalse( |
| 485 otherOptions.querySelector('.fit-to-page-checkbox').checked); |
| 472 | 486 |
| 473 checkSectionVisible(otherOptionsDiv, true); | 487 this.waitForAnimationToEnd('other-options-collapsible'); |
| 474 | |
| 475 checkElementDisplayed( | |
| 476 otherOptionsDiv.querySelector('.fit-to-page-container'), true); | |
| 477 expectFalse( | |
| 478 otherOptionsDiv.querySelector('.fit-to-page-checkbox').checked); | |
| 479 }); | 488 }); |
| 480 | 489 |
| 481 // Make sure that custom margins controls are properly set up. | 490 // Make sure that custom margins controls are properly set up. |
| 482 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() { | 491 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() { |
| 483 var initialSettingsSetEvent = | 492 this.setInitialSettings(); |
| 484 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 493 this.setLocalDestinations(); |
| 485 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 494 this.setCapabilities(getCddTemplate("FooDevice")); |
| 486 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
| 487 | |
| 488 var localDestsSetEvent = | |
| 489 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
| 490 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 491 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 492 | |
| 493 var capsSetEvent = | |
| 494 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 495 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 496 this.nativeLayer_.dispatchEvent(capsSetEvent); | |
| 497 | 495 |
| 498 printPreview.printTicketStore_.marginsType.updateValue( | 496 printPreview.printTicketStore_.marginsType.updateValue( |
| 499 print_preview.ticket_items.MarginsType.Value.CUSTOM); | 497 print_preview.ticket_items.MarginsType.Value.CUSTOM); |
| 500 | 498 |
| 501 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { | 499 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { |
| 502 var control = $('preview-area').querySelector('.margin-control-' + margin); | 500 var control = $('preview-area').querySelector('.margin-control-' + margin); |
| 503 assertNotEquals(null, control); | 501 assertNotEquals(null, control); |
| 504 var input = control.querySelector('.margin-control-textbox'); | 502 var input = control.querySelector('.margin-control-textbox'); |
| 505 assertTrue(input.hasAttribute('aria-label')); | 503 assertTrue(input.hasAttribute('aria-label')); |
| 506 assertNotEquals('undefined', input.getAttribute('aria-label')); | 504 assertNotEquals('undefined', input.getAttribute('aria-label')); |
| 507 }); | 505 }); |
| 506 this.waitForAnimationToEnd('more-settings'); |
| 508 }); | 507 }); |
| 509 | 508 |
| 510 // Page layout has zero margins. Hide header and footer option. | 509 // Page layout has zero margins. Hide header and footer option. |
| 511 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter', | 510 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter', |
| 512 function() { | 511 function() { |
| 513 var initialSettingsSetEvent = | 512 this.setInitialSettings(); |
| 514 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 513 this.setLocalDestinations(); |
| 515 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 514 this.setCapabilities(getCddTemplate("FooDevice")); |
| 516 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
| 517 | 515 |
| 518 var localDestsSetEvent = | 516 var otherOptions = $('other-options-settings'); |
| 519 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | 517 var headerFooter = otherOptions.querySelector('.header-footer-container'); |
| 520 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 521 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 522 | |
| 523 var capsSetEvent = | |
| 524 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 525 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 526 this.nativeLayer_.dispatchEvent(capsSetEvent); | |
| 527 | |
| 528 var moreSettingsDiv = $('more-settings'); | |
| 529 var otherOptionsDiv = $('other-options-settings'); | |
| 530 var headerFooterEl = | |
| 531 otherOptionsDiv.querySelector('.header-footer-container'); | |
| 532 | 518 |
| 533 // Check that options are collapsed (section is visible, because duplex is | 519 // Check that options are collapsed (section is visible, because duplex is |
| 534 // available). | 520 // available). |
| 535 checkSectionVisible(otherOptionsDiv, true); | 521 checkSectionVisible(otherOptions, true); |
| 536 checkElementDisplayed(headerFooterEl, false); | 522 checkElementDisplayed(headerFooter, false); |
| 537 // Expand it. | |
| 538 checkSectionVisible(moreSettingsDiv, true); | |
| 539 moreSettingsDiv.click(); | |
| 540 | 523 |
| 541 checkElementDisplayed(headerFooterEl, true); | 524 this.expandMoreSettings(); |
| 525 |
| 526 checkElementDisplayed(headerFooter, true); |
| 542 | 527 |
| 543 printPreview.printTicketStore_.marginsType.updateValue( | 528 printPreview.printTicketStore_.marginsType.updateValue( |
| 544 print_preview.ticket_items.MarginsType.Value.CUSTOM); | 529 print_preview.ticket_items.MarginsType.Value.CUSTOM); |
| 545 printPreview.printTicketStore_.customMargins.updateValue( | 530 printPreview.printTicketStore_.customMargins.updateValue( |
| 546 new print_preview.Margins(0, 0, 0, 0)); | 531 new print_preview.Margins(0, 0, 0, 0)); |
| 547 | 532 |
| 548 checkElementDisplayed(headerFooterEl, false); | 533 checkElementDisplayed(headerFooter, false); |
| 534 |
| 535 this.waitForAnimationToEnd('more-settings'); |
| 549 }); | 536 }); |
| 550 | 537 |
| 551 // Page layout has half-inch margins. Show header and footer option. | 538 // Page layout has half-inch margins. Show header and footer option. |
| 552 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter', | 539 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter', |
| 553 function() { | 540 function() { |
| 554 var initialSettingsSetEvent = | 541 this.setInitialSettings(); |
| 555 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 542 this.setLocalDestinations(); |
| 556 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 543 this.setCapabilities(getCddTemplate("FooDevice")); |
| 557 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
| 558 | 544 |
| 559 var localDestsSetEvent = | 545 var otherOptions = $('other-options-settings'); |
| 560 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | 546 var headerFooter = otherOptions.querySelector('.header-footer-container'); |
| 561 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 562 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 563 | |
| 564 var capsSetEvent = | |
| 565 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 566 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 567 this.nativeLayer_.dispatchEvent(capsSetEvent); | |
| 568 | |
| 569 var moreSettingsDiv = $('more-settings'); | |
| 570 var otherOptionsDiv = $('other-options-settings'); | |
| 571 var headerFooterEl = | |
| 572 otherOptionsDiv.querySelector('.header-footer-container'); | |
| 573 | 547 |
| 574 // Check that options are collapsed (section is visible, because duplex is | 548 // Check that options are collapsed (section is visible, because duplex is |
| 575 // available). | 549 // available). |
| 576 checkSectionVisible(otherOptionsDiv, true); | 550 checkSectionVisible(otherOptions, true); |
| 577 checkElementDisplayed(headerFooterEl, false); | 551 checkElementDisplayed(headerFooter, false); |
| 578 // Expand it. | |
| 579 checkSectionVisible(moreSettingsDiv, true); | |
| 580 moreSettingsDiv.click(); | |
| 581 | 552 |
| 582 checkElementDisplayed(headerFooterEl, true); | 553 this.expandMoreSettings(); |
| 554 |
| 555 checkElementDisplayed(headerFooter, true); |
| 583 | 556 |
| 584 printPreview.printTicketStore_.marginsType.updateValue( | 557 printPreview.printTicketStore_.marginsType.updateValue( |
| 585 print_preview.ticket_items.MarginsType.Value.CUSTOM); | 558 print_preview.ticket_items.MarginsType.Value.CUSTOM); |
| 586 printPreview.printTicketStore_.customMargins.updateValue( | 559 printPreview.printTicketStore_.customMargins.updateValue( |
| 587 new print_preview.Margins(36, 36, 36, 36)); | 560 new print_preview.Margins(36, 36, 36, 36)); |
| 588 | 561 |
| 589 checkElementDisplayed(headerFooterEl, true); | 562 checkElementDisplayed(headerFooter, true); |
| 563 |
| 564 this.waitForAnimationToEnd('more-settings'); |
| 590 }); | 565 }); |
| 591 | 566 |
| 592 // Page layout has zero top and bottom margins. Hide header and footer option. | 567 // Page layout has zero top and bottom margins. Hide header and footer option. |
| 593 TEST_F('PrintPreviewWebUITest', | 568 TEST_F('PrintPreviewWebUITest', |
| 594 'ZeroTopAndBottomMarginsHideHeaderFooter', | 569 'ZeroTopAndBottomMarginsHideHeaderFooter', |
| 595 function() { | 570 function() { |
| 596 var initialSettingsSetEvent = | 571 this.setInitialSettings(); |
| 597 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 572 this.setLocalDestinations(); |
| 598 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 573 this.setCapabilities(getCddTemplate("FooDevice")); |
| 599 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
| 600 | 574 |
| 601 var localDestsSetEvent = | 575 var otherOptions = $('other-options-settings'); |
| 602 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | 576 var headerFooter = otherOptions.querySelector('.header-footer-container'); |
| 603 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 604 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 605 | |
| 606 var capsSetEvent = | |
| 607 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 608 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 609 this.nativeLayer_.dispatchEvent(capsSetEvent); | |
| 610 | |
| 611 var moreSettingsDiv = $('more-settings'); | |
| 612 var otherOptionsDiv = $('other-options-settings'); | |
| 613 var headerFooterEl = | |
| 614 otherOptionsDiv.querySelector('.header-footer-container'); | |
| 615 | 577 |
| 616 // Check that options are collapsed (section is visible, because duplex is | 578 // Check that options are collapsed (section is visible, because duplex is |
| 617 // available). | 579 // available). |
| 618 checkSectionVisible(otherOptionsDiv, true); | 580 checkSectionVisible(otherOptions, true); |
| 619 checkElementDisplayed(headerFooterEl, false); | 581 checkElementDisplayed(headerFooter, false); |
| 620 // Expand it. | |
| 621 checkSectionVisible(moreSettingsDiv, true); | |
| 622 moreSettingsDiv.click(); | |
| 623 | 582 |
| 624 checkElementDisplayed(headerFooterEl, true); | 583 this.expandMoreSettings(); |
| 584 |
| 585 checkElementDisplayed(headerFooter, true); |
| 625 | 586 |
| 626 printPreview.printTicketStore_.marginsType.updateValue( | 587 printPreview.printTicketStore_.marginsType.updateValue( |
| 627 print_preview.ticket_items.MarginsType.Value.CUSTOM); | 588 print_preview.ticket_items.MarginsType.Value.CUSTOM); |
| 628 printPreview.printTicketStore_.customMargins.updateValue( | 589 printPreview.printTicketStore_.customMargins.updateValue( |
| 629 new print_preview.Margins(0, 36, 0, 36)); | 590 new print_preview.Margins(0, 36, 0, 36)); |
| 630 | 591 |
| 631 checkElementDisplayed(headerFooterEl, false); | 592 checkElementDisplayed(headerFooter, false); |
| 593 |
| 594 this.waitForAnimationToEnd('more-settings'); |
| 632 }); | 595 }); |
| 633 | 596 |
| 634 // Page layout has zero top and half-inch bottom margin. Show header and footer | 597 // Page layout has zero top and half-inch bottom margin. Show header and footer |
| 635 // option. | 598 // option. |
| 636 TEST_F('PrintPreviewWebUITest', | 599 TEST_F('PrintPreviewWebUITest', |
| 637 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter', | 600 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter', |
| 638 function() { | 601 function() { |
| 639 var initialSettingsSetEvent = | 602 this.setInitialSettings(); |
| 640 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 603 this.setLocalDestinations(); |
| 641 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 604 this.setCapabilities(getCddTemplate("FooDevice")); |
| 642 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | 605 |
| 643 | 606 var otherOptions = $('other-options-settings'); |
| 644 var localDestsSetEvent = | 607 var headerFooter = otherOptions.querySelector('.header-footer-container'); |
| 645 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
| 646 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 647 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 648 | |
| 649 var capsSetEvent = | |
| 650 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 651 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 652 this.nativeLayer_.dispatchEvent(capsSetEvent); | |
| 653 | |
| 654 var moreSettingsDiv = $('more-settings'); | |
| 655 var otherOptionsDiv = $('other-options-settings'); | |
| 656 var headerFooterEl = | |
| 657 otherOptionsDiv.querySelector('.header-footer-container'); | |
| 658 | 608 |
| 659 // Check that options are collapsed (section is visible, because duplex is | 609 // Check that options are collapsed (section is visible, because duplex is |
| 660 // available). | 610 // available). |
| 661 checkSectionVisible(otherOptionsDiv, true); | 611 checkSectionVisible(otherOptions, true); |
| 662 checkElementDisplayed(headerFooterEl, false); | 612 checkElementDisplayed(headerFooter, false); |
| 663 // Expand it. | 613 |
| 664 checkSectionVisible(moreSettingsDiv, true); | 614 this.expandMoreSettings(); |
| 665 moreSettingsDiv.click(); | 615 |
| 666 | 616 checkElementDisplayed(headerFooter, true); |
| 667 checkElementDisplayed(headerFooterEl, true); | |
| 668 | 617 |
| 669 printPreview.printTicketStore_.marginsType.updateValue( | 618 printPreview.printTicketStore_.marginsType.updateValue( |
| 670 print_preview.ticket_items.MarginsType.Value.CUSTOM); | 619 print_preview.ticket_items.MarginsType.Value.CUSTOM); |
| 671 printPreview.printTicketStore_.customMargins.updateValue( | 620 printPreview.printTicketStore_.customMargins.updateValue( |
| 672 new print_preview.Margins(0, 36, 36, 36)); | 621 new print_preview.Margins(0, 36, 36, 36)); |
| 673 | 622 |
| 674 checkElementDisplayed(headerFooterEl, true); | 623 checkElementDisplayed(headerFooter, true); |
| 624 |
| 625 this.waitForAnimationToEnd('more-settings'); |
| 675 }); | 626 }); |
| 676 | 627 |
| 677 // Test that the color settings, one option, standard monochrome. | 628 // Test that the color settings, one option, standard monochrome. |
| 678 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() { | 629 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() { |
| 679 this.setUpPreview(); | 630 this.setInitialSettings(); |
| 631 this.setLocalDestinations(); |
| 680 | 632 |
| 681 // Only one option, standard monochrome. | 633 // Only one option, standard monochrome. |
| 682 var capsSetEvent = | 634 var device = getCddTemplate("FooDevice"); |
| 683 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 635 device.capabilities.printer.color = { |
| 684 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 685 capsSetEvent.settingsInfo.capabilities.printer.color = { | |
| 686 "option": [ | 636 "option": [ |
| 687 {"is_default": true, "type": "STANDARD_MONOCHROME"} | 637 {"is_default": true, "type": "STANDARD_MONOCHROME"} |
| 688 ] | 638 ] |
| 689 }; | 639 }; |
| 690 this.nativeLayer_.dispatchEvent(capsSetEvent); | 640 this.setCapabilities(device); |
| 691 | 641 |
| 692 checkSectionVisible($('color-settings'), false); | 642 checkSectionVisible($('color-settings'), false); |
| 643 |
| 644 this.waitForAnimationToEnd('more-settings'); |
| 693 }); | 645 }); |
| 694 | 646 |
| 695 // Test that the color settings, one option, custom monochrome. | 647 // Test that the color settings, one option, custom monochrome. |
| 696 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome', | 648 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome', |
| 697 function() { | 649 function() { |
| 698 this.setUpPreview(); | 650 this.setInitialSettings(); |
| 651 this.setLocalDestinations(); |
| 699 | 652 |
| 700 // Only one option, standard monochrome. | 653 // Only one option, standard monochrome. |
| 701 var capsSetEvent = | 654 var device = getCddTemplate("FooDevice"); |
| 702 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 655 device.capabilities.printer.color = { |
| 703 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 704 capsSetEvent.settingsInfo.capabilities.printer.color = { | |
| 705 "option": [ | 656 "option": [ |
| 706 {"is_default": true, "type": "CUSTOM_MONOCHROME", "vendor_id": "42"} | 657 {"is_default": true, "type": "CUSTOM_MONOCHROME", "vendor_id": "42"} |
| 707 ] | 658 ] |
| 708 }; | 659 }; |
| 709 this.nativeLayer_.dispatchEvent(capsSetEvent); | 660 this.setCapabilities(device); |
| 710 | 661 |
| 711 checkSectionVisible($('color-settings'), false); | 662 checkSectionVisible($('color-settings'), false); |
| 663 |
| 664 this.waitForAnimationToEnd('more-settings'); |
| 712 }); | 665 }); |
| 713 | 666 |
| 714 // Test that the color settings, one option, standard color. | 667 // Test that the color settings, one option, standard color. |
| 715 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() { | 668 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() { |
| 716 this.setUpPreview(); | 669 this.setInitialSettings(); |
| 717 | 670 this.setLocalDestinations(); |
| 718 var capsSetEvent = | 671 |
| 719 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 672 var device = getCddTemplate("FooDevice"); |
| 720 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | 673 device.capabilities.printer.color = { |
| 721 capsSetEvent.settingsInfo.capabilities.printer.color = { | |
| 722 "option": [ | 674 "option": [ |
| 723 {"is_default": true, "type": "STANDARD_COLOR"} | 675 {"is_default": true, "type": "STANDARD_COLOR"} |
| 724 ] | 676 ] |
| 725 }; | 677 }; |
| 726 this.nativeLayer_.dispatchEvent(capsSetEvent); | 678 this.setCapabilities(device); |
| 727 | 679 |
| 728 checkSectionVisible($('color-settings'), false); | 680 checkSectionVisible($('color-settings'), false); |
| 681 |
| 682 this.waitForAnimationToEnd('more-settings'); |
| 729 }); | 683 }); |
| 730 | 684 |
| 731 // Test that the color settings, one option, custom color. | 685 // Test that the color settings, one option, custom color. |
| 732 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() { | 686 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() { |
| 733 this.setUpPreview(); | 687 this.setInitialSettings(); |
| 734 | 688 this.setLocalDestinations(); |
| 735 var capsSetEvent = | 689 |
| 736 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 690 var device = getCddTemplate("FooDevice"); |
| 737 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | 691 device.capabilities.printer.color = { |
| 738 capsSetEvent.settingsInfo.capabilities.printer.color = { | |
| 739 "option": [ | 692 "option": [ |
| 740 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"} | 693 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"} |
| 741 ] | 694 ] |
| 742 }; | 695 }; |
| 743 this.nativeLayer_.dispatchEvent(capsSetEvent); | 696 this.setCapabilities(device); |
| 744 | 697 |
| 745 checkSectionVisible($('color-settings'), false); | 698 checkSectionVisible($('color-settings'), false); |
| 699 |
| 700 this.waitForAnimationToEnd('more-settings'); |
| 746 }); | 701 }); |
| 747 | 702 |
| 748 // Test that the color settings, two options, both standard, defaults to color. | 703 // Test that the color settings, two options, both standard, defaults to color. |
| 749 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor', | 704 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor', |
| 750 function() { | 705 function() { |
| 751 this.setUpPreview(); | 706 this.setInitialSettings(); |
| 752 | 707 this.setLocalDestinations(); |
| 753 var capsSetEvent = | 708 |
| 754 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 709 var device = getCddTemplate("FooDevice"); |
| 755 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | 710 device.capabilities.printer.color = { |
| 756 capsSetEvent.settingsInfo.capabilities.printer.color = { | |
| 757 "option": [ | 711 "option": [ |
| 758 {"type": "STANDARD_MONOCHROME"}, | 712 {"type": "STANDARD_MONOCHROME"}, |
| 759 {"is_default": true, "type": "STANDARD_COLOR"} | 713 {"is_default": true, "type": "STANDARD_COLOR"} |
| 760 ] | 714 ] |
| 761 }; | 715 }; |
| 762 this.nativeLayer_.dispatchEvent(capsSetEvent); | 716 this.setCapabilities(device); |
| 763 | 717 |
| 764 checkSectionVisible($('color-settings'), true); | 718 checkSectionVisible($('color-settings'), true); |
| 765 expectEquals( | 719 expectEquals( |
| 766 'color', | 720 'color', |
| 767 $('color-settings').querySelector('.color-settings-select').value); | 721 $('color-settings').querySelector('.color-settings-select').value); |
| 722 |
| 723 this.waitForAnimationToEnd('more-settings'); |
| 768 }); | 724 }); |
| 769 | 725 |
| 770 // Test that the color settings, two options, both standard, defaults to | 726 // Test that the color settings, two options, both standard, defaults to |
| 771 // monochrome. | 727 // monochrome. |
| 772 TEST_F('PrintPreviewWebUITest', | 728 TEST_F('PrintPreviewWebUITest', |
| 773 'TestColorSettingsBothStandardDefaultMonochrome', function() { | 729 'TestColorSettingsBothStandardDefaultMonochrome', function() { |
| 774 this.setUpPreview(); | 730 this.setInitialSettings(); |
| 775 | 731 this.setLocalDestinations(); |
| 776 var capsSetEvent = | 732 |
| 777 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 733 var device = getCddTemplate("FooDevice"); |
| 778 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | 734 device.capabilities.printer.color = { |
| 779 capsSetEvent.settingsInfo.capabilities.printer.color = { | |
| 780 "option": [ | 735 "option": [ |
| 781 {"is_default": true, "type": "STANDARD_MONOCHROME"}, | 736 {"is_default": true, "type": "STANDARD_MONOCHROME"}, |
| 782 {"type": "STANDARD_COLOR"} | 737 {"type": "STANDARD_COLOR"} |
| 783 ] | 738 ] |
| 784 }; | 739 }; |
| 785 this.nativeLayer_.dispatchEvent(capsSetEvent); | 740 this.setCapabilities(device); |
| 786 | 741 |
| 787 checkSectionVisible($('color-settings'), true); | 742 checkSectionVisible($('color-settings'), true); |
| 788 expectEquals( | 743 expectEquals( |
| 789 'bw', $('color-settings').querySelector('.color-settings-select').value); | 744 'bw', $('color-settings').querySelector('.color-settings-select').value); |
| 745 |
| 746 this.waitForAnimationToEnd('more-settings'); |
| 790 }); | 747 }); |
| 791 | 748 |
| 792 // Test that the color settings, two options, both custom, defaults to color. | 749 // Test that the color settings, two options, both custom, defaults to color. |
| 793 TEST_F('PrintPreviewWebUITest', | 750 TEST_F('PrintPreviewWebUITest', |
| 794 'TestColorSettingsBothCustomDefaultColor', function() { | 751 'TestColorSettingsBothCustomDefaultColor', function() { |
| 795 this.setUpPreview(); | 752 this.setInitialSettings(); |
| 796 | 753 this.setLocalDestinations(); |
| 797 var capsSetEvent = | 754 |
| 798 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 755 var device = getCddTemplate("FooDevice"); |
| 799 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | 756 device.capabilities.printer.color = { |
| 800 capsSetEvent.settingsInfo.capabilities.printer.color = { | |
| 801 "option": [ | 757 "option": [ |
| 802 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"}, | 758 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"}, |
| 803 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"} | 759 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"} |
| 804 ] | 760 ] |
| 805 }; | 761 }; |
| 806 this.nativeLayer_.dispatchEvent(capsSetEvent); | 762 this.setCapabilities(device); |
| 807 | 763 |
| 808 checkSectionVisible($('color-settings'), true); | 764 checkSectionVisible($('color-settings'), true); |
| 809 expectEquals( | 765 expectEquals( |
| 810 'color', | 766 'color', |
| 811 $('color-settings').querySelector('.color-settings-select').value); | 767 $('color-settings').querySelector('.color-settings-select').value); |
| 768 |
| 769 this.waitForAnimationToEnd('more-settings'); |
| 812 }); | 770 }); |
| 813 | 771 |
| 814 // Test to verify that duplex settings are set according to the printer | 772 // Test to verify that duplex settings are set according to the printer |
| 815 // capabilities. | 773 // capabilities. |
| 816 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() { | 774 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() { |
| 817 var initialSettingsSetEvent = | 775 this.setInitialSettings(); |
| 818 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 776 this.setLocalDestinations(); |
| 819 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 777 this.setCapabilities(getCddTemplate("FooDevice")); |
| 820 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | 778 |
| 821 | 779 var otherOptions = $('other-options-settings'); |
| 822 var localDestsSetEvent = | 780 checkSectionVisible(otherOptions, true); |
| 823 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | 781 expectFalse(otherOptions.querySelector('.duplex-container').hidden); |
| 824 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | 782 expectFalse(otherOptions.querySelector('.duplex-checkbox').checked); |
| 825 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | 783 |
| 826 | 784 this.waitForAnimationToEnd('more-settings'); |
| 827 var otherOptionsDiv = $('other-options-settings'); | |
| 828 var duplexDiv = otherOptionsDiv.querySelector('.duplex-container'); | |
| 829 var duplexCheckbox = otherOptionsDiv.querySelector('.duplex-checkbox'); | |
| 830 | |
| 831 var capsSetEvent = | |
| 832 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 833 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 834 this.nativeLayer_.dispatchEvent(capsSetEvent); | |
| 835 | |
| 836 checkSectionVisible(otherOptionsDiv, true); | |
| 837 expectFalse(duplexDiv.hidden); | |
| 838 expectFalse(duplexCheckbox.checked); | |
| 839 }); | 785 }); |
| 840 | 786 |
| 841 // Test to verify that duplex settings are set according to the printer | 787 // Test to verify that duplex settings are set according to the printer |
| 842 // capabilities. | 788 // capabilities. |
| 843 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() { | 789 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() { |
| 844 var initialSettingsSetEvent = | 790 this.setInitialSettings(); |
| 845 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 791 this.setLocalDestinations(); |
| 846 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 792 var device = getCddTemplate("FooDevice"); |
| 847 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | 793 delete device.capabilities.printer.duplex; |
| 848 | 794 this.setCapabilities(device); |
| 849 var localDestsSetEvent = | |
| 850 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
| 851 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 852 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 853 | |
| 854 var moreSettingsDiv = $('more-settings'); | |
| 855 var otherOptionsDiv = $('other-options-settings'); | |
| 856 var duplexDiv = otherOptionsDiv.querySelector('.duplex-container'); | |
| 857 | |
| 858 var capsSetEvent = | |
| 859 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 860 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 861 delete capsSetEvent.settingsInfo.capabilities.printer.duplex; | |
| 862 this.nativeLayer_.dispatchEvent(capsSetEvent); | |
| 863 | 795 |
| 864 // Check that it is collapsed. | 796 // Check that it is collapsed. |
| 865 checkSectionVisible(otherOptionsDiv, false); | 797 var otherOptions = $('other-options-settings'); |
| 866 // Expand it. | 798 checkSectionVisible(otherOptions, false); |
| 867 checkSectionVisible(moreSettingsDiv, true); | 799 |
| 868 moreSettingsDiv.click(); | 800 this.expandMoreSettings(); |
| 801 |
| 869 // Now it should be visible. | 802 // Now it should be visible. |
| 870 checkSectionVisible(otherOptionsDiv, true); | 803 checkSectionVisible(otherOptions, true); |
| 871 expectTrue(duplexDiv.hidden); | 804 expectTrue(otherOptions.querySelector('.duplex-container').hidden); |
| 805 |
| 806 this.waitForAnimationToEnd('more-settings'); |
| 872 }); | 807 }); |
| 873 | 808 |
| 874 // Test that changing the selected printer updates the preview. | 809 // Test that changing the selected printer updates the preview. |
| 875 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { | 810 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { |
| 876 | 811 this.setInitialSettings(); |
| 877 var initialSettingsSetEvent = | 812 this.setLocalDestinations(); |
| 878 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 813 this.setCapabilities(getCddTemplate("FooDevice")); |
| 879 initialSettingsSetEvent.initialSettings = this.initialSettings_; | |
| 880 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | |
| 881 | |
| 882 var localDestsSetEvent = | |
| 883 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
| 884 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
| 885 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | |
| 886 | |
| 887 var capsSetEvent = | |
| 888 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 889 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); | |
| 890 this.nativeLayer_.dispatchEvent(capsSetEvent); | |
| 891 | 814 |
| 892 var previewGenerator = mock(print_preview.PreviewGenerator); | 815 var previewGenerator = mock(print_preview.PreviewGenerator); |
| 893 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy(); | 816 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy(); |
| 894 previewGenerator.expects(exactly(6)).requestPreview(); | 817 previewGenerator.expects(exactly(6)).requestPreview(); |
| 895 | 818 |
| 896 var barDestination; | 819 var barDestination; |
| 897 var destinations = printPreview.destinationStore_.destinations(); | 820 var destinations = printPreview.destinationStore_.destinations(); |
| 898 for (var destination, i = 0; destination = destinations[i]; i++) { | 821 for (var destination, i = 0; destination = destinations[i]; i++) { |
| 899 if (destination.id == 'BarDevice') { | 822 if (destination.id == 'BarDevice') { |
| 900 barDestination = destination; | 823 barDestination = destination; |
| 901 break; | 824 break; |
| 902 } | 825 } |
| 903 } | 826 } |
| 904 | 827 |
| 905 printPreview.destinationStore_.selectDestination(barDestination); | 828 printPreview.destinationStore_.selectDestination(barDestination); |
| 906 | 829 |
| 907 var capsSetEvent = | 830 var device = getCddTemplate("BarDevice"); |
| 908 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 831 device.capabilities.printer.color = { |
| 909 capsSetEvent.settingsInfo = getCddTemplate("BarDevice"); | |
| 910 capsSetEvent.settingsInfo.capabilities.printer.color = { | |
| 911 "option": [ | 832 "option": [ |
| 912 {"is_default": true, "type": "STANDARD_MONOCHROME"} | 833 {"is_default": true, "type": "STANDARD_MONOCHROME"} |
| 913 ] | 834 ] |
| 914 }; | 835 }; |
| 915 this.nativeLayer_.dispatchEvent(capsSetEvent); | 836 this.setCapabilities(device); |
| 837 |
| 838 this.waitForAnimationToEnd('more-settings'); |
| 916 }); | 839 }); |
| 917 | 840 |
| 918 // Test that error message is displayed when plugin doesn't exist. | 841 // Test that error message is displayed when plugin doesn't exist. |
| 919 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() { | 842 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() { |
| 920 var previewAreaEl = $('preview-area'); | 843 var previewAreaEl = $('preview-area'); |
| 921 | 844 |
| 922 var loadingMessageEl = | 845 var loadingMessageEl = |
| 923 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0]; | 846 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0]; |
| 924 expectEquals(true, loadingMessageEl.hidden); | 847 expectEquals(true, loadingMessageEl.hidden); |
| 925 | 848 |
| 926 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( | 849 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( |
| 927 'preview-area-preview-failed-message')[0]; | 850 'preview-area-preview-failed-message')[0]; |
| 928 expectEquals(true, previewFailedMessageEl.hidden); | 851 expectEquals(true, previewFailedMessageEl.hidden); |
| 929 | 852 |
| 930 var printFailedMessageEl = | 853 var printFailedMessageEl = |
| 931 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0]; | 854 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0]; |
| 932 expectEquals(true, printFailedMessageEl.hidden); | 855 expectEquals(true, printFailedMessageEl.hidden); |
| 933 | 856 |
| 934 var customMessageEl = | 857 var customMessageEl = |
| 935 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; | 858 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; |
| 936 expectEquals(false, customMessageEl.hidden); | 859 expectEquals(false, customMessageEl.hidden); |
| 860 |
| 861 testDone(); |
| 937 }); | 862 }); |
| OLD | NEW |