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

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

Issue 10083060: [Print Preview]: Added code to support pdf fit to page functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 8 years, 8 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/renderer/print_web_view_helper.cc ('k') | printing/print_job_constants.h » ('j') | 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 * @extends {testing.Test} 7 * @extends {testing.Test}
8 * @constructor 8 * @constructor
9 */ 9 */
10 function PrintPreviewWebUITest() {} 10 function PrintPreviewWebUITest() {}
11 11
12 PrintPreviewWebUITest.prototype = { 12 PrintPreviewWebUITest.prototype = {
13 __proto__: testing.Test.prototype, 13 __proto__: testing.Test.prototype,
14 14
15 /** 15 /**
16 * Browse to the sample page, cause print preview & call preLoad(). 16 * Browse to the sample page, cause print preview & call preLoad().
17 * @type {string} 17 * @type {string}
18 * @override 18 * @override
19 */ 19 */
20 browsePrintPreload: 'print_preview_hello_world_test.html', 20 browsePrintPreload: 'print_preview_hello_world_test.html',
21 21
22 /** 22 /**
23 * Register a mock handler to ensure expectations are met and print preview 23 * Register a mock handler to ensure expectations are met and print preview
24 * behaves correctly. 24 * behaves correctly.
25 * @type {Function} 25 * @type {Function}
26 * @this {PrintPreviewWebUITest}
26 * @override 27 * @override
27 */ 28 */
28 preLoad: function() { 29 preLoad: function() {
29 this.makeAndRegisterMockHandler(['getInitialSettings', 30 this.makeAndRegisterMockHandler(['getInitialSettings',
30 'getPrinters', 31 'getPrinters',
31 'getPreview', 32 'getPreview',
32 'print', 33 'print',
33 'getPrinterCapabilities', 34 'getPrinterCapabilities',
34 'showSystemDialog', 35 'showSystemDialog',
35 'morePrinters', 36 'morePrinters',
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 114
114 /** 115 /**
115 * Create the PDF plugin or reload the existing one. This function replaces 116 * Create the PDF plugin or reload the existing one. This function replaces
116 * createOrReloadPDFPlugin defined in 117 * createOrReloadPDFPlugin defined in
117 * chrome/browser/resources/print_preview/preview_area.js when there is no 118 * 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 * 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 * 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 * empty methods, which are used by testing and that would be provided by the
121 * HTMLEmbedElement when the PDF plugin exists. 122 * HTMLEmbedElement when the PDF plugin exists.
122 * @param {number} srcDataIndex Preview data source index. 123 * @param {number} srcDataIndex Preview data source index.
124 * @this {PrintPreviewWebUITest}
123 */ 125 */
124 createOrReloadPDFPlugin: function(srcDataIndex) { 126 createOrReloadPDFPlugin: function(srcDataIndex) {
125 var pdfViewer = $('pdf-viewer'); 127 var pdfViewer = $('pdf-viewer');
126 if (pdfViewer) 128 if (pdfViewer)
127 return; 129 return;
128 130
129 var previewUid = 1; 131 var previewUid = 1;
130 pdfViewer = document.createElement('div'); 132 pdfViewer = document.createElement('div');
131 pdfViewer.setAttribute('id', 'pdf-viewer'); 133 pdfViewer.setAttribute('id', 'pdf-viewer');
132 pdfViewer.setAttribute('type', 134 pdfViewer.setAttribute('type',
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 */ 188 */
187 var fooIndex = 0; 189 var fooIndex = 0;
188 190
189 /** 191 /**
190 * The expected index of the "bar" printer returned by the stubbed handler. 192 * The expected index of the "bar" printer returned by the stubbed handler.
191 * @type {number} 193 * @type {number}
192 * @const 194 * @const
193 */ 195 */
194 var barIndex = 1; 196 var barIndex = 1;
195 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
196 // Test some basic assumptions about the print preview WebUI. 205 // Test some basic assumptions about the print preview WebUI.
197 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { 206 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
198 var printerList = $('printer-list'); 207 var printerList = $('printer-list');
199 assertNotEquals(null, printerList); 208 assertNotEquals(null, printerList);
200 assertGE(printerList.options.length, printerListMinLength); 209 assertGE(printerList.options.length, printerListMinLength);
201 expectEquals(fooIndex, printerList.selectedIndex); 210 expectEquals(fooIndex, printerList.selectedIndex);
202 expectEquals('FooName', printerList.options[fooIndex].text, 211 expectEquals('FooName', printerList.options[fooIndex].text,
203 'fooIndex=' + fooIndex); 212 'fooIndex=' + fooIndex);
204 expectEquals('FooDevice', printerList.options[fooIndex].value, 213 expectEquals('FooDevice', printerList.options[fooIndex].value,
205 'fooIndex=' + fooIndex); 214 'fooIndex=' + fooIndex);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 * Verify that |section| visibility matches |visible|. 252 * Verify that |section| visibility matches |visible|.
244 * @param {HTMLDivElement} section The section to check. 253 * @param {HTMLDivElement} section The section to check.
245 * @param {boolean} visible The expected state of visibility. 254 * @param {boolean} visible The expected state of visibility.
246 */ 255 */
247 function checkSectionVisible(section, visible) { 256 function checkSectionVisible(section, visible) {
248 assertNotEquals(null, section); 257 assertNotEquals(null, section);
249 expectEquals(section.classList.contains('visible'), visible, 258 expectEquals(section.classList.contains('visible'), visible,
250 'section=' + section); 259 'section=' + section);
251 } 260 }
252 261
262 /**
263 * Verify that |section| style display matches |value|.
264 * @param {HTMLDivElement} section The section to check.
265 * @param {string} value The expected display style value.
266 */
267 function checkSectionDisplayStyle(section, value) {
268 assertNotEquals(null, section);
dpapad 2012/04/21 01:36:06 Isn't there a assertNotNull() method?
269 expectEquals(section.style.display, value, 'section=' + section);
270 }
271
253 // Test that disabled settings hide the disabled sections. 272 // Test that disabled settings hide the disabled sections.
254 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { 273 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
255 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice'). 274 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice').
256 will(callFunction(function() { 275 will(callFunction(function() {
257 updateWithPrinterCapabilities({ 276 updateWithPrinterCapabilities({
258 disableColorOption: true, 277 disableColorOption: true,
259 setColorAsDefault: true, 278 setColorAsDefault: true,
260 disableCopiesOption: true, 279 disableCopiesOption: true,
261 disableLandscapeOption: true, 280 disableLandscapeOption: true,
262 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX, 281 printerDefaultDuplexValue: print_preview.CopiesSettings.SIMPLEX,
263 }); 282 });
264 })); 283 }));
265 284
266 updateControlsWithSelectedPrinterCapabilities(); 285 updateControlsWithSelectedPrinterCapabilities();
267 286
268 checkSectionVisible(layoutSettings.layoutOption_, false); 287 checkSectionVisible(layoutSettings.layoutOption_, false);
269 checkSectionVisible(colorSettings.colorOption_, false); 288 checkSectionVisible(colorSettings.colorOption_, false);
270 checkSectionVisible(copiesSettings.copiesOption_, false); 289 checkSectionVisible(copiesSettings.copiesOption_, false);
271 }); 290 });
272 291
292 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the
293 // fit to page option.
294 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedHideFitToPageOption',
295 function() {
296 var savedArgs = new SaveMockArguments();
297 this.mockHandler.expects(once()).getPreview(savedArgs.match(ANYTHING)).
298 will(callFunctionWithSavedArgs(savedArgs, function(args) {
299 updatePrintPreview(2, JSON.parse(args[0]).requestID);
300 }));
301
302 this.mockGlobals.expects(once()).updateWithPrinterCapabilities(
303 savedArgs.match(ANYTHING)).
304 will(callGlobalWithSavedArgs(
305 savedArgs, 'updateWithPrinterCapabilities'));
306
307 setInitialSettings({previewModifiable: false});
308 var printerList = $('printer-list');
309 assertNotEquals(null, printerList, 'printerList');
310 assertGE(printerList.options.length, printerListMinLength);
311 for (var i = 0; i < printerList.options.length; i++) {
312 if (printerList.options[i].text == saveAsPDFOptionStr &&
313 printerList.options[i].value == saveAsPDFOptionStr) {
314 printerList.selectedIndex = i;
315 break;
316 }
317 }
318 updateControlsWithSelectedPrinterCapabilities();
319 checkSectionDisplayStyle(fitToPageSettings.fitToPageOption_, 'none');
320 });
321
322 // When the source is 'HTML', we always hide the fit to page option.
323 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLHideFitToPageOption', function() {
324 var savedArgs = new SaveMockArguments();
325 this.mockHandler.expects(once()).getPreview(savedArgs.match(ANYTHING)).
326 will(callFunctionWithSavedArgs(savedArgs, function(args) {
327 updatePrintPreview(2, JSON.parse(args[0]).requestID);
328 }));
329
330 this.mockGlobals.expects(once()).updateWithPrinterCapabilities(
331 savedArgs.match(ANYTHING)).
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 expectFalse(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
273 // Page layout has zero margins. Hide header and footer option. 406 // Page layout has zero margins. Hide header and footer option.
274 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter', 407 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
275 function() { 408 function() {
276 setInitialSettings({previewModifiable: true}); 409 setInitialSettings({previewModifiable: true});
277 onDidGetDefaultPageLayout({ 410 onDidGetDefaultPageLayout({
278 contentWidth: 100, contentHeight: 200, marginLeft: 0, marginRight: 0, 411 contentWidth: 100, contentHeight: 200, marginLeft: 0, marginRight: 0,
279 marginTop: 0, marginBottom: 0, printableAreaX: 0, printableAreaY: 0, 412 marginTop: 0, marginBottom: 0, printableAreaX: 0, printableAreaY: 0,
280 printableAreaWidth: 100, printableAreaHeight: 200}, true); 413 printableAreaWidth: 100, printableAreaHeight: 200}, true);
281 checkSectionVisible(headerFooterSettings.headerFooterOption_, false); 414 checkSectionDisplayStyle(headerFooterSettings.headerFooterOption_, 'none');
282 }); 415 });
283 416
284 // Page layout has non-zero margins. Show header and footer option. 417 // Page layout has non-zero margins. Show header and footer option.
285 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter', 418 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter',
286 function() { 419 function() {
287 setInitialSettings({previewModifiable: true}); 420 setInitialSettings({previewModifiable: true});
288 onDidGetDefaultPageLayout({ 421 onDidGetDefaultPageLayout({
289 contentWidth: 100, contentHeight: 200, marginLeft: 3, marginRight: 2, 422 contentWidth: 100, contentHeight: 200, marginLeft: 3, marginRight: 2,
290 marginTop: 4, marginBottom: 1, printableAreaX: 1, printableAreaY: 1, 423 marginTop: 4, marginBottom: 1, printableAreaX: 1, printableAreaY: 1,
291 printableAreaWidth: 103, printableAreaHeight: 203}, true); 424 printableAreaWidth: 103, printableAreaHeight: 203}, true);
292 checkSectionVisible(headerFooterSettings.headerFooterOption_, true); 425 checkSectionDisplayStyle(headerFooterSettings.headerFooterOption_, 'block');
293 }); 426 });
294 427
295 // Page layout has zero top and bottom margins. Hide header and footer option. 428 // Page layout has zero top and bottom margins. Hide header and footer option.
296 TEST_F('PrintPreviewWebUITest', 'ZeroTopAndBottomMarginsHideHeaderFooter', 429 TEST_F('PrintPreviewWebUITest', 'ZeroTopAndBottomMarginsHideHeaderFooter',
297 function() { 430 function() {
298 setInitialSettings({previewModifiable: true}); 431 setInitialSettings({previewModifiable: true});
299 onDidGetDefaultPageLayout({ 432 onDidGetDefaultPageLayout({
300 contentWidth: 100, contentHeight: 200, marginLeft: 3, marginRight: 2, 433 contentWidth: 100, contentHeight: 200, marginLeft: 3, marginRight: 2,
301 marginTop: 0, marginBottom: 0, printableAreaX: 1, printableAreaY: 1, 434 marginTop: 0, marginBottom: 0, printableAreaX: 1, printableAreaY: 1,
302 printableAreaWidth: 98, printableAreaHeight: 198}, false); 435 printableAreaWidth: 98, printableAreaHeight: 198}, false);
303 checkSectionVisible(headerFooterSettings.headerFooterOption_, false); 436 checkSectionDisplayStyle(headerFooterSettings.headerFooterOption_, 'none');
304 }); 437 });
305 438
306 // Page layout has zero top and non-zero bottom margin. Show header and footer 439 // Page layout has zero top and non-zero bottom margin. Show header and footer
307 // option. 440 // option.
308 TEST_F('PrintPreviewWebUITest', 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter', 441 TEST_F('PrintPreviewWebUITest', 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
309 function() { 442 function() {
310 setInitialSettings({previewModifiable: true}); 443 setInitialSettings({previewModifiable: true});
311 onDidGetDefaultPageLayout({ 444 onDidGetDefaultPageLayout({
312 contentWidth: 100, contentHeight: 200, marginLeft: 6, marginRight: 4, 445 contentWidth: 100, contentHeight: 200, marginLeft: 6, marginRight: 4,
313 marginTop: 0, marginBottom: 3, printableAreaX: 1, printableAreaY: 1, 446 marginTop: 0, marginBottom: 3, printableAreaX: 1, printableAreaY: 1,
314 printableAreaWidth: 103, printableAreaHeight: 208}, false); 447 printableAreaWidth: 103, printableAreaHeight: 208}, false);
315 checkSectionVisible(headerFooterSettings.headerFooterOption_, true); 448 checkSectionDisplayStyle(headerFooterSettings.headerFooterOption_, 'block');
316 }); 449 });
317 450
318 // Test that the color settings are set according to the printer capabilities. 451 // Test that the color settings are set according to the printer capabilities.
319 TEST_F('PrintPreviewWebUITest', 'TestColorSettings', function() { 452 TEST_F('PrintPreviewWebUITest', 'TestColorSettings', function() {
320 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice'). 453 this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice').
321 will(callFunction(function() { 454 will(callFunction(function() {
322 updateWithPrinterCapabilities({ 455 updateWithPrinterCapabilities({
323 disableColorOption: false, 456 disableColorOption: false,
324 setColorAsDefault: true, 457 setColorAsDefault: true,
325 disableCopiesOption: false, 458 disableCopiesOption: false,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 587
455 // Test that error message is displayed when plugin doesn't exist. 588 // Test that error message is displayed when plugin doesn't exist.
456 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() { 589 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() {
457 var errorButton = $('error-button'); 590 var errorButton = $('error-button');
458 assertNotEquals(null, errorButton); 591 assertNotEquals(null, errorButton);
459 expectFalse(errorButton.disabled); 592 expectFalse(errorButton.disabled);
460 var errorText = $('custom-message'); 593 var errorText = $('custom-message');
461 assertNotEquals(null, errorText); 594 assertNotEquals(null, errorText);
462 expectFalse(errorText.hidden); 595 expectFalse(errorText.hidden);
463 }); 596 });
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper.cc ('k') | printing/print_job_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698