Index: chrome/browser/resources/print_preview/print_preview.js |
diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js |
index ac3a0ab789135db2746d6fe3b522398b759867d9..559eda17ea0ff57afcbe78d3b641dafbc1e89c6d 100644 |
--- a/chrome/browser/resources/print_preview/print_preview.js |
+++ b/chrome/browser/resources/print_preview/print_preview.js |
@@ -285,7 +285,10 @@ cr.define('print_preview', function() { |
this.nativeLayer_, |
print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED, |
this.onPrivetPrintFailed_.bind(this)); |
- |
+ this.tracker.add( |
+ this.nativeLayer_, |
+ print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST, |
+ this.onManipulateSettingsForTest_.bind(this)); |
this.tracker.add( |
$('system-dialog-link'), |
@@ -691,6 +694,9 @@ cr.define('print_preview', function() { |
onPreviewGenerationDone_: function() { |
this.isPreviewGenerationInProgress_ = false; |
this.printHeader_.isPrintButtonEnabled = true; |
+ if (global['onManipulateSettingsForTest']) { |
+ this.nativeLayer_.doneManipulatingSettings(); |
+ } |
this.printIfReady_(); |
}, |
@@ -889,6 +895,99 @@ cr.define('print_preview', function() { |
localStrings.getString('couldNotPrint')); |
}, |
+ onManipulateSettingsForTest_: function(event) { |
+ if (event.messageName == 'SAVE_AS_PDF') { |
+ this.destinationStore_.selectDefaultDestination_(); |
+ } |
+ else if (event.messageName == 'LAYOUT_SETTINGS') { |
+ if (event.isPortrait == true) { |
+ var portrait = document.getElementsByClassName( |
+ 'layout-settings-portrait-radio')[0]; |
+ if (portrait) { |
+ portrait.click(); |
+ } else { |
+ this.nativeLayer_.doneManipulatingSettings(); |
+ } |
+ } else { |
+ var landscape = document.getElementsByClassName( |
+ 'layout-settings-landscape-radio')[0]; |
+ if (landscape) { |
+ landscape.click(); |
+ } else { |
ivandavid
2014/06/18 00:26:00
I think this handles this situation. I will have t
Lei Zhang
2014/06/18 00:47:58
The entire layout settings block here can be simpl
|
+ this.nativeLayer_.doneManipulatingSettings(); |
+ } |
+ } |
+ } |
+ else if (event.messageName == 'PAGE_NUMBERS') { |
+ if (event.pageNumbers != '') { |
+ var pageSettingsCustomInput = document.getElementsByClassName( |
+ 'page-settings-custom-input')[0]; |
+ if (pageSettingsCustomInput) { |
+ pageSettingsCustomInput.value = event.pageSettings; |
+ } |
+ } else { |
+ this.nativeLayer_.doneManipulatingSettings(); |
+ } |
+ } |
+ else if (event.messageName == 'HEADERS_AND_FOOTERS') { |
+ if (event.headersAndFooters == false) { |
Lei Zhang
2014/06/18 00:47:58
The if and else cases here also have a lot of dupl
|
+ var headerFooterCheckbox = document.getElementsByClassName( |
+ 'header-footer-checkbox')[0]; |
+ if (headerFooterCheckbox) { |
+ if (headerFooterCheckbox.checked == true) { |
Lei Zhang
2014/06/18 00:47:58
In general, I think in JS you can just do: if (foo
|
+ this.otherOptionsSettings_.headerFooterCheckbox_.click(); |
+ } else { |
+ this.nativeLayer_.doneManipulatingSettings(); |
+ } |
+ } |
+ } else { |
+ var headerFooterCheckbox = document.getElementsByClassName( |
+ 'header-footer-checkbox')[0]; |
+ if (headerFooterCheckbox) { |
+ if (headerFooterCheckbox.checked == false) { |
+ this.otherOptionsSettings_.headerFooterCheckbox_.click(); |
+ } else { |
+ this.nativeLayer_.doneManipulatingSettings(); |
+ } |
+ } |
+ } |
+ } |
+ else if (event.messageName == 'BACKGROUND_COLORS_AND_IMAGES') { |
+ if (event.backgroundColorsAndImages == true) { |
+ var backgroundCheckbox = document.getElementsByClassName( |
+ 'css-background-checkbox')[0]; |
+ if (backgroundCheckbox) { |
+ if (backgroundCheckbox.checked == false) { |
+ this.otherOptionsSettings_.cssBackgroundCheckbox_.click(); |
+ } else { |
+ this.nativeLayer_.doneManipulatingSettings(); |
+ } |
+ } |
+ } else { |
+ var backgroundCheckbox = document.getElementsByClassName( |
+ 'css-background-checkbox')[0]; |
+ if (backgroundCheckbox) { |
+ if (backgroundCheckbox.checked == true) { |
+ this.otherOptionsSettings_.cssBackgroundCheckbox_.click(); |
+ } else { |
+ this.nativeLayer_.doneManipulatingSettings(); |
+ } |
+ } |
+ } |
+ } |
+ else if (event.messageName == 'MARGINS') { |
+ var marginSettingsSelect = |
+ document.getElementsByClassName('margin-settings-select')[0]; |
+ var index = parseInt(event.margins, 10); |
+ if (marginSettingsSelect && index != 0) { |
+ marginSettingsSelect.selectedIndex = index; |
+ this.marginSettings_.onSelectChange_(); |
+ } else { |
+ this.nativeLayer_.doneManipulatingSettings(); |
+ } |
+ } |
+ }, |
+ |
/** |
* Called when the open-cloud-print-dialog link is clicked. Opens the Google |
* Cloud Print web dialog. |