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

Side by Side Diff: chrome/test/data/webui/print_preview.js

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix fit-to-page tests Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * Test fixture for print preview WebUI testing. 6 * Test fixture for print preview WebUI testing.
7 * @constructor
7 * @extends {testing.Test} 8 * @extends {testing.Test}
8 * @constructor
9 */ 9 */
10 function PrintPreviewWebUITest() {} 10 function PrintPreviewWebUITest() {
11 testing.Test.call(this);
12 this.nativeLayer_ = null;
13 this.initialSettings_ = null;
14 this.localDestinationInfos_ = null;
15 }
11 16
12 PrintPreviewWebUITest.prototype = { 17 PrintPreviewWebUITest.prototype = {
13 __proto__: testing.Test.prototype, 18 __proto__: testing.Test.prototype,
14 19
15 /** 20 /**
16 * Browse to the sample page, cause print preview & call preLoad(). 21 * Browse to the sample page, cause print preview & call preLoad().
17 * @type {string} 22 * @type {string}
18 * @override 23 * @override
19 */ 24 */
20 browsePrintPreload: 'print_preview_hello_world_test.html', 25 browsePrintPreload: 'print_preview_hello_world_test.html',
21 26
22 /** 27 /**
23 * Register a mock handler to ensure expectations are met and print preview 28 * Stub out low-level functionality like the NativeLayer and
24 * behaves correctly. 29 * CloudPrintInterface.
25 * @type {Function}
26 * @this {PrintPreviewWebUITest} 30 * @this {PrintPreviewWebUITest}
27 * @override 31 * @override
28 */ 32 */
29 preLoad: function() { 33 preLoad: function() {
30 this.makeAndRegisterMockHandler(['getInitialSettings', 34 window.addEventListener('DOMContentLoaded', function() {
31 'getPrinters', 35 function NativeLayerStub() {
32 'getPreview', 36 cr.EventTarget.call(this);
33 'print', 37 }
34 'getPrinterCapabilities', 38 NativeLayerStub.prototype = {
35 'showSystemDialog', 39 __proto__: cr.EventTarget.prototype,
36 'morePrinters', 40 startGetInitialSettings: function() {},
37 'signIn', 41 startGetLocalDestinations: function() {},
38 'addCloudPrinter', 42 startGetLocalDestinationCapabilities: function(destinationId) {}
39 'manageCloudPrinters', 43 };
40 'manageLocalPrinters',
41 'closePrintPreviewTab',
42 'hidePreview',
43 'cancelPendingPrintRequest',
44 'saveLastPrinter',
45 ]);
46 44
47 // Register stubs for methods expected to be called before tests 45 this.nativeLayer_ = new NativeLayerStub();
48 // run. Specific expectations can be made in the tests themselves. 46 printPreview.nativeLayer_ = this.nativeLayer_;
49 this.mockHandler.stubs().getInitialSettings().
50 will(callFunction(function() {
51 setDefaultPrinter('FooDevice');
52 }));
53 this.mockHandler.stubs().getPrinterCapabilities(NOT_NULL).
54 will(callFunction(function() {
55 updateWithPrinterCapabilities({
56 disableColorOption: true,
57 setColorAsDefault: true,
58 disableCopiesOption: true,
59 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX,
60 });
61 }));
62 var savedArgs = new SaveMockArguments();
63 this.mockHandler.stubs().getPreview(savedArgs.match(NOT_NULL)).
64 will(callFunctionWithSavedArgs(savedArgs, function(args) {
65 updatePrintPreview(1, JSON.parse(args[0]).requestID);
66 }));
67 47
68 this.mockHandler.stubs().getPrinters(). 48 function CloudPrintInterfaceStub() {
69 will(callFunction(function() { 49 cr.EventTarget.call(this);
70 setPrinters([{ 50 }
71 printerName: 'FooName', 51 CloudPrintInterfaceStub.prototype = {
72 deviceName: 'FooDevice', 52 __proto__: cr.EventTarget.prototype,
73 }, { 53 search: function(isRecent) {}
74 printerName: 'BarName', 54 };
75 deviceName: 'BarDevice', 55 var oldCpInterfaceEventType = cloudprint.CloudPrintInterface.EventType;
76 }, 56 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub;
77 ]); 57 cloudprint.CloudPrintInterface.EventType = oldCpInterfaceEventType;
78 }));
79 58
80 this.makeAndRegisterMockGlobals(['updateWithPrinterCapabilities']); 59 print_preview.PreviewArea.prototype.checkPluginCompatibility_ =
81 this.mockGlobals.stubs().updateWithPrinterCapabilities( 60 function() {
82 savedArgs.match(ANYTHING)). 61 return false;
83 will(callGlobalWithSavedArgs( 62 };
84 savedArgs, 'updateWithPrinterCapabilities')); 63 }.bind(this));
85
86 // Override checkCompatiblePluginExists to return a value consistent with
87 // the state being tested and stub out the pdf viewer if it doesn't exist,
88 // such as on non-official builds. When the plugin exists, use the real
89 // thing.
90 var self = this;
91 window.addEventListener('DOMContentLoaded', function() {
92 if (!this.checkCompatiblePluginExists()) {
93 // TODO(scr) remove this after tests pass consistently.
94 console.info('no PDF Plugin; providing fake methods.');
95
96 // Initializing |previewArea| object here because we need to replace a
97 // method.
98 this.previewArea = print_preview.PreviewArea.getInstance();
99 this.previewArea.createOrReloadPDFPlugin =
100 self.createOrReloadPDFPlugin.bind(previewArea);
101 }
102
103 this.checkCompatiblePluginExists =
104 self.checkCompatiblePluginExists;
105 });
106 }, 64 },
107 65
108 /** 66 /**
109 * Generate a real C++ class; don't typedef. 67 * Generate a real C++ class; don't typedef.
110 * @type {?string} 68 * @type {?string}
111 * @override 69 * @override
112 */ 70 */
113 typedefCppFixture: null, 71 typedefCppFixture: null,
114 72
115 /** 73 /**
116 * Create the PDF plugin or reload the existing one. This function replaces
117 * createOrReloadPDFPlugin defined in
118 * chrome/browser/resources/print_preview/preview_area.js when there is no
119 * official pdf plugin so that the WebUI logic can be tested. It creates and
120 * attaches an HTMLDivElement to the |mainview| element with attributes and
121 * empty methods, which are used by testing and that would be provided by the
122 * HTMLEmbedElement when the PDF plugin exists.
123 * @param {number} srcDataIndex Preview data source index.
124 * @this {PrintPreviewWebUITest} 74 * @this {PrintPreviewWebUITest}
75 * @override
125 */ 76 */
126 createOrReloadPDFPlugin: function(srcDataIndex) { 77 setUp: function() {
127 var pdfViewer = $('pdf-viewer'); 78 Mock4JS.clearMocksToVerify();
128 if (pdfViewer)
129 return;
130 79
131 var previewUid = 1; 80 this.initialSettings_ = new print_preview.NativeInitialSettings(
132 pdfViewer = document.createElement('div'); 81 false /*isInKioskAutoPrintMode*/,
133 pdfViewer.setAttribute('id', 'pdf-viewer'); 82 ',' /*thousandsDelimeter*/,
134 pdfViewer.setAttribute('type', 83 '.' /*decimalDelimeter*/,
135 'application/x-google-chrome-print-preview-pdf'); 84 1 /*unitType*/,
136 pdfViewer.setAttribute( 85 true /*isDocumentModifiable*/,
137 'src', 86 0 /*marginsType*/,
138 'chrome://print/' + previewUid + '/' + srcDataIndex + '/print.pdf'); 87 null /*customMargins*/,
139 pdfViewer.setAttribute('aria-live', 'polite'); 88 true /*isDuplexEnabled*/,
140 pdfViewer.setAttribute('aria-atomic', 'true'); 89 false /*isHeaderFooterEnabled*/,
141 function fakeFunction() {} 90 'FooDevice' /*initialDestinationId*/);
142 pdfViewer.onload = fakeFunction; 91 this.localDestinationInfos_ = [
143 pdfViewer.goToPage = fakeFunction; 92 { printerName: 'FooName', deviceName: 'FooDevice' },
144 pdfViewer.removePrintButton = fakeFunction; 93 { printerName: 'BarName', deviceName: 'BarDevice' }
145 pdfViewer.fitToHeight = fakeFunction; 94 ];
146 pdfViewer.grayscale = fakeFunction; 95 }
147 pdfViewer.getZoomLevel = fakeFunction;
148 pdfViewer.setZoomLevel = fakeFunction;
149 pdfViewer.pageXOffset = fakeFunction;
150 pdfViewer.pageYOffset = fakeFunction;
151 pdfViewer.setPageNumbers = fakeFunction;
152 pdfViewer.setPageXOffset = fakeFunction;
153 pdfViewer.setPageYOffset = fakeFunction;
154 pdfViewer.getHeight = fakeFunction;
155 pdfViewer.getWidth = fakeFunction;
156 pdfViewer.getPageLocationNormalized = fakeFunction;
157 pdfViewer.onScroll = fakeFunction;
158 pdfViewer.onPluginSizeChanged = fakeFunction;
159 pdfViewer.getHorizontalScrollbarThickness = fakeFunction;
160 pdfViewer.getVerticalScrollbarThickness = fakeFunction;
161 $('mainview').appendChild(pdfViewer);
162 this.pdfPlugin_ = pdfViewer;
163 onPDFLoad();
164 },
165
166 /**
167 * Always return true so tests run on systems without plugin available.
168 * @return {boolean} Always true.
169 */
170 checkCompatiblePluginExists: function() {
171 return true;
172 },
173 }; 96 };
174 97
175 GEN('#include "chrome/test/data/webui/print_preview.h"'); 98 GEN('#include "chrome/test/data/webui/print_preview.h"');
176 99
177 /**
178 * The expected length of the |printer-list| element.
179 * @type {number}
180 * @const
181 */
182 var printerListMinLength = 2;
183
184 /**
185 * The expected index of the "foo" printer returned by the stubbed handler.
186 * @type {number}
187 * @const
188 */
189 var fooIndex = 0;
190
191 /**
192 * The expected index of the "bar" printer returned by the stubbed handler.
193 * @type {number}
194 * @const
195 */
196 var barIndex = 1;
197
198 /**
199 * The expected "Save as PDF" option text returned by the stubbed handler.
200 * @type {string}
201 * @const
202 */
203 var saveAsPDFOptionStr = 'Save as PDF';
204
205 // Test some basic assumptions about the print preview WebUI. 100 // Test some basic assumptions about the print preview WebUI.
206 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { 101 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
207 var printerList = $('printer-list'); 102 var initialSettingsSetEvent =
103 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
104 initialSettingsSetEvent.initialSettings = this.initialSettings_;
105 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
106
107 var localDestsSetEvent =
108 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
109 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
110 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
111
112 var printerList = $('destination-settings').
113 getElementsByClassName('destination-settings-select')[0];
208 assertNotEquals(null, printerList); 114 assertNotEquals(null, printerList);
209 assertGE(printerList.options.length, printerListMinLength); 115 assertGE(printerList.options.length, 2);
210 expectEquals(fooIndex, printerList.selectedIndex); 116 expectEquals(0, printerList.selectedIndex);
211 expectEquals('FooName', printerList.options[fooIndex].text, 117 expectEquals('FooName', printerList.options[0].text, 'fooIndex=0');
212 'fooIndex=' + fooIndex); 118 expectEquals('FooDevice', printerList.options[0].value, 'fooIndex=0');
213 expectEquals('FooDevice', printerList.options[fooIndex].value, 119 expectEquals('BarName', printerList.options[1].text, 'barIndex=1');
kmadhusu 2012/05/18 20:13:46 Is there any specific reason to use numbers rather
214 'fooIndex=' + fooIndex); 120 expectEquals('BarDevice', printerList.options[1].value, 'barIndex=1');
215 expectEquals('BarName', printerList.options[barIndex].text,
216 'barIndex=' + barIndex);
217 expectEquals('BarDevice', printerList.options[barIndex].value,
218 'barIndex=' + barIndex);
219 }); 121 });
220 122
221 // Test that the printer list is structured correctly after calling 123 // Test that the printer list is structured correctly after calling
222 // addCloudPrinters with an empty list. 124 // addCloudPrinters with an empty list.
223 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { 125 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
224 cloudprint.addCloudPrinters([], addDestinationListOptionAtPosition); 126 var initialSettingsSetEvent =
225 var printerList = $('printer-list'); 127 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
128 initialSettingsSetEvent.initialSettings = this.initialSettings_;
129 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
130
131 var localDestsSetEvent =
132 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
133 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
134 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
135
136 var cloudPrintEnableEvent =
137 new cr.Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE);
138 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url';
139 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent);
140
141 var searchDoneEvent =
142 new cr.Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE);
143 searchDoneEvent.printers = [];
144 searchDoneEvent.isRecent = true;
145 searchDoneEvent.email = 'foo@chromium.org';
146 printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent);
147
148 var printerList = $('destination-settings').
149 getElementsByClassName('destination-settings-select')[0];
226 assertNotEquals(null, printerList); 150 assertNotEquals(null, printerList);
227 }); 151 assertGE(printerList.options.length, 2);
228 152 expectEquals(0, printerList.selectedIndex);
229 // Test that the printer list is structured correctly after attempting to add 153 expectEquals('FooName', printerList.options[0].text, 'fooIndex=0');
230 // individual cloud printers until no more can be added. 154 expectEquals('FooDevice', printerList.options[0].value, 'fooIndex=0');
231 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloud', function() { 155 expectEquals('BarName', printerList.options[1].text, 'barIndex=1');
232 var printerList = $('printer-list'); 156 expectEquals('BarDevice', printerList.options[1].value, 'barIndex=1');
233 assertNotEquals(null, printerList);
234 var printer = new Object;
235 printer['name'] = 'FooCloud';
236 for (var i = 0; i < maxCloudPrinters; i++) {
237 printer['id'] = String(i);
238 cloudprint.addCloudPrinters([printer], addDestinationListOptionAtPosition);
239 expectEquals('FooCloud', printerList.options[i].text);
240 expectEquals(String(i), printerList.options[i].value);
241 }
242 cloudprint.addCloudPrinters([printer], addDestinationListOptionAtPosition);
243 expectNotEquals('FooCloud', printerList.options[i].text);
244 expectNotEquals(String(i), printerList.options[i].value);
245 for (var i = 0; i < maxCloudPrinters; i++) {
246 expectEquals('FooCloud', printerList.options[i].text);
247 expectEquals(String(i), printerList.options[i].value);
248 }
249 }); 157 });
250 158
251 /** 159 /**
252 * Verify that |section| visibility matches |visible|. 160 * Verify that |section| visibility matches |visible|.
253 * @param {HTMLDivElement} section The section to check. 161 * @param {HTMLDivElement} section The section to check.
254 * @param {boolean} visible The expected state of visibility. 162 * @param {boolean} visible The expected state of visibility.
255 */ 163 */
256 function checkSectionVisible(section, visible) { 164 function checkSectionVisible(section, visible) {
257 assertNotEquals(null, section); 165 assertNotEquals(null, section);
258 expectEquals(section.classList.contains('visible'), visible, 166 expectEquals(
259 'section=' + section); 167 visible, section.classList.contains('visible'), 'section=' + section.id);
260 } 168 }
261 169
262 /** 170 function checkElementDisplayed(el, isDisplayed) {
263 * Verify that |section| style display matches |value|. 171 assertNotEquals(null, el);
264 * @param {HTMLDivElement} section The section to check. 172 expectEquals(isDisplayed, el.style.display != 'none');
265 * @param {string} value The expected display style value.
266 */
267 function checkSectionDisplayStyle(section, value) {
268 assertNotEquals(null, section);
269 expectEquals(section.style.display, value, 'section=' + section);
270 } 173 }
271 174
272 // Test that disabled settings hide the disabled sections. 175 // Test that disabled settings hide the disabled sections.
273 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { 176 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
274 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice'). 177 var initialSettingsSetEvent =
275 will(callFunction(function() { 178 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
276 updateWithPrinterCapabilities({ 179 initialSettingsSetEvent.initialSettings = this.initialSettings_;
277 disableColorOption: true, 180 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
278 setColorAsDefault: true, 181
279 disableCopiesOption: true, 182 var localDestsSetEvent =
280 disableLandscapeOption: true, 183 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
281 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX, 184 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
282 }); 185 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
283 })); 186
284 187 checkSectionVisible($('layout-settings'), true);
285 updateControlsWithSelectedPrinterCapabilities(); 188 checkSectionVisible($('color-settings'), true);
286 189 checkSectionVisible($('copies-settings'), true);
287 checkSectionVisible(layoutSettings.layoutOption_, false); 190
288 checkSectionVisible(colorSettings.colorOption_, false); 191 var capsSetEvent =
289 checkSectionVisible(copiesSettings.copiesOption_, false); 192 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
193 capsSetEvent.settingsInfo = {
194 'disableColorOption': true,
195 'setColorAsDefault': true,
196 'disableCopiesOption': true,
197 'disableLandscapeOption': true,
198 'printerDefaultDuplexValue': 0
199 };
200 this.nativeLayer_.dispatchEvent(capsSetEvent);
201
202 checkSectionVisible($('layout-settings'), false);
203 checkSectionVisible($('color-settings'), false);
204 checkSectionVisible($('copies-settings'), false);
290 }); 205 });
291 206
292 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the 207 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the
293 // fit to page option. 208 // fit to page option.
294 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedHideFitToPageOption', 209 TEST_F(
295 function() { 210 'PrintPreviewWebUITest',
296 var savedArgs = new SaveMockArguments(); 211 'PrintToPDFSelectedHideFitToPageOption',
297 this.mockHandler.expects(once()).getPreview(savedArgs.match(ANYTHING)). 212 function() {
298 will(callFunctionWithSavedArgs(savedArgs, function(args) { 213 // Add PDF printer.
299 updatePrintPreview(2, JSON.parse(args[0]).requestID); 214 this.initialSettings_.isDocumentModifiable_ = false;
300 })); 215 this.initialSettings_.initialDestinationId_ = 'Save as PDF';
301 216 this.localDestinationInfos_.push(
302 this.mockGlobals.expects(once()).updateWithPrinterCapabilities( 217 {printerName: 'Save as PDF', deviceName: 'Save as PDF'});
303 savedArgs.match(ANYTHING)). 218
304 will(callGlobalWithSavedArgs( 219 var initialSettingsSetEvent =
305 savedArgs, 'updateWithPrinterCapabilities')); 220 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
306 221 initialSettingsSetEvent.initialSettings = this.initialSettings_;
307 setInitialSettings({previewModifiable: false}); 222 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
308 var printerList = $('printer-list'); 223
309 assertNotEquals(null, printerList, 'printerList'); 224 var localDestsSetEvent =
310 assertGE(printerList.options.length, printerListMinLength); 225 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
311 for (var i = 0; i < printerList.options.length; i++) { 226 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
312 if (printerList.options[i].text == saveAsPDFOptionStr && 227 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
313 printerList.options[i].value == saveAsPDFOptionStr) { 228
314 printerList.selectedIndex = i; 229 var capsSetEvent =
230 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
231 capsSetEvent.settingsInfo = {
232 'disableColorOption': false,
233 'setColorAsDefault': true,
234 'disableCopiesOption': true,
235 'disableLandscapeOption': true,
236 'printerDefaultDuplexValue': 0
237 };
238 this.nativeLayer_.dispatchEvent(capsSetEvent);
239
240 checkElementDisplayed(
241 $('other-options-settings').
242 querySelector('.other-options-settings-fit-to-page'),
243 false);
244 });
245
246 // When the source is 'HTML', we always hide the fit to page option.
247 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLHideFitToPageOption', function() {
248 var initialSettingsSetEvent =
249 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
250 initialSettingsSetEvent.initialSettings = this.initialSettings_;
251 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
252
253 var localDestsSetEvent =
254 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
255 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
256 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
257
258 var capsSetEvent =
259 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
260 capsSetEvent.settingsInfo = {
261 'disableColorOption': false,
262 'setColorAsDefault': true,
263 'disableCopiesOption': true,
264 'disableLandscapeOption': true,
265 'printerDefaultDuplexValue': 0
266 };
267 this.nativeLayer_.dispatchEvent(capsSetEvent);
268
269 checkElementDisplayed(
270 $('other-options-settings').
271 querySelector('.other-options-settings-fit-to-page'),
272 false);
273 });
274
275 // When the source is "PDF", depending on the selected destination printer, we
276 // show/hide the fit to page option.
277 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFShowFitToPageOption', function() {
278 this.initialSettings_.isDocumentModifiable_ = false;
279
280 var initialSettingsSetEvent =
281 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
282 initialSettingsSetEvent.initialSettings = this.initialSettings_;
283 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
284
285 var localDestsSetEvent =
286 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
287 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
288 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
289
290 var capsSetEvent =
291 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
292 capsSetEvent.settingsInfo = {
293 'disableColorOption': false,
294 'setColorAsDefault': true,
295 'disableCopiesOption': true,
296 'disableLandscapeOption': true,
297 'printerDefaultDuplexValue': 0
298 };
299 this.nativeLayer_.dispatchEvent(capsSetEvent);
300
301 checkElementDisplayed(
302 $('other-options-settings').
303 querySelector('.other-options-settings-fit-to-page'),
304 true);
305 expectTrue(
306 $('other-options-settings').querySelector(
307 '.other-options-settings-fit-to-page-checkbox').checked);
308 });
309
310 // When the print scaling is disabled for the source "PDF", we show the fit
311 // to page option but the state is unchecked by default.
312 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() {
313 this.initialSettings_.isDocumentModifiable_ = false;
314
315 var initialSettingsSetEvent =
316 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
317 initialSettingsSetEvent.initialSettings = this.initialSettings_;
318 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
319
320 var localDestsSetEvent =
321 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
322 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
323 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
324
325 var capsSetEvent =
326 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
327 capsSetEvent.settingsInfo = {
328 'disableColorOption': false,
329 'setColorAsDefault': true,
330 'disableCopiesOption': true,
331 'disableLandscapeOption': true,
332 'printerDefaultDuplexValue': 0
333 };
334 this.nativeLayer_.dispatchEvent(capsSetEvent);
335
336 // Indicate that the PDF does not support scaling by default.
337 cr.dispatchSimpleEvent(
338 this.nativeLayer_, print_preview.NativeLayer.EventType.DISABLE_SCALING);
339
340 checkElementDisplayed(
341 $('other-options-settings').
342 querySelector('.other-options-settings-fit-to-page'),
343 true);
344 expectFalse(
345 $('other-options-settings').querySelector(
346 '.other-options-settings-fit-to-page-checkbox').checked);
347 });
348
349 // Page layout has zero margins. Hide header and footer option.
350 TEST_F(
351 'PrintPreviewWebUITest',
352 'PageLayoutHasNoMarginsHideHeaderFooter',
353 function() {
354 var initialSettingsSetEvent =
355 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
356 initialSettingsSetEvent.initialSettings = this.initialSettings_;
357 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
358
359 var localDestsSetEvent =
360 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
361 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
362 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
363
364 var capsSetEvent =
365 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
366 capsSetEvent.settingsInfo = {
367 'disableColorOption': false,
368 'setColorAsDefault': true,
369 'disableCopiesOption': true,
370 'disableLandscapeOption': true,
371 'printerDefaultDuplexValue': 0
372 };
373 this.nativeLayer_.dispatchEvent(capsSetEvent);
374
375 checkElementDisplayed(
376 $('other-options-settings').
377 querySelector('.other-options-settings-header-footer'),
378 true);
379
380 printPreview.printTicketStore_.updateMarginsType(
381 print_preview.ticket_items.MarginsType.Value.CUSTOM);
382 printPreview.printTicketStore_.updateCustomMargins(
383 new print_preview.Margins(0, 0, 0, 0));
384
385 checkElementDisplayed(
386 $('other-options-settings').
387 querySelector('.other-options-settings-header-footer'),
388 false);
389 });
390
391 // Page layout has half-inch margins. Show header and footer option.
392 TEST_F(
393 'PrintPreviewWebUITest',
kmadhusu 2012/05/18 20:13:46 nit: This argument can go to line 392.
394 'PageLayoutHasMarginsShowHeaderFooter',
395 function() {
396 var initialSettingsSetEvent =
397 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
398 initialSettingsSetEvent.initialSettings = this.initialSettings_;
399 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
400
401 var localDestsSetEvent =
402 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
403 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
404 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
405
406 var capsSetEvent =
407 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
408 capsSetEvent.settingsInfo = {
409 'disableColorOption': false,
410 'setColorAsDefault': true,
411 'disableCopiesOption': true,
412 'disableLandscapeOption': true,
413 'printerDefaultDuplexValue': 0
414 };
415 this.nativeLayer_.dispatchEvent(capsSetEvent);
416
417 checkElementDisplayed(
418 $('other-options-settings').
419 querySelector('.other-options-settings-header-footer'),
420 true);
421
422 printPreview.printTicketStore_.updateMarginsType(
423 print_preview.ticket_items.MarginsType.Value.CUSTOM);
424 printPreview.printTicketStore_.updateCustomMargins(
425 new print_preview.Margins(36, 36, 36, 36));
426
427 checkElementDisplayed(
428 $('other-options-settings').
429 querySelector('.other-options-settings-header-footer'),
430 true);
431 });
432
433 // Page layout has zero top and bottom margins. Hide header and footer option.
434 TEST_F(
435 'PrintPreviewWebUITest',
436 'ZeroTopAndBottomMarginsHideHeaderFooter',
437 function() {
438 var initialSettingsSetEvent =
439 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
440 initialSettingsSetEvent.initialSettings = this.initialSettings_;
441 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
442
443 var localDestsSetEvent =
444 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
445 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
446 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
447
448 var capsSetEvent =
449 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
450 capsSetEvent.settingsInfo = {
451 'disableColorOption': false,
452 'setColorAsDefault': true,
453 'disableCopiesOption': true,
454 'disableLandscapeOption': true,
455 'printerDefaultDuplexValue': 0
456 };
457 this.nativeLayer_.dispatchEvent(capsSetEvent);
458
459 checkElementDisplayed(
460 $('other-options-settings').
461 querySelector('.other-options-settings-header-footer'),
462 true);
463
464 printPreview.printTicketStore_.updateMarginsType(
465 print_preview.ticket_items.MarginsType.Value.CUSTOM);
466 printPreview.printTicketStore_.updateCustomMargins(
467 new print_preview.Margins(0, 36, 0, 36));
468
469 checkElementDisplayed(
470 $('other-options-settings').
471 querySelector('.other-options-settings-header-footer'),
472 false);
473 });
474
475 // Page layout has zero top and half-inch bottom margin. Show header and footer
476 // option.
477 TEST_F(
478 'PrintPreviewWebUITest',
479 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
480 function() {
481 var initialSettingsSetEvent =
482 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
483 initialSettingsSetEvent.initialSettings = this.initialSettings_;
484 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
485
486 var localDestsSetEvent =
487 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
488 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
489 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
490
491 var capsSetEvent =
492 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
493 capsSetEvent.settingsInfo = {
494 'disableColorOption': false,
495 'setColorAsDefault': true,
496 'disableCopiesOption': true,
497 'disableLandscapeOption': true,
498 'printerDefaultDuplexValue': 0
499 };
500 this.nativeLayer_.dispatchEvent(capsSetEvent);
501
502 checkElementDisplayed(
503 $('other-options-settings').
504 querySelector('.other-options-settings-header-footer'),
505 true);
506
507 printPreview.printTicketStore_.updateMarginsType(
508 print_preview.ticket_items.MarginsType.Value.CUSTOM);
509 printPreview.printTicketStore_.updateCustomMargins(
510 new print_preview.Margins(0, 36, 36, 36));
511
512 checkElementDisplayed(
513 $('other-options-settings').
514 querySelector('.other-options-settings-header-footer'),
515 true);
516 });
517
518 // Test that the color settings are set according to the printer capabilities.
519 TEST_F('PrintPreviewWebUITest', 'TestColorSettings', function() {
520 var initialSettingsSetEvent =
521 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
522 initialSettingsSetEvent.initialSettings = this.initialSettings_;
523 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
524
525 var localDestsSetEvent =
526 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
527 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
528 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
529
530 checkSectionVisible($('color-settings'), true);
531
532 var capsSetEvent =
533 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
534 capsSetEvent.settingsInfo = {
535 'disableColorOption': false,
536 'setColorAsDefault': true,
537 'disableCopiesOption': true,
538 'disableLandscapeOption': true,
539 'printerDefaultDuplexValue': 0
540 };
541 this.nativeLayer_.dispatchEvent(capsSetEvent);
542
543 checkSectionVisible($('color-settings'), true);
544
545 var colorOption = $('color-settings').getElementsByClassName(
546 'color-settings-color-option')[0];
547 var bwOption = $('color-settings').getElementsByClassName(
548 'color-settings-bw-option')[0];
549 expectTrue(colorOption.checked);
550 expectFalse(bwOption.checked);
551
552 var capsSetEvent =
553 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
554 capsSetEvent.settingsInfo = {
555 'disableColorOption': false,
556 'setColorAsDefault': false,
557 'disableCopiesOption': false,
558 'disableLandscapeOption': false,
559 'printerDefaultDuplexValue': 0
560 };
561 this.nativeLayer_.dispatchEvent(capsSetEvent);
562
563 checkSectionVisible($('color-settings'), true);
564 expectFalse(colorOption.checked);
565 expectTrue(bwOption.checked);
566 });
567
568 // Test to verify that duplex settings are set according to the printer
569 // capabilities.
570 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettings', function() {
571 var initialSettingsSetEvent =
572 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
573 // Need to override test defaults for the initial settings, because initial
574 // duplex value needs to be unspecified.
575 initialSettingsSetEvent.initialSettings =
576 new print_preview.NativeInitialSettings(
577 false /*isInKioskAutoPrintMode*/,
578 ',' /*thousandsDelimeter*/,
579 '.' /*decimalDelimeter*/,
580 1 /*unitType*/,
581 true /*isDocumentModifiable*/,
582 0 /*marginsType*/,
583 null /*customMargins*/,
584 null /*isDuplexEnabled*/,
585 false /*isHeaderFooterEnabled*/,
586 'FooDevice' /*initialDestinationId*/);
587 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
588
589 var localDestsSetEvent =
590 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
591 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
592 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
593
594 var copiesDiv = $('copies-settings');
595 var duplexDiv = copiesDiv.getElementsByClassName('copies-settings-duplex')[0];
596 var duplexCheckbox = copiesDiv.getElementsByClassName(
597 'copies-settings-duplex-checkbox')[0];
598
599 var capsSetEvent =
600 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
601 capsSetEvent.settingsInfo = {
602 'disableColorOption': false,
603 'setColorAsDefault': true,
604 'disableCopiesOption': false,
605 'disableLandscapeOption': true,
606 'printerDefaultDuplexValue': 0
607 };
608 this.nativeLayer_.dispatchEvent(capsSetEvent);
609
610 checkSectionVisible(copiesDiv, true);
611 expectFalse(duplexDiv.hidden);
612 expectFalse(duplexCheckbox.checked);
613
614 // If the printer default duplex value is UNKNOWN_DUPLEX_MODE, hide the
615 // two sided option.
616 var capsSetEvent =
617 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
618 capsSetEvent.settingsInfo = {
619 'disableColorOption': false,
620 'setColorAsDefault': false,
621 'disableCopiesOption': false,
622 'disableLandscapeOption': false,
623 'printerDefaultDuplexValue': -1
624 };
625 this.nativeLayer_.dispatchEvent(capsSetEvent);
626
627 checkSectionVisible(copiesDiv, true);
628 expectTrue(duplexDiv.hidden);
629
630 var capsSetEvent =
631 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
632 capsSetEvent.settingsInfo = {
633 'disableColorOption': false,
634 'setColorAsDefault': false,
635 'disableCopiesOption': false,
636 'disableLandscapeOption': false,
637 'printerDefaultDuplexValue': 1
638 };
639 this.nativeLayer_.dispatchEvent(capsSetEvent);
640
641 checkSectionVisible(copiesDiv, true);
642 expectFalse(duplexDiv.hidden);
643 expectTrue(duplexCheckbox.checked);
644 });
645
646 // Test that changing the selected printer updates the preview.
647 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
648
649 var initialSettingsSetEvent =
650 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
651 initialSettingsSetEvent.initialSettings = this.initialSettings_;
652 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
653
654 var localDestsSetEvent =
655 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
656 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
657 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
658
659 var capsSetEvent =
660 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
661 capsSetEvent.settingsInfo = {
662 'disableColorOption': false,
663 'setColorAsDefault': true,
664 'disableCopiesOption': true,
665 'disableLandscapeOption': true,
666 'printerDefaultDuplexValue': 0
667 };
668 this.nativeLayer_.dispatchEvent(capsSetEvent);
669
670 var previewGenerator = mock(print_preview.PreviewGenerator);
671 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy();
672 previewGenerator.expects(once()).requestPreview();
673
674 var barDestination;
675 var destinations = printPreview.destinationStore_.destinations;
676 for (var destination, i = 0; destination = destinations[i]; i++) {
677 if (destination.id == 'BarDevice') {
678 barDestination = destination;
315 break; 679 break;
316 } 680 }
317 } 681 }
318 updateControlsWithSelectedPrinterCapabilities(); 682
319 checkSectionDisplayStyle(fitToPageSettings.fitToPageOption_, 'none'); 683 printPreview.destinationStore_.selectDestination(barDestination);
320 }); 684
321 685 var capsSetEvent =
322 // When the source is 'HTML', we always hide the fit to page option. 686 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
323 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLHideFitToPageOption', function() { 687 capsSetEvent.settingsInfo = {
324 var savedArgs = new SaveMockArguments(); 688 'disableColorOption': true,
325 this.mockHandler.expects(once()).getPreview(savedArgs.match(ANYTHING)). 689 'setColorAsDefault': false,
326 will(callFunctionWithSavedArgs(savedArgs, function(args) { 690 'disableCopiesOption': true,
327 updatePrintPreview(2, JSON.parse(args[0]).requestID); 691 'disableLandscapeOption': true,
328 })); 692 'printerDefaultDuplexValue': 0
329 693 };
330 this.mockGlobals.expects(once()).updateWithPrinterCapabilities( 694 this.nativeLayer_.dispatchEvent(capsSetEvent);
331 savedArgs.match(ANYTHING)). 695 });
332 will(callGlobalWithSavedArgs(
333 savedArgs, 'updateWithPrinterCapabilities'));
334
335 setInitialSettings({previewModifiable: true});
336 var printerList = $('printer-list');
337 assertNotEquals(null, printerList, 'printerList');
338 assertGE(printerList.options.length, printerListMinLength);
339 updateControlsWithSelectedPrinterCapabilities();
340 checkSectionDisplayStyle(fitToPageSettings.fitToPageOption_, 'none');
341 expectTrue(fitToPageSettings.hasFitToPage());
342 });
343
344 // When the source is "PDF", depending on the selected destination printer, we
345 // show/hide the fit to page option.
346 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFShowFitToPageOption', function() {
347 var savedArgs = new SaveMockArguments();
348 this.mockHandler.expects(once()).getPreview(savedArgs.match(ANYTHING)).
349 will(callFunctionWithSavedArgs(savedArgs, function(args) {
350 updatePrintPreview(2, JSON.parse(args[0]).requestID);
351 }));
352
353 this.mockGlobals.expects(once()).updateWithPrinterCapabilities(
354 savedArgs.match(ANYTHING)).
355 will(callGlobalWithSavedArgs(
356 savedArgs, 'updateWithPrinterCapabilities'));
357
358 setInitialSettings({previewModifiable: false});
359 var printerList = $('printer-list');
360 assertNotEquals(null, printerList, 'printerList');
361 assertGE(printerList.options.length, printerListMinLength);
362 var saveAsPDFOptionSelected = false;
363 var selectedPrinterOption = printerList.options[printerList.selectedIndex];
364 if (selectedPrinterOption.text == saveAsPDFOptionStr &&
365 selectedPrinterOption.value == saveAsPDFOptionStr) {
366 saveAsPDFOptionSelected = true;
367 }
368 updateControlsWithSelectedPrinterCapabilities();
369 checkSectionDisplayStyle(fitToPageSettings.fitToPageOption_,
370 saveAsPDFOptionSelected ? 'none' : 'block');
371 expectTrue(fitToPageSettings.hasFitToPage());
372 });
373
374 // When the print scaling is disabled for the source "PDF", we show the fit
375 // to page option but the state is unchecked by default.
376 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() {
377 var savedArgs = new SaveMockArguments();
378 this.mockHandler.expects(once()).getPreview(savedArgs.match(ANYTHING)).
379 will(callFunctionWithSavedArgs(savedArgs, function(args) {
380 updatePrintPreview(2, JSON.parse(args[0]).requestID);
381 }));
382
383 this.mockGlobals.expects(once()).updateWithPrinterCapabilities(
384 savedArgs.match(ANYTHING)).
385 will(callGlobalWithSavedArgs(
386 savedArgs, 'updateWithPrinterCapabilities'));
387
388 setInitialSettings({previewModifiable: false});
389 var printerList = $('printer-list');
390 assertNotEquals(null, printerList, 'printerList');
391 assertGE(printerList.options.length, printerListMinLength);
392 var saveAsPDFOptionSelected = false;
393 var selectedPrinterOption = printerList.options[printerList.selectedIndex];
394 if (selectedPrinterOption.text == saveAsPDFOptionStr &&
395 selectedPrinterOption.value == saveAsPDFOptionStr) {
396 saveAsPDFOptionSelected = true;
397 }
398 updateControlsWithSelectedPrinterCapabilities();
399 printScalingDisabledForSourcePDF();
400 checkSectionDisplayStyle(fitToPageSettings.fitToPageOption_,
401 saveAsPDFOptionSelected ? 'none' : 'block');
402 // Make sure the fit to page checkbox is unchecked.
403 expectFalse(fitToPageSettings.hasFitToPage());
404 });
405
406 // Page layout has zero margins. Hide header and footer option.
407 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
408 function() {
409 setInitialSettings({previewModifiable: true});
410 onDidGetDefaultPageLayout({
411 contentWidth: 100, contentHeight: 200, marginLeft: 0, marginRight: 0,
412 marginTop: 0, marginBottom: 0, printableAreaX: 0, printableAreaY: 0,
413 printableAreaWidth: 100, printableAreaHeight: 200}, true);
414 checkSectionDisplayStyle(headerFooterSettings.headerFooterOption_, 'none');
415 });
416
417 // Page layout has non-zero margins. Show header and footer option.
418 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter',
419 function() {
420 setInitialSettings({previewModifiable: true});
421 onDidGetDefaultPageLayout({
422 contentWidth: 100, contentHeight: 200, marginLeft: 3, marginRight: 2,
423 marginTop: 4, marginBottom: 1, printableAreaX: 1, printableAreaY: 1,
424 printableAreaWidth: 103, printableAreaHeight: 203}, true);
425 checkSectionDisplayStyle(headerFooterSettings.headerFooterOption_, 'block');
426 });
427
428 // Page layout has zero top and bottom margins. Hide header and footer option.
429 TEST_F('PrintPreviewWebUITest', 'ZeroTopAndBottomMarginsHideHeaderFooter',
430 function() {
431 setInitialSettings({previewModifiable: true});
432 onDidGetDefaultPageLayout({
433 contentWidth: 100, contentHeight: 200, marginLeft: 3, marginRight: 2,
434 marginTop: 0, marginBottom: 0, printableAreaX: 1, printableAreaY: 1,
435 printableAreaWidth: 98, printableAreaHeight: 198}, false);
436 checkSectionDisplayStyle(headerFooterSettings.headerFooterOption_, 'none');
437 });
438
439 // Page layout has zero top and non-zero bottom margin. Show header and footer
440 // option.
441 TEST_F('PrintPreviewWebUITest', 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
442 function() {
443 setInitialSettings({previewModifiable: true});
444 onDidGetDefaultPageLayout({
445 contentWidth: 100, contentHeight: 200, marginLeft: 6, marginRight: 4,
446 marginTop: 0, marginBottom: 3, printableAreaX: 1, printableAreaY: 1,
447 printableAreaWidth: 103, printableAreaHeight: 208}, false);
448 checkSectionDisplayStyle(headerFooterSettings.headerFooterOption_, 'block');
449 });
450
451 // Test that the color settings are set according to the printer capabilities.
452 TEST_F('PrintPreviewWebUITest', 'TestColorSettings', function() {
453 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice').
454 will(callFunction(function() {
455 updateWithPrinterCapabilities({
456 disableColorOption: false,
457 setColorAsDefault: true,
458 disableCopiesOption: false,
459 disableLandscapeOption: false,
460 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX,
461 });
462 }));
463
464 updateControlsWithSelectedPrinterCapabilities();
465 expectTrue(colorSettings.colorRadioButton.checked);
466 expectFalse(colorSettings.bwRadioButton.checked);
467
468 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice').
469 will(callFunction(function() {
470 updateWithPrinterCapabilities({
471 disableColorOption: false,
472 setColorAsDefault: false,
473 disableCopiesOption: false,
474 disableLandscapeOption: false,
475 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX,
476 });
477 }));
478
479 updateControlsWithSelectedPrinterCapabilities();
480 expectFalse(colorSettings.colorRadioButton.checked);
481 expectTrue(colorSettings.bwRadioButton.checked);
482 });
483
484 // Test to verify that duplex settings are set according to the printer
485 // capabilities.
486 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettings', function() {
487 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice').
488 will(callFunction(function() {
489 updateWithPrinterCapabilities({
490 disableColorOption: false,
491 setColorAsDefault: false,
492 disableCopiesOption: false,
493 disableLandscapeOption: false,
494 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX,
495 });
496 }));
497 updateControlsWithSelectedPrinterCapabilities();
498 expectEquals(copiesSettings.duplexMode, print_preview.CopiesSettings.SIMPLEX);
499 expectEquals(copiesSettings.twoSidedOption_.hidden, false);
500
501 // If the printer default duplex value is UNKNOWN_DUPLEX_MODE, hide the
502 // two sided option.
503 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice').
504 will(callFunction(function() {
505 updateWithPrinterCapabilities({
506 disableColorOption: false,
507 setColorAsDefault: false,
508 disableCopiesOption: false,
509 disableLandscapeOption: false,
510 printerDefaultDuplexValue:
511 print_preview.CopiesSettings.UNKNOWN_DUPLEX_MODE,
512 });
513 }));
514 updateControlsWithSelectedPrinterCapabilities();
515 expectEquals(copiesSettings.duplexMode,
516 print_preview.CopiesSettings.UNKNOWN_DUPLEX_MODE);
517 expectEquals(copiesSettings.twoSidedOption_.hidden, true);
518
519 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice').
520 will(callFunction(function() {
521 updateWithPrinterCapabilities({
522 disableColorOption: false,
523 setColorAsDefault: false,
524 disableCopiesOption: false,
525 disableLandscapeOption: false,
526 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX,
527 });
528 }));
529 updateControlsWithSelectedPrinterCapabilities();
530 expectEquals(copiesSettings.twoSidedOption_.hidden, false);
531 expectEquals(copiesSettings.duplexMode, print_preview.CopiesSettings.SIMPLEX);
532 copiesSettings.twoSidedCheckbox.checked = true;
533 expectEquals(
534 copiesSettings.duplexMode, print_preview.CopiesSettings.LONG_EDGE);
535 });
536
537 // Test that changing the selected printer updates the preview.
538 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
539 var savedArgs = new SaveMockArguments();
540 this.mockHandler.expects(once()).getPreview(savedArgs.match(ANYTHING)).
541 will(callFunctionWithSavedArgs(savedArgs, function(args) {
542 updatePrintPreview(2, JSON.parse(args[0]).requestID);
543 }));
544
545 this.mockGlobals.expects(once()).updateWithPrinterCapabilities(
546 savedArgs.match(ANYTHING)).
547 will(callGlobalWithSavedArgs(
548 savedArgs, 'updateWithPrinterCapabilities'));
549
550 var printerList = $('printer-list');
551 assertNotEquals(null, printerList, 'printerList');
552 assertGE(printerList.options.length, printerListMinLength);
553 expectEquals(fooIndex, printerList.selectedIndex,
554 'fooIndex=' + fooIndex);
555 var oldLastPreviewRequestID = lastPreviewRequestID;
556 ++printerList.selectedIndex;
557 updateControlsWithSelectedPrinterCapabilities();
558 expectNotEquals(oldLastPreviewRequestID, lastPreviewRequestID);
559 });
560
561 /**
562 * Test fixture to test case when no PDF plugin exists.
563 * @extends {PrintPreviewWebUITest}
564 * @constructor
565 */
566 function PrintPreviewNoPDFWebUITest() {}
567
568 PrintPreviewNoPDFWebUITest.prototype = {
569 __proto__: PrintPreviewWebUITest.prototype,
570
571 /**
572 * Provide a typedef for C++ to correspond to JS subclass.
573 * @type {?string}
574 * @override
575 */
576 typedefCppFixture: 'PrintPreviewWebUITest',
577
578 /**
579 * Always return false to simulate failure and check expected error condition.
580 * @return {boolean} Always false.
581 * @override
582 */
583 checkCompatiblePluginExists: function() {
584 return false;
585 },
586 };
587 696
588 // Test that error message is displayed when plugin doesn't exist. 697 // Test that error message is displayed when plugin doesn't exist.
589 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() { 698 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
590 var errorButton = $('error-button'); 699 var previewAreaEl = $('preview-area');
591 assertNotEquals(null, errorButton); 700
592 expectFalse(errorButton.disabled); 701 var loadingMessageEl =
593 var errorText = $('custom-message'); 702 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0];
594 assertNotEquals(null, errorText); 703 expectEquals('none', loadingMessageEl.style.display);
595 expectFalse(errorText.hidden); 704
596 }); 705 var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
706 'preview-area-preview-failed-message')[0];
707 expectEquals('none', previewFailedMessageEl.style.display);
708
709 var printFailedMessageEl =
710 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0];
711 expectEquals('none', printFailedMessageEl.style.display);
712
713 var customMessageEl =
714 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0];
715 expectEquals('', customMessageEl.style.display);
716 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698