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

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

Powered by Google App Engine
This is Rietveld 408576698