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

Unified 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 onManipulateSettings_() 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 side-by-side diff with in-line comments
Download patch
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..2cfedb67852d46bc1ed5f277e80df7d5faa27898 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,96 @@ 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.
Dan Beam 2014/06/20 02:45:17 @private
Aleksey Shlyapnikov 2014/06/20 17:27:22 * @param {Event} event Event object that contains
ivandavid 2014/06/20 21:31:45 Done.
ivandavid 2014/06/20 21:31:45 Done.
+ */
+ onManipulateSettingsForTest_: function(event) {
+ if ('SAVE_AS_PDF' in event.settings) {
Aleksey Shlyapnikov 2014/06/20 17:27:22 ALL_CAPS property names look awkward and misleadin
ivandavid 2014/06/20 21:31:45 Done.
+ this.destinationStore_.selectDefaultDestination_();
Aleksey Shlyapnikov 2014/06/20 17:27:22 Since you added the failure handling logic, check
ivandavid 2014/06/20 21:31:44 Done.
+ } else if ('LAYOUT_SETTINGS' in event.settings) {
+ var element = document.querySelector(
+ event.settings['LAYOUT_SETTINGS'] ?
Aleksey Shlyapnikov 2014/06/20 17:27:22 var element = document.querySelector(event.setting
ivandavid 2014/06/20 21:31:45 Done.
+ '.layout-settings-portrait-radio' :
+ '.layout-settings-landscape-radio');
+ if (element) {
+ if (element.clicked) {
Aleksey Shlyapnikov 2014/06/20 17:27:22 Crash here will also fail the test, right? Why add
ivandavid 2014/06/20 21:31:45 I am not sure what you mean here. Is the problem t
Aleksey Shlyapnikov 2014/06/20 22:13:49 No, what I mean is the test will crash if you remo
+ this.nativeLayer_.previewReady();
+ } else {
+ element.click();
+ }
+ } else {
+ this.nativeLayer_.previewFailed();
+ }
+ } else if ('PAGE_NUMBERS' in event.settings) {
+ var textbox = document.querySelector('.page-settings-custom-input');
+ if (textbox) {
+ if (textbox.value == event.settings['PAGE_NUMBERS']) {
Aleksey Shlyapnikov 2014/06/20 17:27:22 event.settings.pageRange The same for all other s
ivandavid 2014/06/20 21:31:45 Done.
+ 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'];
+
+ // Triggers the re-rendering of the preview area as
+ // just setting the value isn't sufficient.
+ var radio = document.querySelector(
+ '.page-settings-custom-radio');
Aleksey Shlyapnikov 2014/06/20 17:27:22 Fits one line.
ivandavid 2014/06/20 21:31:45 Done.
+ 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');
Aleksey Shlyapnikov 2014/06/20 17:27:22 It does fit into one line.
ivandavid 2014/06/20 21:31:45 Done.
+ if (checkbox) {
+ if (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');
Aleksey Shlyapnikov 2014/06/20 17:27:22 Fits one line.
ivandavid 2014/06/20 21:31:45 Done.
+ if (checkbox) {
+ if (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');
Aleksey Shlyapnikov 2014/06/20 17:27:22 Fits one line.
ivandavid 2014/06/20 21:31:45 Done.
+ 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

Powered by Google App Engine
This is Rietveld 408576698