Chromium Code Reviews| 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 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1052 // Now it should be visible. | 1052 // Now it should be visible. |
| 1053 checkSectionVisible(otherOptions, true); | 1053 checkSectionVisible(otherOptions, true); |
| 1054 expectTrue(otherOptions.querySelector('#duplex-container').hidden); | 1054 expectTrue(otherOptions.querySelector('#duplex-container').hidden); |
| 1055 | 1055 |
| 1056 return whenAnimationDone('more-settings'); | 1056 return whenAnimationDone('more-settings'); |
| 1057 }); | 1057 }); |
| 1058 }); | 1058 }); |
| 1059 | 1059 |
| 1060 // Test that changing the selected printer updates the preview. | 1060 // Test that changing the selected printer updates the preview. |
| 1061 test('PrinterChangeUpdatesPreview', function() { | 1061 test('PrinterChangeUpdatesPreview', function() { |
| 1062 // Preview generator | |
| 1063 previewArea.previewGenerator_ = | |
| 1064 new print_preview.PreviewGenerator(printPreview.destinationStore_, | |
| 1065 printPreview.printTicketStore_, nativeLayer, | |
| 1066 printPreview.documentInfo_); | |
| 1067 | |
| 1062 return setupSettingsAndDestinationsWithCapabilities().then(function() { | 1068 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 1063 var previewGenerator = mock(print_preview.PreviewGenerator); | 1069 return nativeLayer.whenCalled('getPreview'); |
| 1064 previewArea.previewGenerator_ = previewGenerator.proxy(); | 1070 }).then(function(args0) { |
| 1065 | 1071 expectEquals(0, args0.requestId); |
| 1066 // The number of settings that can change due to a change in the | 1072 expectEquals('FooDevice', args0.destination.id); |
| 1067 // destination that will therefore dispatch ticket item change events. | 1073 nativeLayer.resetResolver('getPreview'); |
| 1068 previewGenerator.expects(exactly(9)).requestPreview(); | |
| 1069 | 1074 |
| 1070 // Setup capabilities for BarDevice. | 1075 // Setup capabilities for BarDevice. |
| 1071 var device = getCddTemplate('BarDevice'); | 1076 var device = getCddTemplate('BarDevice'); |
| 1072 device.capabilities.printer.color = { | 1077 device.capabilities.printer.color = { |
| 1073 'option': [ | 1078 'option': [ |
| 1074 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} | 1079 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} |
| 1075 ] | 1080 ] |
| 1076 }; | 1081 }; |
| 1077 nativeLayer.setLocalDestinationCapabilities(device); | 1082 nativeLayer.setLocalDestinationCapabilities(device); |
| 1078 | |
| 1079 // Select BarDevice | 1083 // Select BarDevice |
| 1080 var barDestination = | 1084 var barDestination = |
| 1081 printPreview.destinationStore_.destinations().find( | 1085 printPreview.destinationStore_.destinations().find( |
| 1082 function(d) { | 1086 function(d) { |
| 1083 return d.id == 'BarDevice'; | 1087 return d.id == 'BarDevice'; |
| 1084 }); | 1088 }); |
| 1085 printPreview.destinationStore_.selectDestination(barDestination); | 1089 printPreview.destinationStore_.selectDestination(barDestination); |
| 1086 return nativeLayer.whenCalled('getPrinterCapabilities', 'BarDevice'); | 1090 return nativeLayer.whenCalled('getPrinterCapabilities', 'BarDevice'); |
| 1087 }).then(function(){ | 1091 }).then(function(){ |
| 1088 return whenAnimationDone('more-settings'); | 1092 // Verify new preview is requested with new ID and destination. |
| 1093 return nativeLayer.whenCalled('getPreview'); | |
| 1094 }).then(function(args1) { | |
| 1095 expectEquals(1, args1.requestId); | |
| 1096 expectEquals('BarDevice', args1.destination.id); | |
| 1089 }); | 1097 }); |
| 1090 }); | 1098 }); |
| 1091 | 1099 |
| 1092 // Test that error message is displayed when plugin doesn't exist. | 1100 // Test that error message is displayed when plugin doesn't exist. |
| 1093 test('NoPDFPluginErrorMessage', function() { | 1101 test('NoPDFPluginErrorMessage', function() { |
| 1094 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('FooDevice')); | 1102 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('FooDevice')); |
| 1095 setInitialSettings(); | 1103 setInitialSettings(); |
| 1096 return nativeLayer.whenCalled('getInitialSettings').then(function() { | 1104 return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| 1097 var previewAreaEl = $('preview-area'); | 1105 var previewAreaEl = $('preview-area'); |
| 1098 | 1106 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1226 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID1')); | 1234 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID1')); |
| 1227 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID2')) | 1235 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID2')) |
| 1228 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID3')); | 1236 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID3')); |
| 1229 | 1237 |
| 1230 // Use a real preview generator. | 1238 // Use a real preview generator. |
| 1231 previewArea.previewGenerator_ = | 1239 previewArea.previewGenerator_ = |
| 1232 new print_preview.PreviewGenerator(printPreview.destinationStore_, | 1240 new print_preview.PreviewGenerator(printPreview.destinationStore_, |
| 1233 printPreview.printTicketStore_, nativeLayer, | 1241 printPreview.printTicketStore_, nativeLayer, |
| 1234 printPreview.documentInfo_); | 1242 printPreview.documentInfo_); |
| 1235 | 1243 |
| 1236 // Preview generator starts out with inFlightRequestId_ == -1. The id | 1244 // For crbug.com/666595. If multiple destinations are fetched there may |
| 1237 // increments by 1 for each startGetPreview call it makes. It should only | 1245 // be multiple preview requests. This verifies the first fetch is for |
| 1238 // make one such call during initialization or there will be a race; see | 1246 // ID1, which ensures no other destinations are fetched earlier. The last |
| 1239 // crbug.com/666595 | 1247 // destination retrieved before timeout will end up in the preview |
| 1240 expectEquals(-1, previewArea.previewGenerator_.inFlightRequestId_); | 1248 // request. Ensure this is also ID1. |
|
rbpotter
2017/06/29 01:13:53
Note: This always catches the bug linked, as the c
| |
| 1241 setInitialSettings(); | 1249 setInitialSettings(); |
| 1242 return nativeLayer.whenCalled('getInitialSettings').then(function() { | 1250 var initialSettingsSet = nativeLayer.whenCalled('getInitialSettings'); |
| 1243 return nativeLayer.whenCalled('getPrinterCapabilities', 'ID1'); | 1251 return initialSettingsSet.then(function() { |
| 1244 }).then(function() { | 1252 return nativeLayer.whenCalled('getPrinterCapabilities'); |
| 1245 expectEquals(0, previewArea.previewGenerator_.inFlightRequestId_); | 1253 }).then(function(id) { |
| 1254 expectEquals('ID1', id); | |
| 1255 return nativeLayer.whenCalled('getPreview'); | |
| 1256 }).then(function(preview_args) { | |
| 1257 expectEquals(0, preview_args.requestId); | |
| 1258 expectEquals('ID1', preview_args.destination.id); | |
| 1246 }); | 1259 }); |
| 1247 }); | 1260 }); |
| 1248 | 1261 |
| 1249 // Test that invalid settings errors disable the print preview and display | 1262 // Test that invalid settings errors disable the print preview and display |
| 1250 // an error and that the preview dialog can be recovered by selecting a | 1263 // an error and that the preview dialog can be recovered by selecting a |
| 1251 // new destination. | 1264 // new destination. |
| 1252 test('InvalidSettingsError', function() { | 1265 test('InvalidSettingsError', function() { |
| 1253 return setupSettingsAndDestinationsWithCapabilities().then(function() { | 1266 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 1254 // Manually enable the print header. This is needed since there is no | 1267 // Manually enable the print header. This is needed since there is no |
| 1255 // plugin during test, so it will be set as disabled normally. | 1268 // plugin during test, so it will be set as disabled normally. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1316 | 1329 |
| 1317 // Test the preview generator to make sure the generate draft parameter is | 1330 // 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. | 1331 // set correctly. It should be false if the only change is the page range. |
| 1319 test('GenerateDraft', function() { | 1332 test('GenerateDraft', function() { |
| 1320 // Use a real preview generator. | 1333 // Use a real preview generator. |
| 1321 previewArea.previewGenerator_ = | 1334 previewArea.previewGenerator_ = |
| 1322 new print_preview.PreviewGenerator(printPreview.destinationStore_, | 1335 new print_preview.PreviewGenerator(printPreview.destinationStore_, |
| 1323 printPreview.printTicketStore_, nativeLayer, | 1336 printPreview.printTicketStore_, nativeLayer, |
| 1324 printPreview.documentInfo_); | 1337 printPreview.documentInfo_); |
| 1325 return setupSettingsAndDestinationsWithCapabilities().then(function() { | 1338 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 1339 return nativeLayer.whenCalled('getPreview'); | |
| 1340 }).then(function(args0) { | |
| 1326 // The first request should generate draft because there was no | 1341 // The first request should generate draft because there was no |
| 1327 // previous print preview draft. | 1342 // previous print preview draft. |
| 1328 expectTrue(nativeLayer.generateDraft()); | 1343 expectTrue(args0.generateDraft); |
| 1344 expectEquals(0, args0.requestId); | |
| 1345 nativeLayer.resetResolver('getPreview'); | |
| 1329 | 1346 |
| 1330 // Change the page range - no new draft needed. | 1347 // Change the page range - no new draft needed. |
| 1331 printPreview.printTicketStore_.pageRange.updateValue('2'); | 1348 printPreview.printTicketStore_.pageRange.updateValue('2'); |
| 1332 expectFalse(nativeLayer.generateDraft()); | 1349 return nativeLayer.whenCalled('getPreview'); |
| 1350 }).then(function(args1) { | |
| 1351 expectFalse(args1.generateDraft); | |
| 1352 expectEquals(1, args1.requestId); | |
| 1353 nativeLayer.resetResolver('getPreview'); | |
| 1333 | 1354 |
| 1334 // Change the margin type - need to regenerate again. | 1355 // Change the margin type - need to regenerate again. |
| 1335 printPreview.printTicketStore_.marginsType.updateValue( | 1356 printPreview.printTicketStore_.marginsType.updateValue( |
| 1336 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); | 1357 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); |
| 1337 expectTrue(nativeLayer.generateDraft()); | 1358 return nativeLayer.whenCalled('getPreview'); |
| 1359 }).then(function(args2) { | |
| 1360 expectTrue(args2.generateDraft); | |
| 1361 expectEquals(2, args2.requestId); | |
| 1338 }); | 1362 }); |
| 1339 }); | 1363 }); |
| 1340 | 1364 |
| 1341 // Test that the policy to use the system default printer by default | 1365 // Test that the policy to use the system default printer by default |
| 1342 // instead of the most recently used destination works. | 1366 // instead of the most recently used destination works. |
| 1343 test('SystemDefaultPrinterPolicy', function() { | 1367 test('SystemDefaultPrinterPolicy', function() { |
| 1344 // Add recent destination. | 1368 // Add recent destination. |
| 1345 initialSettings.serializedAppStateStr_ = JSON.stringify({ | 1369 initialSettings.serializedAppStateStr_ = JSON.stringify({ |
| 1346 version: 2, | 1370 version: 2, |
| 1347 recentDestinations: [ | 1371 recentDestinations: [ |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1368 return setupSettingsAndDestinationsWithCapabilities().then(function() { | 1392 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 1369 // The system default destination should be used instead of the | 1393 // The system default destination should be used instead of the |
| 1370 // most recent destination. | 1394 // most recent destination. |
| 1371 assertEquals( | 1395 assertEquals( |
| 1372 'FooDevice', | 1396 'FooDevice', |
| 1373 printPreview.destinationStore_.selectedDestination.id); | 1397 printPreview.destinationStore_.selectedDestination.id); |
| 1374 }); | 1398 }); |
| 1375 }); | 1399 }); |
| 1376 }); | 1400 }); |
| 1377 }); | 1401 }); |
| OLD | NEW |