Chromium Code Reviews| 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..d2b014ff5e3cfad847fbb46a39e4d704b627ea52 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,7 @@ cr.define('print_preview', function() { |
| onPreviewGenerationDone_: function() { |
| this.isPreviewGenerationInProgress_ = false; |
| this.printHeader_.isPrintButtonEnabled = true; |
| + this.nativeLayer_.previewReady(); |
| this.printIfReady_(); |
| }, |
| @@ -890,6 +894,97 @@ cr.define('print_preview', function() { |
| }, |
| /** |
| + * Called when the print preview settings need to be changed for testing. |
| + * @param {Event} event Event object that contains that option that is to |
| + * be changed and what to set that option. |
| + */ |
| + onManipulateSettingsForTest_: function(event) { |
| + if ('SAVE_AS_PDF' in event.settings) { |
| + this.destinationStore_.selectDefaultDestination_(); |
| + } else if ('LAYOUT_SETTINGS' in event.settings) { |
| + var element = document.querySelector( |
| + event.settings['LAYOUT_SETTINGS'] ? |
| + '.layout-settings-portrait-radio' : |
| + '.layout-settings-landscape-radio'); |
| + if (element) { |
| + if (element.clicked) { |
| + this.nativeLayer_.previewReady(); |
| + } else { |
| + element.click(); |
| + } |
| + } else { |
| + this.nativeLayer_.previewFailed(); |
| + } |
| + } else if ('PAGE_NUMBERS' in event.settings) { |
|
ivandavid
2014/06/20 01:00:26
Rewrote the whole section because it wasn't workin
|
| + var textbox = document.querySelector('.page-settings-custom-input'); |
| + if (textbox) { |
| + if (textbox.value == event.settings['PAGE_NUMBERS']) { |
| + this.nativeLayer_.previewReady(); |
| + } else { |
| + // Assuming that the string format is correct for now. |
| + // TODO: Will need a way to validate it just so the test doesn't |
| + // hang mysteriously if the string isn't correct. |
| + textbox.value = event.settings['PAGE_NUMBERS']; |
| + var radio = document.querySelector( |
| + '.page-settings-custom-radio'); |
| + if (radio) { |
| + radio.click(); |
| + } else { |
| + this.nativeLayer_.previewFailed(); |
| + } |
| + } |
| + } else { |
| + this.nativeLayer_.previewFailed(); |
| + } |
| + } else if ('HEADERS_AND_FOOTERS' in event.settings) { |
| + var checkbox = document.querySelector( |
| + '.header-footer-checkbox'); |
| + if (checkbox) { |
| + if ((event.settings['HEADERS_AND_FOOTERS'] && checkbox.checked) || |
| + (!event.settings['HEADERS_AND_FOOTERS'] && !checkbox.checked)) { |
| + this.nativeLayer_.previewReady(); |
| + } else { |
| + checkbox.click(); |
| + } |
| + } else { |
| + this.nativeLayer_.previewFailed(); |
| + } |
| + } else if ('BACKGROUND_COLORS_AND_IMAGES' in event.settings) { |
| + var checkbox = document.querySelector( |
| + '.css-background-checkbox'); |
| + if (checkbox) { |
| + if ((event.settings['BACKGROUND_COLORS_AND_IMAGES'] && |
| + checkbox.checked) || |
| + (!event.settings['BACKGROUND_COLORS_AND_IMAGES'] && |
| + !checkbox.checked)) { |
| + this.nativeLayer_.previewReady(); |
| + } else { |
| + checkbox.click(); |
| + } |
| + } else { |
| + this.nativeLayer_.previewFailed(); |
| + } |
| + } else if ('MARGINS' in event.settings) { |
| + var element = |
| + document.querySelector('.margin-settings-select'); |
| + var index = parseInt(event.margins, 10); |
| + if (element) { |
| + if (event.settings['MARGINS'] == element.selectedIndex) { |
| + this.nativeLayer_.previewReady(); |
| + } else if (event.settings['MARGINS'] >= 0 && |
| + event.settings['MARGINS'] < element.length) { |
| + element.selectedIndex = event.settings['MARGINS']; |
| + this.marginSettings_.onSelectChange_(); |
| + } else { |
| + this.nativeLayer_.previewFailed(); |
| + } |
| + } else { |
| + this.nativeLayer_.previewFailed(); |
| + } |
| + } |
| + }, |
| + |
| + /** |
| * Called when the open-cloud-print-dialog link is clicked. Opens the Google |
| * Cloud Print web dialog. |
| * @private |