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

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

Powered by Google App Engine
This is Rietveld 408576698