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..28219eff25a6052589e36c7d1ee6f05fe56875ee 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,95 @@ 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) { |
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
|
+ var destinations = this.destinationStore_.destinations(); |
+ var didSet = false; |
+ for (var i = 0; i < destinations.length; i++) { |
+ if (destinations[i].id == print_preview.Destination.GooglePromotedId. |
+ 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.
|
+ this.destinationStore_.selectDestination(destinations[i]); |
+ didSet = true; |
+ break; |
Dan Beam
2014/06/21 02:44:11
return;
ivandavid
2014/06/24 18:49:52
Done.
|
+ } |
+ } |
+ if (!didSet) |
Dan Beam
2014/06/21 02:44:11
^ remove didSet
ivandavid
2014/06/24 18:49:52
Done.
|
+ this.nativeLayer_.previewFailedForTest(); |
Aleksey Shlyapnikov
2014/06/20 22:13:50
var pdfDestination = null;
...
pdfDestination = de
ivandavid
2014/06/24 18:49:52
Done.
|
+ } 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
|
+ var element = document.querySelector( |
+ event.settings.layoutSettings.portrait ? |
+ '.layout-settings-portrait-radio' : |
+ '.layout-settings-landscape-radio'); |
Aleksey Shlyapnikov
2014/06/20 22:13:50
4 more spaces indent for these two lines.
|
+ if (element) { |
Dan Beam
2014/06/21 02:44:11
if (!element) {
this.nativeLayer_.previewFailedF
|
+ if (element.clicked) |
+ this.nativeLayer_.previewReadyForTest(); |
+ else |
+ element.click(); |
+ } else |
+ 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.
|
+ |
+ } else if ('pageRange' in event.settings) { |
+ var textbox = document.querySelector('.page-settings-custom-input'); |
+ 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
|
+ if (textbox.value == event.settings.pageRange) |
+ this.nativeLayer_.previewReadyForTest(); |
+ 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. |
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.
|
+ textbox.value = event.settings.pageRange; |
+ |
+ // Triggers the re-rendering of the preview area as |
+ // just setting the value isn't sufficient. |
+ var radio = document.querySelector('.page-settings-custom-radio'); |
+ if (radio) |
Dan Beam
2014/06/21 02:44:11
if (!radio) { ... usual failure stuff + return ...
|
+ radio.click(); |
+ else |
+ this.nativeLayer_.previewFailedForTest(); |
+ } |
+ } else |
+ this.nativeLayer_.previewFailedForTest(); |
+ } else if ('headersAndFooters' in event.settings) { |
+ var checkbox = document.querySelector( |
+ '.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.
|
+ if (checkbox) { |
+ if (event.settings.headersAndFooters == checkbox.checked) |
+ this.nativeLayer_.previewReadyForTest(); |
+ else |
+ checkbox.click(); |
+ } else |
+ this.nativeLayer_.previewFailedForTest(); |
+ } else if ('backgroundColorsAndImages' in event.settings) { |
+ var checkbox = document.querySelector('.css-background-checkbox'); |
+ if (checkbox) { |
+ if (event.settings.backgroundColorsAndImages == checkbox.checked) |
+ this.nativeLayer_.previewReadyForTest(); |
+ else |
+ checkbox.click(); |
+ } else |
+ this.nativeLayer_.previewFailedForTest(); |
+ } else if ('margins' in event.settings) { |
+ var element = document.querySelector('.margin-settings-select'); |
+ if (element) { |
+ if (event.settings.margins == element.selectedIndex) |
+ this.nativeLayer_.previewReadyForTest(); |
+ else if (event.settings.margins >= 0 && |
+ event.settings.margins < element.length) { |
Aleksey Shlyapnikov
2014/06/20 22:13:50
Fix indent.
ivandavid
2014/06/24 18:49:52
Done.
|
+ element.selectedIndex = event.settings.margins; |
+ this.marginSettings_.onSelectChange_(); |
+ } else |
+ this.nativeLayer_.previewFailedForTest(); |
+ } else |
+ this.nativeLayer_.previewFailedForTest(); |
+ } |
Dan Beam
2014/06/21 02:44:11
feel free to return early or break this method int
|
+ }, |
+ |
+ /** |
* Called when the open-cloud-print-dialog link is clicked. Opens the Google |
* Cloud Print web dialog. |
* @private |