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

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

Issue 2962983002: Print Preview: change getPreview to cr.sendWithPromise (Closed)
Patch Set: Rebase Created 3 years, 5 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
OLDNEW
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 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 // Now it should be visible. 1072 // Now it should be visible.
1073 checkSectionVisible(otherOptions, true); 1073 checkSectionVisible(otherOptions, true);
1074 expectTrue(otherOptions.querySelector('#duplex-container').hidden); 1074 expectTrue(otherOptions.querySelector('#duplex-container').hidden);
1075 1075
1076 return whenAnimationDone('more-settings'); 1076 return whenAnimationDone('more-settings');
1077 }); 1077 });
1078 }); 1078 });
1079 1079
1080 // Test that changing the selected printer updates the preview. 1080 // Test that changing the selected printer updates the preview.
1081 test('PrinterChangeUpdatesPreview', function() { 1081 test('PrinterChangeUpdatesPreview', function() {
1082 // Preview generator
1083 previewArea.previewGenerator_ =
1084 new print_preview.PreviewGenerator(printPreview.destinationStore_,
1085 printPreview.printTicketStore_, nativeLayer,
1086 printPreview.documentInfo_);
1087
1082 return setupSettingsAndDestinationsWithCapabilities().then(function() { 1088 return setupSettingsAndDestinationsWithCapabilities().then(function() {
1083 var previewGenerator = mock(print_preview.PreviewGenerator); 1089 return nativeLayer.whenCalled('getPreview');
1084 previewArea.previewGenerator_ = previewGenerator.proxy(); 1090 }).then(function(args0) {
1085 1091 expectEquals(0, args0.requestId);
1086 // The number of settings that can change due to a change in the 1092 expectEquals('FooDevice', args0.destination.id);
1087 // destination that will therefore dispatch ticket item change events. 1093 nativeLayer.resetResolver('getPreview');
1088 previewGenerator.expects(exactly(9)).requestPreview();
1089 1094
1090 // Setup capabilities for BarDevice. 1095 // Setup capabilities for BarDevice.
1091 var device = getCddTemplate('BarDevice'); 1096 var device = getCddTemplate('BarDevice');
1092 device.capabilities.printer.color = { 1097 device.capabilities.printer.color = {
1093 'option': [ 1098 'option': [
1094 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} 1099 {'is_default': true, 'type': 'STANDARD_MONOCHROME'}
1095 ] 1100 ]
1096 }; 1101 };
1097 nativeLayer.setLocalDestinationCapabilities(device); 1102 nativeLayer.setLocalDestinationCapabilities(device);
1098
1099 // Select BarDevice 1103 // Select BarDevice
1100 var barDestination = 1104 var barDestination =
1101 printPreview.destinationStore_.destinations().find( 1105 printPreview.destinationStore_.destinations().find(
1102 function(d) { 1106 function(d) {
1103 return d.id == 'BarDevice'; 1107 return d.id == 'BarDevice';
1104 }); 1108 });
1105 printPreview.destinationStore_.selectDestination(barDestination); 1109 printPreview.destinationStore_.selectDestination(barDestination);
1106 return nativeLayer.whenCalled('getPrinterCapabilities', 'BarDevice'); 1110 return nativeLayer.whenCalled('getPrinterCapabilities', 'BarDevice');
1107 }).then(function(){ 1111 }).then(function(){
1108 return whenAnimationDone('more-settings'); 1112 // Verify new preview is requested with new ID and destination.
1113 return nativeLayer.whenCalled('getPreview');
1114 }).then(function(args1) {
1115 expectEquals(1, args1.requestId);
1116 expectEquals('BarDevice', args1.destination.id);
1109 }); 1117 });
1110 }); 1118 });
1111 1119
1112 // Test that error message is displayed when plugin doesn't exist. 1120 // Test that error message is displayed when plugin doesn't exist.
1113 test('NoPDFPluginErrorMessage', function() { 1121 test('NoPDFPluginErrorMessage', function() {
1114 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('FooDevice')); 1122 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('FooDevice'));
1115 setInitialSettings(); 1123 setInitialSettings();
1116 return nativeLayer.whenCalled('getInitialSettings').then(function() { 1124 return nativeLayer.whenCalled('getInitialSettings').then(function() {
1117 var previewAreaEl = $('preview-area'); 1125 var previewAreaEl = $('preview-area');
1118 1126
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID1')); 1254 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID1'));
1247 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID2')) 1255 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID2'))
1248 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID3')); 1256 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID3'));
1249 1257
1250 // Use a real preview generator. 1258 // Use a real preview generator.
1251 previewArea.previewGenerator_ = 1259 previewArea.previewGenerator_ =
1252 new print_preview.PreviewGenerator(printPreview.destinationStore_, 1260 new print_preview.PreviewGenerator(printPreview.destinationStore_,
1253 printPreview.printTicketStore_, nativeLayer, 1261 printPreview.printTicketStore_, nativeLayer,
1254 printPreview.documentInfo_); 1262 printPreview.documentInfo_);
1255 1263
1256 // Preview generator starts out with inFlightRequestId_ == -1. The id 1264 // For crbug.com/666595. If multiple destinations are fetched there may
1257 // increments by 1 for each startGetPreview call it makes. It should only 1265 // be multiple preview requests. This verifies the first fetch is for
1258 // make one such call during initialization or there will be a race; see 1266 // ID1, which ensures no other destinations are fetched earlier. The last
1259 // crbug.com/666595 1267 // destination retrieved before timeout will end up in the preview
1260 expectEquals(-1, previewArea.previewGenerator_.inFlightRequestId_); 1268 // request. Ensure this is also ID1.
1261 setInitialSettings(); 1269 setInitialSettings();
1262 return nativeLayer.whenCalled('getInitialSettings').then(function() { 1270 var initialSettingsSet = nativeLayer.whenCalled('getInitialSettings');
1263 return nativeLayer.whenCalled('getPrinterCapabilities', 'ID1'); 1271 return initialSettingsSet.then(function() {
1264 }).then(function() { 1272 return nativeLayer.whenCalled('getPrinterCapabilities');
1265 expectEquals(0, previewArea.previewGenerator_.inFlightRequestId_); 1273 }).then(function(id) {
1274 expectEquals('ID1', id);
1275 return nativeLayer.whenCalled('getPreview');
1276 }).then(function(preview_args) {
1277 expectEquals(0, preview_args.requestId);
1278 expectEquals('ID1', preview_args.destination.id);
1266 }); 1279 });
1267 }); 1280 });
1268 1281
1269 // Test that invalid settings errors disable the print preview and display 1282 // Test that invalid settings errors disable the print preview and display
1270 // an error and that the preview dialog can be recovered by selecting a 1283 // an error and that the preview dialog can be recovered by selecting a
1271 // new destination. 1284 // new destination.
1272 test('InvalidSettingsError', function() { 1285 test('InvalidSettingsError', function() {
1273 return setupSettingsAndDestinationsWithCapabilities().then(function() { 1286 return setupSettingsAndDestinationsWithCapabilities().then(function() {
1274 // Manually enable the print header. This is needed since there is no 1287 // Manually enable the print header. This is needed since there is no
1275 // plugin during test, so it will be set as disabled normally. 1288 // plugin during test, so it will be set as disabled normally.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 1373
1361 // Test the preview generator to make sure the generate draft parameter is 1374 // Test the preview generator to make sure the generate draft parameter is
1362 // set correctly. It should be false if the only change is the page range. 1375 // set correctly. It should be false if the only change is the page range.
1363 test('GenerateDraft', function() { 1376 test('GenerateDraft', function() {
1364 // Use a real preview generator. 1377 // Use a real preview generator.
1365 previewArea.previewGenerator_ = 1378 previewArea.previewGenerator_ =
1366 new print_preview.PreviewGenerator(printPreview.destinationStore_, 1379 new print_preview.PreviewGenerator(printPreview.destinationStore_,
1367 printPreview.printTicketStore_, nativeLayer, 1380 printPreview.printTicketStore_, nativeLayer,
1368 printPreview.documentInfo_); 1381 printPreview.documentInfo_);
1369 return setupSettingsAndDestinationsWithCapabilities().then(function() { 1382 return setupSettingsAndDestinationsWithCapabilities().then(function() {
1383 return nativeLayer.whenCalled('getPreview');
1384 }).then(function(args0) {
1370 // The first request should generate draft because there was no 1385 // The first request should generate draft because there was no
1371 // previous print preview draft. 1386 // previous print preview draft.
1372 expectTrue(nativeLayer.generateDraft()); 1387 expectTrue(args0.generateDraft);
1388 expectEquals(0, args0.requestId);
1389 nativeLayer.resetResolver('getPreview');
1373 1390
1374 // Change the page range - no new draft needed. 1391 // Change the page range - no new draft needed.
1375 printPreview.printTicketStore_.pageRange.updateValue('2'); 1392 printPreview.printTicketStore_.pageRange.updateValue('2');
1376 expectFalse(nativeLayer.generateDraft()); 1393 return nativeLayer.whenCalled('getPreview');
1394 }).then(function(args1) {
1395 expectFalse(args1.generateDraft);
1396 expectEquals(1, args1.requestId);
1397 nativeLayer.resetResolver('getPreview');
1377 1398
1378 // Change the margin type - need to regenerate again. 1399 // Change the margin type - need to regenerate again.
1379 printPreview.printTicketStore_.marginsType.updateValue( 1400 printPreview.printTicketStore_.marginsType.updateValue(
1380 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); 1401 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS);
1381 expectTrue(nativeLayer.generateDraft()); 1402 return nativeLayer.whenCalled('getPreview');
1403 }).then(function(args2) {
1404 expectTrue(args2.generateDraft);
1405 expectEquals(2, args2.requestId);
1382 }); 1406 });
1383 }); 1407 });
1384 1408
1385 // Test that the policy to use the system default printer by default 1409 // Test that the policy to use the system default printer by default
1386 // instead of the most recently used destination works. 1410 // instead of the most recently used destination works.
1387 test('SystemDefaultPrinterPolicy', function() { 1411 test('SystemDefaultPrinterPolicy', function() {
1388 // Add recent destination. 1412 // Add recent destination.
1389 initialSettings.serializedAppStateStr_ = JSON.stringify({ 1413 initialSettings.serializedAppStateStr_ = JSON.stringify({
1390 version: 2, 1414 version: 2,
1391 recentDestinations: [ 1415 recentDestinations: [
(...skipping 20 matching lines...) Expand all
1412 return setupSettingsAndDestinationsWithCapabilities().then(function() { 1436 return setupSettingsAndDestinationsWithCapabilities().then(function() {
1413 // The system default destination should be used instead of the 1437 // The system default destination should be used instead of the
1414 // most recent destination. 1438 // most recent destination.
1415 assertEquals( 1439 assertEquals(
1416 'FooDevice', 1440 'FooDevice',
1417 printPreview.destinationStore_.selectedDestination.id); 1441 printPreview.destinationStore_.selectedDestination.id);
1418 }); 1442 });
1419 }); 1443 });
1420 }); 1444 });
1421 }); 1445 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698