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..0809d7b9cd44429e8f9badf3ef9f33e54e28ebe6 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_.previewReadyForTest(); |
this.printIfReady_(); |
}, |
@@ -890,6 +894,144 @@ cr.define('print_preview', function() { |
}, |
/** |
+ * Called when the print preview settings need to be changed for testing. |
+ * @param {Event} event Event object that contains the option that is to |
+ * be changed and what to set that option. |
+ * @private |
+ */ |
+ onManipulateSettingsForTest_: function(event) { |
+ if ('selectSaveAsPdfDestination' in event.settings) { |
+ this.saveAsPdfForTest_(); // No parameters needed. |
ivandavid
2014/07/03 03:12:03
I split up this function and not native_layer.onMa
|
+ } else if ('layoutSettings' in event.settings) { |
+ this.setLayoutSettingsForTest_(event.settings.layoutSettings.portrait); |
+ } else if ('pageRange' in event.settings) { |
+ this.setPageRangeForTest_(event.settings.pageRange); |
+ } else if ('headersAndFooters' in event.settings) { |
+ this.setHeadersAndFootersForTest_(event.settings.headersAndFooters); |
+ } else if ('backgroundColorsAndImages' in event.settings) { |
+ this.setBackgroundColorsAndImagesForTest_( |
+ event.settings.backgroundColorsAndImages); |
+ } else if ('margins' in event.settings) { |
+ this.setMarginsForTest_(event.settings.margins); |
+ } |
+ }, |
+ |
+ /** |
+ * Called by onManipulateSettingsForTest_(). Sets the print destination |
+ * as a pdf. |
+ * @private |
+ */ |
+ saveAsPdfForTest_: function() { |
+ if (print_preview.Destination.GooglePromotedId.SAVE_AS_PDF == |
+ this.destinationStore_.selectedDestination.id) { |
+ this.nativeLayer_.previewReadyForTest(); |
+ return; |
+ } |
+ |
+ var destinations = this.destinationStore_.destinations(); |
+ var pdfDestination = null; |
+ for (var i = 0; i < destinations.length; i++) { |
+ if (destinations[i].id == |
+ print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
+ pdfDestination = destinations[i]; |
+ break; |
+ } |
+ } |
+ |
+ if (pdfDestination) |
+ this.destinationStore_.selectDestination(pdfDestination); |
+ else |
+ this.nativeLayer_.previewFailedForTest(); |
Dan Beam
2014/07/07 23:08:12
indent off
ivandavid
2014/07/08 01:07:42
Done.
|
+ }, |
+ |
+ /** |
+ * Called by onManipulateSettingsForTest_(). Sets the layout settings to |
+ * either portrait or landscape. |
+ * @param {boolean} portrait If true then the portrait settings is to be |
Dan Beam
2014/07/07 23:08:12
nit: @param {boolean} portrait Whether to use port
ivandavid
2014/07/08 01:07:42
Done.
|
+ * set, otherwise, the landscape settings is set. |
+ * @private |
+ */ |
+ setLayoutSettingsForTest_: function(portrait) { |
+ var element = document.querySelector( |
+ portrait ? |
+ '.layout-settings-portrait-radio' : |
+ '.layout-settings-landscape-radio'); |
+ if (element.checked) |
+ this.nativeLayer_.previewReadyForTest(); |
+ else |
+ element.click(); |
Dan Beam
2014/07/07 23:08:12
indent off
ivandavid
2014/07/08 01:07:42
Done.
|
+ }, |
+ |
+ /** |
+ * Called by onManipulateSettingsForTest_(). Sets the page range for |
+ * for the print preview settings. |
+ * @param {string} pageRange Sets the page range to the desired value(s). |
Dan Beam
2014/07/07 23:08:12
nit
* @param {string} pageRange A comma separated
ivandavid
2014/07/08 01:07:42
Done.
|
+ * |
+ * |pageRange| is a comma separated page range. |
+ * Example: "1-5,9" will print pages 1 through 5 and page 9. |
+ * The pages specified must be less than or equal to the maximum |
+ * page number. |
+ * @private |
+ */ |
+ setPageRangeForTest_: function(pageRange) { |
+ var textbox = document.querySelector('.page-settings-custom-input'); |
+ if (textbox.value == pageRange) { |
+ this.nativeLayer_.previewReadyForTest(); |
+ } else { |
+ textbox.value = pageRange; |
+ document.querySelector('.page-settings-custom-radio').click(); |
Dan Beam
2014/07/07 23:08:12
can you just do .click() event when the value's th
ivandavid
2014/07/08 01:07:42
No, it doesn't cause the preview area to be genera
Dan Beam
2014/07/08 04:25:13
ok
|
+ } |
+ }, |
+ |
+ /** |
+ * Called by onManipulateSettings_(). Checks or unchecks the headers and |
+ * footers option on print preview. |
+ * @param {boolean} headersAndFooters If true, the checkbox should be |
Dan Beam
2014/07/07 23:08:12
Whether the "Headers and footer" checkbox should b
ivandavid
2014/07/08 01:07:42
Done.
|
+ * checked. Otherwise it should be unchecked. |
+ * @private |
+ */ |
+ setHeadersAndFootersForTest_: function(headersAndFooters) { |
+ var checkbox = document.querySelector('.header-footer-checkbox'); |
+ if (headersAndFooters == checkbox.checked) |
+ this.nativeLayer_.previewReadyForTest(); |
+ else |
+ checkbox.click(); |
+ }, |
+ |
+ /** |
+ * Called by onManipulateSettings_(). Checks or unchecks the background |
+ * colors and images option on print preview. |
+ * @param {boolean} backgroundColorsAndImages If true, the checkbox should |
+ * be checked. Otherwise it should be unchecked. |
+ * @private |
+ */ |
+ setBackgroundColorsAndImagesForTest_: function(backgroundColorsAndImages) { |
+ var checkbox = document.querySelector('.css-background-checkbox'); |
+ if (backgroundColorsAndImages == checkbox.checked) |
+ this.nativeLayer_.previewReadyForTest(); |
+ else |
+ checkbox.click(); |
+ }, |
+ |
+ /** |
+ * Called by onManipulateSettings_(). Sets the margin settings |
+ * that are desired. Custom margin settings aren't currently supported. |
+ * @param {number} margins The desired margins combobox index. Must be |
+ * a valid index or else the test fails. |
Dan Beam
2014/07/07 23:08:12
@private
ivandavid
2014/07/08 01:07:42
Done.
|
+ */ |
+ setMarginsForTest_: function(margins) { |
+ var combobox = document.querySelector('.margin-settings-select'); |
+ if (margins == combobox.selectedIndex) { |
+ this.nativeLayer_.previewReadyForTest(); |
+ } else if (margins >= 0 && margins < combobox.length) { |
+ combobox.selectedIndex = margins; |
+ this.marginSettings_.onSelectChange_(); |
+ } else { |
+ this.nativeLayer_.previewFailedForTest(); |
+ } |
+ }, |
+ |
+ /** |
ivandavid
2014/07/08 01:07:42
Sorry for the double indents. I was writing python
|
* Called when the open-cloud-print-dialog link is clicked. Opens the Google |
* Cloud Print web dialog. |
* @private |