OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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() {} |
(...skipping 21 matching lines...) Expand all Loading... |
32 /** | 32 /** |
33 * Create a handler class with empty methods to allow mocking to register | 33 * Create a handler class with empty methods to allow mocking to register |
34 * expectations and for registration of handlers with chrome.send. | 34 * expectations and for registration of handlers with chrome.send. |
35 * @constructor | 35 * @constructor |
36 */ | 36 */ |
37 function MockPrintPreviewHandler() {} | 37 function MockPrintPreviewHandler() {} |
38 | 38 |
39 MockPrintPreviewHandler.prototype = { | 39 MockPrintPreviewHandler.prototype = { |
40 getDefaultPrinter: function() {}, | 40 getDefaultPrinter: function() {}, |
41 getPrinters: function() {}, | 41 getPrinters: function() {}, |
42 getPreview: function(settings) {}, | 42 getPreview: function(settings, draft_page_count, modifiable) {}, |
43 print: function(settings) {}, | 43 print: function(settings) {}, |
44 getPrinterCapabilities: function(printerName) {}, | 44 getPrinterCapabilities: function(printerName) {}, |
45 showSystemDialog: function() {}, | 45 showSystemDialog: function() {}, |
46 morePrinters: function() {}, | 46 morePrinters: function() {}, |
47 signIn: function() {}, | 47 signIn: function() {}, |
48 addCloudPrinter: function() {}, | 48 addCloudPrinter: function() {}, |
49 manageCloudPrinters: function() {}, | 49 manageCloudPrinters: function() {}, |
50 manageLocalPrinters: function() {}, | 50 manageLocalPrinters: function() {}, |
51 closePrintPreviewTab: function() {}, | 51 closePrintPreviewTab: function() {}, |
52 hidePreview: function() {}, | 52 hidePreview: function() {}, |
(...skipping 12 matching lines...) Expand all Loading... |
65 mockHandler.stubs().getPrinterCapabilities(NOT_NULL). | 65 mockHandler.stubs().getPrinterCapabilities(NOT_NULL). |
66 will(callFunction(function() { | 66 will(callFunction(function() { |
67 updateWithPrinterCapabilities({ | 67 updateWithPrinterCapabilities({ |
68 disableColorOption: true, | 68 disableColorOption: true, |
69 setColorAsDefault: true, | 69 setColorAsDefault: true, |
70 disableCopiesOption: true, | 70 disableCopiesOption: true, |
71 }); | 71 }); |
72 })); | 72 })); |
73 var savedArgs = new SaveMockArguments(); | 73 var savedArgs = new SaveMockArguments(); |
74 mockHandler.stubs().getPreview(savedArgs.match(NOT_NULL)). | 74 mockHandler.stubs().getPreview(savedArgs.match(NOT_NULL)). |
75 will(callFunctionWithSavedArgs(savedArgs, function(options) { | 75 will(callFunctionWithSavedArgs(savedArgs, function(args) { |
76 updatePrintPreview('title', true, 1, JSON.parse(options).requestID); | 76 updatePrintPreview(1, JSON.parse(args[0]).requestID); |
77 })); | 77 })); |
78 | 78 |
79 mockHandler.stubs().getPrinters(). | 79 mockHandler.stubs().getPrinters(). |
80 will(callFunction(function() { | 80 will(callFunction(function() { |
81 setUseCloudPrint(false, ''); | 81 setUseCloudPrint(false, ''); |
82 setPrinters([{ | 82 setPrinters([{ |
83 printerName: 'FooName', | 83 printerName: 'FooName', |
84 deviceName: 'FooDevice', | 84 deviceName: 'FooDevice', |
85 }, { | 85 }, { |
86 printerName: 'BarName', | 86 printerName: 'BarName', |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 typedefCppFixture: null, | 136 typedefCppFixture: null, |
137 | 137 |
138 /** | 138 /** |
139 * Create the PDF plugin or reload the existing one. This function replaces | 139 * Create the PDF plugin or reload the existing one. This function replaces |
140 * createPDFPlugin defined in | 140 * createPDFPlugin defined in |
141 * chrome/browser/resources/print_preview/print_preview.js when there is no | 141 * chrome/browser/resources/print_preview/print_preview.js when there is no |
142 * official pdf plugin so that the WebUI logic can be tested. It creates and | 142 * official pdf plugin so that the WebUI logic can be tested. It creates and |
143 * attaches an HTMLDivElement to the |mainview| element with attributes and | 143 * attaches an HTMLDivElement to the |mainview| element with attributes and |
144 * empty methods, which are used by testing and that would be provided by the | 144 * empty methods, which are used by testing and that would be provided by the |
145 * HTMLEmbedElement when the PDF plugin exists. | 145 * HTMLEmbedElement when the PDF plugin exists. |
146 * @param {string} previewUid Preview unique identifier. | 146 * @param {number} srcDataIndex Preview data source index. |
147 */ | 147 */ |
148 createPDFPlugin: function(previewUid) { | 148 createPDFPlugin: function(srcDataIndex) { |
149 var pdfViewer = $('pdf-viewer'); | 149 var pdfViewer = $('pdf-viewer'); |
150 if (pdfViewer) | 150 if (pdfViewer) |
151 return; | 151 return; |
152 | 152 |
| 153 var previewUid = 1; |
153 pdfViewer = document.createElement('div'); | 154 pdfViewer = document.createElement('div'); |
154 pdfViewer.setAttribute('id', 'pdf-viewer'); | 155 pdfViewer.setAttribute('id', 'pdf-viewer'); |
155 pdfViewer.setAttribute('type', | 156 pdfViewer.setAttribute('type', |
156 'application/x-google-chrome-print-preview-pdf'); | 157 'application/x-google-chrome-print-preview-pdf'); |
157 pdfViewer.setAttribute( | 158 pdfViewer.setAttribute( |
158 'src', 'chrome://print/' + previewUid + '/print.pdf'); | 159 'src', |
| 160 'chrome://print/' + previewUid + '/' + srcDataIndex + '/print.pdf'); |
159 pdfViewer.setAttribute('aria-live', 'polite'); | 161 pdfViewer.setAttribute('aria-live', 'polite'); |
160 pdfViewer.setAttribute('aria-atomic', 'true'); | 162 pdfViewer.setAttribute('aria-atomic', 'true'); |
161 function fakeFunction() {} | 163 function fakeFunction() {} |
162 pdfViewer.onload = fakeFunction; | 164 pdfViewer.onload = fakeFunction; |
163 pdfViewer.goToPage = fakeFunction; | 165 pdfViewer.goToPage = fakeFunction; |
164 pdfViewer.removePrintButton = fakeFunction; | 166 pdfViewer.removePrintButton = fakeFunction; |
165 pdfViewer.fitToHeight = fakeFunction; | 167 pdfViewer.fitToHeight = fakeFunction; |
166 pdfViewer.grayscale = fakeFunction; | 168 pdfViewer.grayscale = fakeFunction; |
167 $('mainview').appendChild(pdfViewer); | 169 $('mainview').appendChild(pdfViewer); |
168 onPDFLoad(); | 170 onPDFLoad(); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 | 336 |
335 updateControlsWithSelectedPrinterCapabilities(); | 337 updateControlsWithSelectedPrinterCapabilities(); |
336 expectFalse(colorSettings.colorRadioButton.checked); | 338 expectFalse(colorSettings.colorRadioButton.checked); |
337 expectTrue(colorSettings.bwRadioButton.checked); | 339 expectTrue(colorSettings.bwRadioButton.checked); |
338 }); | 340 }); |
339 | 341 |
340 // Test that changing the selected printer updates the preview. | 342 // Test that changing the selected printer updates the preview. |
341 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { | 343 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { |
342 var savedArgs = new SaveMockArguments(); | 344 var savedArgs = new SaveMockArguments(); |
343 this.mockHandler.expects(once()).getPreview(savedArgs.match(ANYTHING)). | 345 this.mockHandler.expects(once()).getPreview(savedArgs.match(ANYTHING)). |
344 will(callFunctionWithSavedArgs(savedArgs, function(options) { | 346 will(callFunctionWithSavedArgs(savedArgs, function(args) { |
345 updatePrintPreview('title', true, 2, | 347 updatePrintPreview(2, JSON.parse(args[0]).requestID); |
346 JSON.parse(options).requestID); | |
347 })); | 348 })); |
348 | 349 |
349 this.mockGlobals.expects(once()).updateWithPrinterCapabilities( | 350 this.mockGlobals.expects(once()).updateWithPrinterCapabilities( |
350 savedArgs.match(ANYTHING)). | 351 savedArgs.match(ANYTHING)). |
351 will(callGlobalWithSavedArgs( | 352 will(callGlobalWithSavedArgs( |
352 savedArgs, 'updateWithPrinterCapabilities')); | 353 savedArgs, 'updateWithPrinterCapabilities')); |
353 | 354 |
354 var printerList = $('printer-list'); | 355 var printerList = $('printer-list'); |
355 assertNotEquals(null, printerList, 'printerList'); | 356 assertNotEquals(null, printerList, 'printerList'); |
356 assertGE(printerList.options.length, printerListMinLength); | 357 assertGE(printerList.options.length, printerListMinLength); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 392 |
392 // Test that error message is displayed when plugin doesn't exist. | 393 // Test that error message is displayed when plugin doesn't exist. |
393 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() { | 394 TEST_F('PrintPreviewNoPDFWebUITest', 'TestErrorMessage', function() { |
394 var errorButton = $('error-button'); | 395 var errorButton = $('error-button'); |
395 assertNotEquals(null, errorButton); | 396 assertNotEquals(null, errorButton); |
396 expectFalse(errorButton.disabled); | 397 expectFalse(errorButton.disabled); |
397 var errorText = $('error-text'); | 398 var errorText = $('error-text'); |
398 assertNotEquals(null, errorText); | 399 assertNotEquals(null, errorText); |
399 expectFalse(errorText.classList.contains('hidden')); | 400 expectFalse(errorText.classList.contains('hidden')); |
400 }); | 401 }); |
OLD | NEW |