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

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

Issue 601083004: Enable a11y audit for chrome://print and fix failing tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed c++ dependency from js for async test Created 6 years, 2 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/browser/resources/print_preview/settings/destination_settings.html ('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 (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
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
48 /** 54 /**
49 * Stub out low-level functionality like the NativeLayer and 55 * Stub out low-level functionality like the NativeLayer and
50 * CloudPrintInterface. 56 * CloudPrintInterface.
51 * @this {PrintPreviewWebUITest} 57 * @this {PrintPreviewWebUITest}
52 * @override 58 * @override
53 */ 59 */
54 preLoad: function() { 60 preLoad: function() {
55 window.addEventListener('DOMContentLoaded', function() { 61 window.addEventListener('DOMContentLoaded', function() {
56 function NativeLayerStub() { 62 function NativeLayerStub() {
57 cr.EventTarget.call(this); 63 cr.EventTarget.call(this);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 { printerName: 'BarName', deviceName: 'BarDevice' } 138 { printerName: 'BarName', deviceName: 'BarDevice' }
133 ]; 139 ];
134 this.nativeLayer_ = printPreview.nativeLayer_; 140 this.nativeLayer_ = printPreview.nativeLayer_;
135 } 141 }
136 }; 142 };
137 143
138 GEN('#include "chrome/test/data/webui/print_preview.h"'); 144 GEN('#include "chrome/test/data/webui/print_preview.h"');
139 145
140 // Test some basic assumptions about the print preview WebUI. 146 // Test some basic assumptions about the print preview WebUI.
141 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { 147 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
142 var initialSettingsSetEvent = 148 this.setUpPreview();
143 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
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 149
152 var recentList = $('destination-search').querySelector('.recent-list ul'); 150 var recentList = $('destination-search').querySelector('.recent-list ul');
153 var localList = $('destination-search').querySelector('.local-list ul'); 151 var localList = $('destination-search').querySelector('.local-list ul');
154 assertNotEquals(null, recentList); 152 assertNotEquals(null, recentList);
155 assertEquals(1, recentList.childNodes.length); 153 assertEquals(1, recentList.childNodes.length);
156 assertEquals('FooName', 154 assertEquals('FooName',
157 recentList.childNodes.item(0).querySelector( 155 recentList.childNodes.item(0).querySelector(
158 '.destination-list-item-name').textContent); 156 '.destination-list-item-name').textContent);
159 157
160 assertNotEquals(null, localList); 158 assertNotEquals(null, localList);
161 assertEquals(3, localList.childNodes.length); 159 assertEquals(3, localList.childNodes.length);
162 assertEquals('Save as PDF', 160 assertEquals('Save as PDF',
163 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). 161 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX).
164 querySelector('.destination-list-item-name').textContent); 162 querySelector('.destination-list-item-name').textContent);
165 assertEquals('FooName', 163 assertEquals('FooName',
166 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). 164 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
167 querySelector('.destination-list-item-name').textContent); 165 querySelector('.destination-list-item-name').textContent);
168 assertEquals('BarName', 166 assertEquals('BarName',
169 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). 167 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
170 querySelector('.destination-list-item-name').textContent); 168 querySelector('.destination-list-item-name').textContent);
171 }); 169 });
172 170
173 // Test that the printer list is structured correctly after calling 171 // Test that the printer list is structured correctly after calling
174 // addCloudPrinters with an empty list. 172 // addCloudPrinters with an empty list.
175 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { 173 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
176 var initialSettingsSetEvent = 174 this.setUpPreview();
177 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
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 175
186 var cloudPrintEnableEvent = 176 var cloudPrintEnableEvent =
187 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); 177 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE);
188 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; 178 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url';
189 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent); 179 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent);
190 180
191 var searchDoneEvent = 181 var searchDoneEvent =
192 new Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE); 182 new Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE);
193 searchDoneEvent.printers = []; 183 searchDoneEvent.printers = [];
194 searchDoneEvent.isRecent = true; 184 searchDoneEvent.isRecent = true;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); 282 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
293 283
294 checkElementDisplayed($('system-dialog-link'), false); 284 checkElementDisplayed($('system-dialog-link'), false);
295 }); 285 });
296 286
297 // Test that disabled settings hide the disabled sections. 287 // Test that disabled settings hide the disabled sections.
298 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { 288 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
299 checkSectionVisible($('layout-settings'), false); 289 checkSectionVisible($('layout-settings'), false);
300 checkSectionVisible($('color-settings'), false); 290 checkSectionVisible($('color-settings'), false);
301 checkSectionVisible($('copies-settings'), false); 291 checkSectionVisible($('copies-settings'), false);
302 292 this.setUpPreview();
303 var initialSettingsSetEvent =
304 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
305 initialSettingsSetEvent.initialSettings = this.initialSettings_;
306 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
307
308 var localDestsSetEvent =
309 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
310 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
311 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
312 293
313 var capsSetEvent = 294 var capsSetEvent =
314 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 295 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
315 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 296 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
316 capsSetEvent.settingsInfo.capabilities.printer.color = { 297 capsSetEvent.settingsInfo.capabilities.printer.color = {
317 "option": [ 298 "option": [
318 {"is_default": true, "type": "STANDARD_COLOR"} 299 {"is_default": true, "type": "STANDARD_COLOR"}
319 ] 300 ]
320 }; 301 };
321 delete capsSetEvent.settingsInfo.capabilities.printer.copies; 302 delete capsSetEvent.settingsInfo.capabilities.printer.copies;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 349 }
369 } 350 }
370 } 351 }
371 }; 352 };
372 this.nativeLayer_.dispatchEvent(capsSetEvent); 353 this.nativeLayer_.dispatchEvent(capsSetEvent);
373 354
374 checkSectionVisible($('other-options-settings'), false); 355 checkSectionVisible($('other-options-settings'), false);
375 checkSectionVisible($('media-size-settings'), false); 356 checkSectionVisible($('media-size-settings'), false);
376 }); 357 });
377 358
378 // When the source is 'HTML', we always hide the fit to page option and show 359 // When the source is "PDF", depending on the selected destination printer, we
379 // media size option. 360 // show/hide the fit to page option and hide media size selection.
380 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() { 361 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() {
381 var initialSettingsSetEvent = 362 this.initialSettings_.isDocumentModifiable_ = false;
382 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); 363 this.setUpPreview();
383 initialSettingsSetEvent.initialSettings = this.initialSettings_;
384 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
385
386 var localDestsSetEvent =
387 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
388 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
389 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
390 364
391 var capsSetEvent = 365 var capsSetEvent =
392 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 366 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
393 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 367 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
394 this.nativeLayer_.dispatchEvent(capsSetEvent); 368 this.nativeLayer_.dispatchEvent(capsSetEvent);
395 369
396 var moreSettingsDiv = $('more-settings'); 370 var otherOptions = $('other-options-settings');
397 var mediaSizeDiv = $('media-size-settings'); 371 checkSectionVisible(otherOptions, true);
398 var otherOptionsDiv = $('other-options-settings');
399 var fitToPageEl = otherOptionsDiv.querySelector('.fit-to-page-container');
400
401 // Check that options are collapsed (section is visible, because duplex is
402 // available).
403 checkSectionVisible(otherOptionsDiv, true);
404 checkElementDisplayed(fitToPageEl, false);
405 checkSectionVisible(mediaSizeDiv, false);
406 // Expand it.
407 checkSectionVisible(moreSettingsDiv, true);
408 moreSettingsDiv.click();
409
410 checkElementDisplayed(fitToPageEl, false);
411 checkSectionVisible(mediaSizeDiv, true);
412 });
413
414 // When the source is "PDF", depending on the selected destination printer, we
415 // show/hide the fit to page option and hide media size selection.
416 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() {
417 this.initialSettings_.isDocumentModifiable_ = false;
418
419 var initialSettingsSetEvent =
420 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
421 initialSettingsSetEvent.initialSettings = this.initialSettings_;
422 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
423
424 var localDestsSetEvent =
425 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
426 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
427 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
428
429 var capsSetEvent =
430 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
431 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
432 this.nativeLayer_.dispatchEvent(capsSetEvent);
433
434 var otherOptionsDiv = $('other-options-settings');
435
436 checkSectionVisible(otherOptionsDiv, true);
437 checkElementDisplayed( 372 checkElementDisplayed(
438 otherOptionsDiv.querySelector('.fit-to-page-container'), true); 373 otherOptions.querySelector('.fit-to-page-container'), true);
439 expectTrue( 374 expectTrue(
440 otherOptionsDiv.querySelector('.fit-to-page-checkbox').checked); 375 otherOptions.querySelector('.fit-to-page-checkbox').checked);
441 checkSectionVisible($('media-size-settings'), true); 376 checkSectionVisible($('media-size-settings'), true);
442 }); 377 });
443 378
444 // When the print scaling is disabled for the source "PDF", we show the fit 379 // When the print scaling is disabled for the source "PDF", we show the fit
445 // to page option but the state is unchecked by default. 380 // to page option but the state is unchecked by default.
446 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() { 381 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() {
447 this.initialSettings_.isDocumentModifiable_ = false; 382 this.initialSettings_.isDocumentModifiable_ = false;
448 383 this.setUpPreview();
449 var initialSettingsSetEvent =
450 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
451 initialSettingsSetEvent.initialSettings = this.initialSettings_;
452 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
453
454 var localDestsSetEvent =
455 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
456 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
457 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
458 384
459 var capsSetEvent = 385 var capsSetEvent =
460 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 386 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
461 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 387 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
462 this.nativeLayer_.dispatchEvent(capsSetEvent); 388 this.nativeLayer_.dispatchEvent(capsSetEvent);
463 389
464 // Indicate that the PDF does not support scaling by default. 390 // Indicate that the PDF does not support scaling by default.
465 cr.dispatchSimpleEvent( 391 cr.dispatchSimpleEvent(
466 this.nativeLayer_, print_preview.NativeLayer.EventType.DISABLE_SCALING); 392 this.nativeLayer_, print_preview.NativeLayer.EventType.DISABLE_SCALING);
467 393
468 var otherOptionsDiv = $('other-options-settings'); 394 var otherOptions = $('other-options-settings');
469 395 checkSectionVisible(otherOptions, true);
470 checkSectionVisible(otherOptionsDiv, true);
471
472 checkElementDisplayed( 396 checkElementDisplayed(
473 otherOptionsDiv.querySelector('.fit-to-page-container'), true); 397 otherOptions.querySelector('.fit-to-page-container'), true);
474 expectFalse( 398 expectFalse(
475 otherOptionsDiv.querySelector('.fit-to-page-checkbox').checked); 399 otherOptions.querySelector('.fit-to-page-checkbox').checked);
476 }); 400 });
477 401
478 // Make sure that custom margins controls are properly set up. 402 // Make sure that custom margins controls are properly set up.
479 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() { 403 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() {
480 var initialSettingsSetEvent = 404 this.setUpPreview();
481 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
482 initialSettingsSetEvent.initialSettings = this.initialSettings_;
483 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
484
485 var localDestsSetEvent =
486 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
487 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
488 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
489 405
490 var capsSetEvent = 406 var capsSetEvent =
491 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 407 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
492 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 408 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
493 this.nativeLayer_.dispatchEvent(capsSetEvent); 409 this.nativeLayer_.dispatchEvent(capsSetEvent);
494 410
495 printPreview.printTicketStore_.marginsType.updateValue( 411 printPreview.printTicketStore_.marginsType.updateValue(
496 print_preview.ticket_items.MarginsType.Value.CUSTOM); 412 print_preview.ticket_items.MarginsType.Value.CUSTOM);
497 413
498 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { 414 ['left', 'top', 'right', 'bottom'].forEach(function(margin) {
499 var control = $('preview-area').querySelector('.margin-control-' + margin); 415 var control = $('preview-area').querySelector('.margin-control-' + margin);
500 assertNotEquals(null, control); 416 assertNotEquals(null, control);
501 var input = control.querySelector('.margin-control-textbox'); 417 var input = control.querySelector('.margin-control-textbox');
502 assertTrue(input.hasAttribute('aria-label')); 418 assertTrue(input.hasAttribute('aria-label'));
503 assertNotEquals('undefined', input.getAttribute('aria-label')); 419 assertNotEquals('undefined', input.getAttribute('aria-label'));
504 }); 420 });
505 }); 421 });
506 422
507 // Page layout has zero margins. Hide header and footer option.
508 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
509 function() {
510 var initialSettingsSetEvent =
511 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
512 initialSettingsSetEvent.initialSettings = this.initialSettings_;
513 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
514
515 var localDestsSetEvent =
516 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
517 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
518 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
519
520 var capsSetEvent =
521 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
522 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
523 this.nativeLayer_.dispatchEvent(capsSetEvent);
524
525 var moreSettingsDiv = $('more-settings');
526 var otherOptionsDiv = $('other-options-settings');
527 var headerFooterEl =
528 otherOptionsDiv.querySelector('.header-footer-container');
529
530 // Check that options are collapsed (section is visible, because duplex is
531 // available).
532 checkSectionVisible(otherOptionsDiv, true);
533 checkElementDisplayed(headerFooterEl, false);
534 // Expand it.
535 checkSectionVisible(moreSettingsDiv, true);
536 moreSettingsDiv.click();
537
538 checkElementDisplayed(headerFooterEl, true);
539
540 printPreview.printTicketStore_.marginsType.updateValue(
541 print_preview.ticket_items.MarginsType.Value.CUSTOM);
542 printPreview.printTicketStore_.customMargins.updateValue(
543 new print_preview.Margins(0, 0, 0, 0));
544
545 checkElementDisplayed(headerFooterEl, false);
546 });
547
548 // Page layout has half-inch margins. Show header and footer option.
549 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter',
550 function() {
551 var initialSettingsSetEvent =
552 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
553 initialSettingsSetEvent.initialSettings = this.initialSettings_;
554 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
555
556 var localDestsSetEvent =
557 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
558 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
559 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
560
561 var capsSetEvent =
562 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
563 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
564 this.nativeLayer_.dispatchEvent(capsSetEvent);
565
566 var moreSettingsDiv = $('more-settings');
567 var otherOptionsDiv = $('other-options-settings');
568 var headerFooterEl =
569 otherOptionsDiv.querySelector('.header-footer-container');
570
571 // Check that options are collapsed (section is visible, because duplex is
572 // available).
573 checkSectionVisible(otherOptionsDiv, true);
574 checkElementDisplayed(headerFooterEl, false);
575 // Expand it.
576 checkSectionVisible(moreSettingsDiv, true);
577 moreSettingsDiv.click();
578
579 checkElementDisplayed(headerFooterEl, true);
580
581 printPreview.printTicketStore_.marginsType.updateValue(
582 print_preview.ticket_items.MarginsType.Value.CUSTOM);
583 printPreview.printTicketStore_.customMargins.updateValue(
584 new print_preview.Margins(36, 36, 36, 36));
585
586 checkElementDisplayed(headerFooterEl, true);
587 });
588
589 // Page layout has zero top and bottom margins. Hide header and footer option.
590 TEST_F('PrintPreviewWebUITest',
591 'ZeroTopAndBottomMarginsHideHeaderFooter',
592 function() {
593 var initialSettingsSetEvent =
594 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
595 initialSettingsSetEvent.initialSettings = this.initialSettings_;
596 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
597
598 var localDestsSetEvent =
599 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
600 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
601 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
602
603 var capsSetEvent =
604 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
605 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
606 this.nativeLayer_.dispatchEvent(capsSetEvent);
607
608 var moreSettingsDiv = $('more-settings');
609 var otherOptionsDiv = $('other-options-settings');
610 var headerFooterEl =
611 otherOptionsDiv.querySelector('.header-footer-container');
612
613 // Check that options are collapsed (section is visible, because duplex is
614 // available).
615 checkSectionVisible(otherOptionsDiv, true);
616 checkElementDisplayed(headerFooterEl, false);
617 // Expand it.
618 checkSectionVisible(moreSettingsDiv, true);
619 moreSettingsDiv.click();
620
621 checkElementDisplayed(headerFooterEl, true);
622
623 printPreview.printTicketStore_.marginsType.updateValue(
624 print_preview.ticket_items.MarginsType.Value.CUSTOM);
625 printPreview.printTicketStore_.customMargins.updateValue(
626 new print_preview.Margins(0, 36, 0, 36));
627
628 checkElementDisplayed(headerFooterEl, false);
629 });
630
631 // Page layout has zero top and half-inch bottom margin. Show header and footer
632 // option.
633 TEST_F('PrintPreviewWebUITest',
634 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
635 function() {
636 var initialSettingsSetEvent =
637 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
638 initialSettingsSetEvent.initialSettings = this.initialSettings_;
639 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
640
641 var localDestsSetEvent =
642 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
643 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
644 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
645
646 var capsSetEvent =
647 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
648 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
649 this.nativeLayer_.dispatchEvent(capsSetEvent);
650
651 var moreSettingsDiv = $('more-settings');
652 var otherOptionsDiv = $('other-options-settings');
653 var headerFooterEl =
654 otherOptionsDiv.querySelector('.header-footer-container');
655
656 // Check that options are collapsed (section is visible, because duplex is
657 // available).
658 checkSectionVisible(otherOptionsDiv, true);
659 checkElementDisplayed(headerFooterEl, false);
660 // Expand it.
661 checkSectionVisible(moreSettingsDiv, true);
662 moreSettingsDiv.click();
663
664 checkElementDisplayed(headerFooterEl, true);
665
666 printPreview.printTicketStore_.marginsType.updateValue(
667 print_preview.ticket_items.MarginsType.Value.CUSTOM);
668 printPreview.printTicketStore_.customMargins.updateValue(
669 new print_preview.Margins(0, 36, 36, 36));
670
671 checkElementDisplayed(headerFooterEl, true);
672 });
673
674 // Test that the color settings, one option, standard monochrome. 423 // Test that the color settings, one option, standard monochrome.
675 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() { 424 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() {
676 this.setUpPreview(); 425 this.setUpPreview();
677 426
678 // Only one option, standard monochrome. 427 // Only one option, standard monochrome.
679 var capsSetEvent = 428 var capsSetEvent =
680 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 429 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
681 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 430 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
682 capsSetEvent.settingsInfo.capabilities.printer.color = { 431 capsSetEvent.settingsInfo.capabilities.printer.color = {
683 "option": [ 432 "option": [
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 553
805 checkSectionVisible($('color-settings'), true); 554 checkSectionVisible($('color-settings'), true);
806 expectEquals( 555 expectEquals(
807 'color', 556 'color',
808 $('color-settings').querySelector('.color-settings-select').value); 557 $('color-settings').querySelector('.color-settings-select').value);
809 }); 558 });
810 559
811 // Test to verify that duplex settings are set according to the printer 560 // Test to verify that duplex settings are set according to the printer
812 // capabilities. 561 // capabilities.
813 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() { 562 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
814 var initialSettingsSetEvent = 563 this.setUpPreview();
815 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
816 initialSettingsSetEvent.initialSettings = this.initialSettings_;
817 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
818
819 var localDestsSetEvent =
820 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
821 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
822 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
823
824 var otherOptionsDiv = $('other-options-settings');
825 var duplexDiv = otherOptionsDiv.querySelector('.duplex-container');
826 var duplexCheckbox = otherOptionsDiv.querySelector('.duplex-checkbox');
827 564
828 var capsSetEvent = 565 var capsSetEvent =
829 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 566 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
830 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 567 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
831 this.nativeLayer_.dispatchEvent(capsSetEvent); 568 this.nativeLayer_.dispatchEvent(capsSetEvent);
832 569
833 checkSectionVisible(otherOptionsDiv, true); 570 var otherOptions = $('other-options-settings');
834 expectFalse(duplexDiv.hidden); 571 checkSectionVisible(otherOptions, true);
835 expectFalse(duplexCheckbox.checked); 572 expectFalse(otherOptions.querySelector('.duplex-container').hidden);
836 }); 573 expectFalse(otherOptions.querySelector('.duplex-checkbox').checked);
837
838 // Test to verify that duplex settings are set according to the printer
839 // capabilities.
840 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
841 var initialSettingsSetEvent =
842 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
843 initialSettingsSetEvent.initialSettings = this.initialSettings_;
844 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
845
846 var localDestsSetEvent =
847 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
848 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
849 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
850
851 var moreSettingsDiv = $('more-settings');
852 var otherOptionsDiv = $('other-options-settings');
853 var duplexDiv = otherOptionsDiv.querySelector('.duplex-container');
854
855 var capsSetEvent =
856 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
857 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
858 delete capsSetEvent.settingsInfo.capabilities.printer.duplex;
859 this.nativeLayer_.dispatchEvent(capsSetEvent);
860
861 // Check that it is collapsed.
862 checkSectionVisible(otherOptionsDiv, false);
863 // Expand it.
864 checkSectionVisible(moreSettingsDiv, true);
865 moreSettingsDiv.click();
866 // Now it should be visible.
867 checkSectionVisible(otherOptionsDiv, true);
868 expectTrue(duplexDiv.hidden);
869 }); 574 });
870 575
871 // Test that changing the selected printer updates the preview. 576 // Test that changing the selected printer updates the preview.
872 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { 577 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
873 578 this.setUpPreview();
874 var initialSettingsSetEvent =
875 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
876 initialSettingsSetEvent.initialSettings = this.initialSettings_;
877 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
878
879 var localDestsSetEvent =
880 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
881 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
882 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
883 579
884 var capsSetEvent = 580 var capsSetEvent =
885 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 581 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
886 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 582 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
887 this.nativeLayer_.dispatchEvent(capsSetEvent); 583 this.nativeLayer_.dispatchEvent(capsSetEvent);
888 584
889 var previewGenerator = mock(print_preview.PreviewGenerator); 585 var previewGenerator = mock(print_preview.PreviewGenerator);
890 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy(); 586 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy();
891 previewGenerator.expects(exactly(6)).requestPreview(); 587 previewGenerator.expects(exactly(6)).requestPreview();
892 588
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 'preview-area-preview-failed-message')[0]; 620 'preview-area-preview-failed-message')[0];
925 expectEquals(true, previewFailedMessageEl.hidden); 621 expectEquals(true, previewFailedMessageEl.hidden);
926 622
927 var printFailedMessageEl = 623 var printFailedMessageEl =
928 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0]; 624 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0];
929 expectEquals(true, printFailedMessageEl.hidden); 625 expectEquals(true, printFailedMessageEl.hidden);
930 626
931 var customMessageEl = 627 var customMessageEl =
932 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; 628 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0];
933 expectEquals(false, customMessageEl.hidden); 629 expectEquals(false, customMessageEl.hidden);
934 }); 630 });
hcarmona 2014/10/29 22:24:46 Re-ordered the tests to match their original order
631
632 /**
633 * Async test fixture for print preview WebUI testing.
634 * @constructor
635 * @extends {PrintPreviewWebUITest}
636 */
637 function PrintPreviewWebUIAsyncTest() {
638 }
639
640 PrintPreviewWebUIAsyncTest.prototype = {
641 __proto__: PrintPreviewWebUITest.prototype,
642
643 /** @override */
644 isAsync: true,
645
646 /** @override */
647 typedefCppFixture: 'PrintPreviewWebUITest',
648
649 /**
650 * @this {PrintPreviewWebUIAsyncTest}
651 * @override
652 */
653 setUp: function() {
654 // Setup everything from the base class.
655 PrintPreviewWebUITest.prototype.setUp.call(this);
656
657 // Do this here because all tests need it.
658 this.setUpPreview();
659
660 // Make all transitions and animations take 0ms for testing purposes.
661 // Animations still happen and we will wait for the webkitAnimationEnd event
662 // for the "more-settings" element because it is responsible for hiding a
663 // lot of buttons.
664 var noAnimationStyle = document.createElement('style');
665 noAnimationStyle.textContent =
666 '* {' +
667 ' -webkit-transition-duration: 0s !important;' +
668 ' -webkit-transition-delay: 0s !important;' +
669 ' -webkit-animation-duration: 0s !important;' +
670 ' -webkit-animation-delay: 0s !important;' +
671 '}';
672 document.querySelector('head').appendChild(noAnimationStyle);
673 },
674
675 /**
676 * Even though animation duration and delay is set to zero, it is necessary to
677 * wait until the animation has finished.
678 */
679 waitForAnimationsToEnd: function() {
680 // add a listener for the transition end event
681 document.addEventListener('webkitAnimationEnd', function(e) {
682 if (e.target.id == 'more-settings')
683 testDone();
684 });
685 },
686
687 /**
688 * Expand the 'More Settings' div to expose all options.
689 */
690 expandMoreSettings: function() {
691 var moreSettings = $('more-settings');
692 checkSectionVisible(moreSettings, true);
693 moreSettings.click();
694 }
695 };
696
697 // When the source is 'HTML', we always hide the fit to page option and show
698 // media size option.
699 TEST_F('PrintPreviewWebUIAsyncTest', 'SourceIsHTMLCapabilities', function() {
700 var capsSetEvent =
701 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
702 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
703 this.nativeLayer_.dispatchEvent(capsSetEvent);
704
705 var otherOptions = $('other-options-settings');
706 var fitToPage = otherOptions.querySelector('.fit-to-page-container');
707 var mediaSize = $('media-size-settings');
708
709 // Check that options are collapsed (section is visible, because duplex is
710 // available).
711 checkSectionVisible(otherOptions, true);
712 checkElementDisplayed(fitToPage, false);
713 checkSectionVisible(mediaSize, false);
714
715 this.expandMoreSettings();
716
717 checkElementDisplayed(fitToPage, false);
718 checkSectionVisible(mediaSize, true);
719
720 this.waitForAnimationsToEnd();
721 });
722
723 // Page layout has zero margins. Hide header and footer option.
724 TEST_F('PrintPreviewWebUIAsyncTest', 'PageLayoutHasNoMarginsHideHeaderFooter',
725 function() {
726 var capsSetEvent =
727 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
728 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
729 this.nativeLayer_.dispatchEvent(capsSetEvent);
730
731 var otherOptions = $('other-options-settings');
732 var headerFooter = otherOptions.querySelector('.header-footer-container');
733
734 // Check that options are collapsed (section is visible, because duplex is
735 // available).
736 checkSectionVisible(otherOptions, true);
737 checkElementDisplayed(headerFooter, false);
738
739 this.expandMoreSettings();
740
741 checkElementDisplayed(headerFooter, true);
742
743 printPreview.printTicketStore_.marginsType.updateValue(
744 print_preview.ticket_items.MarginsType.Value.CUSTOM);
745 printPreview.printTicketStore_.customMargins.updateValue(
746 new print_preview.Margins(0, 0, 0, 0));
747
748 checkElementDisplayed(headerFooter, false);
749
750 this.waitForAnimationsToEnd();
751 });
752
753 // Page layout has half-inch margins. Show header and footer option.
754 TEST_F('PrintPreviewWebUIAsyncTest', 'PageLayoutHasMarginsShowHeaderFooter',
755 function() {
756 var capsSetEvent =
757 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
758 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
759 this.nativeLayer_.dispatchEvent(capsSetEvent);
760
761 var otherOptions = $('other-options-settings');
762 var headerFooter = otherOptions.querySelector('.header-footer-container');
763
764 // Check that options are collapsed (section is visible, because duplex is
765 // available).
766 checkSectionVisible(otherOptions, true);
767 checkElementDisplayed(headerFooter, false);
768
769 this.expandMoreSettings();
770
771 checkElementDisplayed(headerFooter, true);
772
773 printPreview.printTicketStore_.marginsType.updateValue(
774 print_preview.ticket_items.MarginsType.Value.CUSTOM);
775 printPreview.printTicketStore_.customMargins.updateValue(
776 new print_preview.Margins(36, 36, 36, 36));
777
778 checkElementDisplayed(headerFooter, true);
779
780 this.waitForAnimationsToEnd();
781 });
782
783 // Page layout has zero top and bottom margins. Hide header and footer option.
784 TEST_F('PrintPreviewWebUIAsyncTest',
785 'ZeroTopAndBottomMarginsHideHeaderFooter',
786 function() {
787 var capsSetEvent =
788 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
789 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
790 this.nativeLayer_.dispatchEvent(capsSetEvent);
791
792 var otherOptions = $('other-options-settings');
793 var headerFooter = otherOptions.querySelector('.header-footer-container');
794
795 // Check that options are collapsed (section is visible, because duplex is
796 // available).
797 checkSectionVisible(otherOptions, true);
798 checkElementDisplayed(headerFooter, false);
799
800 this.expandMoreSettings();
801
802 checkElementDisplayed(headerFooter, true);
803
804 printPreview.printTicketStore_.marginsType.updateValue(
805 print_preview.ticket_items.MarginsType.Value.CUSTOM);
806 printPreview.printTicketStore_.customMargins.updateValue(
807 new print_preview.Margins(0, 36, 0, 36));
808
809 checkElementDisplayed(headerFooter, false);
810
811 this.waitForAnimationsToEnd();
812 });
813
814 // Page layout has zero top and half-inch bottom margin. Show header and footer
815 // option.
816 TEST_F('PrintPreviewWebUIAsyncTest',
817 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
818 function() {
819 var capsSetEvent =
820 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
821 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
822 this.nativeLayer_.dispatchEvent(capsSetEvent);
823
824 var otherOptions = $('other-options-settings');
825 var headerFooter = otherOptions.querySelector('.header-footer-container');
826
827 // Check that options are collapsed (section is visible, because duplex is
828 // available).
829 checkSectionVisible(otherOptions, true);
830 checkElementDisplayed(headerFooter, false);
831
832 this.expandMoreSettings();
833
834 checkElementDisplayed(headerFooter, true);
835
836 printPreview.printTicketStore_.marginsType.updateValue(
837 print_preview.ticket_items.MarginsType.Value.CUSTOM);
838 printPreview.printTicketStore_.customMargins.updateValue(
839 new print_preview.Margins(0, 36, 36, 36));
840
841 checkElementDisplayed(headerFooter, true);
842
843 this.waitForAnimationsToEnd();
844 });
845
846 // Test to verify that duplex settings are set according to the printer
847 // capabilities.
848 TEST_F('PrintPreviewWebUIAsyncTest', 'TestDuplexSettingsFalse', function() {
849 var capsSetEvent =
850 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
851 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
852 delete capsSetEvent.settingsInfo.capabilities.printer.duplex;
853 this.nativeLayer_.dispatchEvent(capsSetEvent);
854
855 // Check that it is collapsed.
856 var otherOptions = $('other-options-settings');
857 checkSectionVisible(otherOptions, false);
858
859 this.expandMoreSettings();
860
861 // Now it should be visible.
862 checkSectionVisible(otherOptions, true);
863 expectTrue(otherOptions.querySelector('.duplex-container').hidden);
864
865 this.waitForAnimationsToEnd();
866 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/print_preview/settings/destination_settings.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698