| 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 = '../../../../../'; | 5 var ROOT_PATH = '../../../../../'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Test fixture for print preview WebUI testing. | 8 * Test fixture for print preview WebUI testing. |
| 9 * @constructor | 9 * @constructor |
| 10 * @extends {testing.Test} | 10 * @extends {testing.Test} |
| 11 */ | 11 */ |
| 12 function PrintPreviewWebUITest() { | 12 function PrintPreviewWebUITest() { |
| 13 testing.Test.call(this); | 13 testing.Test.call(this); |
| 14 this.printPreview_ = null; | 14 this.printPreview_ = null; |
| 15 this.nativeLayer_ = null; | 15 this.nativeLayer_ = null; |
| 16 this.initialSettings_ = null; | 16 this.initialSettings_ = null; |
| 17 this.localDestinationInfos_ = null; | 17 this.localDestinationInfos_ = null; |
| 18 this.previewArea_ = null; | 18 this.previewArea_ = null; |
| 19 } | 19 } |
| 20 | 20 |
| 21 /** | |
| 22 * Index of the "Save as PDF" printer. | |
| 23 * @type {number} | |
| 24 * @const | |
| 25 */ | |
| 26 PrintPreviewWebUITest.PDF_INDEX = 0; | |
| 27 | |
| 28 /** | |
| 29 * Index of the Foo printer. | |
| 30 * @type {number} | |
| 31 * @const | |
| 32 */ | |
| 33 PrintPreviewWebUITest.FOO_INDEX = 1; | |
| 34 | |
| 35 /** | |
| 36 * Index of the Bar printer. | |
| 37 * @type {number} | |
| 38 * @const | |
| 39 */ | |
| 40 PrintPreviewWebUITest.BAR_INDEX = 2; | |
| 41 | |
| 42 PrintPreviewWebUITest.prototype = { | 21 PrintPreviewWebUITest.prototype = { |
| 43 __proto__: testing.Test.prototype, | 22 __proto__: testing.Test.prototype, |
| 44 | 23 |
| 45 /** | 24 /** |
| 46 * Browse to the sample page, cause print preview & call preLoad(). | 25 * Browse to the sample page, cause print preview & call preLoad(). |
| 47 * @type {string} | 26 * @type {string} |
| 48 * @override | 27 * @override |
| 49 */ | 28 */ |
| 50 browsePrintPreload: 'print_preview/print_preview_hello_world_test.html', | 29 browsePrintPreload: 'print_preview/print_preview_hello_world_test.html', |
| 51 | 30 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 'FooDevice' /*systemDefaultDestinationId*/, | 220 'FooDevice' /*systemDefaultDestinationId*/, |
| 242 null /*serializedAppStateStr*/, | 221 null /*serializedAppStateStr*/, |
| 243 null /*serializedDefaultDestinationSelectionRulesStr*/); | 222 null /*serializedDefaultDestinationSelectionRulesStr*/); |
| 244 this.localDestinationInfos_ = [ | 223 this.localDestinationInfos_ = [ |
| 245 { printerName: 'FooName', deviceName: 'FooDevice' }, | 224 { printerName: 'FooName', deviceName: 'FooDevice' }, |
| 246 { printerName: 'BarName', deviceName: 'BarDevice' } | 225 { printerName: 'BarName', deviceName: 'BarDevice' } |
| 247 ]; | 226 ]; |
| 248 }, | 227 }, |
| 249 }; | 228 }; |
| 250 | 229 |
| 251 // Test some basic assumptions about the print preview WebUI. | |
| 252 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { | |
| 253 this.setInitialSettings(); | |
| 254 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
| 255 function() { | |
| 256 this.setLocalDestinations(); | |
| 257 var recentList = | |
| 258 $('destination-search').querySelector('.recent-list ul'); | |
| 259 var localList = | |
| 260 $('destination-search').querySelector('.local-list ul'); | |
| 261 assertNotEquals(null, recentList); | |
| 262 assertEquals(1, recentList.childNodes.length); | |
| 263 assertEquals('FooName', | |
| 264 recentList.childNodes.item(0).querySelector( | |
| 265 '.destination-list-item-name').textContent); | |
| 266 assertNotEquals(null, localList); | |
| 267 assertEquals(3, localList.childNodes.length); | |
| 268 assertEquals('Save as PDF', | |
| 269 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). | |
| 270 querySelector('.destination-list-item-name').textContent); | |
| 271 assertEquals('FooName', | |
| 272 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). | |
| 273 querySelector('.destination-list-item-name').textContent); | |
| 274 assertEquals('BarName', | |
| 275 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). | |
| 276 querySelector('.destination-list-item-name').textContent); | |
| 277 testDone(); | |
| 278 }.bind(this)); | |
| 279 }); | |
| 280 | |
| 281 // Test that the printer list is structured correctly after calling | |
| 282 // addCloudPrinters with an empty list. | |
| 283 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { | |
| 284 this.setInitialSettings(); | |
| 285 | |
| 286 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
| 287 function() { | |
| 288 this.setLocalDestinations(); | |
| 289 | |
| 290 var cloudPrintEnableEvent = | |
| 291 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); | |
| 292 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; | |
| 293 this.nativeLayer_.getEventTarget().dispatchEvent( | |
| 294 cloudPrintEnableEvent); | |
| 295 | |
| 296 var searchDoneEvent = | |
| 297 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE); | |
| 298 searchDoneEvent.printers = []; | |
| 299 searchDoneEvent.isRecent = true; | |
| 300 searchDoneEvent.email = 'foo@chromium.org'; | |
| 301 this.printPreview_.cloudPrintInterface_.dispatchEvent(searchDoneEvent); | |
| 302 | |
| 303 var recentList = | |
| 304 $('destination-search').querySelector('.recent-list ul'); | |
| 305 var localList = | |
| 306 $('destination-search').querySelector('.local-list ul'); | |
| 307 var cloudList = | |
| 308 $('destination-search').querySelector('.cloud-list ul'); | |
| 309 | |
| 310 assertNotEquals(null, recentList); | |
| 311 assertEquals(1, recentList.childNodes.length); | |
| 312 assertEquals('FooName', | |
| 313 recentList.childNodes.item(0). | |
| 314 querySelector('.destination-list-item-name'). | |
| 315 textContent); | |
| 316 | |
| 317 assertNotEquals(null, localList); | |
| 318 assertEquals(3, localList.childNodes.length); | |
| 319 assertEquals('Save as PDF', | |
| 320 localList.childNodes.item( | |
| 321 PrintPreviewWebUITest.PDF_INDEX). | |
| 322 querySelector('.destination-list-item-name'). | |
| 323 textContent); | |
| 324 assertEquals('FooName', | |
| 325 localList.childNodes. | |
| 326 item(PrintPreviewWebUITest.FOO_INDEX). | |
| 327 querySelector('.destination-list-item-name'). | |
| 328 textContent); | |
| 329 assertEquals('BarName', | |
| 330 localList.childNodes. | |
| 331 item(PrintPreviewWebUITest.BAR_INDEX). | |
| 332 querySelector('.destination-list-item-name'). | |
| 333 textContent); | |
| 334 | |
| 335 assertNotEquals(null, cloudList); | |
| 336 assertEquals(0, cloudList.childNodes.length); | |
| 337 | |
| 338 testDone(); | |
| 339 }.bind(this)); | |
| 340 }); | |
| 341 | 230 |
| 342 /** | 231 /** |
| 343 * Verify that |section| visibility matches |visible|. | 232 * Verify that |section| visibility matches |visible|. |
| 344 * @param {HTMLDivElement} section The section to check. | 233 * @param {HTMLDivElement} section The section to check. |
| 345 * @param {boolean} visible The expected state of visibility. | 234 * @param {boolean} visible The expected state of visibility. |
| 346 */ | 235 */ |
| 347 function checkSectionVisible(section, visible) { | 236 function checkSectionVisible(section, visible) { |
| 348 assertNotEquals(null, section); | 237 assertNotEquals(null, section); |
| 349 expectEquals( | 238 expectEquals( |
| 350 visible, section.classList.contains('visible'), 'section=' + section.id); | 239 visible, section.classList.contains('visible'), 'section=' + section.id); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 288 } |
| 400 }; | 289 }; |
| 401 } | 290 } |
| 402 | 291 |
| 403 function isPrintAsImageEnabled() { | 292 function isPrintAsImageEnabled() { |
| 404 // Should be enabled by default on non Windows/Mac | 293 // Should be enabled by default on non Windows/Mac |
| 405 return (!cr.isWindows && !cr.isMac && | 294 return (!cr.isWindows && !cr.isMac && |
| 406 loadTimeData.getBoolean('printPdfAsImageEnabled')); | 295 loadTimeData.getBoolean('printPdfAsImageEnabled')); |
| 407 } | 296 } |
| 408 | 297 |
| 409 // Test restore settings with one destination. | |
| 410 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreLocalDestination', | |
| 411 function() { | |
| 412 this.initialSettings_.serializedAppStateStr_ = | |
| 413 '{"version":2,"recentDestinations":[{"id":"ID", "origin":"local",' + | |
| 414 '"account":"", "capabilities":0, "name":"", "extensionId":"",' + | |
| 415 '"extensionName":""}]}'; | |
| 416 | |
| 417 this.setInitialSettings(); | |
| 418 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
| 419 function() { | |
| 420 testDone(); | |
| 421 }); | |
| 422 }); | |
| 423 | |
| 424 // Test with multiple destinations | |
| 425 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreMultipleDestinations', | |
| 426 function() { | |
| 427 var origin = cr.isChromeOS ? "chrome_os" : "local"; | |
| 428 | |
| 429 var appState = { | |
| 430 'version': 2, | |
| 431 'recentDestinations': [ | |
| 432 { | |
| 433 'id': 'ID1', | |
| 434 'origin': origin, | |
| 435 'account': '', | |
| 436 'capabilities': 0, | |
| 437 'name': '', | |
| 438 'extensionId': '', | |
| 439 'extensionName': '' | |
| 440 }, | |
| 441 { | |
| 442 'id': 'ID2', | |
| 443 'origin': origin, | |
| 444 'account': '', | |
| 445 'capabilities': 0, | |
| 446 'name': '', | |
| 447 'extensionId': '', | |
| 448 'extensionName': '' | |
| 449 }, | |
| 450 { | |
| 451 'id': 'ID3', | |
| 452 'origin': origin, | |
| 453 'account': '', | |
| 454 'capabilities': 0, | |
| 455 'name': '', | |
| 456 'extensionId': '', | |
| 457 'extensionName': '' | |
| 458 } | |
| 459 ] | |
| 460 }; | |
| 461 | |
| 462 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(appState); | |
| 463 this.setInitialSettings(); | |
| 464 | |
| 465 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
| 466 function() { | |
| 467 // Set capabilities for the three recently used destinations + 1 more | |
| 468 this.setCapabilities(getCddTemplate('ID1')); | |
| 469 this.setCapabilities(getCddTemplate('ID2')); | |
| 470 this.setCapabilities(getCddTemplate('ID3')); | |
| 471 this.setCapabilities(getCddTemplate('ID4')); | |
| 472 | |
| 473 // The most recently used destination should be the currently selected | |
| 474 // one. This is ID1. | |
| 475 assertEquals( | |
| 476 'ID1', this.printPreview_.destinationStore_.selectedDestination.id); | |
| 477 | |
| 478 // Look through the destinations. ID1, ID2, and ID3 should all be | |
| 479 // recent. | |
| 480 var destinations = this.printPreview_.destinationStore_.destinations_; | |
| 481 var idsFound = []; | |
| 482 | |
| 483 for (var i = 0; i < destinations.length; i++) { | |
| 484 if (!destinations[i]) | |
| 485 continue; | |
| 486 if (destinations[i].isRecent) | |
| 487 idsFound.push(destinations[i].id); | |
| 488 } | |
| 489 | |
| 490 // Make sure there were 3 recent destinations and that they are the | |
| 491 // correct IDs. | |
| 492 assertEquals(3, idsFound.length); | |
| 493 assertNotEquals(-1, idsFound.indexOf("ID1")); | |
| 494 assertNotEquals(-1, idsFound.indexOf("ID2")); | |
| 495 assertNotEquals(-1, idsFound.indexOf("ID3")); | |
| 496 | |
| 497 testDone(); | |
| 498 }.bind(this)); | |
| 499 }); | |
| 500 | |
| 501 TEST_F('PrintPreviewWebUITest', | |
| 502 'TestPrintPreviewDefaultDestinationSelectionRules', function() { | |
| 503 // It also makes sure these rules do override system default destination. | |
| 504 this.initialSettings_.serializedDefaultDestinationSelectionRulesStr_ = | |
| 505 '{"namePattern":".*Bar.*"}'; | |
| 506 this.setInitialSettings(); | |
| 507 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
| 508 function() { | |
| 509 this.setLocalDestinations(); | |
| 510 | |
| 511 assertEquals( | |
| 512 'BarDevice', | |
| 513 this.printPreview_.destinationStore_.selectedDestination.id); | |
| 514 | |
| 515 testDone(); | |
| 516 }.bind(this)); | |
| 517 }); | |
| 518 | 298 |
| 519 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode', | 299 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode', |
| 520 function() { | 300 function() { |
| 521 if (!cr.isChromeOS) | 301 if (!cr.isChromeOS) |
| 522 this.initialSettings_.isInAppKioskMode_ = true; | 302 this.initialSettings_.isInAppKioskMode_ = true; |
| 523 | 303 |
| 524 this.setInitialSettings(); | 304 this.setInitialSettings(); |
| 525 this.nativeLayer_.whenCalled('getInitialSettings').then( | 305 this.nativeLayer_.whenCalled('getInitialSettings').then( |
| 526 function() { | 306 function() { |
| 527 if (cr.isChromeOS) | 307 if (cr.isChromeOS) |
| (...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1601 expectFalse(this.generateDraft()); | 1381 expectFalse(this.generateDraft()); |
| 1602 | 1382 |
| 1603 // Change the margin type - need to regenerate again. | 1383 // Change the margin type - need to regenerate again. |
| 1604 this.printPreview_.printTicketStore_.marginsType.updateValue( | 1384 this.printPreview_.printTicketStore_.marginsType.updateValue( |
| 1605 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); | 1385 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); |
| 1606 expectTrue(this.generateDraft()); | 1386 expectTrue(this.generateDraft()); |
| 1607 | 1387 |
| 1608 testDone(); | 1388 testDone(); |
| 1609 }.bind(this)); | 1389 }.bind(this)); |
| 1610 }); | 1390 }); |
| OLD | NEW |