Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: chrome/test/data/webui/print_preview/print_preview_tests.js

Issue 2931843003: Print Preview: Change getPrinterCapabilities to cr.sendWithPromise (Closed)
Patch Set: Address comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/webui/print_preview/print_preview_destination_search_test.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 cr.define('print_preview_test', function() { 5 cr.define('print_preview_test', function() {
6 /** 6 /**
7 * Index of the "Save as PDF" printer. 7 * Index of the "Save as PDF" printer.
8 * @type {number} 8 * @type {number}
9 * @const 9 * @const
10 */ 10 */
(...skipping 22 matching lines...) Expand all
33 /** 33 /**
34 * Initialize print preview with the initial settings currently stored in 34 * Initialize print preview with the initial settings currently stored in
35 * |initialSettings|. 35 * |initialSettings|.
36 */ 36 */
37 function setInitialSettings() { 37 function setInitialSettings() {
38 nativeLayer.setInitialSettings(initialSettings); 38 nativeLayer.setInitialSettings(initialSettings);
39 printPreview.initialize(); 39 printPreview.initialize();
40 } 40 }
41 41
42 /** 42 /**
43 * Start loading the local destinations using the destination infos currently 43 * Sets settings and destinations and local destination that is the system
44 * stored in |localDestinationInfos|. 44 * default.
45 * @param {print_preview.PrinterCapabilitiesResponse=} opt_device The
46 * response to use for printer capabilities when the printer represented
47 * by |opt_device| is loaded. To avoid crashing when initialize() is
48 * called, |opt_device| should represent the printer that will be selected
49 * when print preview is first opened, i.e. the system default
50 * destination, or the most recently used destination or destination
51 * selected by the rules string if these parameters are defined in
52 * initialSettings.serializedAppStateStr_.
53 * If |opt_device| is not provided, a default device with ID 'FooDevice'
54 * will be used.
55 * @return {!Promise<print_preview.PrinterCapabilitiesResponse>} a
56 * promise that will resolve when getPrinterCapabilities has been
57 * called for the device (either default or provided).
45 */ 58 */
46 function setLocalDestinations() { 59 function setupSettingsAndDestinationsWithCapabilities(opt_device) {
60 nativeLayer.setInitialSettings(initialSettings);
47 nativeLayer.setLocalDestinations(localDestinationInfos); 61 nativeLayer.setLocalDestinations(localDestinationInfos);
48 printPreview.destinationStore_.startLoadLocalDestinations(); 62 opt_device = opt_device || getCddTemplate('FooDevice', 'FooName');
49 } 63 nativeLayer.setLocalDestinationCapabilities(opt_device);
50 64
51 /** 65 printPreview.initialize();
52 * Initializes print preview with the initial settings currently stored in
53 * |initialSettings|, waits for the getInitialSettings promise to resolve,
54 * and loads local destinations using destination infos currently stored in
55 * |localDestinationInfos|.
56 * @return {!Promise<!Array<!print_preview.LocalDestinationInfo>>} a
57 * promise that will resolve when getPrinters has been resolved by
58 * the native layer stub.
59 */
60 function setupSettingsAndDestinations() {
61 setInitialSettings();
62 return nativeLayer.whenCalled('getInitialSettings').then(function() { 66 return nativeLayer.whenCalled('getInitialSettings').then(function() {
63 setLocalDestinations(); 67 printPreview.destinationStore_.startLoadLocalDestinations();
64 return nativeLayer.whenCalled('getPrinters'); 68 return Promise.all([
69 nativeLayer.whenCalled('getPrinters'),
70 nativeLayer.whenCalled('getPrinterCapabilities')
71 ]);
65 }); 72 });
66 } 73 }
67 74
68 /** 75 /**
69 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will
70 * happen in the same thread.
71 * @param {!Object} device The device whose capabilities should be dispatched.
72 */
73 function setCapabilities(device) {
74 var capsSetEvent =
75 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
76 capsSetEvent.settingsInfo = device;
77 nativeLayer.getEventTarget().dispatchEvent(capsSetEvent);
78 }
79
80 /**
81 * Verify that |section| visibility matches |visible|. 76 * Verify that |section| visibility matches |visible|.
82 * @param {HTMLDivElement} section The section to check. 77 * @param {HTMLDivElement} section The section to check.
83 * @param {boolean} visible The expected state of visibility. 78 * @param {boolean} visible The expected state of visibility.
84 */ 79 */
85 function checkSectionVisible(section, visible) { 80 function checkSectionVisible(section, visible) {
86 assertNotEquals(null, section); 81 assertNotEquals(null, section);
87 expectEquals( 82 expectEquals(
88 visible, 83 visible,
89 section.classList.contains('visible'), 'section=' + section.id); 84 section.classList.contains('visible'), 'section=' + section.id);
90 } 85 }
91 86
92 /** 87 /**
93 * @param {?HTMLElement} el 88 * @param {?HTMLElement} el
94 * @param {boolean} isDisplayed 89 * @param {boolean} isDisplayed
95 */ 90 */
96 function checkElementDisplayed(el, isDisplayed) { 91 function checkElementDisplayed(el, isDisplayed) {
97 assertNotEquals(null, el); 92 assertNotEquals(null, el);
98 expectEquals(isDisplayed, 93 expectEquals(isDisplayed,
99 !el.hidden, 94 !el.hidden,
100 'element="' + el.id + '" of class "' + el.classList + '"'); 95 'element="' + el.id + '" of class "' + el.classList + '"');
101 } 96 }
102 97
103 /** 98 /**
104 * @param {string} printerId 99 * @param {string} printerId
105 * @return {!Object} 100 * @param {string=} opt_printerName Defaults to an empty string.
101 * @return {!print_preview.PrinterCapabilitiesResponse}
106 */ 102 */
107 function getCddTemplate(printerId) { 103 function getCddTemplate(printerId, opt_printerName) {
108 return { 104 return {
109 printerId: printerId, 105 printerId: printerId,
106 printerName: opt_printerName || '',
110 capabilities: { 107 capabilities: {
111 version: '1.0', 108 version: '1.0',
112 printer: { 109 printer: {
113 supported_content_type: [{content_type: 'application/pdf'}], 110 supported_content_type: [{content_type: 'application/pdf'}],
114 collate: {}, 111 collate: {},
115 color: { 112 color: {
116 option: [ 113 option: [
117 {type: 'STANDARD_COLOR', is_default: true}, 114 {type: 'STANDARD_COLOR', is_default: true},
118 {type: 'STANDARD_MONOCHROME'} 115 {type: 'STANDARD_MONOCHROME'}
119 ] 116 ]
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 advancedOptionsSettingsButton.click(); 205 advancedOptionsSettingsButton.click();
209 } 206 }
210 207
211 /** 208 /**
212 * Repeated setup steps for the advanced settings tests. 209 * Repeated setup steps for the advanced settings tests.
213 * Sets capabilities, and verifies advanced options section is visible 210 * Sets capabilities, and verifies advanced options section is visible
214 * after expanding more settings. Then opens the advanced settings overlay 211 * after expanding more settings. Then opens the advanced settings overlay
215 * and verifies it is displayed. 212 * and verifies it is displayed.
216 */ 213 */
217 function startAdvancedSettingsTest(device) { 214 function startAdvancedSettingsTest(device) {
218 setCapabilities(device);
219 expandMoreSettings(); 215 expandMoreSettings();
220 216
221 // Check that the advanced options settings section is visible. 217 // Check that the advanced options settings section is visible.
222 checkSectionVisible($('advanced-options-settings'), true); 218 checkSectionVisible($('advanced-options-settings'), true);
223 219
224 // Open the advanced settings overlay. 220 // Open the advanced settings overlay.
225 openAdvancedSettings(); 221 openAdvancedSettings();
226 222
227 // Check advanced settings overlay is visible by checking that the close 223 // Check advanced settings overlay is visible by checking that the close
228 // button is displayed. 224 // button is displayed.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 ]; 274 ];
279 275
280 nativeLayer = new print_preview.NativeLayerStub(); 276 nativeLayer = new print_preview.NativeLayerStub();
281 print_preview.NativeLayer.setInstance(nativeLayer); 277 print_preview.NativeLayer.setInstance(nativeLayer);
282 printPreview = new print_preview.PrintPreview(); 278 printPreview = new print_preview.PrintPreview();
283 previewArea = printPreview.getPreviewArea(); 279 previewArea = printPreview.getPreviewArea();
284 }); 280 });
285 281
286 // Test some basic assumptions about the print preview WebUI. 282 // Test some basic assumptions about the print preview WebUI.
287 test('PrinterList', function() { 283 test('PrinterList', function() {
288 return setupSettingsAndDestinations().then(function() { 284 return setupSettingsAndDestinationsWithCapabilities().then(function() {
289 var recentList = 285 var recentList =
290 $('destination-search').querySelector('.recent-list ul'); 286 $('destination-search').querySelector('.recent-list ul');
291 var localList = 287 var localList =
292 $('destination-search').querySelector('.local-list ul'); 288 $('destination-search').querySelector('.local-list ul');
293 assertNotEquals(null, recentList); 289 assertNotEquals(null, recentList);
294 assertEquals(1, recentList.childNodes.length); 290 assertEquals(1, recentList.childNodes.length);
295 assertEquals('FooName', 291 assertEquals('FooName',
296 recentList.childNodes.item(0).querySelector( 292 recentList.childNodes.item(0).querySelector(
297 '.destination-list-item-name').textContent); 293 '.destination-list-item-name').textContent);
298 assertNotEquals(null, localList); 294 assertNotEquals(null, localList);
299 assertEquals(3, localList.childNodes.length); 295 assertEquals(3, localList.childNodes.length);
300 assertEquals( 296 assertEquals(
301 'Save as PDF', 297 'Save as PDF',
302 localList.childNodes.item(PDF_INDEX). 298 localList.childNodes.item(PDF_INDEX).
303 querySelector('.destination-list-item-name').textContent); 299 querySelector('.destination-list-item-name').textContent);
304 assertEquals( 300 assertEquals(
305 'FooName', 301 'FooName',
306 localList.childNodes.item(FOO_INDEX). 302 localList.childNodes.item(FOO_INDEX).
307 querySelector('.destination-list-item-name').textContent); 303 querySelector('.destination-list-item-name').textContent);
308 assertEquals( 304 assertEquals(
309 'BarName', 305 'BarName',
310 localList.childNodes.item(BAR_INDEX). 306 localList.childNodes.item(BAR_INDEX).
311 querySelector('.destination-list-item-name').textContent); 307 querySelector('.destination-list-item-name').textContent);
312 }); 308 });
313 }); 309 });
314 310
315 // Test that the printer list is structured correctly after calling 311 // Test that the printer list is structured correctly after calling
316 // addCloudPrinters with an empty list. 312 // addCloudPrinters with an empty list.
317 test('PrinterListCloudEmpty', function() { 313 test('PrinterListCloudEmpty', function() {
318 return setupSettingsAndDestinations().then(function() { 314 return setupSettingsAndDestinationsWithCapabilities().then(function() {
319 var cloudPrintEnableEvent = new Event( 315 var cloudPrintEnableEvent = new Event(
320 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); 316 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE);
321 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; 317 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url';
322 nativeLayer.getEventTarget().dispatchEvent( 318 nativeLayer.getEventTarget().dispatchEvent(
323 cloudPrintEnableEvent); 319 cloudPrintEnableEvent);
324 320
325 var searchDoneEvent = 321 var searchDoneEvent =
326 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE); 322 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE);
327 searchDoneEvent.printers = []; 323 searchDoneEvent.printers = [];
328 searchDoneEvent.isRecent = true; 324 searchDoneEvent.isRecent = true;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 id: 'ID', 370 id: 'ID',
375 origin: cr.isChromeOS ? 'chrome_os' : 'local', 371 origin: cr.isChromeOS ? 'chrome_os' : 'local',
376 account: '', 372 account: '',
377 capabilities: 0, 373 capabilities: 0,
378 name: '', 374 name: '',
379 extensionId: '', 375 extensionId: '',
380 extensionName: '', 376 extensionName: '',
381 }, 377 },
382 ], 378 ],
383 }); 379 });
384 380 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID'));
385 setInitialSettings(); 381 setInitialSettings();
386 return nativeLayer.whenCalled('getInitialSettings'); 382 return nativeLayer.whenCalled('getInitialSettings');
387 }); 383 });
388 384
389 test('RestoreMultipleDestinations', function() { 385 test('RestoreMultipleDestinations', function() {
390 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; 386 var origin = cr.isChromeOS ? 'chrome_os' : 'local';
391 387
392 initialSettings.serializedAppStateStr_ = JSON.stringify({ 388 initialSettings.serializedAppStateStr_ = JSON.stringify({
393 version: 2, 389 version: 2,
394 recentDestinations: [ 390 recentDestinations: [
395 { 391 {
396 id: 'ID1', 392 id: 'ID1',
397 origin: origin, 393 origin: origin,
398 account: '', 394 account: '',
399 capabilities: 0, 395 capabilities: 0,
400 name: '', 396 name: 'One',
401 extensionId: '', 397 extensionId: '',
402 extensionName: '', 398 extensionName: '',
403 }, { 399 }, {
404 id: 'ID2', 400 id: 'ID2',
405 origin: origin, 401 origin: origin,
406 account: '', 402 account: '',
407 capabilities: 0, 403 capabilities: 0,
408 name: '', 404 name: 'Two',
409 extensionId: '', 405 extensionId: '',
410 extensionName: '', 406 extensionName: '',
411 }, { 407 }, {
412 id: 'ID3', 408 id: 'ID3',
413 origin: origin, 409 origin: origin,
414 account: '', 410 account: '',
415 capabilities: 0, 411 capabilities: 0,
416 name: '', 412 name: 'Three',
417 extensionId: '', 413 extensionId: '',
418 extensionName: '', 414 extensionName: '',
419 }, 415 },
420 ], 416 ],
421 }); 417 });
418 // Set all three of these destinations in the local destination infos
419 // (represents currently available printers), plus an extra destination.
420 localDestinationInfos = [
421 { printerName: 'One', deviceName: 'ID1' },
422 { printerName: 'Two', deviceName: 'ID2' },
423 { printerName: 'Three', deviceName: 'ID3' },
424 { printerName: 'Four', deviceName: 'ID4' }
425 ];
422 426
423 setInitialSettings(); 427 // Set up capabilities for ID1. This should be the device that should hav
428 // its capabilities fetched, since it is the most recent. If another
429 // device is selected the native layer will reject the callback.
430 var device = getCddTemplate('ID1', 'One');
424 431
425 return nativeLayer.whenCalled('getInitialSettings').then( 432 return setupSettingsAndDestinationsWithCapabilities(device).then(
426 function() { 433 function() {
427 // Set capabilities for the three recently used destinations + 1
428 // more.
429 setCapabilities(getCddTemplate('ID1'));
430 setCapabilities(getCddTemplate('ID2'));
431 setCapabilities(getCddTemplate('ID3'));
432 setCapabilities(getCddTemplate('ID4'));
433
434 // The most recently used destination should be the currently 434 // The most recently used destination should be the currently
435 // selected one. This is ID1. 435 // selected one. This is ID1.
436 assertEquals( 436 assertEquals(
437 'ID1', printPreview.destinationStore_.selectedDestination.id); 437 'ID1', printPreview.destinationStore_.selectedDestination.id);
438 438
439 // Look through the destinations. ID1, ID2, and ID3 should all be 439 // Look through the destinations. ID1, ID2, and ID3 should all be
440 // recent. 440 // recent.
441 var destinations = printPreview.destinationStore_.destinations_; 441 var destinations = printPreview.destinationStore_.destinations_;
442 var idsFound = []; 442 var idsFound = [];
443 443
(...skipping 10 matching lines...) Expand all
454 assertNotEquals(-1, idsFound.indexOf('ID1')); 454 assertNotEquals(-1, idsFound.indexOf('ID1'));
455 assertNotEquals(-1, idsFound.indexOf('ID2')); 455 assertNotEquals(-1, idsFound.indexOf('ID2'));
456 assertNotEquals(-1, idsFound.indexOf('ID3')); 456 assertNotEquals(-1, idsFound.indexOf('ID3'));
457 }); 457 });
458 }); 458 });
459 459
460 test('DefaultDestinationSelectionRules', function() { 460 test('DefaultDestinationSelectionRules', function() {
461 // It also makes sure these rules do override system default destination. 461 // It also makes sure these rules do override system default destination.
462 initialSettings.serializedDefaultDestinationSelectionRulesStr_ = 462 initialSettings.serializedDefaultDestinationSelectionRulesStr_ =
463 JSON.stringify({namePattern: '.*Bar.*'}); 463 JSON.stringify({namePattern: '.*Bar.*'});
464 // Set this early as the app state selection string will trigger a load 464 return setupSettingsAndDestinationsWithCapabilities(
465 // of local destinations on initialization. 465 getCddTemplate('BarDevice', 'BarName')).then(function() {
466 nativeLayer.setLocalDestinations(localDestinationInfos); 466 assertEquals('BarDevice',
467 setInitialSettings(); 467 printPreview.destinationStore_.selectedDestination.id);
468 return nativeLayer.whenCalled('getInitialSettings').then(function() { 468 });
469 return nativeLayer.whenCalled('getPrinters').then(function() {
470 assertEquals('BarDevice',
471 printPreview.destinationStore_.selectedDestination.id);
472 });
473 });
474 }); 469 });
475 470
476 test('SystemDialogLinkIsHiddenInAppKioskMode', function() { 471 test('SystemDialogLinkIsHiddenInAppKioskMode', function() {
477 if (!cr.isChromeOS) 472 if (!cr.isChromeOS)
478 initialSettings.isInAppKioskMode_ = true; 473 initialSettings.isInAppKioskMode_ = true;
479 474 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('FooDevice'));
480 setInitialSettings(); 475 setInitialSettings();
481 return nativeLayer.whenCalled('getInitialSettings').then( 476 return nativeLayer.whenCalled('getInitialSettings').then(
482 function() { 477 function() {
483 if (cr.isChromeOS) 478 if (cr.isChromeOS)
484 assertEquals(null, $('system-dialog-link')); 479 assertEquals(null, $('system-dialog-link'));
485 else 480 else
486 checkElementDisplayed($('system-dialog-link'), false); 481 checkElementDisplayed($('system-dialog-link'), false);
487 }); 482 });
488 }); 483 });
489 484
490 test('SectionsDisabled', function() { 485 test('SectionsDisabled', function() {
491 checkSectionVisible($('layout-settings'), false); 486 checkSectionVisible($('layout-settings'), false);
492 checkSectionVisible($('color-settings'), false); 487 checkSectionVisible($('color-settings'), false);
493 checkSectionVisible($('copies-settings'), false); 488 checkSectionVisible($('copies-settings'), false);
489 var device = getCddTemplate('FooDevice');
490 device.capabilities.printer.color = {
491 option: [{is_default: true, type: 'STANDARD_COLOR'}]
492 };
493 delete device.capabilities.printer.copies;
494 494
495 return setupSettingsAndDestinations().then(function() { 495 return setupSettingsAndDestinationsWithCapabilities(device)
496 var device = getCddTemplate('FooDevice'); 496 .then(function() {
497 device.capabilities.printer.color = { 497 checkSectionVisible($('layout-settings'), true);
498 option: [{is_default: true, type: 'STANDARD_COLOR'}] 498 checkSectionVisible($('color-settings'), false);
499 }; 499 checkSectionVisible($('copies-settings'), false);
500 delete device.capabilities.printer.copies;
501 setCapabilities(device);
502 500
503 checkSectionVisible($('layout-settings'), true); 501 return whenAnimationDone('other-options-collapsible');
504 checkSectionVisible($('color-settings'), false); 502 });
505 checkSectionVisible($('copies-settings'), false);
506
507 return whenAnimationDone('other-options-collapsible');
508 });
509 }); 503 });
510 504
511 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide 505 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide
512 // the fit to page option. 506 // the fit to page option.
513 test('PrintToPDFSelectedCapabilities', function() { 507 test('PrintToPDFSelectedCapabilities', function() {
514 // Add PDF printer. 508 // Setup initial settings
515 initialSettings.isDocumentModifiable_ = false; 509 initialSettings.isDocumentModifiable_ = false;
516 initialSettings.systemDefaultDestinationId_ = 'Save as PDF'; 510 initialSettings.systemDefaultDestinationId_ = 'Save as PDF';
517 setInitialSettings();
518 511
519 return nativeLayer.whenCalled('getInitialSettings').then(function() { 512 // Set PDF printer
520 var device = { 513 var device = {
521 printerId: 'Save as PDF', 514 printerId: 'Save as PDF',
522 capabilities: { 515 capabilities: {
523 version: '1.0', 516 version: '1.0',
524 printer: { 517 printer: {
525 page_orientation: { 518 page_orientation: {
526 option: [ 519 option: [
527 {type: 'AUTO', is_default: true}, 520 {type: 'AUTO', is_default: true},
528 {type: 'PORTRAIT'}, 521 {type: 'PORTRAIT'},
529 {type: 'LANDSCAPE'} 522 {type: 'LANDSCAPE'}
530 ] 523 ]
531 }, 524 },
532 color: { 525 color: {
533 option: [ 526 option: [
534 {type: 'STANDARD_COLOR', is_default: true} 527 {type: 'STANDARD_COLOR', is_default: true}
535 ] 528 ]
536 }, 529 },
537 media_size: { 530 media_size: {
538 option: [ 531 option: [
539 { name: 'NA_LETTER', 532 { name: 'NA_LETTER',
540 width_microns: 0, 533 width_microns: 0,
541 height_microns: 0, 534 height_microns: 0,
542 is_default: true 535 is_default: true
543 } 536 }
544 ] 537 ]
545 }
546 } 538 }
547 } 539 }
548 }; 540 }
549 setCapabilities(device); 541 };
542 nativeLayer.setLocalDestinationCapabilities(device);
543
544 setInitialSettings();
545 return nativeLayer.whenCalled('getInitialSettings').then(function() {
546 return nativeLayer.whenCalled('getPrinterCapabilities');
547 }).then(function() {
550 var otherOptions = $('other-options-settings'); 548 var otherOptions = $('other-options-settings');
551 // If rasterization is an option, other options should be visible. 549 // If rasterization is an option, other options should be visible.
552 // If not, there should be no available other options. 550 // If not, there should be no available other options.
553 checkSectionVisible(otherOptions, isPrintAsImageEnabled()); 551 checkSectionVisible(otherOptions, isPrintAsImageEnabled());
554 if (isPrintAsImageEnabled()) { 552 if (isPrintAsImageEnabled()) {
555 checkElementDisplayed( 553 checkElementDisplayed(
556 otherOptions.querySelector('#fit-to-page-container'), false); 554 otherOptions.querySelector('#fit-to-page-container'), false);
557 checkElementDisplayed( 555 checkElementDisplayed(
558 otherOptions.querySelector('#rasterize-container'), true); 556 otherOptions.querySelector('#rasterize-container'), true);
559 } 557 }
560 checkSectionVisible($('media-size-settings'), false); 558 checkSectionVisible($('media-size-settings'), false);
561 checkSectionVisible($('scaling-settings'), false); 559 checkSectionVisible($('scaling-settings'), false);
562 }); 560 });
563 }); 561 });
564 562
565 // When the source is 'HTML', we always hide the fit to page option and show 563 // When the source is 'HTML', we always hide the fit to page option and show
566 // media size option. 564 // media size option.
567 test('SourceIsHTMLCapabilities', function() { 565 test('SourceIsHTMLCapabilities', function() {
568 return setupSettingsAndDestinations().then(function() { 566 return setupSettingsAndDestinationsWithCapabilities().then(function() {
569 setCapabilities(getCddTemplate('FooDevice'));
570
571 var otherOptions = $('other-options-settings'); 567 var otherOptions = $('other-options-settings');
572 var fitToPage = otherOptions.querySelector('#fit-to-page-container'); 568 var fitToPage = otherOptions.querySelector('#fit-to-page-container');
573 var rasterize; 569 var rasterize;
574 if (isPrintAsImageEnabled()) 570 if (isPrintAsImageEnabled())
575 rasterize = otherOptions.querySelector('#rasterize-container'); 571 rasterize = otherOptions.querySelector('#rasterize-container');
576 var mediaSize = $('media-size-settings'); 572 var mediaSize = $('media-size-settings');
577 var scalingSettings = $('scaling-settings'); 573 var scalingSettings = $('scaling-settings');
578 574
579 // Check that options are collapsed (section is visible, because 575 // Check that options are collapsed (section is visible, because
580 // duplex is available). 576 // duplex is available).
(...skipping 13 matching lines...) Expand all
594 checkSectionVisible(scalingSettings, true); 590 checkSectionVisible(scalingSettings, true);
595 591
596 return whenAnimationDone('more-settings'); 592 return whenAnimationDone('more-settings');
597 }); 593 });
598 }); 594 });
599 595
600 // When the source is 'PDF', depending on the selected destination printer, 596 // When the source is 'PDF', depending on the selected destination printer,
601 // we show/hide the fit to page option and hide media size selection. 597 // we show/hide the fit to page option and hide media size selection.
602 test('SourceIsPDFCapabilities', function() { 598 test('SourceIsPDFCapabilities', function() {
603 initialSettings.isDocumentModifiable_ = false; 599 initialSettings.isDocumentModifiable_ = false;
604 return setupSettingsAndDestinations().then(function() { 600 return setupSettingsAndDestinationsWithCapabilities().then(function() {
605 setCapabilities(getCddTemplate('FooDevice'));
606
607 var otherOptions = $('other-options-settings'); 601 var otherOptions = $('other-options-settings');
608 var scalingSettings = $('scaling-settings'); 602 var scalingSettings = $('scaling-settings');
609 var fitToPageContainer = 603 var fitToPageContainer =
610 otherOptions.querySelector('#fit-to-page-container'); 604 otherOptions.querySelector('#fit-to-page-container');
611 var rasterizeContainer; 605 var rasterizeContainer;
612 if (isPrintAsImageEnabled()) { 606 if (isPrintAsImageEnabled()) {
613 rasterizeContainer = 607 rasterizeContainer =
614 otherOptions.querySelector('#rasterize-container'); 608 otherOptions.querySelector('#rasterize-container');
615 } 609 }
616 610
(...skipping 13 matching lines...) Expand all
630 checkSectionVisible(scalingSettings, true); 624 checkSectionVisible(scalingSettings, true);
631 625
632 return whenAnimationDone('other-options-collapsible'); 626 return whenAnimationDone('other-options-collapsible');
633 }); 627 });
634 }); 628 });
635 629
636 // When the source is 'PDF', depending on the selected destination printer, 630 // When the source is 'PDF', depending on the selected destination printer,
637 // we show/hide the fit to page option and hide media size selection. 631 // we show/hide the fit to page option and hide media size selection.
638 test('ScalingUnchecksFitToPage', function() { 632 test('ScalingUnchecksFitToPage', function() {
639 initialSettings.isDocumentModifiable_ = false; 633 initialSettings.isDocumentModifiable_ = false;
640 return setupSettingsAndDestinations().then(function() { 634 return setupSettingsAndDestinationsWithCapabilities().then(function() {
641 setCapabilities(getCddTemplate('FooDevice'));
642
643 var otherOptions = $('other-options-settings'); 635 var otherOptions = $('other-options-settings');
644 var scalingSettings = $('scaling-settings'); 636 var scalingSettings = $('scaling-settings');
645 637
646 checkSectionVisible(otherOptions, true); 638 checkSectionVisible(otherOptions, true);
647 var fitToPageContainer = 639 var fitToPageContainer =
648 otherOptions.querySelector('#fit-to-page-container'); 640 otherOptions.querySelector('#fit-to-page-container');
649 checkElementDisplayed(fitToPageContainer, true); 641 checkElementDisplayed(fitToPageContainer, true);
650 expectTrue( 642 expectTrue(
651 fitToPageContainer.querySelector('.checkbox').checked); 643 fitToPageContainer.querySelector('.checkbox').checked);
652 expandMoreSettings(); 644 expandMoreSettings();
(...skipping 15 matching lines...) Expand all
668 fitToPageContainer.querySelector('.checkbox').checked); 660 fitToPageContainer.querySelector('.checkbox').checked);
669 661
670 return whenAnimationDone('other-options-collapsible'); 662 return whenAnimationDone('other-options-collapsible');
671 }); 663 });
672 }); 664 });
673 665
674 // When the number of copies print preset is set for source 'PDF', we update 666 // When the number of copies print preset is set for source 'PDF', we update
675 // the copies value if capability is supported by printer. 667 // the copies value if capability is supported by printer.
676 test('CheckNumCopiesPrintPreset', function() { 668 test('CheckNumCopiesPrintPreset', function() {
677 initialSettings.isDocumentModifiable_ = false; 669 initialSettings.isDocumentModifiable_ = false;
678 return setupSettingsAndDestinations().then(function() { 670 return setupSettingsAndDestinationsWithCapabilities().then(function() {
679 setCapabilities(getCddTemplate('FooDevice'));
680
681 // Indicate that the number of copies print preset is set for source 671 // Indicate that the number of copies print preset is set for source
682 // PDF. 672 // PDF.
683 var printPresetOptions = { 673 var printPresetOptions = {
684 disableScaling: true, 674 disableScaling: true,
685 copies: 2 675 copies: 2
686 }; 676 };
687 var printPresetOptionsEvent = new Event( 677 var printPresetOptionsEvent = new Event(
688 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); 678 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
689 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; 679 printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
690 nativeLayer.getEventTarget(). 680 nativeLayer.getEventTarget().
691 dispatchEvent(printPresetOptionsEvent); 681 dispatchEvent(printPresetOptionsEvent);
692 682
693 checkSectionVisible($('copies-settings'), true); 683 checkSectionVisible($('copies-settings'), true);
694 expectEquals( 684 expectEquals(
695 printPresetOptions.copies, 685 printPresetOptions.copies,
696 parseInt($('copies-settings'). 686 parseInt($('copies-settings').
697 querySelector('.user-value').value)); 687 querySelector('.user-value').value));
698 688
699 return whenAnimationDone('other-options-collapsible'); 689 return whenAnimationDone('other-options-collapsible');
700 }); 690 });
701 }); 691 });
702 692
703 // When the duplex print preset is set for source 'PDF', we update the 693 // When the duplex print preset is set for source 'PDF', we update the
704 // duplex setting if capability is supported by printer. 694 // duplex setting if capability is supported by printer.
705 test('CheckDuplexPrintPreset', function() { 695 test('CheckDuplexPrintPreset', function() {
706 initialSettings.isDocumentModifiable_ = false; 696 initialSettings.isDocumentModifiable_ = false;
707 return setupSettingsAndDestinations().then(function() { 697 return setupSettingsAndDestinationsWithCapabilities().then(function() {
708 setCapabilities(getCddTemplate('FooDevice'));
709
710 // Indicate that the duplex print preset is set to 'long edge' for 698 // Indicate that the duplex print preset is set to 'long edge' for
711 // source PDF. 699 // source PDF.
712 var printPresetOptions = { 700 var printPresetOptions = {
713 duplex: 1 701 duplex: 1
714 }; 702 };
715 var printPresetOptionsEvent = new Event( 703 var printPresetOptionsEvent = new Event(
716 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); 704 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
717 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; 705 printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
718 nativeLayer.getEventTarget(). 706 nativeLayer.getEventTarget().
719 dispatchEvent(printPresetOptionsEvent); 707 dispatchEvent(printPresetOptionsEvent);
720 708
721 var otherOptions = $('other-options-settings'); 709 var otherOptions = $('other-options-settings');
722 checkSectionVisible(otherOptions, true); 710 checkSectionVisible(otherOptions, true);
723 var duplexContainer = 711 var duplexContainer =
724 otherOptions.querySelector('#duplex-container'); 712 otherOptions.querySelector('#duplex-container');
725 checkElementDisplayed(duplexContainer, true); 713 checkElementDisplayed(duplexContainer, true);
726 expectTrue(duplexContainer.querySelector('.checkbox').checked); 714 expectTrue(duplexContainer.querySelector('.checkbox').checked);
727 715
728 return whenAnimationDone('other-options-collapsible'); 716 return whenAnimationDone('other-options-collapsible');
729 }); 717 });
730 }); 718 });
731 719
732 // Make sure that custom margins controls are properly set up. 720 // Make sure that custom margins controls are properly set up.
733 test('CustomMarginsControlsCheck', function() { 721 test('CustomMarginsControlsCheck', function() {
734 return setupSettingsAndDestinations().then(function() { 722 return setupSettingsAndDestinationsWithCapabilities().then(function() {
735 setCapabilities(getCddTemplate('FooDevice'));
736
737 printPreview.printTicketStore_.marginsType.updateValue( 723 printPreview.printTicketStore_.marginsType.updateValue(
738 print_preview.ticket_items.MarginsTypeValue.CUSTOM); 724 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
739 725
740 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { 726 ['left', 'top', 'right', 'bottom'].forEach(function(margin) {
741 var control = 727 var control =
742 $('preview-area').querySelector('.margin-control-' + margin); 728 $('preview-area').querySelector('.margin-control-' + margin);
743 assertNotEquals(null, control); 729 assertNotEquals(null, control);
744 var input = control.querySelector('.margin-control-textbox'); 730 var input = control.querySelector('.margin-control-textbox');
745 assertTrue(input.hasAttribute('aria-label')); 731 assertTrue(input.hasAttribute('aria-label'));
746 assertNotEquals('undefined', input.getAttribute('aria-label')); 732 assertNotEquals('undefined', input.getAttribute('aria-label'));
747 }); 733 });
748 return whenAnimationDone('more-settings'); 734 return whenAnimationDone('more-settings');
749 }); 735 });
750 }); 736 });
751 737
752 // Page layout has zero margins. Hide header and footer option. 738 // Page layout has zero margins. Hide header and footer option.
753 test('PageLayoutHasNoMarginsHideHeaderFooter', function() { 739 test('PageLayoutHasNoMarginsHideHeaderFooter', function() {
754 return setupSettingsAndDestinations().then(function() { 740 return setupSettingsAndDestinationsWithCapabilities().then(function() {
755 setCapabilities(getCddTemplate('FooDevice'));
756
757 var otherOptions = $('other-options-settings'); 741 var otherOptions = $('other-options-settings');
758 var headerFooter = 742 var headerFooter =
759 otherOptions.querySelector('#header-footer-container'); 743 otherOptions.querySelector('#header-footer-container');
760 744
761 // Check that options are collapsed (section is visible, because 745 // Check that options are collapsed (section is visible, because
762 // duplex is available). 746 // duplex is available).
763 checkSectionVisible(otherOptions, true); 747 checkSectionVisible(otherOptions, true);
764 checkElementDisplayed(headerFooter, false); 748 checkElementDisplayed(headerFooter, false);
765 749
766 expandMoreSettings(); 750 expandMoreSettings();
767 751
768 checkElementDisplayed(headerFooter, true); 752 checkElementDisplayed(headerFooter, true);
769 753
770 printPreview.printTicketStore_.marginsType.updateValue( 754 printPreview.printTicketStore_.marginsType.updateValue(
771 print_preview.ticket_items.MarginsTypeValue.CUSTOM); 755 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
772 printPreview.printTicketStore_.customMargins.updateValue( 756 printPreview.printTicketStore_.customMargins.updateValue(
773 new print_preview.Margins(0, 0, 0, 0)); 757 new print_preview.Margins(0, 0, 0, 0));
774 758
775 checkElementDisplayed(headerFooter, false); 759 checkElementDisplayed(headerFooter, false);
776 760
777 return whenAnimationDone('more-settings'); 761 return whenAnimationDone('more-settings');
778 }); 762 });
779 }); 763 });
780 764
781 // Page layout has half-inch margins. Show header and footer option. 765 // Page layout has half-inch margins. Show header and footer option.
782 test('PageLayoutHasMarginsShowHeaderFooter', function() { 766 test('PageLayoutHasMarginsShowHeaderFooter', function() {
783 return setupSettingsAndDestinations().then(function() { 767 return setupSettingsAndDestinationsWithCapabilities().then(function() {
784 setCapabilities(getCddTemplate('FooDevice'));
785
786 var otherOptions = $('other-options-settings'); 768 var otherOptions = $('other-options-settings');
787 var headerFooter = 769 var headerFooter =
788 otherOptions.querySelector('#header-footer-container'); 770 otherOptions.querySelector('#header-footer-container');
789 771
790 // Check that options are collapsed (section is visible, because 772 // Check that options are collapsed (section is visible, because
791 // duplex is available). 773 // duplex is available).
792 checkSectionVisible(otherOptions, true); 774 checkSectionVisible(otherOptions, true);
793 checkElementDisplayed(headerFooter, false); 775 checkElementDisplayed(headerFooter, false);
794 776
795 expandMoreSettings(); 777 expandMoreSettings();
796 778
797 checkElementDisplayed(headerFooter, true); 779 checkElementDisplayed(headerFooter, true);
798 780
799 printPreview.printTicketStore_.marginsType.updateValue( 781 printPreview.printTicketStore_.marginsType.updateValue(
800 print_preview.ticket_items.MarginsTypeValue.CUSTOM); 782 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
801 printPreview.printTicketStore_.customMargins.updateValue( 783 printPreview.printTicketStore_.customMargins.updateValue(
802 new print_preview.Margins(36, 36, 36, 36)); 784 new print_preview.Margins(36, 36, 36, 36));
803 785
804 checkElementDisplayed(headerFooter, true); 786 checkElementDisplayed(headerFooter, true);
805 787
806 return whenAnimationDone('more-settings'); 788 return whenAnimationDone('more-settings');
807 }); 789 });
808 }); 790 });
809 791
810 // Page layout has zero top and bottom margins. Hide header and footer 792 // Page layout has zero top and bottom margins. Hide header and footer
811 // option. 793 // option.
812 test('ZeroTopAndBottomMarginsHideHeaderFooter', function() { 794 test('ZeroTopAndBottomMarginsHideHeaderFooter', function() {
813 return setupSettingsAndDestinations().then(function() { 795 return setupSettingsAndDestinationsWithCapabilities().then(function() {
814 setCapabilities(getCddTemplate('FooDevice'));
815
816 var otherOptions = $('other-options-settings'); 796 var otherOptions = $('other-options-settings');
817 var headerFooter = 797 var headerFooter =
818 otherOptions.querySelector('#header-footer-container'); 798 otherOptions.querySelector('#header-footer-container');
819 799
820 // Check that options are collapsed (section is visible, because 800 // Check that options are collapsed (section is visible, because
821 // duplex is available). 801 // duplex is available).
822 checkSectionVisible(otherOptions, true); 802 checkSectionVisible(otherOptions, true);
823 checkElementDisplayed(headerFooter, false); 803 checkElementDisplayed(headerFooter, false);
824 804
825 expandMoreSettings(); 805 expandMoreSettings();
826 806
827 checkElementDisplayed(headerFooter, true); 807 checkElementDisplayed(headerFooter, true);
828 808
829 printPreview.printTicketStore_.marginsType.updateValue( 809 printPreview.printTicketStore_.marginsType.updateValue(
830 print_preview.ticket_items.MarginsTypeValue.CUSTOM); 810 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
831 printPreview.printTicketStore_.customMargins.updateValue( 811 printPreview.printTicketStore_.customMargins.updateValue(
832 new print_preview.Margins(0, 36, 0, 36)); 812 new print_preview.Margins(0, 36, 0, 36));
833 813
834 checkElementDisplayed(headerFooter, false); 814 checkElementDisplayed(headerFooter, false);
835 815
836 return whenAnimationDone('more-settings'); 816 return whenAnimationDone('more-settings');
837 }); 817 });
838 }); 818 });
839 819
840 // Page layout has zero top and half-inch bottom margin. Show header and 820 // Page layout has zero top and half-inch bottom margin. Show header and
841 // footer option. 821 // footer option.
842 test('ZeroTopAndNonZeroBottomMarginShowHeaderFooter', function() { 822 test('ZeroTopAndNonZeroBottomMarginShowHeaderFooter', function() {
843 return setupSettingsAndDestinations().then(function() { 823 return setupSettingsAndDestinationsWithCapabilities().then(function() {
844 setCapabilities(getCddTemplate('FooDevice'));
845
846 var otherOptions = $('other-options-settings'); 824 var otherOptions = $('other-options-settings');
847 var headerFooter = 825 var headerFooter =
848 otherOptions.querySelector('#header-footer-container'); 826 otherOptions.querySelector('#header-footer-container');
849 827
850 // Check that options are collapsed (section is visible, because 828 // Check that options are collapsed (section is visible, because
851 // duplex is available). 829 // duplex is available).
852 checkSectionVisible(otherOptions, true); 830 checkSectionVisible(otherOptions, true);
853 checkElementDisplayed(headerFooter, false); 831 checkElementDisplayed(headerFooter, false);
854 832
855 expandMoreSettings(); 833 expandMoreSettings();
856 834
857 checkElementDisplayed(headerFooter, true); 835 checkElementDisplayed(headerFooter, true);
858 836
859 printPreview.printTicketStore_.marginsType.updateValue( 837 printPreview.printTicketStore_.marginsType.updateValue(
860 print_preview.ticket_items.MarginsTypeValue.CUSTOM); 838 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
861 printPreview.printTicketStore_.customMargins.updateValue( 839 printPreview.printTicketStore_.customMargins.updateValue(
862 new print_preview.Margins(0, 36, 36, 36)); 840 new print_preview.Margins(0, 36, 36, 36));
863 841
864 checkElementDisplayed(headerFooter, true); 842 checkElementDisplayed(headerFooter, true);
865 843
866 return whenAnimationDone('more-settings'); 844 return whenAnimationDone('more-settings');
867 }); 845 });
868 }); 846 });
869 847
870 // Check header footer availability with small (label) page size. 848 // Check header footer availability with small (label) page size.
871 test('SmallPaperSizeHeaderFooter', function() { 849 test('SmallPaperSizeHeaderFooter', function() {
872 return setupSettingsAndDestinations().then(function() { 850 var device = getCddTemplate('FooDevice');
873 var device = getCddTemplate('FooDevice'); 851 device.capabilities.printer.media_size = {
874 device.capabilities.printer.media_size = { 852 'option': [
875 'option': [ 853 {'name': 'SmallLabel', 'width_microns': 38100,
876 {'name': 'SmallLabel', 'width_microns': 38100, 854 'height_microns': 12700, 'is_default': false},
877 'height_microns': 12700, 'is_default': false}, 855 {'name': 'BigLabel', 'width_microns': 50800,
878 {'name': 'BigLabel', 'width_microns': 50800, 856 'height_microns': 76200, 'is_default': true}
879 'height_microns': 76200, 'is_default': true} 857 ]
880 ] 858 };
881 }; 859 return setupSettingsAndDestinationsWithCapabilities(device)
882 setCapabilities(device); 860 .then(function() {
883
884 var otherOptions = $('other-options-settings'); 861 var otherOptions = $('other-options-settings');
885 var headerFooter = 862 var headerFooter =
886 otherOptions.querySelector('#header-footer-container'); 863 otherOptions.querySelector('#header-footer-container');
887 864
888 // Check that options are collapsed (section is visible, because 865 // Check that options are collapsed (section is visible, because
889 // duplex is available). 866 // duplex is available).
890 checkSectionVisible(otherOptions, true); 867 checkSectionVisible(otherOptions, true);
891 checkElementDisplayed(headerFooter, false); 868 checkElementDisplayed(headerFooter, false);
892 869
893 expandMoreSettings(); 870 expandMoreSettings();
(...skipping 10 matching lines...) Expand all
904 // header/footer. 881 // header/footer.
905 printPreview.printTicketStore_.landscape.updateValue(true); 882 printPreview.printTicketStore_.landscape.updateValue(true);
906 checkElementDisplayed(headerFooter, true); 883 checkElementDisplayed(headerFooter, true);
907 884
908 return whenAnimationDone('more-settings'); 885 return whenAnimationDone('more-settings');
909 }); 886 });
910 }); 887 });
911 888
912 // Test that the color settings, one option, standard monochrome. 889 // Test that the color settings, one option, standard monochrome.
913 test('ColorSettingsMonochrome', function() { 890 test('ColorSettingsMonochrome', function() {
914 return setupSettingsAndDestinations().then(function() { 891 // Only one option, standard monochrome.
915 // Only one option, standard monochrome. 892 var device = getCddTemplate('FooDevice');
916 var device = getCddTemplate('FooDevice'); 893 device.capabilities.printer.color = {
917 device.capabilities.printer.color = { 894 'option': [
918 'option': [ 895 {'is_default': true, 'type': 'STANDARD_MONOCHROME'}
919 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} 896 ]
920 ] 897 };
921 };
922 setCapabilities(device);
923 898
899 return setupSettingsAndDestinationsWithCapabilities(device)
900 .then(function() {
924 checkSectionVisible($('color-settings'), false); 901 checkSectionVisible($('color-settings'), false);
925 902
926 return whenAnimationDone('more-settings'); 903 return whenAnimationDone('more-settings');
927 }); 904 });
928 }); 905 });
929 906
930 // Test that the color settings, one option, custom monochrome. 907 // Test that the color settings, one option, custom monochrome.
931 test('ColorSettingsCustomMonochrome', function() { 908 test('ColorSettingsCustomMonochrome', function() {
932 return setupSettingsAndDestinations().then(function() { 909 // Only one option, standard monochrome.
933 // Only one option, standard monochrome. 910 var device = getCddTemplate('FooDevice');
934 var device = getCddTemplate('FooDevice'); 911 device.capabilities.printer.color = {
935 device.capabilities.printer.color = { 912 'option': [
936 'option': [ 913 {'is_default': true, 'type': 'CUSTOM_MONOCHROME',
937 {'is_default': true, 'type': 'CUSTOM_MONOCHROME', 914 'vendor_id': '42'}
938 'vendor_id': '42'} 915 ]
939 ] 916 };
940 };
941 setCapabilities(device);
942 917
918 return setupSettingsAndDestinationsWithCapabilities(device)
919 .then(function() {
943 checkSectionVisible($('color-settings'), false); 920 checkSectionVisible($('color-settings'), false);
944 921
945 return whenAnimationDone('more-settings'); 922 return whenAnimationDone('more-settings');
946 }); 923 });
947 }); 924 });
948 925
949 // Test that the color settings, one option, standard color. 926 // Test that the color settings, one option, standard color.
950 test('ColorSettingsColor', function() { 927 test('ColorSettingsColor', function() {
951 return setupSettingsAndDestinations().then(function() { 928 var device = getCddTemplate('FooDevice');
952 var device = getCddTemplate('FooDevice'); 929 device.capabilities.printer.color = {
953 device.capabilities.printer.color = { 930 'option': [
954 'option': [ 931 {'is_default': true, 'type': 'STANDARD_COLOR'}
955 {'is_default': true, 'type': 'STANDARD_COLOR'} 932 ]
956 ] 933 };
957 };
958 setCapabilities(device);
959 934
935 return setupSettingsAndDestinationsWithCapabilities(device)
936 .then(function() {
960 checkSectionVisible($('color-settings'), false); 937 checkSectionVisible($('color-settings'), false);
961 938
962 return whenAnimationDone('more-settings'); 939 return whenAnimationDone('more-settings');
963 }); 940 });
964 }); 941 });
965 942
966 // Test that the color settings, one option, custom color. 943 // Test that the color settings, one option, custom color.
967 test('ColorSettingsCustomColor', function() { 944 test('ColorSettingsCustomColor', function() {
968 return setupSettingsAndDestinations().then(function() { 945 var device = getCddTemplate('FooDevice');
969 var device = getCddTemplate('FooDevice'); 946 device.capabilities.printer.color = {
970 device.capabilities.printer.color = { 947 'option': [
971 'option': [ 948 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '42'}
972 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '42'} 949 ]
973 ] 950 };
974 }; 951 return setupSettingsAndDestinationsWithCapabilities(device)
975 setCapabilities(device); 952 .then(function() {
976
977 checkSectionVisible($('color-settings'), false); 953 checkSectionVisible($('color-settings'), false);
978 954
979 return whenAnimationDone('more-settings'); 955 return whenAnimationDone('more-settings');
980 }); 956 });
981 }); 957 });
982 958
983 // Test that the color settings, two options, both standard, defaults to 959 // Test that the color settings, two options, both standard, defaults to
984 // color. 960 // color.
985 test('ColorSettingsBothStandardDefaultColor', function() { 961 test('ColorSettingsBothStandardDefaultColor', function() {
986 return setupSettingsAndDestinations().then(function() { 962 var device = getCddTemplate('FooDevice');
987 var device = getCddTemplate('FooDevice'); 963 device.capabilities.printer.color = {
988 device.capabilities.printer.color = { 964 'option': [
989 'option': [ 965 {'type': 'STANDARD_MONOCHROME'},
990 {'type': 'STANDARD_MONOCHROME'}, 966 {'is_default': true, 'type': 'STANDARD_COLOR'}
991 {'is_default': true, 'type': 'STANDARD_COLOR'} 967 ]
992 ] 968 };
993 }; 969 return setupSettingsAndDestinationsWithCapabilities(device)
994 setCapabilities(device); 970 .then(function() {
995
996 checkSectionVisible($('color-settings'), true); 971 checkSectionVisible($('color-settings'), true);
997 expectEquals( 972 expectEquals(
998 'color', 973 'color',
999 $('color-settings').querySelector( 974 $('color-settings').querySelector(
1000 '.color-settings-select').value); 975 '.color-settings-select').value);
1001 976
1002 return whenAnimationDone('more-settings'); 977 return whenAnimationDone('more-settings');
1003 }); 978 });
1004 }); 979 });
1005 980
1006 // Test that the color settings, two options, both standard, defaults to 981 // Test that the color settings, two options, both standard, defaults to
1007 // monochrome. 982 // monochrome.
1008 test('ColorSettingsBothStandardDefaultMonochrome', function() { 983 test('ColorSettingsBothStandardDefaultMonochrome', function() {
1009 return setupSettingsAndDestinations().then(function() { 984 var device = getCddTemplate('FooDevice');
1010 var device = getCddTemplate('FooDevice'); 985 device.capabilities.printer.color = {
1011 device.capabilities.printer.color = { 986 'option': [
1012 'option': [ 987 {'is_default': true, 'type': 'STANDARD_MONOCHROME'},
1013 {'is_default': true, 'type': 'STANDARD_MONOCHROME'}, 988 {'type': 'STANDARD_COLOR'}
1014 {'type': 'STANDARD_COLOR'} 989 ]
1015 ] 990 };
1016 }; 991 return setupSettingsAndDestinationsWithCapabilities(device)
1017 setCapabilities(device); 992 .then(function() {
1018
1019 checkSectionVisible($('color-settings'), true); 993 checkSectionVisible($('color-settings'), true);
1020 expectEquals( 994 expectEquals(
1021 'bw', 995 'bw',
1022 $('color-settings').querySelector( 996 $('color-settings').querySelector(
1023 '.color-settings-select').value); 997 '.color-settings-select').value);
1024 998
1025 return whenAnimationDone('more-settings'); 999 return whenAnimationDone('more-settings');
1026 }); 1000 });
1027 }); 1001 });
1028 1002
1029 // Test that the color settings, two options, both custom, defaults to 1003 // Test that the color settings, two options, both custom, defaults to
1030 // color. 1004 // color.
1031 test('ColorSettingsBothCustomDefaultColor', function() { 1005 test('ColorSettingsBothCustomDefaultColor', function() {
1032 return setupSettingsAndDestinations().then(function() { 1006 var device = getCddTemplate('FooDevice');
1033 var device = getCddTemplate('FooDevice'); 1007 device.capabilities.printer.color = {
1034 device.capabilities.printer.color = { 1008 'option': [
1035 'option': [ 1009 {'type': 'CUSTOM_MONOCHROME', 'vendor_id': '42'},
1036 {'type': 'CUSTOM_MONOCHROME', 'vendor_id': '42'}, 1010 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '43'}
1037 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '43'} 1011 ]
1038 ] 1012 };
1039 }; 1013 return setupSettingsAndDestinationsWithCapabilities(device)
1040 setCapabilities(device); 1014 .then(function() {
1041
1042 checkSectionVisible($('color-settings'), true); 1015 checkSectionVisible($('color-settings'), true);
1043 expectEquals( 1016 expectEquals(
1044 'color', 1017 'color',
1045 $('color-settings').querySelector( 1018 $('color-settings').querySelector(
1046 '.color-settings-select').value); 1019 '.color-settings-select').value);
1047 1020
1048 return whenAnimationDone('more-settings'); 1021 return whenAnimationDone('more-settings');
1049 }); 1022 });
1050 }); 1023 });
1051 1024
1052 // Test to verify that duplex settings are set according to the printer 1025 // Test to verify that duplex settings are set according to the printer
1053 // capabilities. 1026 // capabilities.
1054 test('DuplexSettingsTrue', function() { 1027 test('DuplexSettingsTrue', function() {
1055 return setupSettingsAndDestinations().then(function() { 1028 return setupSettingsAndDestinationsWithCapabilities().then(function() {
1056 setCapabilities(getCddTemplate('FooDevice'));
1057
1058 var otherOptions = $('other-options-settings'); 1029 var otherOptions = $('other-options-settings');
1059 checkSectionVisible(otherOptions, true); 1030 checkSectionVisible(otherOptions, true);
1060 duplexContainer = otherOptions.querySelector('#duplex-container'); 1031 duplexContainer = otherOptions.querySelector('#duplex-container');
1061 expectFalse(duplexContainer.hidden); 1032 expectFalse(duplexContainer.hidden);
1062 expectFalse(duplexContainer.querySelector('.checkbox').checked); 1033 expectFalse(duplexContainer.querySelector('.checkbox').checked);
1063 1034
1064 return whenAnimationDone('more-settings'); 1035 return whenAnimationDone('more-settings');
1065 }); 1036 });
1066 }); 1037 });
1067 1038
1068 // Test to verify that duplex settings are set according to the printer 1039 // Test to verify that duplex settings are set according to the printer
1069 // capabilities. 1040 // capabilities.
1070 test('DuplexSettingsFalse', function() { 1041 test('DuplexSettingsFalse', function() {
1071 return setupSettingsAndDestinations().then(function() { 1042 var device = getCddTemplate('FooDevice');
1072 var device = getCddTemplate('FooDevice'); 1043 delete device.capabilities.printer.duplex;
1073 delete device.capabilities.printer.duplex; 1044 return setupSettingsAndDestinationsWithCapabilities(device)
1074 setCapabilities(device); 1045 .then(function() {
1075
1076 // Check that it is collapsed. 1046 // Check that it is collapsed.
1077 var otherOptions = $('other-options-settings'); 1047 var otherOptions = $('other-options-settings');
1078 checkSectionVisible(otherOptions, false); 1048 checkSectionVisible(otherOptions, false);
1079 1049
1080 expandMoreSettings(); 1050 expandMoreSettings();
1081 1051
1082 // Now it should be visible. 1052 // Now it should be visible.
1083 checkSectionVisible(otherOptions, true); 1053 checkSectionVisible(otherOptions, true);
1084 expectTrue(otherOptions.querySelector('#duplex-container').hidden); 1054 expectTrue(otherOptions.querySelector('#duplex-container').hidden);
1085 1055
1086 return whenAnimationDone('more-settings'); 1056 return whenAnimationDone('more-settings');
1087 }); 1057 });
1088 }); 1058 });
1089 1059
1090 // Test that changing the selected printer updates the preview. 1060 // Test that changing the selected printer updates the preview.
1091 test('PrinterChangeUpdatesPreview', function() { 1061 test('PrinterChangeUpdatesPreview', function() {
1092 return setupSettingsAndDestinations().then(function() { 1062 return setupSettingsAndDestinationsWithCapabilities().then(function() {
1093 setCapabilities(getCddTemplate('FooDevice'));
1094
1095 var previewGenerator = mock(print_preview.PreviewGenerator); 1063 var previewGenerator = mock(print_preview.PreviewGenerator);
1096 previewArea.previewGenerator_ = previewGenerator.proxy(); 1064 previewArea.previewGenerator_ = previewGenerator.proxy();
1097 1065
1098 // The number of settings that can change due to a change in the 1066 // The number of settings that can change due to a change in the
1099 // destination that will therefore dispatch ticket item change events. 1067 // destination that will therefore dispatch ticket item change events.
1100 previewGenerator.expects(exactly(9)).requestPreview(); 1068 previewGenerator.expects(exactly(9)).requestPreview();
1101 1069
1102 var barDestination = 1070 // Setup capabilities for BarDevice.
1103 printPreview.destinationStore_.destinations().find(
1104 function(d) {
1105 return d.id == 'BarDevice';
1106 });
1107
1108 printPreview.destinationStore_.selectDestination(barDestination);
1109
1110 var device = getCddTemplate('BarDevice'); 1071 var device = getCddTemplate('BarDevice');
1111 device.capabilities.printer.color = { 1072 device.capabilities.printer.color = {
1112 'option': [ 1073 'option': [
1113 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} 1074 {'is_default': true, 'type': 'STANDARD_MONOCHROME'}
1114 ] 1075 ]
1115 }; 1076 };
1116 setCapabilities(device); 1077 nativeLayer.setLocalDestinationCapabilities(device);
1117 1078
1079 // Select BarDevice
1080 var barDestination =
1081 printPreview.destinationStore_.destinations().find(
1082 function(d) {
1083 return d.id == 'BarDevice';
1084 });
1085 printPreview.destinationStore_.selectDestination(barDestination);
1086 return nativeLayer.whenCalled('getPrinterCapabilities', 'BarDevice');
1087 }).then(function(){
1118 return whenAnimationDone('more-settings'); 1088 return whenAnimationDone('more-settings');
1119 }); 1089 });
1120 }); 1090 });
1121 1091
1122 // Test that error message is displayed when plugin doesn't exist. 1092 // Test that error message is displayed when plugin doesn't exist.
1123 test('NoPDFPluginErrorMessage', function() { 1093 test('NoPDFPluginErrorMessage', function() {
1094 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('FooDevice'));
1124 setInitialSettings(); 1095 setInitialSettings();
1125 return nativeLayer.whenCalled('getInitialSettings').then(function() { 1096 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1126 var previewAreaEl = $('preview-area'); 1097 var previewAreaEl = $('preview-area');
1127 1098
1128 var loadingMessageEl = 1099 var loadingMessageEl =
1129 previewAreaEl. 1100 previewAreaEl.
1130 getElementsByClassName('preview-area-loading-message')[0]; 1101 getElementsByClassName('preview-area-loading-message')[0];
1131 expectTrue(loadingMessageEl.hidden); 1102 expectTrue(loadingMessageEl.hidden);
1132 1103
1133 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( 1104 var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
1134 'preview-area-preview-failed-message')[0]; 1105 'preview-area-preview-failed-message')[0];
1135 expectTrue(previewFailedMessageEl.hidden); 1106 expectTrue(previewFailedMessageEl.hidden);
1136 1107
1137 var printFailedMessageEl = 1108 var printFailedMessageEl =
1138 previewAreaEl. 1109 previewAreaEl.
1139 getElementsByClassName('preview-area-print-failed')[0]; 1110 getElementsByClassName('preview-area-print-failed')[0];
1140 expectTrue(printFailedMessageEl.hidden); 1111 expectTrue(printFailedMessageEl.hidden);
1141 1112
1142 var customMessageEl = 1113 var customMessageEl =
1143 previewAreaEl. 1114 previewAreaEl.
1144 getElementsByClassName('preview-area-custom-message')[0]; 1115 getElementsByClassName('preview-area-custom-message')[0];
1145 expectFalse(customMessageEl.hidden); 1116 expectFalse(customMessageEl.hidden);
1146 }); 1117 });
1147 }); 1118 });
1148 1119
1149 // Test custom localized paper names. 1120 // Test custom localized paper names.
1150 test('CustomPaperNames', function() { 1121 test('CustomPaperNames', function() {
1151 return setupSettingsAndDestinations().then(function() { 1122 var customLocalizedMediaName = 'Vendor defined localized media name';
1152 var customLocalizedMediaName = 'Vendor defined localized media name'; 1123 var customMediaName = 'Vendor defined media name';
1153 var customMediaName = 'Vendor defined media name';
1154 1124
1155 var device = getCddTemplate('FooDevice'); 1125 var device = getCddTemplate('FooDevice');
1156 device.capabilities.printer.media_size = { 1126 device.capabilities.printer.media_size = {
1157 option: [ 1127 option: [
1158 { name: 'CUSTOM', 1128 { name: 'CUSTOM',
1159 width_microns: 15900, 1129 width_microns: 15900,
1160 height_microns: 79400, 1130 height_microns: 79400,
1161 is_default: true, 1131 is_default: true,
1162 custom_display_name_localized: [ 1132 custom_display_name_localized: [
1163 { locale: navigator.language, 1133 { locale: navigator.language,
1164 value: customLocalizedMediaName 1134 value: customLocalizedMediaName
1165 } 1135 }
1166 ] 1136 ]
1167 }, 1137 },
1168 { name: 'CUSTOM', 1138 { name: 'CUSTOM',
1169 width_microns: 15900, 1139 width_microns: 15900,
1170 height_microns: 79400, 1140 height_microns: 79400,
1171 custom_display_name: customMediaName 1141 custom_display_name: customMediaName
1172 } 1142 }
1173 ] 1143 ]
1174 }; 1144 };
1175 1145
1176 setCapabilities(device); 1146 return setupSettingsAndDestinationsWithCapabilities(device)
1177 1147 .then(function() {
1178 expandMoreSettings(); 1148 expandMoreSettings();
1179 1149
1180 checkSectionVisible($('media-size-settings'), true); 1150 checkSectionVisible($('media-size-settings'), true);
1181 var mediaSelect = 1151 var mediaSelect =
1182 $('media-size-settings').querySelector('.settings-select'); 1152 $('media-size-settings').querySelector('.settings-select');
1183 // Check the default media item. 1153 // Check the default media item.
1184 expectEquals( 1154 expectEquals(
1185 customLocalizedMediaName, 1155 customLocalizedMediaName,
1186 mediaSelect.options[mediaSelect.selectedIndex].text); 1156 mediaSelect.options[mediaSelect.selectedIndex].text);
1187 // Check the other media item. 1157 // Check the other media item.
1188 expectEquals( 1158 expectEquals(
1189 customMediaName, 1159 customMediaName,
1190 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text); 1160 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text);
1191 1161
1192 return whenAnimationDone('more-settings'); 1162 return whenAnimationDone('more-settings');
1193 }); 1163 });
1194 }); 1164 });
1195 1165
1196 // Test advanced settings with 1 capability (should not display settings 1166 // Test advanced settings with 1 capability (should not display settings
1197 // search box). 1167 // search box).
1198 test('AdvancedSettings1Option', function() { 1168 test('AdvancedSettings1Option', function() {
1199 var device = getCddTemplateWithAdvancedSettings('FooDevice'); 1169 var device = getCddTemplateWithAdvancedSettings('FooDevice');
1200 return setupSettingsAndDestinations().then(function() { 1170 return setupSettingsAndDestinationsWithCapabilities(device)
1171 .then(function() {
1201 startAdvancedSettingsTest(device); 1172 startAdvancedSettingsTest(device);
1202 checkElementDisplayed($('advanced-settings'). 1173 checkElementDisplayed($('advanced-settings').
1203 querySelector('.search-box-area'), false); 1174 querySelector('.search-box-area'), false);
1204 1175
1205 return whenAnimationDone('more-settings'); 1176 return whenAnimationDone('more-settings');
1206 }); 1177 });
1207 }); 1178 });
1208 1179
1209 1180
1210 // Test advanced settings with 2 capabilities (should have settings search 1181 // Test advanced settings with 2 capabilities (should have settings search
1211 // box). 1182 // box).
1212 test('AdvancedSettings2Options', function() { 1183 test('AdvancedSettings2Options', function() {
1213 var device = getCddTemplateWithAdvancedSettings('FooDevice'); 1184 var device = getCddTemplateWithAdvancedSettings('FooDevice');
1214 // Add new capability. 1185 // Add new capability.
1215 device.capabilities.printer.vendor_capability.push({ 1186 device.capabilities.printer.vendor_capability.push({
1216 display_name: 'Paper Type', 1187 display_name: 'Paper Type',
1217 id: 'Paper Type', 1188 id: 'Paper Type',
1218 type: 'SELECT', 1189 type: 'SELECT',
1219 select_cap: { 1190 select_cap: {
1220 option: [ 1191 option: [
1221 {display_name: 'Standard', value: 0, is_default: true}, 1192 {display_name: 'Standard', value: 0, is_default: true},
1222 {display_name: 'Recycled', value: 1}, 1193 {display_name: 'Recycled', value: 1},
1223 {display_name: 'Special', value: 2} 1194 {display_name: 'Special', value: 2}
1224 ] 1195 ]
1225 } 1196 }
1226 }); 1197 });
1227 return setupSettingsAndDestinations().then(function() { 1198 return setupSettingsAndDestinationsWithCapabilities(device)
1199 .then(function() {
1228 startAdvancedSettingsTest(device); 1200 startAdvancedSettingsTest(device);
1229 1201
1230 checkElementDisplayed($('advanced-settings'). 1202 checkElementDisplayed($('advanced-settings').
1231 querySelector('.search-box-area'), true); 1203 querySelector('.search-box-area'), true);
1232 1204
1233 return whenAnimationDone('more-settings'); 1205 return whenAnimationDone('more-settings');
1234 }); 1206 });
1235 }); 1207 });
1236 1208
1237 // Test that initialization with saved destination only issues one call 1209 // Test that initialization with saved destination only issues one call
1238 // to startPreview. 1210 // to startPreview.
1239 test('InitIssuesOneRequest', function() { 1211 test('InitIssuesOneRequest', function() {
1240 // Load in a bunch of recent destinations with non null capabilities. 1212 // Load in a bunch of recent destinations with non null capabilities.
1241 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; 1213 var origin = cr.isChromeOS ? 'chrome_os' : 'local';
1242 initialSettings.serializedAppStateStr_ = JSON.stringify({ 1214 initialSettings.serializedAppStateStr_ = JSON.stringify({
1243 version: 2, 1215 version: 2,
1244 recentDestinations: [1, 2, 3].map(function(i) { 1216 recentDestinations: [1, 2, 3].map(function(i) {
1245 return { 1217 return {
1246 id: 'ID' + i, origin: origin, account: '', 1218 id: 'ID' + i, origin: origin, account: '',
1247 capabilities: getCddTemplate('ID' + i), name: '', 1219 capabilities: getCddTemplate('ID' + i), name: '',
1248 extensionId: '', extensionName: '' 1220 extensionId: '', extensionName: ''
1249 }; 1221 };
1250 }), 1222 }),
1251 }); 1223 });
1252 setCapabilities(getCddTemplate('ID1')); 1224
1253 setCapabilities(getCddTemplate('ID2')); 1225 // Ensure all capabilities are available for fetch.
1254 setCapabilities(getCddTemplate('ID3')); 1226 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID1'));
1227 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID2'))
1228 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID3'));
1255 1229
1256 // Use a real preview generator. 1230 // Use a real preview generator.
1257 previewArea.previewGenerator_ = 1231 previewArea.previewGenerator_ =
1258 new print_preview.PreviewGenerator(printPreview.destinationStore_, 1232 new print_preview.PreviewGenerator(printPreview.destinationStore_,
1259 printPreview.printTicketStore_, nativeLayer, 1233 printPreview.printTicketStore_, nativeLayer,
1260 printPreview.documentInfo_); 1234 printPreview.documentInfo_);
1261 1235
1262 // Preview generator starts out with inFlightRequestId_ == -1. The id 1236 // Preview generator starts out with inFlightRequestId_ == -1. The id
1263 // increments by 1 for each startGetPreview call it makes. It should only 1237 // increments by 1 for each startGetPreview call it makes. It should only
1264 // make one such call during initialization or there will be a race; see 1238 // make one such call during initialization or there will be a race; see
1265 // crbug.com/666595 1239 // crbug.com/666595
1266 expectEquals(-1, previewArea.previewGenerator_.inFlightRequestId_); 1240 expectEquals(-1, previewArea.previewGenerator_.inFlightRequestId_);
1267 setInitialSettings(); 1241 setInitialSettings();
1268 return nativeLayer.whenCalled('getInitialSettings').then(function() { 1242 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1243 return nativeLayer.whenCalled('getPrinterCapabilities', 'ID1');
1244 }).then(function() {
1269 expectEquals(0, previewArea.previewGenerator_.inFlightRequestId_); 1245 expectEquals(0, previewArea.previewGenerator_.inFlightRequestId_);
1270 }); 1246 });
1271 }); 1247 });
1272 1248
1273 // Test that invalid settings errors disable the print preview and display 1249 // Test that invalid settings errors disable the print preview and display
1274 // an error and that the preview dialog can be recovered by selecting a 1250 // an error and that the preview dialog can be recovered by selecting a
1275 // new destination. 1251 // new destination.
1276 test('InvalidSettingsError', function() { 1252 test('InvalidSettingsError', function() {
1277 return setupSettingsAndDestinations().then(function() { 1253 return setupSettingsAndDestinationsWithCapabilities().then(function() {
1278 setCapabilities(getCddTemplate('FooDevice'));
1279
1280 // Manually enable the print header. This is needed since there is no 1254 // Manually enable the print header. This is needed since there is no
1281 // plugin during test, so it will be set as disabled normally. 1255 // plugin during test, so it will be set as disabled normally.
1282 printPreview.printHeader_.isEnabled = true; 1256 printPreview.printHeader_.isEnabled = true;
1283 1257
1284 // There will be an error message in the preview area since the plugin 1258 // There will be an error message in the preview area since the plugin
1285 // is not running. However, it should not be the invalid settings 1259 // is not running. However, it should not be the invalid settings
1286 // error. 1260 // error.
1287 var previewAreaEl = $('preview-area'); 1261 var previewAreaEl = $('preview-area');
1288 var customMessageEl = 1262 var customMessageEl =
1289 previewAreaEl. 1263 previewAreaEl.
(...skipping 22 matching lines...) Expand all
1312 expectedMessageStart)); 1286 expectedMessageStart));
1313 expectTrue(printButton.disabled); 1287 expectTrue(printButton.disabled);
1314 1288
1315 // Select a new destination 1289 // Select a new destination
1316 var barDestination = 1290 var barDestination =
1317 printPreview.destinationStore_.destinations().find( 1291 printPreview.destinationStore_.destinations().find(
1318 function(d) { 1292 function(d) {
1319 return d.id == 'BarDevice'; 1293 return d.id == 'BarDevice';
1320 }); 1294 });
1321 1295
1296 nativeLayer.setLocalDestinationCapabilities(
1297 getCddTemplate('BarDevice'));
1322 printPreview.destinationStore_.selectDestination(barDestination); 1298 printPreview.destinationStore_.selectDestination(barDestination);
1323 1299
1324 // Dispatch events indicating capabilities were fetched and new 1300 return nativeLayer.whenCalled('getPrinterCapabilities', 'BarDevice')
1325 // preview has loaded. 1301 .then(function() {
1326 setCapabilities(getCddTemplate('BarDevice')); 1302 // Dispatch event indicating new preview has loaded.
1327 var previewDoneEvent = new Event( 1303 var previewDoneEvent = new Event(
1328 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); 1304 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE);
1329 previewArea.dispatchEvent(previewDoneEvent); 1305 previewArea.dispatchEvent(previewDoneEvent);
1330 1306
1331 // Has active print button and successfully 'prints', indicating 1307 // Has active print button and successfully 'prints', indicating
1332 // recovery from error state. 1308 // recovery from error state.
1333 expectFalse(printButton.disabled); 1309 expectFalse(printButton.disabled);
1334 expectFalse(nativeLayer.isPrintStarted()); 1310 expectFalse(nativeLayer.isPrintStarted());
1335 printButton.click(); 1311 printButton.click();
1336 expectTrue(nativeLayer.isPrintStarted()); 1312 expectTrue(nativeLayer.isPrintStarted());
1313 });
1337 }); 1314 });
1338 }); 1315 });
1339 1316
1340 // Test the preview generator to make sure the generate draft parameter is 1317 // Test the preview generator to make sure the generate draft parameter is
1341 // set correctly. It should be false if the only change is the page range. 1318 // set correctly. It should be false if the only change is the page range.
1342 test('GenerateDraft', function() { 1319 test('GenerateDraft', function() {
1343 // Use a real preview generator. 1320 // Use a real preview generator.
1344 previewArea.previewGenerator_ = 1321 previewArea.previewGenerator_ =
1345 new print_preview.PreviewGenerator(printPreview.destinationStore_, 1322 new print_preview.PreviewGenerator(printPreview.destinationStore_,
1346 printPreview.printTicketStore_, nativeLayer, 1323 printPreview.printTicketStore_, nativeLayer,
1347 printPreview.documentInfo_); 1324 printPreview.documentInfo_);
1348 return setupSettingsAndDestinations().then(function() { 1325 return setupSettingsAndDestinationsWithCapabilities().then(function() {
1349 setCapabilities(getCddTemplate('FooDevice'));
1350
1351 // The first request should generate draft because there was no 1326 // The first request should generate draft because there was no
1352 // previous print preview draft. 1327 // previous print preview draft.
1353 expectTrue(nativeLayer.generateDraft()); 1328 expectTrue(nativeLayer.generateDraft());
1354 1329
1355 // Change the page range - no new draft needed. 1330 // Change the page range - no new draft needed.
1356 printPreview.printTicketStore_.pageRange.updateValue('2'); 1331 printPreview.printTicketStore_.pageRange.updateValue('2');
1357 expectFalse(nativeLayer.generateDraft()); 1332 expectFalse(nativeLayer.generateDraft());
1358 1333
1359 // Change the margin type - need to regenerate again. 1334 // Change the margin type - need to regenerate again.
1360 printPreview.printTicketStore_.marginsType.updateValue( 1335 printPreview.printTicketStore_.marginsType.updateValue(
1361 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); 1336 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS);
1362 expectTrue(nativeLayer.generateDraft()); 1337 expectTrue(nativeLayer.generateDraft());
1363 }); 1338 });
1364 }); 1339 });
1365 }); 1340 });
1366 }); 1341 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/print_preview/print_preview_destination_search_test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698