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

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

Issue 2920593002: Print Preview: Migrate remaining JS tests to use Mocha. (Closed)
Patch Set: Rebase 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
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 is_default: true 127 is_default: true
128 } 128 }
129 ] 129 ]
130 } 130 }
131 } 131 }
132 } 132 }
133 }; 133 };
134 } 134 }
135 135
136 /** 136 /**
137 * @param {string} printerId
138 * @return {!Object}
139 */
140 function getCddTemplateWithAdvancedSettings(printerId) {
141 var template = getCddTemplate(printerId);
142 template.capabilities.printer.vendor_capability = [{
143 display_name: 'Print Area',
144 id: 'Print Area',
145 type: 'SELECT',
146 select_cap: {
147 option: [
148 {display_name: 'A4', value: 4, is_default: true},
149 {display_name: 'A6', value: 6},
150 {display_name: 'A7', value: 7},
151 ],
152 },
153 }];
154 return template;
155 }
156
157 /**
137 * Even though animation duration and delay is set to zero, it is necessary to 158 * Even though animation duration and delay is set to zero, it is necessary to
138 * wait until the animation has finished. 159 * wait until the animation has finished.
139 * @return {!Promise} A promise firing when the animation is done. 160 * @return {!Promise} A promise firing when the animation is done.
140 */ 161 */
141 function whenAnimationDone(elementId) { 162 function whenAnimationDone(elementId) {
142 return new Promise(function(resolve) { 163 return new Promise(function(resolve) {
143 // Add a listener for the animation end event. 164 // Add a listener for the animation end event.
144 var element = $(elementId); 165 var element = $(elementId);
145 element.addEventListener('animationend', function f(e) { 166 element.addEventListener('animationend', function f(e) {
146 element.removeEventListener(f, 'animationend'); 167 element.removeEventListener(f, 'animationend');
147 resolve(); 168 resolve();
148 }); 169 });
149 }); 170 });
150 } 171 }
151 172
152 /** 173 /**
153 * Expand the 'More Settings' div to expose all options. 174 * Expand the 'More Settings' div to expose all options.
154 */ 175 */
155 function expandMoreSettings() { 176 function expandMoreSettings() {
156 var moreSettings = $('more-settings'); 177 var moreSettings = $('more-settings');
157 checkSectionVisible(moreSettings, true); 178 checkSectionVisible(moreSettings, true);
158 moreSettings.click(); 179 moreSettings.click();
159 } 180 }
160 181
182 // Simulates a click of the advanced options settings button to bring up the
183 // advanced settings overlay.
184 function openAdvancedSettings() {
185 // Check for button and click to view advanced settings section.
186 var advancedOptionsSettingsButton =
187 $('advanced-options-settings').
188 querySelector('.advanced-options-settings-button');
189 checkElementDisplayed(advancedOptionsSettingsButton, true);
190 // Button is disabled during testing due to test version of
191 // testPluginCompatibility() being set to always return false. Enable button
192 // to send click event.
193 advancedOptionsSettingsButton.disabled = false;
194 advancedOptionsSettingsButton.click();
195 }
196
197 /**
198 * Repeated setup steps for the advanced settings tests.
199 * Disables accessiblity errors, sets initial settings, and verifies
200 * advanced options section is visible after expanding more settings.
201 */
202 function setupAdvancedSettingsTest(device) {
203 // Need to disable this since overlay animation will not fully complete.
rbpotter 2017/05/31 23:28:24 Since all tests now run with accessibility issues
dpapad 2017/06/01 00:29:48 Updated.
204 setLocalDestinations();
205 setCapabilities(device);
206 expandMoreSettings();
207
208 // Check that the advanced options settings section is visible.
209 checkSectionVisible($('advanced-options-settings'), true);
210 }
211
161 /** @return {boolean} */ 212 /** @return {boolean} */
162 function isPrintAsImageEnabled() { 213 function isPrintAsImageEnabled() {
163 // Should be enabled by default on non Windows/Mac. 214 // Should be enabled by default on non Windows/Mac.
164 return (!cr.isWindows && !cr.isMac && 215 return (!cr.isWindows && !cr.isMac &&
165 loadTimeData.getBoolean('printPdfAsImageEnabled')); 216 loadTimeData.getBoolean('printPdfAsImageEnabled'));
166 } 217 }
167 218
168 suite('PrintPreview', function() { 219 suite('PrintPreview', function() {
169 suiteSetup(function() { 220 suiteSetup(function() {
170 function CloudPrintInterfaceStub() { 221 function CloudPrintInterfaceStub() {
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 checkElementDisplayed(fitToPage, false); 580 checkElementDisplayed(fitToPage, false);
530 if (isPrintAsImageEnabled()) 581 if (isPrintAsImageEnabled())
531 checkElementDisplayed(rasterize, false); 582 checkElementDisplayed(rasterize, false);
532 checkSectionVisible(mediaSize, true); 583 checkSectionVisible(mediaSize, true);
533 checkSectionVisible(scalingSettings, true); 584 checkSectionVisible(scalingSettings, true);
534 585
535 return whenAnimationDone('more-settings'); 586 return whenAnimationDone('more-settings');
536 }); 587 });
537 }); 588 });
538 589
539 // When the source is "PDF", depending on the selected destination printer, 590 // When the source is 'PDF', depending on the selected destination printer,
540 // we show/hide the fit to page option and hide media size selection. 591 // we show/hide the fit to page option and hide media size selection.
541 test('SourceIsPDFCapabilities', function() { 592 test('SourceIsPDFCapabilities', function() {
542 initialSettings.isDocumentModifiable_ = false; 593 initialSettings.isDocumentModifiable_ = false;
543 setInitialSettings(); 594 setInitialSettings();
544 return nativeLayer.whenCalled('getInitialSettings').then( 595 return nativeLayer.whenCalled('getInitialSettings').then(
545 function() { 596 function() {
546 setLocalDestinations(); 597 setLocalDestinations();
547 setCapabilities(getCddTemplate('FooDevice')); 598 setCapabilities(getCddTemplate('FooDevice'));
548 599
549 var otherOptions = $('other-options-settings'); 600 var otherOptions = $('other-options-settings');
(...skipping 18 matching lines...) Expand all
568 expectFalse( 619 expectFalse(
569 rasterizeContainer.querySelector('.checkbox').checked); 620 rasterizeContainer.querySelector('.checkbox').checked);
570 } 621 }
571 checkSectionVisible($('media-size-settings'), true); 622 checkSectionVisible($('media-size-settings'), true);
572 checkSectionVisible(scalingSettings, true); 623 checkSectionVisible(scalingSettings, true);
573 624
574 return whenAnimationDone('other-options-collapsible'); 625 return whenAnimationDone('other-options-collapsible');
575 }); 626 });
576 }); 627 });
577 628
578 // When the source is "PDF", depending on the selected destination printer, 629 // When the source is 'PDF', depending on the selected destination printer,
579 // we show/hide the fit to page option and hide media size selection. 630 // we show/hide the fit to page option and hide media size selection.
580 test('ScalingUnchecksFitToPage', function() { 631 test('ScalingUnchecksFitToPage', function() {
581 initialSettings.isDocumentModifiable_ = false; 632 initialSettings.isDocumentModifiable_ = false;
582 setInitialSettings(); 633 setInitialSettings();
583 return nativeLayer.whenCalled('getInitialSettings').then( 634 return nativeLayer.whenCalled('getInitialSettings').then(
584 function() { 635 function() {
585 setLocalDestinations(); 636 setLocalDestinations();
586 setCapabilities(getCddTemplate('FooDevice')); 637 setCapabilities(getCddTemplate('FooDevice'));
587 638
588 var otherOptions = $('other-options-settings'); 639 var otherOptions = $('other-options-settings');
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 // duplex setting if capability is supported by printer. 701 // duplex setting if capability is supported by printer.
651 test('CheckDuplexPrintPreset', function() { 702 test('CheckDuplexPrintPreset', function() {
652 initialSettings.isDocumentModifiable_ = false; 703 initialSettings.isDocumentModifiable_ = false;
653 setInitialSettings(); 704 setInitialSettings();
654 705
655 return nativeLayer.whenCalled('getInitialSettings').then( 706 return nativeLayer.whenCalled('getInitialSettings').then(
656 function() { 707 function() {
657 setLocalDestinations(); 708 setLocalDestinations();
658 setCapabilities(getCddTemplate('FooDevice')); 709 setCapabilities(getCddTemplate('FooDevice'));
659 710
660 // Indicate that the duplex print preset is set to "long edge" for 711 // Indicate that the duplex print preset is set to 'long edge' for
661 // source PDF. 712 // source PDF.
662 var printPresetOptions = { 713 var printPresetOptions = {
663 duplex: 1 714 duplex: 1
664 }; 715 };
665 var printPresetOptionsEvent = new Event( 716 var printPresetOptionsEvent = new Event(
666 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); 717 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
667 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; 718 printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
668 nativeLayer.getEventTarget(). 719 nativeLayer.getEventTarget().
669 dispatchEvent(printPresetOptionsEvent); 720 dispatchEvent(printPresetOptionsEvent);
670 721
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 // Oriented in landscape, there should be enough space for 919 // Oriented in landscape, there should be enough space for
869 // header/footer. 920 // header/footer.
870 printPreview.printTicketStore_.landscape.updateValue(true); 921 printPreview.printTicketStore_.landscape.updateValue(true);
871 checkElementDisplayed(headerFooter, true); 922 checkElementDisplayed(headerFooter, true);
872 923
873 return whenAnimationDone('more-settings'); 924 return whenAnimationDone('more-settings');
874 }); 925 });
875 }); 926 });
876 927
877 // Test that the color settings, one option, standard monochrome. 928 // Test that the color settings, one option, standard monochrome.
878 test('TestColorSettingsMonochrome', function() { 929 test('ColorSettingsMonochrome', function() {
879 setInitialSettings(); 930 setInitialSettings();
880 return nativeLayer.whenCalled('getInitialSettings').then(function() { 931 return nativeLayer.whenCalled('getInitialSettings').then(function() {
881 setLocalDestinations(); 932 setLocalDestinations();
882 933
883 // Only one option, standard monochrome. 934 // Only one option, standard monochrome.
884 var device = getCddTemplate('FooDevice'); 935 var device = getCddTemplate('FooDevice');
885 device.capabilities.printer.color = { 936 device.capabilities.printer.color = {
886 'option': [ 937 'option': [
887 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} 938 {'is_default': true, 'type': 'STANDARD_MONOCHROME'}
888 ] 939 ]
889 }; 940 };
890 setCapabilities(device); 941 setCapabilities(device);
891 942
892 checkSectionVisible($('color-settings'), false); 943 checkSectionVisible($('color-settings'), false);
893 944
894 return whenAnimationDone('more-settings'); 945 return whenAnimationDone('more-settings');
895 }); 946 });
896 }); 947 });
897 948
898 // Test that the color settings, one option, custom monochrome. 949 // Test that the color settings, one option, custom monochrome.
899 test('TestColorSettingsCustomMonochrome', function() { 950 test('ColorSettingsCustomMonochrome', function() {
900 setInitialSettings(); 951 setInitialSettings();
901 return nativeLayer.whenCalled('getInitialSettings').then(function() { 952 return nativeLayer.whenCalled('getInitialSettings').then(function() {
902 setLocalDestinations(); 953 setLocalDestinations();
903 954
904 // Only one option, standard monochrome. 955 // Only one option, standard monochrome.
905 var device = getCddTemplate('FooDevice'); 956 var device = getCddTemplate('FooDevice');
906 device.capabilities.printer.color = { 957 device.capabilities.printer.color = {
907 'option': [ 958 'option': [
908 {'is_default': true, 'type': 'CUSTOM_MONOCHROME', 959 {'is_default': true, 'type': 'CUSTOM_MONOCHROME',
909 'vendor_id': '42'} 960 'vendor_id': '42'}
910 ] 961 ]
911 }; 962 };
912 setCapabilities(device); 963 setCapabilities(device);
913 964
914 checkSectionVisible($('color-settings'), false); 965 checkSectionVisible($('color-settings'), false);
915 966
916 return whenAnimationDone('more-settings'); 967 return whenAnimationDone('more-settings');
917 }); 968 });
918 }); 969 });
919 970
920 // Test that the color settings, one option, standard color. 971 // Test that the color settings, one option, standard color.
921 test('TestColorSettingsColor', function() { 972 test('ColorSettingsColor', function() {
922 setInitialSettings(); 973 setInitialSettings();
923 return nativeLayer.whenCalled('getInitialSettings').then(function() { 974 return nativeLayer.whenCalled('getInitialSettings').then(function() {
924 setLocalDestinations(); 975 setLocalDestinations();
925 976
926 var device = getCddTemplate('FooDevice'); 977 var device = getCddTemplate('FooDevice');
927 device.capabilities.printer.color = { 978 device.capabilities.printer.color = {
928 'option': [ 979 'option': [
929 {'is_default': true, 'type': 'STANDARD_COLOR'} 980 {'is_default': true, 'type': 'STANDARD_COLOR'}
930 ] 981 ]
931 }; 982 };
932 setCapabilities(device); 983 setCapabilities(device);
933 984
934 checkSectionVisible($('color-settings'), false); 985 checkSectionVisible($('color-settings'), false);
935 986
936 return whenAnimationDone('more-settings'); 987 return whenAnimationDone('more-settings');
937 }); 988 });
938 }); 989 });
939 990
940 // Test that the color settings, one option, custom color. 991 // Test that the color settings, one option, custom color.
941 test('TestColorSettingsCustomColor', function() { 992 test('ColorSettingsCustomColor', function() {
942 setInitialSettings(); 993 setInitialSettings();
943 return nativeLayer.whenCalled('getInitialSettings').then(function() { 994 return nativeLayer.whenCalled('getInitialSettings').then(function() {
944 setLocalDestinations(); 995 setLocalDestinations();
945 996
946 var device = getCddTemplate('FooDevice'); 997 var device = getCddTemplate('FooDevice');
947 device.capabilities.printer.color = { 998 device.capabilities.printer.color = {
948 'option': [ 999 'option': [
949 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '42'} 1000 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '42'}
950 ] 1001 ]
951 }; 1002 };
952 setCapabilities(device); 1003 setCapabilities(device);
953 1004
954 checkSectionVisible($('color-settings'), false); 1005 checkSectionVisible($('color-settings'), false);
955 1006
956 return whenAnimationDone('more-settings'); 1007 return whenAnimationDone('more-settings');
957 }); 1008 });
958 }); 1009 });
959 1010
960 // Test that the color settings, two options, both standard, defaults to 1011 // Test that the color settings, two options, both standard, defaults to
961 // color. 1012 // color.
962 test('TestColorSettingsBothStandardDefaultColor', function() { 1013 test('ColorSettingsBothStandardDefaultColor', function() {
963 setInitialSettings(); 1014 setInitialSettings();
964 return nativeLayer.whenCalled('getInitialSettings').then(function() { 1015 return nativeLayer.whenCalled('getInitialSettings').then(function() {
965 setLocalDestinations(); 1016 setLocalDestinations();
966 1017
967 var device = getCddTemplate('FooDevice'); 1018 var device = getCddTemplate('FooDevice');
968 device.capabilities.printer.color = { 1019 device.capabilities.printer.color = {
969 'option': [ 1020 'option': [
970 {'type': 'STANDARD_MONOCHROME'}, 1021 {'type': 'STANDARD_MONOCHROME'},
971 {'is_default': true, 'type': 'STANDARD_COLOR'} 1022 {'is_default': true, 'type': 'STANDARD_COLOR'}
972 ] 1023 ]
973 }; 1024 };
974 setCapabilities(device); 1025 setCapabilities(device);
975 1026
976 checkSectionVisible($('color-settings'), true); 1027 checkSectionVisible($('color-settings'), true);
977 expectEquals( 1028 expectEquals(
978 'color', 1029 'color',
979 $('color-settings').querySelector('.color-settings-select').value); 1030 $('color-settings').querySelector('.color-settings-select').value);
980 1031
981 return whenAnimationDone('more-settings'); 1032 return whenAnimationDone('more-settings');
982 }); 1033 });
983 }); 1034 });
984 1035
985 // Test that the color settings, two options, both standard, defaults to 1036 // Test that the color settings, two options, both standard, defaults to
986 // monochrome. 1037 // monochrome.
987 test('TestColorSettingsBothStandardDefaultMonochrome', function() { 1038 test('ColorSettingsBothStandardDefaultMonochrome', function() {
988 setInitialSettings(); 1039 setInitialSettings();
989 return nativeLayer.whenCalled('getInitialSettings').then(function() { 1040 return nativeLayer.whenCalled('getInitialSettings').then(function() {
990 setLocalDestinations(); 1041 setLocalDestinations();
991 1042
992 var device = getCddTemplate('FooDevice'); 1043 var device = getCddTemplate('FooDevice');
993 device.capabilities.printer.color = { 1044 device.capabilities.printer.color = {
994 'option': [ 1045 'option': [
995 {'is_default': true, 'type': 'STANDARD_MONOCHROME'}, 1046 {'is_default': true, 'type': 'STANDARD_MONOCHROME'},
996 {'type': 'STANDARD_COLOR'} 1047 {'type': 'STANDARD_COLOR'}
997 ] 1048 ]
998 }; 1049 };
999 setCapabilities(device); 1050 setCapabilities(device);
1000 1051
1001 checkSectionVisible($('color-settings'), true); 1052 checkSectionVisible($('color-settings'), true);
1002 expectEquals( 1053 expectEquals(
1003 'bw', 1054 'bw',
1004 $('color-settings').querySelector('.color-settings-select').value); 1055 $('color-settings').querySelector('.color-settings-select').value);
1005 1056
1006 return whenAnimationDone('more-settings'); 1057 return whenAnimationDone('more-settings');
1007 }); 1058 });
1008 }); 1059 });
1009 1060
1010 // Test that the color settings, two options, both custom, defaults to 1061 // Test that the color settings, two options, both custom, defaults to
1011 // color. 1062 // color.
1012 test('TestColorSettingsBothCustomDefaultColor', function() { 1063 test('ColorSettingsBothCustomDefaultColor', function() {
1013 setInitialSettings(); 1064 setInitialSettings();
1014 return nativeLayer.whenCalled('getInitialSettings').then( 1065 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1015 function() { 1066 setLocalDestinations();
1016 setLocalDestinations(); 1067
1017 1068 var device = getCddTemplate('FooDevice');
1018 var device = getCddTemplate('FooDevice'); 1069 device.capabilities.printer.color = {
1019 device.capabilities.printer.color = { 1070 'option': [
1020 'option': [ 1071 {'type': 'CUSTOM_MONOCHROME', 'vendor_id': '42'},
1021 {'type': 'CUSTOM_MONOCHROME', 'vendor_id': '42'}, 1072 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '43'}
1022 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '43'} 1073 ]
1074 };
1075 setCapabilities(device);
1076
1077 checkSectionVisible($('color-settings'), true);
1078 expectEquals(
1079 'color',
1080 $('color-settings').querySelector(
1081 '.color-settings-select').value);
1082
1083 return whenAnimationDone('more-settings');
1084 });
1085 });
1086
1087 // Test to verify that duplex settings are set according to the printer
1088 // capabilities.
1089 test('DuplexSettingsTrue', function() {
1090 setInitialSettings();
1091 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1092 setLocalDestinations();
1093 setCapabilities(getCddTemplate('FooDevice'));
1094
1095 var otherOptions = $('other-options-settings');
1096 checkSectionVisible(otherOptions, true);
1097 duplexContainer = otherOptions.querySelector('#duplex-container');
1098 expectFalse(duplexContainer.hidden);
1099 expectFalse(duplexContainer.querySelector('.checkbox').checked);
1100
1101 return whenAnimationDone('more-settings');
1102 });
1103 });
1104
1105 // Test to verify that duplex settings are set according to the printer
1106 // capabilities.
1107 test('DuplexSettingsFalse', function() {
1108 setInitialSettings();
1109 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1110 setLocalDestinations();
1111 var device = getCddTemplate('FooDevice');
1112 delete device.capabilities.printer.duplex;
1113 setCapabilities(device);
1114
1115 // Check that it is collapsed.
1116 var otherOptions = $('other-options-settings');
1117 checkSectionVisible(otherOptions, false);
1118
1119 expandMoreSettings();
1120
1121 // Now it should be visible.
1122 checkSectionVisible(otherOptions, true);
1123 expectTrue(otherOptions.querySelector('#duplex-container').hidden);
1124
1125 return whenAnimationDone('more-settings');
1126 });
1127 });
1128
1129 // Test that changing the selected printer updates the preview.
1130 test('PrinterChangeUpdatesPreview', function() {
1131 setInitialSettings();
1132 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1133 setLocalDestinations();
1134 setCapabilities(getCddTemplate('FooDevice'));
1135
1136 var previewGenerator = mock(print_preview.PreviewGenerator);
1137 previewArea.previewGenerator_ = previewGenerator.proxy();
1138
1139 // The number of settings that can change due to a change in the
1140 // destination that will therefore dispatch ticket item change events.
1141 previewGenerator.expects(exactly(9)).requestPreview();
1142
1143 var barDestination =
1144 printPreview.destinationStore_.destinations().find(
1145 function(d) {
1146 return d.id == 'BarDevice';
1147 });
1148
1149 printPreview.destinationStore_.selectDestination(barDestination);
1150
1151 var device = getCddTemplate('BarDevice');
1152 device.capabilities.printer.color = {
1153 'option': [
1154 {'is_default': true, 'type': 'STANDARD_MONOCHROME'}
1155 ]
1156 };
1157 setCapabilities(device);
1158
1159 return whenAnimationDone('more-settings');
1160 });
1161 });
1162
1163 // Test that error message is displayed when plugin doesn't exist.
1164 test('NoPDFPluginErrorMessage', function() {
1165 setInitialSettings();
1166 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1167 var previewAreaEl = $('preview-area');
1168
1169 var loadingMessageEl =
1170 previewAreaEl.
1171 getElementsByClassName('preview-area-loading-message')[0];
1172 expectTrue(loadingMessageEl.hidden);
1173
1174 var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
1175 'preview-area-preview-failed-message')[0];
1176 expectTrue(previewFailedMessageEl.hidden);
1177
1178 var printFailedMessageEl =
1179 previewAreaEl.
1180 getElementsByClassName('preview-area-print-failed')[0];
1181 expectTrue(printFailedMessageEl.hidden);
1182
1183 var customMessageEl =
1184 previewAreaEl.
1185 getElementsByClassName('preview-area-custom-message')[0];
1186 expectFalse(customMessageEl.hidden);
1187 });
1188 });
1189
1190 // Test custom localized paper names.
1191 test('CustomPaperNames', function() {
1192 setInitialSettings();
1193 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1194 setLocalDestinations();
1195
1196 var customLocalizedMediaName = 'Vendor defined localized media name';
1197 var customMediaName = 'Vendor defined media name';
1198
1199 var device = getCddTemplate('FooDevice');
1200 device.capabilities.printer.media_size = {
1201 option: [
1202 { name: 'CUSTOM',
1203 width_microns: 15900,
1204 height_microns: 79400,
1205 is_default: true,
1206 custom_display_name_localized: [
1207 { locale: navigator.language,
1208 value: customLocalizedMediaName
1209 }
1023 ] 1210 ]
1024 }; 1211 },
1025 setCapabilities(device); 1212 { name: 'CUSTOM',
1026 1213 width_microns: 15900,
1027 checkSectionVisible($('color-settings'), true); 1214 height_microns: 79400,
1028 expectEquals( 1215 custom_display_name: customMediaName
1029 'color', 1216 }
1030 $('color-settings').querySelector( 1217 ]
1031 '.color-settings-select').value); 1218 };
1032 1219
1033 return whenAnimationDone('more-settings'); 1220 setCapabilities(device);
1034 }); 1221
1035 }); 1222 expandMoreSettings();
1036 1223
1224 checkSectionVisible($('media-size-settings'), true);
1225 var mediaSelect =
1226 $('media-size-settings').querySelector('.settings-select');
1227 // Check the default media item.
1228 expectEquals(
1229 customLocalizedMediaName,
1230 mediaSelect.options[mediaSelect.selectedIndex].text);
1231 // Check the other media item.
1232 expectEquals(
1233 customMediaName,
1234 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text);
1235
1236 return whenAnimationDone('more-settings');
1237 });
1238 });
1239
1240 // Test advanced settings with 1 capability (should not display settings
1241 // search box).
1242 test('AdvancedSettings1Option', function() {
1243 var device = getCddTemplateWithAdvancedSettings('FooDevice');
1244 setInitialSettings();
1245 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1246 setupAdvancedSettingsTest(device);
1247
1248 // Open the advanced settings overlay.
1249 openAdvancedSettings();
1250
1251 // Check that advanced settings close button is now visible,
1252 // but not the search box (only 1 capability).
1253 var advancedSettingsCloseButton = $('advanced-settings').
1254 querySelector('.close-button');
1255 checkElementDisplayed(advancedSettingsCloseButton, true);
1256 checkElementDisplayed($('advanced-settings').
1257 querySelector('.search-box-area'), false);
1258
1259 return whenAnimationDone('more-settings');
1260 });
1261 });
1262
1263
1264 // Test advanced settings with 2 capabilities (should have settings search
1265 // box).
1266 test('AdvancedSettings2Options', function() {
1267 var device = getCddTemplateWithAdvancedSettings('FooDevice');
1268 // Add new capability.
1269 device.capabilities.printer.vendor_capability.push({
1270 display_name: 'Paper Type',
1271 id: 'Paper Type',
1272 type: 'SELECT',
1273 select_cap: {
1274 option: [
1275 {display_name: 'Standard', value: 0, is_default: true},
1276 {display_name: 'Recycled', value: 1},
1277 {display_name: 'Special', value: 2}
1278 ]
1279 }
1280 });
1281 setInitialSettings();
1282 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1283 setupAdvancedSettingsTest(device);
1284
1285 // Open the advanced settings overlay.
1286 openAdvancedSettings();
1287
1288 // Check advanced settings is visible and that the search box now
1289 // appears.
1290 var advancedSettingsCloseButton = $('advanced-settings').
1291 querySelector('.close-button');
1292 checkElementDisplayed(advancedSettingsCloseButton, true);
1293 checkElementDisplayed($('advanced-settings').
1294 querySelector('.search-box-area'), true);
1295
1296 return whenAnimationDone('more-settings');
1297 });
1298 });
1299
1300 // Test that initialization with saved destination only issues one call
1301 // to startPreview.
1302 test('InitIssuesOneRequest', function() {
1303 // Load in a bunch of recent destinations with non null capabilities.
1304 var origin = cr.isChromeOS ? 'chrome_os' : 'local';
1305 initialSettings.serializedAppStateStr_ = JSON.stringify({
1306 version: 2,
1307 recentDestinations: [1, 2, 3].map(function(i) {
1308 return {
1309 id: 'ID' + i, origin: origin, account: '',
1310 capabilities: getCddTemplate('ID' + i), name: '',
1311 extensionId: '', extensionName: ''
1312 };
1313 }),
1314 });
1315 setCapabilities(getCddTemplate('ID1'));
1316 setCapabilities(getCddTemplate('ID2'));
1317 setCapabilities(getCddTemplate('ID3'));
1318
1319 // Use a real preview generator.
1320 previewArea.previewGenerator_ =
1321 new print_preview.PreviewGenerator(printPreview.destinationStore_,
1322 printPreview.printTicketStore_, nativeLayer,
1323 printPreview.documentInfo_);
1324
1325 // Preview generator starts out with inFlightRequestId_ == -1. The id
1326 // increments by 1 for each startGetPreview call it makes. It should only
1327 // make one such call during initialization or there will be a race; see
1328 // crbug.com/666595
1329 expectEquals(-1, previewArea.previewGenerator_.inFlightRequestId_);
1330 setInitialSettings();
1331 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1332 expectEquals(0, previewArea.previewGenerator_.inFlightRequestId_);
1333 });
1334 });
1335
1336 // Test that invalid settings errors disable the print preview and display
1337 // an error and that the preview dialog can be recovered by selecting a
1338 // new destination.
1339 test('InvalidSettingsError', function() {
1340 // Setup
1341 setInitialSettings();
1342 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1343 setLocalDestinations();
1344 setCapabilities(getCddTemplate('FooDevice'));
1345
1346 // Manually enable the print header. This is needed since there is no
1347 // plugin during test, so it will be set as disabled normally.
1348 printPreview.printHeader_.isEnabled = true;
1349
1350 // There will be an error message in the preview area since the plugin
1351 // is not running. However, it should not be the invalid settings error.
1352 var previewAreaEl = $('preview-area');
1353 var customMessageEl =
1354 previewAreaEl.
1355 getElementsByClassName('preview-area-custom-message')[0];
1356 expectFalse(customMessageEl.hidden);
1357 var expectedMessageStart = 'The selected printer is not available or '
1358 + 'not installed correctly.'
1359 expectFalse(customMessageEl.textContent.includes(expectedMessageStart));
1360
1361 // Verify that the print button is enabled.
1362 var printHeader = $('print-header');
1363 var printButton = printHeader.querySelector('button.print');
1364 checkElementDisplayed(printButton, true);
1365 expectFalse(printButton.disabled);
1366
1367 // Report invalid settings error.
1368 var invalidSettingsEvent =
1369 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID);
1370 nativeLayer.getEventTarget().dispatchEvent(invalidSettingsEvent);
1371
1372 // Should be in an error state, print button disabled, invalid custom
1373 // error message shown.
1374 expectFalse(customMessageEl.hidden);
1375 expectTrue(customMessageEl.textContent.includes(expectedMessageStart));
1376 expectTrue(printButton.disabled);
1377
1378 // Select a new destination
1379 var barDestination =
1380 printPreview.destinationStore_.destinations().find(
1381 function(d) {
1382 return d.id == 'BarDevice';
1383 });
1384
1385 printPreview.destinationStore_.selectDestination(barDestination);
1386
1387 // Dispatch events indicating capabilities were fetched and new preview
1388 // has loaded.
1389 setCapabilities(getCddTemplate('BarDevice'));
1390 var previewDoneEvent = new Event(
1391 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE);
1392 previewArea.dispatchEvent(previewDoneEvent);
1393
1394 // Has active print button and successfully 'prints', indicating
1395 // recovery from error state.
1396 expectFalse(printButton.disabled);
1397 expectFalse(nativeLayer.isPrintStarted());
1398 printButton.click();
1399 expectTrue(nativeLayer.isPrintStarted());
1400 });
1401 });
1402
1403 // Test the preview generator to make sure the generate draft parameter is
1404 // set correctly. It should be false if the only change is the page range.
1405 test('GenerateDraft', function() {
1406 // Use a real preview generator.
1407 previewArea.previewGenerator_ =
1408 new print_preview.PreviewGenerator(printPreview.destinationStore_,
1409 printPreview.printTicketStore_, nativeLayer,
1410 printPreview.documentInfo_);
1411
1412 setInitialSettings();
1413 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1414 setLocalDestinations();
1415 setCapabilities(getCddTemplate('FooDevice'));
1416
1417 // The first request should generate draft because there was no
1418 // previous print preview draft.
1419 expectTrue(nativeLayer.generateDraft());
1420
1421 // Change the page range - no new draft needed.
1422 printPreview.printTicketStore_.pageRange.updateValue('2');
1423 expectFalse(nativeLayer.generateDraft());
1424
1425 // Change the margin type - need to regenerate again.
1426 printPreview.printTicketStore_.marginsType.updateValue(
1427 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS);
1428 expectTrue(nativeLayer.generateDraft());
1429 });
1430 });
1037 }); 1431 });
1038 }); 1432 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698