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

Side by Side Diff: chrome/browser/resources/print_preview/print_preview.js

Issue 335583004: Added a test that currently is able to print to pdf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed 'if else' bracket style issues. Created 6 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 (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 // TODO(rltoscano): Move data/* into print_preview.data namespace 5 // TODO(rltoscano): Move data/* into print_preview.data namespace
6 6
7 var localStrings = new LocalStrings(templateData); 7 var localStrings = new LocalStrings(templateData);
8 8
9 <include src="component.js"/> 9 <include src="component.js"/>
10 10
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 print_preview.NativeLayer.EventType.SETTINGS_INVALID, 278 print_preview.NativeLayer.EventType.SETTINGS_INVALID,
279 this.onSettingsInvalid_.bind(this)); 279 this.onSettingsInvalid_.bind(this));
280 this.tracker.add( 280 this.tracker.add(
281 this.nativeLayer_, 281 this.nativeLayer_,
282 print_preview.NativeLayer.EventType.DISABLE_SCALING, 282 print_preview.NativeLayer.EventType.DISABLE_SCALING,
283 this.onDisableScaling_.bind(this)); 283 this.onDisableScaling_.bind(this));
284 this.tracker.add( 284 this.tracker.add(
285 this.nativeLayer_, 285 this.nativeLayer_,
286 print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED, 286 print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED,
287 this.onPrivetPrintFailed_.bind(this)); 287 this.onPrivetPrintFailed_.bind(this));
288 288 this.tracker.add(
289 this.nativeLayer_,
290 print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST,
291 this.onManipulateSettingsForTest_.bind(this));
289 292
290 this.tracker.add( 293 this.tracker.add(
291 $('system-dialog-link'), 294 $('system-dialog-link'),
292 'click', 295 'click',
293 this.openSystemPrintDialog_.bind(this)); 296 this.openSystemPrintDialog_.bind(this));
294 this.tracker.add( 297 this.tracker.add(
295 $('cloud-print-dialog-link'), 298 $('cloud-print-dialog-link'),
296 'click', 299 'click',
297 this.onCloudPrintDialogLinkClick_.bind(this)); 300 this.onCloudPrintDialogLinkClick_.bind(this));
298 this.tracker.add( 301 this.tracker.add(
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 this.isPreviewGenerationInProgress_ = true; 687 this.isPreviewGenerationInProgress_ = true;
685 }, 688 },
686 689
687 /** 690 /**
688 * Called when the preview area's preview generation is complete. 691 * Called when the preview area's preview generation is complete.
689 * @private 692 * @private
690 */ 693 */
691 onPreviewGenerationDone_: function() { 694 onPreviewGenerationDone_: function() {
692 this.isPreviewGenerationInProgress_ = false; 695 this.isPreviewGenerationInProgress_ = false;
693 this.printHeader_.isPrintButtonEnabled = true; 696 this.printHeader_.isPrintButtonEnabled = true;
697 this.nativeLayer_.previewReadyForTest();
694 this.printIfReady_(); 698 this.printIfReady_();
695 }, 699 },
696 700
697 /** 701 /**
698 * Called when the preview area's preview failed to load. 702 * Called when the preview area's preview failed to load.
699 * @private 703 * @private
700 */ 704 */
701 onPreviewGenerationFail_: function() { 705 onPreviewGenerationFail_: function() {
702 this.isPreviewGenerationInProgress_ = false; 706 this.isPreviewGenerationInProgress_ = false;
703 this.printHeader_.isPrintButtonEnabled = false; 707 this.printHeader_.isPrintButtonEnabled = false;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 * @private 887 * @private
884 */ 888 */
885 onPrivetPrintFailed_: function(event) { 889 onPrivetPrintFailed_: function(event) {
886 console.error('Privet printing failed with error code ' + 890 console.error('Privet printing failed with error code ' +
887 event.httpError); 891 event.httpError);
888 this.printHeader_.setErrorMessage( 892 this.printHeader_.setErrorMessage(
889 localStrings.getString('couldNotPrint')); 893 localStrings.getString('couldNotPrint'));
890 }, 894 },
891 895
892 /** 896 /**
897 * Called when the print preview settings need to be changed for testing.
898 * @param {Event} event Event object that contains the option that is to
899 * be changed and what to set that option.
900 * @private
901 */
902 onManipulateSettingsForTest_: function(event) {
903 if ('selectSaveAsPdfDestination' in event.settings) {
Dan Beam 2014/06/21 02:44:11 one strategy for splitting this up if ('selectSav
Dan Beam 2014/06/21 02:44:11 another strategy would be to simply make different
Aleksey Shlyapnikov 2014/06/23 19:34:46 I would support keeping native_layer.js involvemen
ivandavid 2014/06/24 18:49:52 I felt that keeping all the code in one function i
904 var destinations = this.destinationStore_.destinations();
905 var didSet = false;
906 for (var i = 0; i < destinations.length; i++) {
907 if (destinations[i].id == print_preview.Destination.GooglePromotedId.
908 SAVE_AS_PDF) {
Aleksey Shlyapnikov 2014/06/20 22:13:49 if (destinations[i].id == print_pre
ivandavid 2014/06/24 18:49:52 Done.
909 this.destinationStore_.selectDestination(destinations[i]);
910 didSet = true;
911 break;
Dan Beam 2014/06/21 02:44:11 return;
ivandavid 2014/06/24 18:49:52 Done.
912 }
913 }
914 if (!didSet)
Dan Beam 2014/06/21 02:44:11 ^ remove didSet
ivandavid 2014/06/24 18:49:52 Done.
915 this.nativeLayer_.previewFailedForTest();
Aleksey Shlyapnikov 2014/06/20 22:13:50 var pdfDestination = null; ... pdfDestination = de
ivandavid 2014/06/24 18:49:52 Done.
916 } else if ('layoutSettings' in event.settings) {
Aleksey Shlyapnikov 2014/06/20 22:13:50 I know that one liners do not require brackets, bu
Dan Beam 2014/06/21 02:27:51 an overwhelming majority of chrome/browser/resourc
ivandavid 2014/06/24 18:49:52 After removing all the unnecessary !element sort o
917 var element = document.querySelector(
918 event.settings.layoutSettings.portrait ?
919 '.layout-settings-portrait-radio' :
920 '.layout-settings-landscape-radio');
Aleksey Shlyapnikov 2014/06/20 22:13:50 4 more spaces indent for these two lines.
921 if (element) {
Dan Beam 2014/06/21 02:44:11 if (!element) { this.nativeLayer_.previewFailedF
922 if (element.clicked)
923 this.nativeLayer_.previewReadyForTest();
924 else
925 element.click();
926 } else
927 this.nativeLayer_.previewFailedForTest();
Aleksey Shlyapnikov 2014/06/20 22:13:49 I think if one part of the statement has braces th
Dan Beam 2014/06/21 02:27:51 yes, should've mentioned this ^
ivandavid 2014/06/24 18:49:52 Done.
928
929 } else if ('pageRange' in event.settings) {
930 var textbox = document.querySelector('.page-settings-custom-input');
931 if (textbox) {
Dan Beam 2014/06/21 02:44:11 if (!textbox) { this.nativeLayer_.previewFailedF
Aleksey Shlyapnikov 2014/06/23 19:34:46 I don't see my extensive comment on the same matte
ivandavid 2014/06/24 18:49:52 Done.
ivandavid 2014/06/24 18:49:52 I think I finally understand what you are saying a
932 if (textbox.value == event.settings.pageRange)
933 this.nativeLayer_.previewReadyForTest();
934 else {
935 // Assuming that the string format is correct for now.
936 // TODO: Will need a way to validate it just so the test doesn't
937 // hang mysteriously if the string isn't correct.
Aleksey Shlyapnikov 2014/06/20 22:13:49 No indent is required.
ivandavid 2014/06/24 18:49:52 I just got rid of the comment.
938 textbox.value = event.settings.pageRange;
939
940 // Triggers the re-rendering of the preview area as
941 // just setting the value isn't sufficient.
942 var radio = document.querySelector('.page-settings-custom-radio');
943 if (radio)
Dan Beam 2014/06/21 02:44:11 if (!radio) { ... usual failure stuff + return ...
944 radio.click();
945 else
946 this.nativeLayer_.previewFailedForTest();
947 }
948 } else
949 this.nativeLayer_.previewFailedForTest();
950 } else if ('headersAndFooters' in event.settings) {
951 var checkbox = document.querySelector(
952 '.header-footer-checkbox');
Aleksey Shlyapnikov 2014/06/20 22:13:49 Fits one line.
ivandavid 2014/06/24 18:49:52 Done.
ivandavid 2014/06/24 18:49:52 Done.
ivandavid 2014/06/24 18:49:52 Done.
953 if (checkbox) {
954 if (event.settings.headersAndFooters == checkbox.checked)
955 this.nativeLayer_.previewReadyForTest();
956 else
957 checkbox.click();
958 } else
959 this.nativeLayer_.previewFailedForTest();
960 } else if ('backgroundColorsAndImages' in event.settings) {
961 var checkbox = document.querySelector('.css-background-checkbox');
962 if (checkbox) {
963 if (event.settings.backgroundColorsAndImages == checkbox.checked)
964 this.nativeLayer_.previewReadyForTest();
965 else
966 checkbox.click();
967 } else
968 this.nativeLayer_.previewFailedForTest();
969 } else if ('margins' in event.settings) {
970 var element = document.querySelector('.margin-settings-select');
971 if (element) {
972 if (event.settings.margins == element.selectedIndex)
973 this.nativeLayer_.previewReadyForTest();
974 else if (event.settings.margins >= 0 &&
975 event.settings.margins < element.length) {
Aleksey Shlyapnikov 2014/06/20 22:13:50 Fix indent.
ivandavid 2014/06/24 18:49:52 Done.
976 element.selectedIndex = event.settings.margins;
977 this.marginSettings_.onSelectChange_();
978 } else
979 this.nativeLayer_.previewFailedForTest();
980 } else
981 this.nativeLayer_.previewFailedForTest();
982 }
Dan Beam 2014/06/21 02:44:11 feel free to return early or break this method int
983 },
984
985 /**
893 * Called when the open-cloud-print-dialog link is clicked. Opens the Google 986 * Called when the open-cloud-print-dialog link is clicked. Opens the Google
894 * Cloud Print web dialog. 987 * Cloud Print web dialog.
895 * @private 988 * @private
896 */ 989 */
897 onCloudPrintDialogLinkClick_: function() { 990 onCloudPrintDialogLinkClick_: function() {
898 assert(this.uiState_ == PrintPreview.UiState_.READY, 991 assert(this.uiState_ == PrintPreview.UiState_.READY,
899 'Opening Google Cloud Print dialog when not in ready state: ' + 992 'Opening Google Cloud Print dialog when not in ready state: ' +
900 this.uiState_); 993 this.uiState_);
901 setIsVisible($('cloud-print-dialog-throbber'), true); 994 setIsVisible($('cloud-print-dialog-throbber'), true);
902 this.setIsEnabled_(false); 995 this.setIsEnabled_(false);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 <include src="search/recent_destination_list.js"/> 1127 <include src="search/recent_destination_list.js"/>
1035 <include src="search/destination_list_item.js"/> 1128 <include src="search/destination_list_item.js"/>
1036 <include src="search/destination_search.js"/> 1129 <include src="search/destination_search.js"/>
1037 <include src="search/search_box.js"/> 1130 <include src="search/search_box.js"/>
1038 <include src="search/fedex_tos.js"/> 1131 <include src="search/fedex_tos.js"/>
1039 1132
1040 window.addEventListener('DOMContentLoaded', function() { 1133 window.addEventListener('DOMContentLoaded', function() {
1041 printPreview = new print_preview.PrintPreview(); 1134 printPreview = new print_preview.PrintPreview();
1042 printPreview.initialize(); 1135 printPreview.initialize();
1043 }); 1136 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698