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

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: Refactored print_preview.js 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 if (global['onManipulateSettingsForTest']) {
698 this.nativeLayer_.doneManipulatingSettings();
Aleksey Shlyapnikov 2014/06/18 21:57:35 Call it this.nativeLayer_.previewReady(), call it
ivandavid 2014/06/20 01:00:26 Done.
699 }
694 this.printIfReady_(); 700 this.printIfReady_();
695 }, 701 },
696 702
697 /** 703 /**
698 * Called when the preview area's preview failed to load. 704 * Called when the preview area's preview failed to load.
699 * @private 705 * @private
700 */ 706 */
701 onPreviewGenerationFail_: function() { 707 onPreviewGenerationFail_: function() {
702 this.isPreviewGenerationInProgress_ = false; 708 this.isPreviewGenerationInProgress_ = false;
703 this.printHeader_.isPrintButtonEnabled = false; 709 this.printHeader_.isPrintButtonEnabled = false;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 * @param {Event} event Event object representing the failure. 888 * @param {Event} event Event object representing the failure.
883 * @private 889 * @private
884 */ 890 */
885 onPrivetPrintFailed_: function(event) { 891 onPrivetPrintFailed_: function(event) {
886 console.error('Privet printing failed with error code ' + 892 console.error('Privet printing failed with error code ' +
887 event.httpError); 893 event.httpError);
888 this.printHeader_.setErrorMessage( 894 this.printHeader_.setErrorMessage(
889 localStrings.getString('couldNotPrint')); 895 localStrings.getString('couldNotPrint'));
890 }, 896 },
891 897
898 onManipulateSettingsForTest_: function(event) {
899 if (event.messageName == 'SAVE_AS_PDF') {
900 this.destinationStore_.selectDefaultDestination_();
901 }
902 else if (event.messageName == 'LAYOUT_SETTINGS') {
903 var layoutChoice = event.isPortrait ?
904 'layout-settings-portrait-radio' :
905 'layout-settings-landscape-radio';
906
907 var element = document.getElementsByClassName(layoutChoice)[0];
908 if (element) {
909 element.click();
Aleksey Shlyapnikov 2014/06/18 21:57:36 What if it is already selected?
ivandavid 2014/06/20 01:00:25 Done.
ivandavid 2014/06/20 01:00:26 I rewrote it so that if it is already selected, it
910 } else {
911 this.nativeLayer_.doneManipulatingSettings();
912 }
Aleksey Shlyapnikov 2014/06/18 21:57:36 So if element is not there, test assumes that ever
ivandavid 2014/06/20 01:00:25 I rewrote this so that if the element == null, the
ivandavid 2014/06/20 01:00:26 Done.
913 }
914 else if (event.messageName == 'PAGE_NUMBERS') {
915 if (event.pageNumbers != '') {
916 var pageSettingsCustomInput = document.getElementsByClassName(
917 'page-settings-custom-input')[0];
918 if (pageSettingsCustomInput) {
919 pageSettingsCustomInput.value = event.pageSettings;
Aleksey Shlyapnikov 2014/06/18 21:57:36 What if it's the same, does it still trigger the p
ivandavid 2014/06/20 01:00:26 I am actually not sure. I rewrote this entire sect
ivandavid 2014/06/20 01:00:26 Done.
920 }
921 } else {
922 this.nativeLayer_.doneManipulatingSettings();
Aleksey Shlyapnikov 2014/06/18 21:57:36 But nothing was actually done, why do we notify he
ivandavid 2014/06/20 01:00:26 Done.
923 }
924 }
925 else if (event.messageName == 'HEADERS_AND_FOOTERS') {
926 var checkbox = document.getElementsByClassName(
927 'header-footer-checkbox')[0];
928 if (checkbox) {
929 if ((event.headersAndFooters && checkbox.checked) ||
Aleksey Shlyapnikov 2014/06/18 21:57:36 Why this condition is in brackets and other is not
ivandavid 2014/06/20 01:00:26 Fixed it. It was a typo.
ivandavid 2014/06/20 01:00:26 Done.
930 !event.headersAndFooters && !checkbox.checked) {
Aleksey Shlyapnikov 2014/06/18 21:57:36 Why not just (event.headersAndFooters == checkbox.
ivandavid 2014/06/20 01:00:25 Fixed in patch set 13. Same change made for the ot
ivandavid 2014/06/20 01:00:25 Done.
931 this.nativeLayer_.doneManipulatingSettings();
932 } else {
933 this.otherOptionsSettings_.headerFooterCheckbox_.click();
Aleksey Shlyapnikov 2014/06/18 21:57:35 You have your checkbox already, why refer to this.
ivandavid 2014/06/20 01:00:25 Done.
934 }
935 }
936 }
937 else if (event.messageName == 'BACKGROUND_COLORS_AND_IMAGES') {
938 var checkbox = document.getElementsByClassName(
939 'css-background-checkbox')[0];
940 if (checkbox) {
941 if ((event.backgroundColorsAndImages && checkbox.checked) ||
942 !event.backgroundColorsAndImages && !checkbox.checked) {
943 this.nativeLayer_.doneManipulatingSettings();
944 }
945 else {
946 this.otherOptionsSettings_.cssBackgroundCheckbox_.click();
947 }
948 }
949 }
950 else if (event.messageName == 'MARGINS') {
Aleksey Shlyapnikov 2014/06/18 21:57:36 Move all elses to the same line with {
ivandavid 2014/06/20 01:00:26 Done.
951 var marginSettingsSelect =
952 document.getElementsByClassName('margin-settings-select')[0];
953 var index = parseInt(event.margins, 10);
954 if (marginSettingsSelect && index != 0) {
Aleksey Shlyapnikov 2014/06/18 21:57:36 Zero index is still valid. Use isNaN to check for
ivandavid 2014/06/20 01:00:26 Rewrote this entire section to account for this an
955 marginSettingsSelect.selectedIndex = index;
956 this.marginSettings_.onSelectChange_();
957 } else {
958 this.nativeLayer_.doneManipulatingSettings();
959 }
960 }
961 },
962
892 /** 963 /**
893 * Called when the open-cloud-print-dialog link is clicked. Opens the Google 964 * Called when the open-cloud-print-dialog link is clicked. Opens the Google
894 * Cloud Print web dialog. 965 * Cloud Print web dialog.
895 * @private 966 * @private
896 */ 967 */
897 onCloudPrintDialogLinkClick_: function() { 968 onCloudPrintDialogLinkClick_: function() {
898 assert(this.uiState_ == PrintPreview.UiState_.READY, 969 assert(this.uiState_ == PrintPreview.UiState_.READY,
899 'Opening Google Cloud Print dialog when not in ready state: ' + 970 'Opening Google Cloud Print dialog when not in ready state: ' +
900 this.uiState_); 971 this.uiState_);
901 setIsVisible($('cloud-print-dialog-throbber'), true); 972 setIsVisible($('cloud-print-dialog-throbber'), true);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 <include src="search/recent_destination_list.js"/> 1105 <include src="search/recent_destination_list.js"/>
1035 <include src="search/destination_list_item.js"/> 1106 <include src="search/destination_list_item.js"/>
1036 <include src="search/destination_search.js"/> 1107 <include src="search/destination_search.js"/>
1037 <include src="search/search_box.js"/> 1108 <include src="search/search_box.js"/>
1038 <include src="search/fedex_tos.js"/> 1109 <include src="search/fedex_tos.js"/>
1039 1110
1040 window.addEventListener('DOMContentLoaded', function() { 1111 window.addEventListener('DOMContentLoaded', function() {
1041 printPreview = new print_preview.PrintPreview(); 1112 printPreview = new print_preview.PrintPreview();
1042 printPreview.initialize(); 1113 printPreview.initialize();
1043 }); 1114 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698