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

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

Issue 2961773003: Print Preview: Update test to check parameters sent to print() (Closed)
Patch Set: Address comments 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
dpapad 2017/06/28 01:28:34 Nit: return {{...}} I think there is a set of bra
rbpotter 2017/06/28 02:36:27 Done.
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
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(args.destination.id, barDevice.printerId);
1350 expectEquals(printTicketStore.landscape.getValue(),
dpapad 2017/06/28 01:28:34 Nit: According to the docs, expected value goes fi
rbpotter 2017/06/28 02:36:27 Done.
1351 getDefaultOrientation(barDevice) == 'LANDSCAPE');
1352 expectEquals(printTicketStore.copies.getValueAsNumber(), 1);
1353 var media_default = getDefaultMediaSize(barDevice);
dpapad 2017/06/28 01:28:34 s/media_default/mediaDefault
rbpotter 2017/06/28 02:36:27 Done.
1354 expectEquals(
1355 printTicketStore.mediaSize.getValue().width_microns,
1356 media_default.width_microns);
1357 expectEquals(
1358 printTicketStore.mediaSize.getValue().height_microns,
1359 media_default.height_microns);
1360 });
1313 }); 1361 });
1314 }); 1362 });
1315 }); 1363 });
1316 1364
1317 // Test the preview generator to make sure the generate draft parameter is 1365 // 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. 1366 // set correctly. It should be false if the only change is the page range.
1319 test('GenerateDraft', function() { 1367 test('GenerateDraft', function() {
1320 // Use a real preview generator. 1368 // Use a real preview generator.
1321 previewArea.previewGenerator_ = 1369 previewArea.previewGenerator_ =
1322 new print_preview.PreviewGenerator(printPreview.destinationStore_, 1370 new print_preview.PreviewGenerator(printPreview.destinationStore_,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 return setupSettingsAndDestinationsWithCapabilities().then(function() { 1416 return setupSettingsAndDestinationsWithCapabilities().then(function() {
1369 // The system default destination should be used instead of the 1417 // The system default destination should be used instead of the
1370 // most recent destination. 1418 // most recent destination.
1371 assertEquals( 1419 assertEquals(
1372 'FooDevice', 1420 'FooDevice',
1373 printPreview.destinationStore_.selectedDestination.id); 1421 printPreview.destinationStore_.selectedDestination.id);
1374 }); 1422 });
1375 }); 1423 });
1376 }); 1424 });
1377 }); 1425 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698