| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 cr.define('print_preview_test', function() { | 5 cr.define('print_preview_test', function() { |
| 6 /** | 6 /** |
| 7 * Index of the "Save as PDF" printer. | 7 * Index of the "Save as PDF" printer. |
| 8 * @type {number} | 8 * @type {number} |
| 9 * @const | 9 * @const |
| 10 */ | 10 */ |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 is_default: true | 138 is_default: true |
| 139 } | 139 } |
| 140 ] | 140 ] |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 }; | 144 }; |
| 145 } | 145 } |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * Get the default media size for |device|. |
| 149 * @param {!print_preview.PrinterCapabilitiesResponse} device |
| 150 * @return {{width_microns: number, |
| 151 * height_microns: number}} The width and height of the default |
| 152 * media. |
| 153 */ |
| 154 function getDefaultMediaSize(device) { |
| 155 var size = device.capabilities.printer.media_size.option.find( |
| 156 function(opt) { return opt.is_default; }); |
| 157 return { width_microns: size.width_microns, |
| 158 height_microns: size.height_microns }; |
| 159 } |
| 160 |
| 161 /** |
| 162 * Get the default page orientation for |device|. |
| 163 * @param {!print_preview.PrinterCapabilitiesResponse} device |
| 164 * @return {string} The default orientation. |
| 165 */ |
| 166 function getDefaultOrientation(device) { |
| 167 return device.capabilities.printer.page_orientation.option.find( |
| 168 function(opt) { return opt.is_default; }).type; |
| 169 } |
| 170 |
| 171 |
| 172 /** |
| 148 * @param {string} printerId | 173 * @param {string} printerId |
| 149 * @return {!Object} | 174 * @return {!Object} |
| 150 */ | 175 */ |
| 151 function getCddTemplateWithAdvancedSettings(printerId) { | 176 function getCddTemplateWithAdvancedSettings(printerId) { |
| 152 var template = getCddTemplate(printerId); | 177 var template = getCddTemplate(printerId); |
| 153 template.capabilities.printer.vendor_capability = [{ | 178 template.capabilities.printer.vendor_capability = [{ |
| 154 display_name: 'Print Area', | 179 display_name: 'Print Area', |
| 155 id: 'Print Area', | 180 id: 'Print Area', |
| 156 type: 'SELECT', | 181 type: 'SELECT', |
| 157 select_cap: { | 182 select_cap: { |
| (...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 expectedMessageStart)); | 1311 expectedMessageStart)); |
| 1287 expectTrue(printButton.disabled); | 1312 expectTrue(printButton.disabled); |
| 1288 | 1313 |
| 1289 // Select a new destination | 1314 // Select a new destination |
| 1290 var barDestination = | 1315 var barDestination = |
| 1291 printPreview.destinationStore_.destinations().find( | 1316 printPreview.destinationStore_.destinations().find( |
| 1292 function(d) { | 1317 function(d) { |
| 1293 return d.id == 'BarDevice'; | 1318 return d.id == 'BarDevice'; |
| 1294 }); | 1319 }); |
| 1295 | 1320 |
| 1296 nativeLayer.setLocalDestinationCapabilities( | 1321 var barDevice = getCddTemplate('BarDevice'); |
| 1297 getCddTemplate('BarDevice')); | 1322 nativeLayer.setLocalDestinationCapabilities(barDevice); |
| 1298 printPreview.destinationStore_.selectDestination(barDestination); | 1323 printPreview.destinationStore_.selectDestination(barDestination); |
| 1299 | 1324 |
| 1300 return nativeLayer.whenCalled('getPrinterCapabilities', 'BarDevice') | 1325 return nativeLayer.whenCalled('getPrinterCapabilities', 'BarDevice') |
| 1301 .then(function() { | 1326 .then(function() { |
| 1302 // Dispatch event indicating new preview has loaded. | 1327 // Dispatch event indicating new preview has loaded. |
| 1303 var previewDoneEvent = new Event( | 1328 var previewDoneEvent = new Event( |
| 1304 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); | 1329 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); |
| 1305 previewArea.dispatchEvent(previewDoneEvent); | 1330 previewArea.dispatchEvent(previewDoneEvent); |
| 1306 | 1331 |
| 1307 // Has active print button and successfully 'prints', indicating | 1332 // Has active print button and successfully 'prints', indicating |
| 1308 // recovery from error state. | 1333 // recovery from error state. |
| 1309 expectFalse(printButton.disabled); | 1334 expectFalse(printButton.disabled); |
| 1310 printButton.click(); | 1335 printButton.click(); |
| 1311 // This should result in a call to print. | 1336 // This should result in a call to print. |
| 1312 return nativeLayer.whenCalled('print'); | 1337 return nativeLayer.whenCalled('print').then( |
| 1338 /** |
| 1339 * @param {{destination: !print_preview.Destination, |
| 1340 * printTicketStore: !print_preview.PrintTicketStore, |
| 1341 * cloudPrintInterface: print_preview |
| 1342 * .CloudPrintInterface, |
| 1343 * documentInfo: print_preview.DocumentInfo}} args |
| 1344 * The arguments that print() was called with. |
| 1345 */ |
| 1346 function(args) { |
| 1347 // Sanity check some printing argument values. |
| 1348 var printTicketStore = args.printTicketStore; |
| 1349 expectEquals(barDevice.printerId, args.destination.id); |
| 1350 expectEquals( |
| 1351 getDefaultOrientation(barDevice) == 'LANDSCAPE', |
| 1352 printTicketStore.landscape.getValue()); |
| 1353 expectEquals(1, printTicketStore.copies.getValueAsNumber()); |
| 1354 var mediaDefault = getDefaultMediaSize(barDevice); |
| 1355 expectEquals( |
| 1356 mediaDefault.width_microns, |
| 1357 printTicketStore.mediaSize.getValue().width_microns); |
| 1358 expectEquals( |
| 1359 mediaDefault.height_microns, |
| 1360 printTicketStore.mediaSize.getValue().height_microns); |
| 1361 }); |
| 1313 }); | 1362 }); |
| 1314 }); | 1363 }); |
| 1315 }); | 1364 }); |
| 1316 | 1365 |
| 1317 // Test the preview generator to make sure the generate draft parameter is | 1366 // Test the preview generator to make sure the generate draft parameter is |
| 1318 // set correctly. It should be false if the only change is the page range. | 1367 // set correctly. It should be false if the only change is the page range. |
| 1319 test('GenerateDraft', function() { | 1368 test('GenerateDraft', function() { |
| 1320 // Use a real preview generator. | 1369 // Use a real preview generator. |
| 1321 previewArea.previewGenerator_ = | 1370 previewArea.previewGenerator_ = |
| 1322 new print_preview.PreviewGenerator(printPreview.destinationStore_, | 1371 new print_preview.PreviewGenerator(printPreview.destinationStore_, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1368 return setupSettingsAndDestinationsWithCapabilities().then(function() { | 1417 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 1369 // The system default destination should be used instead of the | 1418 // The system default destination should be used instead of the |
| 1370 // most recent destination. | 1419 // most recent destination. |
| 1371 assertEquals( | 1420 assertEquals( |
| 1372 'FooDevice', | 1421 'FooDevice', |
| 1373 printPreview.destinationStore_.selectedDestination.id); | 1422 printPreview.destinationStore_.selectedDestination.id); |
| 1374 }); | 1423 }); |
| 1375 }); | 1424 }); |
| 1376 }); | 1425 }); |
| 1377 }); | 1426 }); |
| OLD | NEW |