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

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: Address reviewer comments 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} 30 * @this {PrintPreviewWebUITest}
26 * @override 31 * @override
27 */ 32 */
28 preLoad: function() { 33 preLoad: function() {
29 this.makeAndRegisterMockHandler(['getInitialSettings', 34 window.addEventListener('DOMContentLoaded', function() {
30 'getPrinters', 35 function NativeLayerStub() {
31 'getPreview', 36 cr.EventTarget.call(this);
32 'print', 37 }
33 'getPrinterCapabilities', 38 NativeLayerStub.prototype = {
34 'showSystemDialog', 39 __proto__: cr.EventTarget.prototype,
35 'morePrinters', 40 startGetInitialSettings: function() {},
36 'signIn', 41 startGetLocalDestinations: function() {},
37 'addCloudPrinter', 42 startGetLocalDestinationCapabilities: function(destinationId) {}
38 'manageCloudPrinters', 43 };
39 'manageLocalPrinters',
40 'closePrintPreviewTab',
41 'hidePreview',
42 'cancelPendingPrintRequest',
43 'saveLastPrinter',
44 ]);
45 44
46 // Register stubs for methods expected to be called before tests 45 this.nativeLayer_ = new NativeLayerStub();
47 // run. Specific expectations can be made in the tests themselves. 46 printPreview.nativeLayer_ = this.nativeLayer_;
48 this.mockHandler.stubs().getInitialSettings().
49 will(callFunction(function() {
50 setDefaultPrinter('FooDevice');
51 }));
52 this.mockHandler.stubs().getPrinterCapabilities(NOT_NULL).
53 will(callFunction(function() {
54 updateWithPrinterCapabilities({
55 disableColorOption: true,
56 setColorAsDefault: true,
57 disableCopiesOption: true,
58 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX,
59 });
60 }));
61 var savedArgs = new SaveMockArguments();
62 this.mockHandler.stubs().getPreview(savedArgs.match(NOT_NULL)).
63 will(callFunctionWithSavedArgs(savedArgs, function(args) {
64 updatePrintPreview(1, JSON.parse(args[0]).requestID);
65 }));
66 47
67 this.mockHandler.stubs().getPrinters(). 48 function CloudPrintInterfaceStub() {
68 will(callFunction(function() { 49 cr.EventTarget.call(this);
69 setPrinters([{ 50 }
70 printerName: 'FooName', 51 CloudPrintInterfaceStub.prototype = {
71 deviceName: 'FooDevice', 52 __proto__: cr.EventTarget.prototype,
72 }, { 53 search: function(isRecent) {}
73 printerName: 'BarName', 54 };
74 deviceName: 'BarDevice', 55 var oldCpInterfaceEventType = cloudprint.CloudPrintInterface.EventType;
75 }, 56 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub;
76 ]); 57 cloudprint.CloudPrintInterface.EventType = oldCpInterfaceEventType;
77 }));
78 58
79 this.makeAndRegisterMockGlobals(['updateWithPrinterCapabilities']); 59 print_preview.PreviewArea.prototype.checkPluginCompatibility_ =
80 this.mockGlobals.stubs().updateWithPrinterCapabilities( 60 function() {
81 savedArgs.match(ANYTHING)). 61 return false;
82 will(callGlobalWithSavedArgs( 62 };
83 savedArgs, 'updateWithPrinterCapabilities')); 63 }.bind(this));
84
85 // Override checkCompatiblePluginExists to return a value consistent with
86 // the state being tested and stub out the pdf viewer if it doesn't exist,
87 // such as on non-official builds. When the plugin exists, use the real
88 // thing.
89 var self = this;
90 window.addEventListener('DOMContentLoaded', function() {
91 if (!this.checkCompatiblePluginExists()) {
92 // TODO(scr) remove this after tests pass consistently.
93 console.info('no PDF Plugin; providing fake methods.');
94
95 // Initializing |previewArea| object here because we need to replace a
96 // method.
97 this.previewArea = print_preview.PreviewArea.getInstance();
98 this.previewArea.createOrReloadPDFPlugin =
99 self.createOrReloadPDFPlugin.bind(previewArea);
100 }
101
102 this.checkCompatiblePluginExists =
103 self.checkCompatiblePluginExists;
104 });
105 }, 64 },
106 65
107 /** 66 /**
108 * Generate a real C++ class; don't typedef. 67 * Generate a real C++ class; don't typedef.
109 * @type {?string} 68 * @type {?string}
110 * @override 69 * @override
111 */ 70 */
112 typedefCppFixture: null, 71 typedefCppFixture: null,
113 72
114 /** 73 /**
115 * Create the PDF plugin or reload the existing one. This function replaces 74 * @this {PrintPreviewWebUITest}
116 * createOrReloadPDFPlugin defined in 75 * @override
117 * chrome/browser/resources/print_preview/preview_area.js when there is no
118 * official pdf plugin so that the WebUI logic can be tested. It creates and
119 * attaches an HTMLDivElement to the |mainview| element with attributes and
120 * empty methods, which are used by testing and that would be provided by the
121 * HTMLEmbedElement when the PDF plugin exists.
122 * @param {number} srcDataIndex Preview data source index.
123 */ 76 */
124 createOrReloadPDFPlugin: function(srcDataIndex) { 77 setUp: function() {
125 var pdfViewer = $('pdf-viewer'); 78 Mock4JS.clearMocksToVerify();
126 if (pdfViewer)
127 return;
128 79
129 var previewUid = 1; 80 this.initialSettings_ = new print_preview.NativeInitialSettings(
130 pdfViewer = document.createElement('div'); 81 false /*isInKioskAutoPrintMode*/,
131 pdfViewer.setAttribute('id', 'pdf-viewer'); 82 ',' /*thousandsDelimeter*/,
132 pdfViewer.setAttribute('type', 83 '.' /*decimalDelimeter*/,
133 'application/x-google-chrome-print-preview-pdf'); 84 1 /*unitType*/,
134 pdfViewer.setAttribute( 85 true /*isDocumentModifiable*/,
135 'src', 86 0 /*marginsType*/,
136 'chrome://print/' + previewUid + '/' + srcDataIndex + '/print.pdf'); 87 null /*customMargins*/,
137 pdfViewer.setAttribute('aria-live', 'polite'); 88 true /*isDuplexEnabled*/,
138 pdfViewer.setAttribute('aria-atomic', 'true'); 89 false /*isHeaderFooterEnabled*/,
139 function fakeFunction() {} 90 'FooDevice' /*initialDestinationId*/);
140 pdfViewer.onload = fakeFunction; 91 this.localDestinationInfos_ = [
141 pdfViewer.goToPage = fakeFunction; 92 { printerName: 'FooName', deviceName: 'FooDevice' },
142 pdfViewer.removePrintButton = fakeFunction; 93 { printerName: 'BarName', deviceName: 'BarDevice' }
143 pdfViewer.fitToHeight = fakeFunction; 94 ];
144 pdfViewer.grayscale = fakeFunction; 95 }
145 pdfViewer.getZoomLevel = fakeFunction;
146 pdfViewer.setZoomLevel = fakeFunction;
147 pdfViewer.pageXOffset = fakeFunction;
148 pdfViewer.pageYOffset = fakeFunction;
149 pdfViewer.setPageNumbers = fakeFunction;
150 pdfViewer.setPageXOffset = fakeFunction;
151 pdfViewer.setPageYOffset = fakeFunction;
152 pdfViewer.getHeight = fakeFunction;
153 pdfViewer.getWidth = fakeFunction;
154 pdfViewer.getPageLocationNormalized = fakeFunction;
155 pdfViewer.onScroll = fakeFunction;
156 pdfViewer.onPluginSizeChanged = fakeFunction;
157 pdfViewer.getHorizontalScrollbarThickness = fakeFunction;
158 pdfViewer.getVerticalScrollbarThickness = fakeFunction;
159 $('mainview').appendChild(pdfViewer);
160 this.pdfPlugin_ = pdfViewer;
161 onPDFLoad();
162 },
163
164 /**
165 * Always return true so tests run on systems without plugin available.
166 * @return {boolean} Always true.
167 */
168 checkCompatiblePluginExists: function() {
169 return true;
170 },
171 }; 96 };
172 97
173 GEN('#include "chrome/test/data/webui/print_preview.h"'); 98 GEN('#include "chrome/test/data/webui/print_preview.h"');
174 99
175 /**
176 * The expected length of the |printer-list| element.
177 * @type {number}
178 * @const
179 */
180 var printerListMinLength = 2;
181
182 /**
183 * The expected index of the "foo" printer returned by the stubbed handler.
184 * @type {number}
185 * @const
186 */
187 var fooIndex = 0;
188
189 /**
190 * The expected index of the "bar" printer returned by the stubbed handler.
191 * @type {number}
192 * @const
193 */
194 var barIndex = 1;
195
196 // Test some basic assumptions about the print preview WebUI. 100 // Test some basic assumptions about the print preview WebUI.
197 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { 101 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
198 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];
199 assertNotEquals(null, printerList); 114 assertNotEquals(null, printerList);
200 assertGE(printerList.options.length, printerListMinLength); 115 assertGE(printerList.options.length, 2);
201 expectEquals(fooIndex, printerList.selectedIndex); 116 expectEquals(0, printerList.selectedIndex);
202 expectEquals('FooName', printerList.options[fooIndex].text, 117 expectEquals('FooName', printerList.options[0].text, 'fooIndex=0');
203 'fooIndex=' + fooIndex); 118 expectEquals('FooDevice', printerList.options[0].value, 'fooIndex=0');
204 expectEquals('FooDevice', printerList.options[fooIndex].value, 119 expectEquals('BarName', printerList.options[1].text, 'barIndex=1');
205 'fooIndex=' + fooIndex); 120 expectEquals('BarDevice', printerList.options[1].value, 'barIndex=1');
206 expectEquals('BarName', printerList.options[barIndex].text,
207 'barIndex=' + barIndex);
208 expectEquals('BarDevice', printerList.options[barIndex].value,
209 'barIndex=' + barIndex);
210 }); 121 });
211 122
212 // Test that the printer list is structured correctly after calling 123 // Test that the printer list is structured correctly after calling
213 // addCloudPrinters with an empty list. 124 // addCloudPrinters with an empty list.
214 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { 125 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
215 cloudprint.addCloudPrinters([], addDestinationListOptionAtPosition); 126 var initialSettingsSetEvent =
216 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];
217 assertNotEquals(null, printerList); 150 assertNotEquals(null, printerList);
218 }); 151 assertGE(printerList.options.length, 2);
219 152 expectEquals(0, printerList.selectedIndex);
220 // Test that the printer list is structured correctly after attempting to add 153 expectEquals('FooName', printerList.options[0].text, 'fooIndex=0');
221 // individual cloud printers until no more can be added. 154 expectEquals('FooDevice', printerList.options[0].value, 'fooIndex=0');
222 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloud', function() { 155 expectEquals('BarName', printerList.options[1].text, 'barIndex=1');
223 var printerList = $('printer-list'); 156 expectEquals('BarDevice', printerList.options[1].value, 'barIndex=1');
224 assertNotEquals(null, printerList);
225 var printer = new Object;
226 printer['name'] = 'FooCloud';
227 for (var i = 0; i < maxCloudPrinters; i++) {
228 printer['id'] = String(i);
229 cloudprint.addCloudPrinters([printer], addDestinationListOptionAtPosition);
230 expectEquals('FooCloud', printerList.options[i].text);
231 expectEquals(String(i), printerList.options[i].value);
232 }
233 cloudprint.addCloudPrinters([printer], addDestinationListOptionAtPosition);
234 expectNotEquals('FooCloud', printerList.options[i].text);
235 expectNotEquals(String(i), printerList.options[i].value);
236 for (var i = 0; i < maxCloudPrinters; i++) {
237 expectEquals('FooCloud', printerList.options[i].text);
238 expectEquals(String(i), printerList.options[i].value);
239 }
240 }); 157 });
241 158
242 /** 159 /**
243 * Verify that |section| visibility matches |visible|. 160 * Verify that |section| visibility matches |visible|.
244 * @param {HTMLDivElement} section The section to check. 161 * @param {HTMLDivElement} section The section to check.
245 * @param {boolean} visible The expected state of visibility. 162 * @param {boolean} visible The expected state of visibility.
246 */ 163 */
247 function checkSectionVisible(section, visible) { 164 function checkSectionVisible(section, visible) {
248 assertNotEquals(null, section); 165 assertNotEquals(null, section);
249 expectEquals(section.classList.contains('visible'), visible, 166 expectEquals(
250 'section=' + section); 167 visible, section.classList.contains('visible'), 'section=' + section.id);
251 } 168 }
252 169
253 // Test that disabled settings hide the disabled sections. 170 // Test that disabled settings hide the disabled sections.
254 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { 171 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
255 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice'). 172 var initialSettingsSetEvent =
256 will(callFunction(function() { 173 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
257 updateWithPrinterCapabilities({ 174 initialSettingsSetEvent.initialSettings = this.initialSettings_;
258 disableColorOption: true, 175 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
259 setColorAsDefault: true, 176
260 disableCopiesOption: true, 177 var localDestsSetEvent =
261 disableLandscapeOption: true, 178 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
262 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX, 179 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
263 }); 180 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
264 })); 181
265 182 checkSectionVisible($('layout-settings'), true);
266 updateControlsWithSelectedPrinterCapabilities(); 183 checkSectionVisible($('color-settings'), true);
267 184 checkSectionVisible($('copies-settings'), true);
268 checkSectionVisible(layoutSettings.layoutOption_, false); 185
269 checkSectionVisible(colorSettings.colorOption_, false); 186 var capsSetEvent =
270 checkSectionVisible(copiesSettings.copiesOption_, false); 187 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
188 capsSetEvent.settingsInfo = {
189 'disableColorOption': true,
190 'setColorAsDefault': true,
191 'disableCopiesOption': true,
192 'disableLandscapeOption': true,
193 'printerDefaultDuplexValue': 0
194 };
195 this.nativeLayer_.dispatchEvent(capsSetEvent);
196
197 checkSectionVisible($('layout-settings'), false);
198 checkSectionVisible($('color-settings'), false);
199 checkSectionVisible($('copies-settings'), false);
271 }); 200 });
272 201
273 // Page layout has zero margins. Hide header and footer option. 202 // Page layout has zero margins. Hide header and footer option.
274 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter', 203 TEST_F(
275 function() { 204 'PrintPreviewWebUITest',
276 setInitialSettings({previewModifiable: true}); 205 'PageLayoutHasNoMarginsHideHeaderFooter',
277 onDidGetDefaultPageLayout({ 206 function() {
278 contentWidth: 100, contentHeight: 200, marginLeft: 0, marginRight: 0, 207 var initialSettingsSetEvent =
279 marginTop: 0, marginBottom: 0, printableAreaX: 0, printableAreaY: 0, 208 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
280 printableAreaWidth: 100, printableAreaHeight: 200}, true); 209 initialSettingsSetEvent.initialSettings = this.initialSettings_;
281 checkSectionVisible(headerFooterSettings.headerFooterOption_, false); 210 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
282 }); 211
283 212 var localDestsSetEvent =
284 // Page layout has non-zero margins. Show header and footer option. 213 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
285 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter', 214 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
286 function() { 215 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
287 setInitialSettings({previewModifiable: true}); 216
288 onDidGetDefaultPageLayout({ 217 checkSectionVisible($('header-footer-settings'), true);
289 contentWidth: 100, contentHeight: 200, marginLeft: 3, marginRight: 2, 218
290 marginTop: 4, marginBottom: 1, printableAreaX: 1, printableAreaY: 1, 219 printPreview.printTicketStore_.updateMarginsType(
291 printableAreaWidth: 103, printableAreaHeight: 203}, true); 220 print_preview.ticket_items.MarginsType.Value.CUSTOM);
292 checkSectionVisible(headerFooterSettings.headerFooterOption_, true); 221 printPreview.printTicketStore_.updateCustomMarginsInPts(
222 new print_preview.Margins(0, 0, 0, 0));
223
224 checkSectionVisible($('header-footer-settings'), false);
225 });
226
227 // Page layout has half-inch margins. Show header and footer option.
228 TEST_F(
229 'PrintPreviewWebUITest',
230 'PageLayoutHasMarginsShowHeaderFooter',
231 function() {
232 var initialSettingsSetEvent =
233 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
234 initialSettingsSetEvent.initialSettings = this.initialSettings_;
235 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
236
237 var localDestsSetEvent =
238 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
239 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
240 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
241
242 checkSectionVisible($('header-footer-settings'), true);
243
244 printPreview.printTicketStore_.updateMarginsType(
245 print_preview.ticket_items.MarginsType.Value.CUSTOM);
246 printPreview.printTicketStore_.updateCustomMarginsInPts(
247 new print_preview.Margins(36, 36, 36, 36));
248
249 checkSectionVisible($('header-footer-settings'), true);
293 }); 250 });
294 251
295 // Page layout has zero top and bottom margins. Hide header and footer option. 252 // Page layout has zero top and bottom margins. Hide header and footer option.
296 TEST_F('PrintPreviewWebUITest', 'ZeroTopAndBottomMarginsHideHeaderFooter', 253 TEST_F(
297 function() { 254 'PrintPreviewWebUITest',
298 setInitialSettings({previewModifiable: true}); 255 'ZeroTopAndBottomMarginsHideHeaderFooter',
299 onDidGetDefaultPageLayout({ 256 function() {
300 contentWidth: 100, contentHeight: 200, marginLeft: 3, marginRight: 2, 257 var initialSettingsSetEvent =
301 marginTop: 0, marginBottom: 0, printableAreaX: 1, printableAreaY: 1, 258 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
302 printableAreaWidth: 98, printableAreaHeight: 198}, false); 259 initialSettingsSetEvent.initialSettings = this.initialSettings_;
303 checkSectionVisible(headerFooterSettings.headerFooterOption_, false); 260 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
304 }); 261
305 262 var localDestsSetEvent =
306 // Page layout has zero top and non-zero bottom margin. Show header and footer 263 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
264 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
265 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
266
267 checkSectionVisible($('header-footer-settings'), true);
268
269 printPreview.printTicketStore_.updateMarginsType(
270 print_preview.ticket_items.MarginsType.Value.CUSTOM);
271 printPreview.printTicketStore_.updateCustomMarginsInPts(
272 new print_preview.Margins(0, 36, 0, 36));
273
274 checkSectionVisible($('header-footer-settings'), false);
275 });
276
277 // Page layout has zero top and half-inch bottom margin. Show header and footer
307 // option. 278 // option.
308 TEST_F('PrintPreviewWebUITest', 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter', 279 TEST_F(
309 function() { 280 'PrintPreviewWebUITest',
310 setInitialSettings({previewModifiable: true}); 281 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
311 onDidGetDefaultPageLayout({ 282 function() {
312 contentWidth: 100, contentHeight: 200, marginLeft: 6, marginRight: 4, 283 var initialSettingsSetEvent =
313 marginTop: 0, marginBottom: 3, printableAreaX: 1, printableAreaY: 1, 284 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
314 printableAreaWidth: 103, printableAreaHeight: 208}, false); 285 initialSettingsSetEvent.initialSettings = this.initialSettings_;
315 checkSectionVisible(headerFooterSettings.headerFooterOption_, true); 286 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
287
288 var localDestsSetEvent =
289 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
290 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
291 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
292
293 checkSectionVisible($('header-footer-settings'), true);
294
295 printPreview.printTicketStore_.updateMarginsType(
296 print_preview.ticket_items.MarginsType.Value.CUSTOM);
297 printPreview.printTicketStore_.updateCustomMarginsInPts(
298 new print_preview.Margins(0, 36, 36, 36));
299
300 checkSectionVisible($('header-footer-settings'), true);
316 }); 301 });
317 302
318 // Test that the color settings are set according to the printer capabilities. 303 // Test that the color settings are set according to the printer capabilities.
319 TEST_F('PrintPreviewWebUITest', 'TestColorSettings', function() { 304 TEST_F('PrintPreviewWebUITest', 'TestColorSettings', function() {
320 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice'). 305 var initialSettingsSetEvent =
321 will(callFunction(function() { 306 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
322 updateWithPrinterCapabilities({ 307 initialSettingsSetEvent.initialSettings = this.initialSettings_;
323 disableColorOption: false, 308 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
324 setColorAsDefault: true, 309
325 disableCopiesOption: false, 310 var localDestsSetEvent =
326 disableLandscapeOption: false, 311 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
327 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX, 312 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
328 }); 313 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
329 })); 314
330 315 checkSectionVisible($('color-settings'), true);
331 updateControlsWithSelectedPrinterCapabilities(); 316
332 expectTrue(colorSettings.colorRadioButton.checked); 317 var capsSetEvent =
333 expectFalse(colorSettings.bwRadioButton.checked); 318 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
334 319 capsSetEvent.settingsInfo = {
335 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice'). 320 'disableColorOption': false,
336 will(callFunction(function() { 321 'setColorAsDefault': true,
337 updateWithPrinterCapabilities({ 322 'disableCopiesOption': true,
338 disableColorOption: false, 323 'disableLandscapeOption': true,
339 setColorAsDefault: false, 324 'printerDefaultDuplexValue': 0
340 disableCopiesOption: false, 325 };
341 disableLandscapeOption: false, 326 this.nativeLayer_.dispatchEvent(capsSetEvent);
342 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX, 327
343 }); 328 checkSectionVisible($('color-settings'), true);
344 })); 329
345 330 var colorOption = $('color-settings').getElementsByClassName(
346 updateControlsWithSelectedPrinterCapabilities(); 331 'color-settings-color-option')[0];
347 expectFalse(colorSettings.colorRadioButton.checked); 332 var bwOption = $('color-settings').getElementsByClassName(
348 expectTrue(colorSettings.bwRadioButton.checked); 333 'color-settings-bw-option')[0];
334 expectTrue(colorOption.checked);
335 expectFalse(bwOption.checked);
336
337 var capsSetEvent =
338 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
339 capsSetEvent.settingsInfo = {
340 'disableColorOption': false,
341 'setColorAsDefault': false,
342 'disableCopiesOption': false,
343 'disableLandscapeOption': false,
344 'printerDefaultDuplexValue': 0
345 };
346 this.nativeLayer_.dispatchEvent(capsSetEvent);
347
348 checkSectionVisible($('color-settings'), true);
349 expectFalse(colorOption.checked);
350 expectTrue(bwOption.checked);
349 }); 351 });
350 352
351 // Test to verify that duplex settings are set according to the printer 353 // Test to verify that duplex settings are set according to the printer
352 // capabilities. 354 // capabilities.
353 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettings', function() { 355 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettings', function() {
354 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice'). 356 var initialSettingsSetEvent =
355 will(callFunction(function() { 357 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
356 updateWithPrinterCapabilities({ 358 // Need to override test defaults for the initial settings, because initial
357 disableColorOption: false, 359 // duplex value needs to be unspecified.
358 setColorAsDefault: false, 360 initialSettingsSetEvent.initialSettings =
359 disableCopiesOption: false, 361 new print_preview.NativeInitialSettings(
360 disableLandscapeOption: false, 362 false /*isInKioskAutoPrintMode*/,
361 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX, 363 ',' /*thousandsDelimeter*/,
362 }); 364 '.' /*decimalDelimeter*/,
363 })); 365 1 /*unitType*/,
364 updateControlsWithSelectedPrinterCapabilities(); 366 true /*isDocumentModifiable*/,
365 expectEquals(copiesSettings.duplexMode, print_preview.CopiesSettings.SIMPLEX); 367 0 /*marginsType*/,
366 expectEquals(copiesSettings.twoSidedOption_.hidden, false); 368 null /*customMargins*/,
369 null /*isDuplexEnabled*/,
370 false /*isHeaderFooterEnabled*/,
371 'FooDevice' /*initialDestinationId*/);
372 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
373
374 var localDestsSetEvent =
375 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
376 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
377 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
378
379 var copiesDiv = $('copies-settings');
380 var duplexDiv = copiesDiv.getElementsByClassName('copies-settings-duplex')[0];
381 var duplexCheckbox = copiesDiv.getElementsByClassName(
382 'copies-settings-duplex-checkbox')[0];
383
384 checkSectionVisible(copiesDiv, true);
385 expectFalse(duplexDiv.hidden);
386 expectTrue(duplexCheckbox.checked);
387
388 var capsSetEvent =
389 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
390 capsSetEvent.settingsInfo = {
391 'disableColorOption': false,
392 'setColorAsDefault': true,
393 'disableCopiesOption': false,
394 'disableLandscapeOption': true,
395 'printerDefaultDuplexValue': 0
396 };
397 this.nativeLayer_.dispatchEvent(capsSetEvent);
398
399 checkSectionVisible(copiesDiv, true);
400 expectFalse(duplexDiv.hidden);
401 expectFalse(duplexCheckbox.checked);
367 402
368 // If the printer default duplex value is UNKNOWN_DUPLEX_MODE, hide the 403 // If the printer default duplex value is UNKNOWN_DUPLEX_MODE, hide the
369 // two sided option. 404 // two sided option.
370 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice'). 405 var capsSetEvent =
371 will(callFunction(function() { 406 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
372 updateWithPrinterCapabilities({ 407 capsSetEvent.settingsInfo = {
373 disableColorOption: false, 408 'disableColorOption': false,
374 setColorAsDefault: false, 409 'setColorAsDefault': false,
375 disableCopiesOption: false, 410 'disableCopiesOption': false,
376 disableLandscapeOption: false, 411 'disableLandscapeOption': false,
377 printerDefaultDuplexValue: 412 'printerDefaultDuplexValue': -1
378 print_preview.CopiesSettings.UNKNOWN_DUPLEX_MODE, 413 };
379 }); 414 this.nativeLayer_.dispatchEvent(capsSetEvent);
380 })); 415
381 updateControlsWithSelectedPrinterCapabilities(); 416 checkSectionVisible(copiesDiv, true);
382 expectEquals(copiesSettings.duplexMode, 417 expectTrue(duplexDiv.hidden);
383 print_preview.CopiesSettings.UNKNOWN_DUPLEX_MODE); 418
384 expectEquals(copiesSettings.twoSidedOption_.hidden, true); 419 var capsSetEvent =
385 420 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
386 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice'). 421 capsSetEvent.settingsInfo = {
387 will(callFunction(function() { 422 'disableColorOption': false,
388 updateWithPrinterCapabilities({ 423 'setColorAsDefault': false,
389 disableColorOption: false, 424 'disableCopiesOption': false,
390 setColorAsDefault: false, 425 'disableLandscapeOption': false,
391 disableCopiesOption: false, 426 'printerDefaultDuplexValue': 1
392 disableLandscapeOption: false, 427 };
393 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX, 428 this.nativeLayer_.dispatchEvent(capsSetEvent);
394 }); 429
395 })); 430 checkSectionVisible(copiesDiv, true);
396 updateControlsWithSelectedPrinterCapabilities(); 431 expectFalse(duplexDiv.hidden);
397 expectEquals(copiesSettings.twoSidedOption_.hidden, false); 432 expectTrue(duplexCheckbox.checked);
398 expectEquals(copiesSettings.duplexMode, print_preview.CopiesSettings.SIMPLEX);
399 copiesSettings.twoSidedCheckbox.checked = true;
400 expectEquals(
401 copiesSettings.duplexMode, print_preview.CopiesSettings.LONG_EDGE);
402 }); 433 });
403 434
404 // Test that changing the selected printer updates the preview. 435 // Test that changing the selected printer updates the preview.
405 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { 436 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
406 var savedArgs = new SaveMockArguments(); 437
407 this.mockHandler.expects(once()).getPreview(savedArgs.match(ANYTHING)). 438 var initialSettingsSetEvent =
408 will(callFunctionWithSavedArgs(savedArgs, function(args) { 439 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
409 updatePrintPreview(2, JSON.parse(args[0]).requestID); 440 initialSettingsSetEvent.initialSettings = this.initialSettings_;
410 })); 441 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
411 442
412 this.mockGlobals.expects(once()).updateWithPrinterCapabilities( 443 var localDestsSetEvent =
413 savedArgs.match(ANYTHING)). 444 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
414 will(callGlobalWithSavedArgs( 445 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
415 savedArgs, 'updateWithPrinterCapabilities')); 446 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
416 447
417 var printerList = $('printer-list'); 448 var capsSetEvent =
418 assertNotEquals(null, printerList, 'printerList'); 449 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
419 assertGE(printerList.options.length, printerListMinLength); 450 capsSetEvent.settingsInfo = {
420 expectEquals(fooIndex, printerList.selectedIndex, 451 'disableColorOption': false,
421 'fooIndex=' + fooIndex); 452 'setColorAsDefault': true,
422 var oldLastPreviewRequestID = lastPreviewRequestID; 453 'disableCopiesOption': true,
423 ++printerList.selectedIndex; 454 'disableLandscapeOption': true,
424 updateControlsWithSelectedPrinterCapabilities(); 455 'printerDefaultDuplexValue': 0
425 expectNotEquals(oldLastPreviewRequestID, lastPreviewRequestID); 456 };
426 }); 457 this.nativeLayer_.dispatchEvent(capsSetEvent);
427 458
428 /** 459 var previewGenerator = mock(print_preview.PreviewGenerator);
429 * Test fixture to test case when no PDF plugin exists. 460 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy();
430 * @extends {PrintPreviewWebUITest} 461 previewGenerator.expects(once()).requestPreview();
431 * @constructor 462
432 */ 463 var barDestination;
433 function PrintPreviewNoPDFWebUITest() {} 464 var destinations = printPreview.destinationStore_.destinations;
434 465 for (var destination, i = 0; destination = destinations[i]; i++) {
435 PrintPreviewNoPDFWebUITest.prototype = { 466 if (destination.id == 'BarDevice') {
436 __proto__: PrintPreviewWebUITest.prototype, 467 barDestination = destination;
437 468 break;
438 /** 469 }
439 * Provide a typedef for C++ to correspond to JS subclass. 470 }
440 * @type {?string} 471
441 * @override 472 printPreview.destinationStore_.selectDestination(barDestination);
442 */ 473
443 typedefCppFixture: 'PrintPreviewWebUITest', 474 var capsSetEvent =
444 475 new cr.Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
445 /** 476 capsSetEvent.settingsInfo = {
446 * Always return false to simulate failure and check expected error condition. 477 'disableColorOption': true,
447 * @return {boolean} Always false. 478 'setColorAsDefault': false,
448 * @override 479 'disableCopiesOption': true,
449 */ 480 'disableLandscapeOption': true,
450 checkCompatiblePluginExists: function() { 481 'printerDefaultDuplexValue': 0
451 return false; 482 };
452 }, 483 this.nativeLayer_.dispatchEvent(capsSetEvent);
453 }; 484 });
454 485
455 // Test that error message is displayed when plugin doesn't exist. 486 // Test that error message is displayed when plugin doesn't exist.
456 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() { 487 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
457 var errorButton = $('error-button'); 488 var previewAreaEl = $('preview-area');
458 assertNotEquals(null, errorButton); 489
459 expectFalse(errorButton.disabled); 490 var loadingMessageEl =
460 var errorText = $('custom-message'); 491 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0];
461 assertNotEquals(null, errorText); 492 expectEquals('none', loadingMessageEl.style.display);
462 expectFalse(errorText.hidden); 493
463 }); 494 var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
495 'preview-area-preview-failed-message')[0];
496 expectEquals('none', previewFailedMessageEl.style.display);
497
498 var printFailedMessageEl =
499 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0];
500 expectEquals('none', printFailedMessageEl.style.display);
501
502 var customMessageEl =
503 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0];
504 expectEquals('', customMessageEl.style.display);
505 });
OLDNEW
« chrome/browser/resources/print_preview/native_layer.js ('K') | « chrome/chrome_tests.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698