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

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

Issue 2881213003: Print Preview: Use cr.sendWithPromise for getInitialSettings (Closed)
Patch Set: Address comments Created 3 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 GEN('#include "base/feature_list.h"'); 5 GEN('#include "base/feature_list.h"');
6 GEN('#include "chrome/common/chrome_features.h"'); 6 GEN('#include "chrome/common/chrome_features.h"');
7 7
8 var ROOT_PATH = '../../../../';
9
8 /** 10 /**
9 * Test fixture for print preview WebUI testing. 11 * Test fixture for print preview WebUI testing.
10 * @constructor 12 * @constructor
11 * @extends {testing.Test} 13 * @extends {testing.Test}
12 */ 14 */
13 function PrintPreviewWebUITest() { 15 function PrintPreviewWebUITest() {
14 testing.Test.call(this); 16 testing.Test.call(this);
17 this.printPreview_ = null;
15 this.nativeLayer_ = null; 18 this.nativeLayer_ = null;
16 this.initialSettings_ = null; 19 this.initialSettings_ = null;
17 this.localDestinationInfos_ = null; 20 this.localDestinationInfos_ = null;
18 this.previewArea_ = null; 21 this.previewArea_ = null;
19 } 22 }
20 23
21 /** 24 /**
22 * Index of the "Save as PDF" printer. 25 * Index of the "Save as PDF" printer.
23 * @type {number} 26 * @type {number}
24 * @const 27 * @const
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 GEN('#endif'); 76 GEN('#endif');
74 }, 77 },
75 78
76 /** 79 /**
77 * Stub out low-level functionality like the NativeLayer and 80 * Stub out low-level functionality like the NativeLayer and
78 * CloudPrintInterface. 81 * CloudPrintInterface.
79 * @this {PrintPreviewWebUITest} 82 * @this {PrintPreviewWebUITest}
80 * @override 83 * @override
81 */ 84 */
82 preLoad: function() { 85 preLoad: function() {
86 window.isTest = true;
83 window.addEventListener('DOMContentLoaded', function() { 87 window.addEventListener('DOMContentLoaded', function() {
88 /**
89 * Test version of the native layer.
90 * @constructor
91 * @extends {settings.TestBrowserProxy}
92 */
84 function NativeLayerStub() { 93 function NativeLayerStub() {
85 cr.EventTarget.call(this); 94 settings.TestBrowserProxy.call(this, [ 'getInitialSettings' ]);
95 this.eventTarget_ = new cr.EventTarget();
86 this.printStarted_ = false; 96 this.printStarted_ = false;
87 this.generateDraft_ = false; 97 this.generateDraft_ = false;
98 this.initialSettings_ = null;
88 } 99 }
89 NativeLayerStub.prototype = { 100 NativeLayerStub.prototype = {
90 __proto__: cr.EventTarget.prototype, 101 __proto__: settings.TestBrowserProxy.prototype,
102 getEventTarget: function() { return this.eventTarget_; },
91 isPrintStarted: function() { return this.printStarted_; }, 103 isPrintStarted: function() { return this.printStarted_; },
92 generateDraft: function() { return this.generateDraft_; }, 104 generateDraft: function() { return this.generateDraft_; },
105 getInitialSettings: function() {
106 this.methodCalled('getInitialSettings');
107 return Promise.resolve(this.initialSettings_);
108 },
93 previewReadyForTest: function() {}, 109 previewReadyForTest: function() {},
94 startGetInitialSettings: function() {},
95 startGetLocalDestinations: function() {}, 110 startGetLocalDestinations: function() {},
96 startGetPrivetDestinations: function() {}, 111 startGetPrivetDestinations: function() {},
97 startGetExtensionDestinations: function() {}, 112 startGetExtensionDestinations: function() {},
98 startGetLocalDestinationCapabilities: function(destinationId) {}, 113 startGetLocalDestinationCapabilities: function(destinationId) {},
99 startGetPreview: function(destination, printTicketStore, documentInfo, 114 startGetPreview: function(destination, printTicketStore, documentInfo,
100 generateDraft, requestId) { 115 generateDraft, requestId) {
101 this.generateDraft_ = generateDraft; 116 this.generateDraft_ = generateDraft;
102 }, 117 },
103 startHideDialog: function () {}, 118 startHideDialog: function () {},
104 startPrint: function () { this.printStarted_ = true; } 119 startPrint: function () { this.printStarted_ = true; }
(...skipping 15 matching lines...) Expand all
120 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub; 135 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub;
121 cloudprint.CloudPrintInterfaceEventType = oldCpInterfaceEventType; 136 cloudprint.CloudPrintInterfaceEventType = oldCpInterfaceEventType;
122 137
123 print_preview.PreviewArea.prototype.checkPluginCompatibility_ = 138 print_preview.PreviewArea.prototype.checkPluginCompatibility_ =
124 function() { 139 function() {
125 return false; 140 return false;
126 }; 141 };
127 }.bind(this)); 142 }.bind(this));
128 }, 143 },
129 144
145 extraLibraries: [
146 ROOT_PATH + 'ui/webui/resources/js/cr.js',
147 ROOT_PATH + 'ui/webui/resources/js/promise_resolver.js',
148 ROOT_PATH + 'ui/webui/resources/js/util.js',
149 ROOT_PATH + 'chrome/test/data/webui/settings/test_browser_proxy.js',
150 ],
151
130 /** 152 /**
131 * Dispatch the INITIAL_SETTINGS_SET event. This call is NOT async and will 153 * Creates an instance of print_preview.PrintPreview and initializes the
132 * happen in the same thread. 154 * |nativeLayer_| and |previewArea_|.
133 */ 155 */
134 setInitialSettings: function() { 156 createPrintPreview: function() {
135 var initialSettingsSetEvent = 157 this.printPreview_ = new print_preview.PrintPreview();
136 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); 158 this.nativeLayer_ = this.printPreview_.nativeLayer_;
137 initialSettingsSetEvent.initialSettings = this.initialSettings_; 159 this.previewArea_ = this.printPreview_.previewArea_;
138 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
139 }, 160 },
140 161
141 /** 162 /**
163 * Initialize print preview with the initial settings currently stored in
164 * |this.initialSettings_|. Creates |this.printPreview_| if it does not
165 * already exist.
166 */
167 setInitialSettings: function() {
168 if (!this.printPreview_) {
169 this.printPreview_ = new print_preview.PrintPreview();
170 this.nativeLayer_ = this.printPreview_.nativeLayer_;
171 this.previewArea_ = this.printPreview_.previewArea_;
172 }
173 this.nativeLayer_.initialSettings_ = this.initialSettings_;
174 this.printPreview_.initialize();
175 testing.Test.disableAnimationsAndTransitions();
176 // Enable when failure is resolved.
177 // AX_TEXT_03: http://crbug.com/559209
178 this.accessibilityAuditConfig.ignoreSelectors(
179 'multipleLabelableElementsPerLabel',
180 '#page-settings > .right-column > *');
181 },
182
183 /**
142 * Dispatch the LOCAL_DESTINATIONS_SET event. This call is NOT async and will 184 * Dispatch the LOCAL_DESTINATIONS_SET event. This call is NOT async and will
143 * happen in the same thread. 185 * happen in the same thread.
144 */ 186 */
145 setLocalDestinations: function() { 187 setLocalDestinations: function() {
146 var localDestsSetEvent = 188 var localDestsSetEvent =
147 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); 189 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
148 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; 190 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
149 this.nativeLayer_.dispatchEvent(localDestsSetEvent); 191 this.nativeLayer_.getEventTarget().dispatchEvent(localDestsSetEvent);
150 }, 192 },
151 193
152 /** 194 /**
153 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will 195 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will
154 * happen in the same thread. 196 * happen in the same thread.
155 * @device - The device whose capabilities should be dispatched. 197 * @device - The device whose capabilities should be dispatched.
156 */ 198 */
157 setCapabilities: function(device) { 199 setCapabilities: function(device) {
158 var capsSetEvent = 200 var capsSetEvent =
159 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 201 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
160 capsSetEvent.settingsInfo = device; 202 capsSetEvent.settingsInfo = device;
161 this.nativeLayer_.dispatchEvent(capsSetEvent); 203 this.nativeLayer_.getEventTarget().dispatchEvent(capsSetEvent);
162 }, 204 },
163 205
164 /** 206 /**
165 * Dispatch the PREVIEW_GENERATION_DONE event. This call is NOT async and 207 * Dispatch the PREVIEW_GENERATION_DONE event. This call is NOT async and
166 * will happen in the same thread. 208 * will happen in the same thread.
167 */ 209 */
168 dispatchPreviewDone: function() { 210 dispatchPreviewDone: function() {
169 var previewDoneEvent = 211 var previewDoneEvent =
170 new Event(print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); 212 new Event(print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE);
171 this.previewArea_.dispatchEvent(previewDoneEvent); 213 this.previewArea_.dispatchEvent(previewDoneEvent);
172 }, 214 },
173 215
174 /** 216 /**
175 * Dispatch the SETTINGS_INVALID event. This call is NOT async and will 217 * Dispatch the SETTINGS_INVALID event. This call is NOT async and will
176 * happen in the same thread. 218 * happen in the same thread.
177 */ 219 */
178 dispatchInvalidSettings: function() { 220 dispatchInvalidSettings: function() {
179 var invalidSettingsEvent = 221 var invalidSettingsEvent =
180 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); 222 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID);
181 this.nativeLayer_.dispatchEvent(invalidSettingsEvent); 223 this.nativeLayer_.getEventTarget().dispatchEvent(invalidSettingsEvent);
182 }, 224 },
183 225
184 /** 226 /**
185 * @return {boolean} Whether the UI has "printed" or not. (called startPrint 227 * @return {boolean} Whether the UI has "printed" or not. (called startPrint
186 * on the native layer) 228 * on the native layer)
187 */ 229 */
188 hasPrinted: function() { 230 hasPrinted: function() {
189 return this.nativeLayer_.isPrintStarted(); 231 return this.nativeLayer_.isPrintStarted();
190 }, 232 },
191 233
(...skipping 29 matching lines...) Expand all
221 moreSettings.click(); 263 moreSettings.click();
222 }, 264 },
223 265
224 /** 266 /**
225 * Repeated setup steps for the advanced settings tests. 267 * Repeated setup steps for the advanced settings tests.
226 * Disables accessiblity errors, sets initial settings, and verifies 268 * Disables accessiblity errors, sets initial settings, and verifies
227 * advanced options section is visible after expanding more settings. 269 * advanced options section is visible after expanding more settings.
228 */ 270 */
229 setupAdvancedSettingsTest: function(device) { 271 setupAdvancedSettingsTest: function(device) {
230 // Need to disable this since overlay animation will not fully complete. 272 // Need to disable this since overlay animation will not fully complete.
231 this.accessibilityIssuesAreErrors = false;
232 this.setInitialSettings();
233 this.setLocalDestinations(); 273 this.setLocalDestinations();
234 this.setCapabilities(device); 274 this.setCapabilities(device);
235 this.expandMoreSettings(); 275 this.expandMoreSettings();
236 276
237 // Check that the advanced options settings section is visible. 277 // Check that the advanced options settings section is visible.
238 checkSectionVisible($('advanced-options-settings'), true); 278 checkSectionVisible($('advanced-options-settings'), true);
239 }, 279 },
240 280
241 /** 281 /**
242 * Generate a real C++ class; don't typedef. 282 * Generate a real C++ class; don't typedef.
(...skipping 20 matching lines...) Expand all
263 'title' /*documentTitle*/, 303 'title' /*documentTitle*/,
264 true /*documentHasSelection*/, 304 true /*documentHasSelection*/,
265 false /*selectionOnly*/, 305 false /*selectionOnly*/,
266 'FooDevice' /*systemDefaultDestinationId*/, 306 'FooDevice' /*systemDefaultDestinationId*/,
267 null /*serializedAppStateStr*/, 307 null /*serializedAppStateStr*/,
268 null /*serializedDefaultDestinationSelectionRulesStr*/); 308 null /*serializedDefaultDestinationSelectionRulesStr*/);
269 this.localDestinationInfos_ = [ 309 this.localDestinationInfos_ = [
270 { printerName: 'FooName', deviceName: 'FooDevice' }, 310 { printerName: 'FooName', deviceName: 'FooDevice' },
271 { printerName: 'BarName', deviceName: 'BarDevice' } 311 { printerName: 'BarName', deviceName: 'BarDevice' }
272 ]; 312 ];
273 this.nativeLayer_ = printPreview.nativeLayer_; 313 },
274 this.previewArea_ = printPreview.previewArea_;
275
276 testing.Test.disableAnimationsAndTransitions();
277
278 // Enable when failure is resolved.
279 // AX_TEXT_03: http://crbug.com/559209
280 this.accessibilityAuditConfig.ignoreSelectors(
281 'multipleLabelableElementsPerLabel',
282 '#page-settings > .right-column > *');
283 }
284 }; 314 };
285 315
286 GEN('#include "chrome/test/data/webui/print_preview.h"'); 316 GEN('#include "chrome/test/data/webui/print_preview.h"');
287 317
288 // Test some basic assumptions about the print preview WebUI. 318 // Test some basic assumptions about the print preview WebUI.
289 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { 319 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
290 this.setInitialSettings(); 320 this.setInitialSettings();
291 this.setLocalDestinations(); 321 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
292 322 function() {
293 var recentList = $('destination-search').querySelector('.recent-list ul'); 323 this.setLocalDestinations();
294 var localList = $('destination-search').querySelector('.local-list ul'); 324 var recentList =
295 assertNotEquals(null, recentList); 325 $('destination-search').querySelector('.recent-list ul');
296 assertEquals(1, recentList.childNodes.length); 326 var localList =
297 assertEquals('FooName', 327 $('destination-search').querySelector('.local-list ul');
298 recentList.childNodes.item(0).querySelector( 328 assertNotEquals(null, recentList);
299 '.destination-list-item-name').textContent); 329 assertEquals(1, recentList.childNodes.length);
300 330 assertEquals('FooName',
301 assertNotEquals(null, localList); 331 recentList.childNodes.item(0).querySelector(
dpapad 2017/05/19 02:07:06 Indentation seems off. It is neither 4 spaces from
rbpotter 2017/05/19 02:25:38 Done.
302 assertEquals(3, localList.childNodes.length); 332 '.destination-list-item-name').textContent);
303 assertEquals('Save as PDF', 333 assertNotEquals(null, localList);
304 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). 334 assertEquals(3, localList.childNodes.length);
305 querySelector('.destination-list-item-name').textContent); 335 assertEquals('Save as PDF',
306 assertEquals('FooName', 336 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX).
307 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). 337 querySelector('.destination-list-item-name').textContent);
308 querySelector('.destination-list-item-name').textContent); 338 assertEquals('FooName',
309 assertEquals('BarName', 339 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
310 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). 340 querySelector('.destination-list-item-name').textContent);
311 querySelector('.destination-list-item-name').textContent); 341 assertEquals('BarName',
312 342 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
313 testDone(); 343 querySelector('.destination-list-item-name').textContent);
344 testDone();
345 }.bind(this));
314 }); 346 });
315 347
316 // Test that the printer list is structured correctly after calling 348 // Test that the printer list is structured correctly after calling
317 // addCloudPrinters with an empty list. 349 // addCloudPrinters with an empty list.
318 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { 350 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
319 this.setInitialSettings(); 351 this.setInitialSettings();
320 this.setLocalDestinations();
321 352
322 var cloudPrintEnableEvent = 353 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
323 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); 354 function() {
324 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; 355 this.setLocalDestinations();
325 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent);
326 356
327 var searchDoneEvent = 357 var cloudPrintEnableEvent =
328 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE); 358 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE);
329 searchDoneEvent.printers = []; 359 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url';
330 searchDoneEvent.isRecent = true; 360 this.nativeLayer_.getEventTarget().dispatchEvent(
331 searchDoneEvent.email = 'foo@chromium.org'; 361 cloudPrintEnableEvent);
332 printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent);
333 362
334 var recentList = $('destination-search').querySelector('.recent-list ul'); 363 var searchDoneEvent =
335 var localList = $('destination-search').querySelector('.local-list ul'); 364 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE);
336 var cloudList = $('destination-search').querySelector('.cloud-list ul'); 365 searchDoneEvent.printers = [];
366 searchDoneEvent.isRecent = true;
367 searchDoneEvent.email = 'foo@chromium.org';
368 this.printPreview_.cloudPrintInterface_.dispatchEvent(searchDoneEvent);
337 369
338 assertNotEquals(null, recentList); 370 var recentList =
339 assertEquals(1, recentList.childNodes.length); 371 $('destination-search').querySelector('.recent-list ul');
340 assertEquals('FooName', 372 var localList =
341 recentList.childNodes.item(0).querySelector( 373 $('destination-search').querySelector('.local-list ul');
342 '.destination-list-item-name').textContent); 374 var cloudList =
375 $('destination-search').querySelector('.cloud-list ul');
343 376
344 assertNotEquals(null, localList); 377 assertNotEquals(null, recentList);
345 assertEquals(3, localList.childNodes.length); 378 assertEquals(1, recentList.childNodes.length);
346 assertEquals('Save as PDF', 379 assertEquals('FooName',
347 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). 380 recentList.childNodes.item(0).
dpapad 2017/05/19 02:07:06 Indentation looks off here. Shouldn't it be asser
rbpotter 2017/05/19 02:25:38 Done.
348 querySelector('.destination-list-item-name').textContent); 381 querySelector('.destination-list-item-name').
349 assertEquals('FooName', 382 textContent);
350 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
351 querySelector('.destination-list-item-name').textContent);
352 assertEquals('BarName',
353 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
354 querySelector('.destination-list-item-name').textContent);
355 383
356 assertNotEquals(null, cloudList); 384 assertNotEquals(null, localList);
357 assertEquals(0, cloudList.childNodes.length); 385 assertEquals(3, localList.childNodes.length);
386 assertEquals('Save as PDF',
387 localList.childNodes.item(
388 PrintPreviewWebUITest.PDF_INDEX).
389 querySelector('.destination-list-item-name').
390 textContent);
391 assertEquals('FooName',
392 localList.childNodes.
393 item(PrintPreviewWebUITest.FOO_INDEX).
394 querySelector('.destination-list-item-name').
395 textContent);
396 assertEquals('BarName',
397 localList.childNodes.
398 item(PrintPreviewWebUITest.BAR_INDEX).
399 querySelector('.destination-list-item-name').
400 textContent);
358 401
359 testDone(); 402 assertNotEquals(null, cloudList);
403 assertEquals(0, cloudList.childNodes.length);
404
405 testDone();
406 }.bind(this));
360 }); 407 });
361 408
362 /** 409 /**
363 * Verify that |section| visibility matches |visible|. 410 * Verify that |section| visibility matches |visible|.
364 * @param {HTMLDivElement} section The section to check. 411 * @param {HTMLDivElement} section The section to check.
365 * @param {boolean} visible The expected state of visibility. 412 * @param {boolean} visible The expected state of visibility.
366 */ 413 */
367 function checkSectionVisible(section, visible) { 414 function checkSectionVisible(section, visible) {
368 assertNotEquals(null, section); 415 assertNotEquals(null, section);
369 expectEquals( 416 expectEquals(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return !cr.isWindows && !cr.isMac; 471 return !cr.isWindows && !cr.isMac;
425 } 472 }
426 473
427 // Test restore settings with one destination. 474 // Test restore settings with one destination.
428 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreLocalDestination', 475 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreLocalDestination',
429 function() { 476 function() {
430 this.initialSettings_.serializedAppStateStr_ = 477 this.initialSettings_.serializedAppStateStr_ =
431 '{"version":2,"recentDestinations":[{"id":"ID", "origin":"local",' + 478 '{"version":2,"recentDestinations":[{"id":"ID", "origin":"local",' +
432 '"account":"", "capabilities":0, "name":"", "extensionId":"",' + 479 '"account":"", "capabilities":0, "name":"", "extensionId":"",' +
433 '"extensionName":""}]}'; 480 '"extensionName":""}]}';
481
434 this.setInitialSettings(); 482 this.setInitialSettings();
435 483 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
436 testDone(); 484 function() {
485 testDone();
486 });
437 }); 487 });
438 488
439 // Test with multiple destinations 489 // Test with multiple destinations
440 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreMultipleDestinations', 490 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreMultipleDestinations',
441 function() { 491 function() {
442 var origin = cr.isChromeOS ? "chrome_os" : "local"; 492 var origin = cr.isChromeOS ? "chrome_os" : "local";
443 493
444 var appState = { 494 var appState = {
445 'version': 2, 495 'version': 2,
446 'recentDestinations': [ 496 'recentDestinations': [
(...skipping 21 matching lines...) Expand all
468 'account': '', 518 'account': '',
469 'capabilities': 0, 519 'capabilities': 0,
470 'name': '', 520 'name': '',
471 'extensionId': '', 521 'extensionId': '',
472 'extensionName': '' 522 'extensionName': ''
473 } 523 }
474 ] 524 ]
475 }; 525 };
476 526
477 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(appState); 527 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(appState);
478
479 this.setInitialSettings(); 528 this.setInitialSettings();
480 529
481 // Set capabilities for the three recently used destinations + 1 more 530 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
482 this.setCapabilities(getCddTemplate('ID1')); 531 function() {
483 this.setCapabilities(getCddTemplate('ID2')); 532 // Set capabilities for the three recently used destinations + 1 more
484 this.setCapabilities(getCddTemplate('ID3')); 533 this.setCapabilities(getCddTemplate('ID1'));
485 this.setCapabilities(getCddTemplate('ID4')); 534 this.setCapabilities(getCddTemplate('ID2'));
535 this.setCapabilities(getCddTemplate('ID3'));
536 this.setCapabilities(getCddTemplate('ID4'));
486 537
487 // The most recently used destination should be the currently selected one. 538 // The most recently used destination should be the currently selected
488 // This is ID1. 539 // one. This is ID1.
489 assertEquals( 540 assertEquals(
490 'ID1', printPreview.destinationStore_.selectedDestination.id); 541 'ID1', this.printPreview_.destinationStore_.selectedDestination.id);
491 542
492 // Look through the destinations. ID1, ID2, and ID3 should all be recent. 543 // Look through the destinations. ID1, ID2, and ID3 should all be
493 var destinations = printPreview.destinationStore_.destinations_; 544 // recent.
494 var ids_found = []; 545 var destinations = this.printPreview_.destinationStore_.destinations_;
546 var ids_found = [];
495 547
496 for (var i = 0; i < destinations.length; i++) { 548 for (var i = 0; i < destinations.length; i++) {
497 if (!destinations[i]) 549 if (!destinations[i])
498 continue; 550 continue;
499 if (destinations[i].isRecent) 551 if (destinations[i].isRecent)
500 ids_found.push(destinations[i].id); 552 ids_found.push(destinations[i].id);
501 } 553 }
502 554
503 // Make sure there were 3 recent destinations and that they are the correct 555 // Make sure there were 3 recent destinations and that they are the
504 // IDs. 556 // correct IDs.
505 assertEquals(3, ids_found.length); 557 assertEquals(3, ids_found.length);
506 assertNotEquals(-1, ids_found.indexOf("ID1")); 558 assertNotEquals(-1, ids_found.indexOf("ID1"));
507 assertNotEquals(-1, ids_found.indexOf("ID2")); 559 assertNotEquals(-1, ids_found.indexOf("ID2"));
508 assertNotEquals(-1, ids_found.indexOf("ID3")); 560 assertNotEquals(-1, ids_found.indexOf("ID3"));
509 561
510 testDone(); 562 testDone();
563 }.bind(this));
511 }); 564 });
512 565
513 TEST_F('PrintPreviewWebUITest', 566 TEST_F('PrintPreviewWebUITest',
514 'TestPrintPreviewDefaultDestinationSelectionRules', function() { 567 'TestPrintPreviewDefaultDestinationSelectionRules', function() {
515 // It also makes sure these rules do override system default destination. 568 // It also makes sure these rules do override system default destination.
516 this.initialSettings_.serializedDefaultDestinationSelectionRulesStr_ = 569 this.initialSettings_.serializedDefaultDestinationSelectionRulesStr_ =
517 '{"namePattern":".*Bar.*"}'; 570 '{"namePattern":".*Bar.*"}';
518 this.setInitialSettings(); 571 this.setInitialSettings();
519 this.setLocalDestinations(); 572 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
573 function() {
574 this.setLocalDestinations();
520 575
521 assertEquals( 576 assertEquals(
522 'BarDevice', printPreview.destinationStore_.selectedDestination.id); 577 'BarDevice',
578 this.printPreview_.destinationStore_.selectedDestination.id);
523 579
524 testDone(); 580 testDone();
581 }.bind(this));
525 }); 582 });
526 583
527 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode', 584 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode',
528 function() { 585 function() {
529 if (cr.isChromeOS) { 586 if (!cr.isChromeOS)
530 assertEquals(null, $('system-dialog-link'));
531 } else {
532 this.initialSettings_.isInAppKioskMode_ = true; 587 this.initialSettings_.isInAppKioskMode_ = true;
533 this.setInitialSettings();
534 588
535 checkElementDisplayed($('system-dialog-link'), false); 589 this.setInitialSettings();
536 } 590 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
537 591 function() {
538 testDone(); 592 if (cr.isChromeOS)
593 assertEquals(null, $('system-dialog-link'));
594 else
595 checkElementDisplayed($('system-dialog-link'), false);
596 testDone();
597 });
539 }); 598 });
540 599
541 // Test that disabled settings hide the disabled sections. 600 // Test that disabled settings hide the disabled sections.
542 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { 601 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
602 this.createPrintPreview();
543 checkSectionVisible($('layout-settings'), false); 603 checkSectionVisible($('layout-settings'), false);
544 checkSectionVisible($('color-settings'), false); 604 checkSectionVisible($('color-settings'), false);
545 checkSectionVisible($('copies-settings'), false); 605 checkSectionVisible($('copies-settings'), false);
546 606
547 this.setInitialSettings(); 607 this.setInitialSettings();
548 this.setLocalDestinations(); 608 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
549 var device = getCddTemplate("FooDevice"); 609 function() {
550 device.capabilities.printer.color = { 610 this.setLocalDestinations();
551 "option": [ 611 var device = getCddTemplate("FooDevice");
552 {"is_default": true, "type": "STANDARD_COLOR"} 612 device.capabilities.printer.color = {
553 ] 613 "option": [
554 }; 614 {"is_default": true, "type": "STANDARD_COLOR"}
555 delete device.capabilities.printer.copies; 615 ]
556 this.setCapabilities(device); 616 };
617 delete device.capabilities.printer.copies;
618 this.setCapabilities(device);
557 619
558 checkSectionVisible($('layout-settings'), true); 620 checkSectionVisible($('layout-settings'), true);
559 checkSectionVisible($('color-settings'), false); 621 checkSectionVisible($('color-settings'), false);
560 checkSectionVisible($('copies-settings'), false); 622 checkSectionVisible($('copies-settings'), false);
561 623
562 this.waitForAnimationToEnd('other-options-collapsible'); 624 this.waitForAnimationToEnd('other-options-collapsible');
625 }.bind(this));
563 }); 626 });
564 627
565 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the 628 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the
566 // fit to page option. 629 // fit to page option.
567 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() { 630 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() {
568 // Add PDF printer. 631 // Add PDF printer.
569 this.initialSettings_.isDocumentModifiable_ = false; 632 this.initialSettings_.isDocumentModifiable_ = false;
570 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF'; 633 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF';
571 this.setInitialSettings(); 634 this.setInitialSettings();
572 635
573 var device = { 636 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
574 printerId: 'Save as PDF', 637 function() {
575 capabilities: { 638 var device = {
576 version: '1.0', 639 printerId: 'Save as PDF',
577 printer: { 640 capabilities: {
578 page_orientation: { 641 version: '1.0',
579 option: [ 642 printer: {
580 {type: 'AUTO', is_default: true}, 643 page_orientation: {
581 {type: 'PORTRAIT'}, 644 option: [
582 {type: 'LANDSCAPE'} 645 {type: 'AUTO', is_default: true},
583 ] 646 {type: 'PORTRAIT'},
584 }, 647 {type: 'LANDSCAPE'}
585 color: { 648 ]
586 option: [ 649 },
587 {type: 'STANDARD_COLOR', is_default: true} 650 color: {
588 ] 651 option: [
589 }, 652 {type: 'STANDARD_COLOR', is_default: true}
590 media_size: { 653 ]
591 option: [ 654 },
592 { name: 'NA_LETTER', 655 media_size: {
593 width_microns: 0, 656 option: [
594 height_microns: 0, 657 { name: 'NA_LETTER',
595 is_default: true 658 width_microns: 0,
659 height_microns: 0,
660 is_default: true
661 }
662 ]
663 }
596 } 664 }
597 ] 665 }
666 };
667 this.setCapabilities(device);
668
669 var otherOptions = $('other-options-settings');
670 // If rasterization is an option, other options should be visible. If
671 // not, there should be no available other options.
672 checkSectionVisible(otherOptions, isPrintAsImageEnabled());
673 if (isPrintAsImageEnabled()) {
674 checkElementDisplayed(
675 otherOptions.querySelector('#fit-to-page-container'), false);
676 checkElementDisplayed(
677 otherOptions.querySelector('#rasterize-container'), true);
598 } 678 }
599 } 679 checkSectionVisible($('media-size-settings'), false);
600 } 680 checkSectionVisible($('scaling-settings'), false);
601 };
602 this.setCapabilities(device);
603 681
604 var otherOptions = $('other-options-settings'); 682 testDone();
605 // If rasterization is an option, other options should be visible. If not, 683 }.bind(this));
606 // there should be no available other options.
607 checkSectionVisible(otherOptions, isPrintAsImageEnabled());
608 if (isPrintAsImageEnabled()) {
609 checkElementDisplayed(
610 otherOptions.querySelector('#fit-to-page-container'), false);
611 checkElementDisplayed(
612 otherOptions.querySelector('#rasterize-container'), true);
613 }
614 checkSectionVisible($('media-size-settings'), false);
615 checkSectionVisible($('scaling-settings'), false);
616
617 testDone();
618 }); 684 });
619 685
620 // When the source is 'HTML', we always hide the fit to page option and show 686 // When the source is 'HTML', we always hide the fit to page option and show
621 // media size option. 687 // media size option.
622 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() { 688 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() {
623 this.setInitialSettings(); 689 this.setInitialSettings();
624 this.setLocalDestinations(); 690 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
625 this.setCapabilities(getCddTemplate("FooDevice")); 691 function() {
692 this.setLocalDestinations();
693 this.setCapabilities(getCddTemplate("FooDevice"));
626 694
627 var otherOptions = $('other-options-settings'); 695 var otherOptions = $('other-options-settings');
628 var fitToPage = otherOptions.querySelector('#fit-to-page-container'); 696 var fitToPage = otherOptions.querySelector('#fit-to-page-container');
629 var rasterize; 697 var rasterize;
630 if (isPrintAsImageEnabled()) 698 if (isPrintAsImageEnabled())
631 rasterize = otherOptions.querySelector('#rasterize-container'); 699 rasterize = otherOptions.querySelector('#rasterize-container');
632 var mediaSize = $('media-size-settings'); 700 var mediaSize = $('media-size-settings');
633 var scalingSettings = $('scaling-settings'); 701 var scalingSettings = $('scaling-settings');
634 702
635 // Check that options are collapsed (section is visible, because duplex is 703 // Check that options are collapsed (section is visible, because duplex
636 // available). 704 // is available).
637 checkSectionVisible(otherOptions, true); 705 checkSectionVisible(otherOptions, true);
638 checkElementDisplayed(fitToPage, false); 706 checkElementDisplayed(fitToPage, false);
639 if (isPrintAsImageEnabled()) 707 if (isPrintAsImageEnabled())
640 checkElementDisplayed(rasterize, false); 708 checkElementDisplayed(rasterize, false);
641 checkSectionVisible(mediaSize, false); 709 checkSectionVisible(mediaSize, false);
642 checkSectionVisible(scalingSettings, false); 710 checkSectionVisible(scalingSettings, false);
643 711
644 this.expandMoreSettings(); 712 this.expandMoreSettings();
645 713
646 checkElementDisplayed(fitToPage, false); 714 checkElementDisplayed(fitToPage, false);
647 if (isPrintAsImageEnabled()) 715 if (isPrintAsImageEnabled())
648 checkElementDisplayed(rasterize, false); 716 checkElementDisplayed(rasterize, false);
649 checkSectionVisible(mediaSize, true); 717 checkSectionVisible(mediaSize, true);
650 checkSectionVisible(scalingSettings, true); 718 checkSectionVisible(scalingSettings, true);
651 719
652 this.waitForAnimationToEnd('more-settings'); 720 this.waitForAnimationToEnd('more-settings');
721 }.bind(this));
653 }); 722 });
654 723
655 // When the source is "PDF", depending on the selected destination printer, we 724 // When the source is "PDF", depending on the selected destination printer, we
656 // show/hide the fit to page option and hide media size selection. 725 // show/hide the fit to page option and hide media size selection.
657 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() { 726 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() {
658 this.initialSettings_.isDocumentModifiable_ = false; 727 this.initialSettings_.isDocumentModifiable_ = false;
659 this.setInitialSettings(); 728 this.setInitialSettings();
660 this.setLocalDestinations(); 729 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
661 this.setCapabilities(getCddTemplate("FooDevice")); 730 function() {
731 this.setLocalDestinations();
732 this.setCapabilities(getCddTemplate("FooDevice"));
662 733
663 var otherOptions = $('other-options-settings'); 734 var otherOptions = $('other-options-settings');
664 var scalingSettings = $('scaling-settings'); 735 var scalingSettings = $('scaling-settings');
665 var fitToPageContainer = 736 var fitToPageContainer =
666 otherOptions.querySelector('#fit-to-page-container'); 737 otherOptions.querySelector('#fit-to-page-container');
667 var rasterizeContainer; 738 var rasterizeContainer;
668 if (isPrintAsImageEnabled()) { 739 if (isPrintAsImageEnabled()) {
669 rasterizeContainer = 740 rasterizeContainer =
670 otherOptions.querySelector('#rasterize-container'); 741 otherOptions.querySelector('#rasterize-container');
671 } 742 }
672 743
673 checkSectionVisible(otherOptions, true); 744 checkSectionVisible(otherOptions, true);
674 checkElementDisplayed(fitToPageContainer, true); 745 checkElementDisplayed(fitToPageContainer, true);
675 if (isPrintAsImageEnabled()) 746 if (isPrintAsImageEnabled())
676 checkElementDisplayed(rasterizeContainer, false); 747 checkElementDisplayed(rasterizeContainer, false);
677 expectTrue( 748 expectTrue(
678 fitToPageContainer.querySelector('.checkbox').checked); 749 fitToPageContainer.querySelector('.checkbox').checked);
679 this.expandMoreSettings(); 750 this.expandMoreSettings();
680 if (isPrintAsImageEnabled()) { 751 if (isPrintAsImageEnabled()) {
681 checkElementDisplayed(rasterizeContainer, true); 752 checkElementDisplayed(rasterizeContainer, true);
682 expectFalse( 753 expectFalse(
683 rasterizeContainer.querySelector('.checkbox').checked); 754 rasterizeContainer.querySelector('.checkbox').checked);
684 } 755 }
685 checkSectionVisible($('media-size-settings'), true); 756 checkSectionVisible($('media-size-settings'), true);
686 checkSectionVisible(scalingSettings, true); 757 checkSectionVisible(scalingSettings, true);
687 758
688 this.waitForAnimationToEnd('other-options-collapsible'); 759 this.waitForAnimationToEnd('other-options-collapsible');
760 }.bind(this));
689 }); 761 });
690 762
691 // When the source is "PDF", depending on the selected destination printer, we 763 // When the source is "PDF", depending on the selected destination printer, we
692 // show/hide the fit to page option and hide media size selection. 764 // show/hide the fit to page option and hide media size selection.
693 TEST_F('PrintPreviewWebUITest', 'ScalingUnchecksFitToPage', function() { 765 TEST_F('PrintPreviewWebUITest', 'ScalingUnchecksFitToPage', function() {
694 this.initialSettings_.isDocumentModifiable_ = false; 766 this.initialSettings_.isDocumentModifiable_ = false;
695 this.setInitialSettings(); 767 this.setInitialSettings();
696 this.setLocalDestinations(); 768 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
697 this.setCapabilities(getCddTemplate("FooDevice")); 769 function() {
770 this.setLocalDestinations();
771 this.setCapabilities(getCddTemplate("FooDevice"));
698 772
699 var otherOptions = $('other-options-settings'); 773 var otherOptions = $('other-options-settings');
700 var scalingSettings = $('scaling-settings'); 774 var scalingSettings = $('scaling-settings');
701 775
702 checkSectionVisible(otherOptions, true); 776 checkSectionVisible(otherOptions, true);
703 var fitToPageContainer = 777 var fitToPageContainer =
704 otherOptions.querySelector('#fit-to-page-container'); 778 otherOptions.querySelector('#fit-to-page-container');
705 checkElementDisplayed(fitToPageContainer, true); 779 checkElementDisplayed(fitToPageContainer, true);
706 expectTrue( 780 expectTrue(
707 fitToPageContainer.querySelector('.checkbox').checked); 781 fitToPageContainer.querySelector('.checkbox').checked);
708 this.expandMoreSettings(); 782 this.expandMoreSettings();
709 checkSectionVisible($('media-size-settings'), true); 783 checkSectionVisible($('media-size-settings'), true);
710 checkSectionVisible(scalingSettings, true); 784 checkSectionVisible(scalingSettings, true);
711 785
712 // Change scaling input 786 // Change scaling input
713 var scalingInput = scalingSettings.querySelector('.user-value'); 787 var scalingInput = scalingSettings.querySelector('.user-value');
714 expectEquals('100', scalingInput.value); 788 expectEquals('100', scalingInput.value);
715 scalingInput.stepUp(5); 789 scalingInput.stepUp(5);
716 expectEquals('105', scalingInput.value); 790 expectEquals('105', scalingInput.value);
717 791
718 // Trigger the event 792 // Trigger the event
719 var enterEvent = document.createEvent('Event'); 793 var enterEvent = document.createEvent('Event');
720 enterEvent.initEvent('keydown'); 794 enterEvent.initEvent('keydown');
721 enterEvent.keyCode = 'Enter'; 795 enterEvent.keyCode = 'Enter';
722 scalingInput.dispatchEvent(enterEvent); 796 scalingInput.dispatchEvent(enterEvent);
723 expectFalse( 797 expectFalse(
724 fitToPageContainer.querySelector('.checkbox').checked); 798 fitToPageContainer.querySelector('.checkbox').checked);
725 799
726 this.waitForAnimationToEnd('other-options-collapsible'); 800 this.waitForAnimationToEnd('other-options-collapsible');
801 }.bind(this));
727 }); 802 });
728 803
729 // When the number of copies print preset is set for source 'PDF', we update 804 // When the number of copies print preset is set for source 'PDF', we update
730 // the copies value if capability is supported by printer. 805 // the copies value if capability is supported by printer.
731 TEST_F('PrintPreviewWebUITest', 'CheckNumCopiesPrintPreset', function() { 806 TEST_F('PrintPreviewWebUITest', 'CheckNumCopiesPrintPreset', function() {
732 this.initialSettings_.isDocumentModifiable_ = false; 807 this.initialSettings_.isDocumentModifiable_ = false;
733 this.setInitialSettings(); 808 this.setInitialSettings();
734 this.setLocalDestinations(); 809 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
735 this.setCapabilities(getCddTemplate("FooDevice")); 810 function() {
811 this.setLocalDestinations();
812 this.setCapabilities(getCddTemplate("FooDevice"));
736 813
737 // Indicate that the number of copies print preset is set for source PDF. 814 // Indicate that the number of copies print preset is set for source
738 var printPresetOptions = { 815 // PDF.
739 disableScaling: true, 816 var printPresetOptions = {
740 copies: 2 817 disableScaling: true,
741 }; 818 copies: 2
742 var printPresetOptionsEvent = new Event( 819 };
743 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); 820 var printPresetOptionsEvent = new Event(
744 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; 821 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
745 this.nativeLayer_.dispatchEvent(printPresetOptionsEvent); 822 printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
823 this.nativeLayer_.getEventTarget().
824 dispatchEvent(printPresetOptionsEvent);
746 825
747 checkSectionVisible($('copies-settings'), true); 826 checkSectionVisible($('copies-settings'), true);
748 expectEquals( 827 expectEquals(
749 printPresetOptions.copies, 828 printPresetOptions.copies,
750 parseInt($('copies-settings').querySelector('.user-value').value)); 829 parseInt($('copies-settings').querySelector('.user-value').value));
751 830
752 this.waitForAnimationToEnd('other-options-collapsible'); 831 this.waitForAnimationToEnd('other-options-collapsible');
832 }.bind(this));
753 }); 833 });
754 834
755 // When the duplex print preset is set for source 'PDF', we update the 835 // When the duplex print preset is set for source 'PDF', we update the
756 // duplex setting if capability is supported by printer. 836 // duplex setting if capability is supported by printer.
757 TEST_F('PrintPreviewWebUITest', 'CheckDuplexPrintPreset', function() { 837 TEST_F('PrintPreviewWebUITest', 'CheckDuplexPrintPreset', function() {
758 this.initialSettings_.isDocumentModifiable_ = false; 838 this.initialSettings_.isDocumentModifiable_ = false;
759 this.setInitialSettings(); 839 this.setInitialSettings();
760 this.setLocalDestinations();
761 this.setCapabilities(getCddTemplate("FooDevice"));
762 840
763 // Indicate that the duplex print preset is set to "long edge" for source PDF. 841 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
764 var printPresetOptions = { 842 function() {
765 duplex: 1 843 this.setLocalDestinations();
766 }; 844 this.setCapabilities(getCddTemplate("FooDevice"));
767 var printPresetOptionsEvent = new Event(
768 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
769 printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
770 this.nativeLayer_.dispatchEvent(printPresetOptionsEvent);
771 845
772 var otherOptions = $('other-options-settings'); 846 // Indicate that the duplex print preset is set to "long edge" for
773 checkSectionVisible(otherOptions, true); 847 // source PDF.
774 var duplexContainer = otherOptions.querySelector('#duplex-container'); 848 var printPresetOptions = {
775 checkElementDisplayed(duplexContainer, true); 849 duplex: 1
776 expectTrue(duplexContainer.querySelector('.checkbox').checked); 850 };
851 var printPresetOptionsEvent = new Event(
852 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
853 printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
854 this.nativeLayer_.getEventTarget().
855 dispatchEvent(printPresetOptionsEvent);
777 856
778 this.waitForAnimationToEnd('other-options-collapsible'); 857 var otherOptions = $('other-options-settings');
858 checkSectionVisible(otherOptions, true);
859 var duplexContainer = otherOptions.querySelector('#duplex-container');
860 checkElementDisplayed(duplexContainer, true);
861 expectTrue(duplexContainer.querySelector('.checkbox').checked);
862
863 this.waitForAnimationToEnd('other-options-collapsible');
864 }.bind(this));
779 }); 865 });
780 866
781 // Make sure that custom margins controls are properly set up. 867 // Make sure that custom margins controls are properly set up.
782 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() { 868 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() {
783 this.setInitialSettings(); 869 this.setInitialSettings();
784 this.setLocalDestinations(); 870 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
785 this.setCapabilities(getCddTemplate("FooDevice")); 871 function() {
872 this.setLocalDestinations();
873 this.setCapabilities(getCddTemplate("FooDevice"));
786 874
787 printPreview.printTicketStore_.marginsType.updateValue( 875 this.printPreview_.printTicketStore_.marginsType.updateValue(
788 print_preview.ticket_items.MarginsTypeValue.CUSTOM); 876 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
789 877
790 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { 878 ['left', 'top', 'right', 'bottom'].forEach(function(margin) {
791 var control = $('preview-area').querySelector('.margin-control-' + margin); 879 var control =
792 assertNotEquals(null, control); 880 $('preview-area').querySelector('.margin-control-' + margin);
793 var input = control.querySelector('.margin-control-textbox'); 881 assertNotEquals(null, control);
794 assertTrue(input.hasAttribute('aria-label')); 882 var input = control.querySelector('.margin-control-textbox');
795 assertNotEquals('undefined', input.getAttribute('aria-label')); 883 assertTrue(input.hasAttribute('aria-label'));
796 }); 884 assertNotEquals('undefined', input.getAttribute('aria-label'));
797 this.waitForAnimationToEnd('more-settings'); 885 });
886 this.waitForAnimationToEnd('more-settings');
887 }.bind(this));
798 }); 888 });
799 889
800 // Page layout has zero margins. Hide header and footer option. 890 // Page layout has zero margins. Hide header and footer option.
801 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter', 891 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
802 function() { 892 function() {
803 this.setInitialSettings(); 893 this.setInitialSettings();
804 this.setLocalDestinations(); 894 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
805 this.setCapabilities(getCddTemplate("FooDevice")); 895 function() {
896 this.setLocalDestinations();
897 this.setCapabilities(getCddTemplate("FooDevice"));
806 898
807 var otherOptions = $('other-options-settings'); 899 var otherOptions = $('other-options-settings');
808 var headerFooter = otherOptions.querySelector('#header-footer-container'); 900 var headerFooter =
901 otherOptions.querySelector('#header-footer-container');
809 902
810 // Check that options are collapsed (section is visible, because duplex is 903 // Check that options are collapsed (section is visible, because duplex
811 // available). 904 // is available).
812 checkSectionVisible(otherOptions, true); 905 checkSectionVisible(otherOptions, true);
813 checkElementDisplayed(headerFooter, false); 906 checkElementDisplayed(headerFooter, false);
814 907
815 this.expandMoreSettings(); 908 this.expandMoreSettings();
816 909
817 checkElementDisplayed(headerFooter, true); 910 checkElementDisplayed(headerFooter, true);
818 911
819 printPreview.printTicketStore_.marginsType.updateValue( 912 this.printPreview_.printTicketStore_.marginsType.updateValue(
820 print_preview.ticket_items.MarginsTypeValue.CUSTOM); 913 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
821 printPreview.printTicketStore_.customMargins.updateValue( 914 this.printPreview_.printTicketStore_.customMargins.updateValue(
822 new print_preview.Margins(0, 0, 0, 0)); 915 new print_preview.Margins(0, 0, 0, 0));
823 916
824 checkElementDisplayed(headerFooter, false); 917 checkElementDisplayed(headerFooter, false);
825 918
826 this.waitForAnimationToEnd('more-settings'); 919 this.waitForAnimationToEnd('more-settings');
920 }.bind(this));
827 }); 921 });
828 922
829 // Page layout has half-inch margins. Show header and footer option. 923 // Page layout has half-inch margins. Show header and footer option.
830 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter', 924 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter',
831 function() { 925 function() {
832 this.setInitialSettings(); 926 this.setInitialSettings();
833 this.setLocalDestinations(); 927 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
834 this.setCapabilities(getCddTemplate("FooDevice")); 928 function() {
929 this.setLocalDestinations();
930 this.setCapabilities(getCddTemplate("FooDevice"));
835 931
836 var otherOptions = $('other-options-settings'); 932 var otherOptions = $('other-options-settings');
837 var headerFooter = otherOptions.querySelector('#header-footer-container'); 933 var headerFooter =
934 otherOptions.querySelector('#header-footer-container');
838 935
839 // Check that options are collapsed (section is visible, because duplex is 936 // Check that options are collapsed (section is visible, because duplex
840 // available). 937 // is available).
841 checkSectionVisible(otherOptions, true); 938 checkSectionVisible(otherOptions, true);
842 checkElementDisplayed(headerFooter, false); 939 checkElementDisplayed(headerFooter, false);
843 940
844 this.expandMoreSettings(); 941 this.expandMoreSettings();
845 942
846 checkElementDisplayed(headerFooter, true); 943 checkElementDisplayed(headerFooter, true);
847 944
848 printPreview.printTicketStore_.marginsType.updateValue( 945 this.printPreview_.printTicketStore_.marginsType.updateValue(
849 print_preview.ticket_items.MarginsTypeValue.CUSTOM); 946 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
850 printPreview.printTicketStore_.customMargins.updateValue( 947 this.printPreview_.printTicketStore_.customMargins.updateValue(
851 new print_preview.Margins(36, 36, 36, 36)); 948 new print_preview.Margins(36, 36, 36, 36));
852 949
853 checkElementDisplayed(headerFooter, true); 950 checkElementDisplayed(headerFooter, true);
854 951
855 this.waitForAnimationToEnd('more-settings'); 952 this.waitForAnimationToEnd('more-settings');
953 }.bind(this));
856 }); 954 });
857 955
858 // Page layout has zero top and bottom margins. Hide header and footer option. 956 // Page layout has zero top and bottom margins. Hide header and footer option.
859 TEST_F('PrintPreviewWebUITest', 957 TEST_F('PrintPreviewWebUITest',
860 'ZeroTopAndBottomMarginsHideHeaderFooter', 958 'ZeroTopAndBottomMarginsHideHeaderFooter',
861 function() { 959 function() {
862 this.setInitialSettings(); 960 this.setInitialSettings();
863 this.setLocalDestinations(); 961 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
864 this.setCapabilities(getCddTemplate("FooDevice")); 962 function() {
963 this.setLocalDestinations();
964 this.setCapabilities(getCddTemplate("FooDevice"));
865 965
866 var otherOptions = $('other-options-settings'); 966 var otherOptions = $('other-options-settings');
867 var headerFooter = otherOptions.querySelector('#header-footer-container'); 967 var headerFooter =
968 otherOptions.querySelector('#header-footer-container');
868 969
869 // Check that options are collapsed (section is visible, because duplex is 970 // Check that options are collapsed (section is visible, because duplex
870 // available). 971 // is available).
871 checkSectionVisible(otherOptions, true); 972 checkSectionVisible(otherOptions, true);
872 checkElementDisplayed(headerFooter, false); 973 checkElementDisplayed(headerFooter, false);
873 974
874 this.expandMoreSettings(); 975 this.expandMoreSettings();
875 976
876 checkElementDisplayed(headerFooter, true); 977 checkElementDisplayed(headerFooter, true);
877 978
878 printPreview.printTicketStore_.marginsType.updateValue( 979 this.printPreview_.printTicketStore_.marginsType.updateValue(
879 print_preview.ticket_items.MarginsTypeValue.CUSTOM); 980 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
880 printPreview.printTicketStore_.customMargins.updateValue( 981 this.printPreview_.printTicketStore_.customMargins.updateValue(
881 new print_preview.Margins(0, 36, 0, 36)); 982 new print_preview.Margins(0, 36, 0, 36));
882 983
883 checkElementDisplayed(headerFooter, false); 984 checkElementDisplayed(headerFooter, false);
884 985
885 this.waitForAnimationToEnd('more-settings'); 986 this.waitForAnimationToEnd('more-settings');
987 }.bind(this));
886 }); 988 });
887 989
888 // Page layout has zero top and half-inch bottom margin. Show header and footer 990 // Page layout has zero top and half-inch bottom margin. Show header and footer
889 // option. 991 // option.
890 TEST_F('PrintPreviewWebUITest', 992 TEST_F('PrintPreviewWebUITest',
891 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter', 993 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
892 function() { 994 function() {
893 this.setInitialSettings(); 995 this.setInitialSettings();
894 this.setLocalDestinations(); 996 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
895 this.setCapabilities(getCddTemplate("FooDevice")); 997 function() {
998 this.setLocalDestinations();
999 this.setCapabilities(getCddTemplate("FooDevice"));
896 1000
897 var otherOptions = $('other-options-settings'); 1001 var otherOptions = $('other-options-settings');
898 var headerFooter = otherOptions.querySelector('#header-footer-container'); 1002 var headerFooter =
1003 otherOptions.querySelector('#header-footer-container');
899 1004
900 // Check that options are collapsed (section is visible, because duplex is 1005 // Check that options are collapsed (section is visible, because duplex
901 // available). 1006 // is available).
902 checkSectionVisible(otherOptions, true); 1007 checkSectionVisible(otherOptions, true);
903 checkElementDisplayed(headerFooter, false); 1008 checkElementDisplayed(headerFooter, false);
904 1009
905 this.expandMoreSettings(); 1010 this.expandMoreSettings();
906 1011
907 checkElementDisplayed(headerFooter, true); 1012 checkElementDisplayed(headerFooter, true);
908 1013
909 printPreview.printTicketStore_.marginsType.updateValue( 1014 this.printPreview_.printTicketStore_.marginsType.updateValue(
910 print_preview.ticket_items.MarginsTypeValue.CUSTOM); 1015 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
911 printPreview.printTicketStore_.customMargins.updateValue( 1016 this.printPreview_.printTicketStore_.customMargins.updateValue(
912 new print_preview.Margins(0, 36, 36, 36)); 1017 new print_preview.Margins(0, 36, 36, 36));
913 1018
914 checkElementDisplayed(headerFooter, true); 1019 checkElementDisplayed(headerFooter, true);
915 1020
916 this.waitForAnimationToEnd('more-settings'); 1021 this.waitForAnimationToEnd('more-settings');
1022 }.bind(this));
917 }); 1023 });
918 1024
919 // Check header footer availability with small (label) page size. 1025 // Check header footer availability with small (label) page size.
920 TEST_F('PrintPreviewWebUITest', 'SmallPaperSizeHeaderFooter', function() { 1026 TEST_F('PrintPreviewWebUITest', 'SmallPaperSizeHeaderFooter', function() {
921 this.setInitialSettings(); 1027 this.setInitialSettings();
922 this.setLocalDestinations(); 1028 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
923 var device = getCddTemplate("FooDevice"); 1029 function() {
924 device.capabilities.printer.media_size = { 1030 this.setLocalDestinations();
925 "option": [ 1031 var device = getCddTemplate("FooDevice");
926 {"name": "SmallLabel", "width_microns": 38100, "height_microns": 12700, 1032 device.capabilities.printer.media_size = {
927 "is_default": false}, 1033 "option": [
928 {"name": "BigLabel", "width_microns": 50800, "height_microns": 76200, 1034 {"name": "SmallLabel", "width_microns": 38100,
929 "is_default": true} 1035 "height_microns": 12700, "is_default": false},
930 ] 1036 {"name": "BigLabel", "width_microns": 50800,
931 }; 1037 "height_microns": 76200, "is_default": true}
932 this.setCapabilities(device); 1038 ]
1039 };
1040 this.setCapabilities(device);
933 1041
934 var otherOptions = $('other-options-settings'); 1042 var otherOptions = $('other-options-settings');
935 var headerFooter = otherOptions.querySelector('#header-footer-container'); 1043 var headerFooter =
1044 otherOptions.querySelector('#header-footer-container');
936 1045
937 // Check that options are collapsed (section is visible, because duplex is 1046 // Check that options are collapsed (section is visible, because duplex
938 // available). 1047 // is available).
939 checkSectionVisible(otherOptions, true); 1048 checkSectionVisible(otherOptions, true);
940 checkElementDisplayed(headerFooter, false); 1049 checkElementDisplayed(headerFooter, false);
941 1050
942 this.expandMoreSettings(); 1051 this.expandMoreSettings();
943 1052
944 // Big label should have header/footer 1053 // Big label should have header/footer
945 checkElementDisplayed(headerFooter, true); 1054 checkElementDisplayed(headerFooter, true);
946 1055
947 // Small label should not 1056 // Small label should not
948 printPreview.printTicketStore_.mediaSize.updateValue( 1057 this.printPreview_.printTicketStore_.mediaSize.updateValue(
949 device.capabilities.printer.media_size.option[0]); 1058 device.capabilities.printer.media_size.option[0]);
950 checkElementDisplayed(headerFooter, false); 1059 checkElementDisplayed(headerFooter, false);
951 1060
952 // Oriented in landscape, there should be enough space for header/footer. 1061 // Oriented in landscape, there should be enough space for
953 printPreview.printTicketStore_.landscape.updateValue(true); 1062 // header/footer.
954 checkElementDisplayed(headerFooter, true); 1063 this.printPreview_.printTicketStore_.landscape.updateValue(true);
1064 checkElementDisplayed(headerFooter, true);
955 1065
956 this.waitForAnimationToEnd('more-settings'); 1066 this.waitForAnimationToEnd('more-settings');
1067 }.bind(this));
957 }); 1068 });
958 1069
959 // Test that the color settings, one option, standard monochrome. 1070 // Test that the color settings, one option, standard monochrome.
960 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() { 1071 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() {
961 this.setInitialSettings(); 1072 this.setInitialSettings();
962 this.setLocalDestinations(); 1073 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1074 function() {
1075 this.setLocalDestinations();
963 1076
964 // Only one option, standard monochrome. 1077 // Only one option, standard monochrome.
965 var device = getCddTemplate("FooDevice"); 1078 var device = getCddTemplate("FooDevice");
966 device.capabilities.printer.color = { 1079 device.capabilities.printer.color = {
967 "option": [ 1080 "option": [
968 {"is_default": true, "type": "STANDARD_MONOCHROME"} 1081 {"is_default": true, "type": "STANDARD_MONOCHROME"}
969 ] 1082 ]
970 }; 1083 };
971 this.setCapabilities(device); 1084 this.setCapabilities(device);
972 1085
973 checkSectionVisible($('color-settings'), false); 1086 checkSectionVisible($('color-settings'), false);
974 1087
975 this.waitForAnimationToEnd('more-settings'); 1088 this.waitForAnimationToEnd('more-settings');
1089 }.bind(this));
976 }); 1090 });
977 1091
978 // Test that the color settings, one option, custom monochrome. 1092 // Test that the color settings, one option, custom monochrome.
979 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome', 1093 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome',
980 function() { 1094 function() {
981 this.setInitialSettings(); 1095 this.setInitialSettings();
982 this.setLocalDestinations(); 1096 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1097 function() {
1098 this.setLocalDestinations();
983 1099
984 // Only one option, standard monochrome. 1100 // Only one option, standard monochrome.
985 var device = getCddTemplate("FooDevice"); 1101 var device = getCddTemplate("FooDevice");
986 device.capabilities.printer.color = { 1102 device.capabilities.printer.color = {
987 "option": [ 1103 "option": [
988 {"is_default": true, "type": "CUSTOM_MONOCHROME", "vendor_id": "42"} 1104 {"is_default": true, "type": "CUSTOM_MONOCHROME",
989 ] 1105 "vendor_id": "42"}
990 }; 1106 ]
991 this.setCapabilities(device); 1107 };
1108 this.setCapabilities(device);
992 1109
993 checkSectionVisible($('color-settings'), false); 1110 checkSectionVisible($('color-settings'), false);
994 1111
995 this.waitForAnimationToEnd('more-settings'); 1112 this.waitForAnimationToEnd('more-settings');
1113 }.bind(this));
996 }); 1114 });
997 1115
998 // Test that the color settings, one option, standard color. 1116 // Test that the color settings, one option, standard color.
999 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() { 1117 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() {
1000 this.setInitialSettings(); 1118 this.setInitialSettings();
1001 this.setLocalDestinations(); 1119 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1120 function() {
1121 this.setLocalDestinations();
1002 1122
1003 var device = getCddTemplate("FooDevice"); 1123 var device = getCddTemplate("FooDevice");
1004 device.capabilities.printer.color = { 1124 device.capabilities.printer.color = {
1005 "option": [ 1125 "option": [
1006 {"is_default": true, "type": "STANDARD_COLOR"} 1126 {"is_default": true, "type": "STANDARD_COLOR"}
1007 ] 1127 ]
1008 }; 1128 };
1009 this.setCapabilities(device); 1129 this.setCapabilities(device);
1010 1130
1011 checkSectionVisible($('color-settings'), false); 1131 checkSectionVisible($('color-settings'), false);
1012 1132
1013 this.waitForAnimationToEnd('more-settings'); 1133 this.waitForAnimationToEnd('more-settings');
1134 }.bind(this));
1014 }); 1135 });
1015 1136
1016 // Test that the color settings, one option, custom color. 1137 // Test that the color settings, one option, custom color.
1017 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() { 1138 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() {
1018 this.setInitialSettings(); 1139 this.setInitialSettings();
1019 this.setLocalDestinations(); 1140 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1141 function() {
1142 this.setLocalDestinations();
1020 1143
1021 var device = getCddTemplate("FooDevice"); 1144 var device = getCddTemplate("FooDevice");
1022 device.capabilities.printer.color = { 1145 device.capabilities.printer.color = {
1023 "option": [ 1146 "option": [
1024 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"} 1147 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"}
1025 ] 1148 ]
1026 }; 1149 };
1027 this.setCapabilities(device); 1150 this.setCapabilities(device);
1028 1151
1029 checkSectionVisible($('color-settings'), false); 1152 checkSectionVisible($('color-settings'), false);
1030 1153
1031 this.waitForAnimationToEnd('more-settings'); 1154 this.waitForAnimationToEnd('more-settings');
1155 }.bind(this));
1032 }); 1156 });
1033 1157
1034 // Test that the color settings, two options, both standard, defaults to color. 1158 // Test that the color settings, two options, both standard, defaults to color.
1035 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor', 1159 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor',
1036 function() { 1160 function() {
1037 this.setInitialSettings(); 1161 this.setInitialSettings();
1038 this.setLocalDestinations(); 1162 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1163 function() {
1164 this.setLocalDestinations();
1039 1165
1040 var device = getCddTemplate("FooDevice"); 1166 var device = getCddTemplate("FooDevice");
1041 device.capabilities.printer.color = { 1167 device.capabilities.printer.color = {
1042 "option": [ 1168 "option": [
1043 {"type": "STANDARD_MONOCHROME"}, 1169 {"type": "STANDARD_MONOCHROME"},
1044 {"is_default": true, "type": "STANDARD_COLOR"} 1170 {"is_default": true, "type": "STANDARD_COLOR"}
1045 ] 1171 ]
1046 }; 1172 };
1047 this.setCapabilities(device); 1173 this.setCapabilities(device);
1048 1174
1049 checkSectionVisible($('color-settings'), true); 1175 checkSectionVisible($('color-settings'), true);
1050 expectEquals( 1176 expectEquals(
1051 'color', 1177 'color',
1052 $('color-settings').querySelector('.color-settings-select').value); 1178 $('color-settings').querySelector('.color-settings-select').value);
1053 1179
1054 this.waitForAnimationToEnd('more-settings'); 1180 this.waitForAnimationToEnd('more-settings');
1181 }.bind(this));
1055 }); 1182 });
1056 1183
1057 // Test that the color settings, two options, both standard, defaults to 1184 // Test that the color settings, two options, both standard, defaults to
1058 // monochrome. 1185 // monochrome.
1059 TEST_F('PrintPreviewWebUITest', 1186 TEST_F('PrintPreviewWebUITest',
1060 'TestColorSettingsBothStandardDefaultMonochrome', function() { 1187 'TestColorSettingsBothStandardDefaultMonochrome', function() {
1061 this.setInitialSettings(); 1188 this.setInitialSettings();
1062 this.setLocalDestinations(); 1189 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1063 1190 function() {
1064 var device = getCddTemplate("FooDevice"); 1191 this.setLocalDestinations();
1065 device.capabilities.printer.color = { 1192
1066 "option": [ 1193 var device = getCddTemplate("FooDevice");
1067 {"is_default": true, "type": "STANDARD_MONOCHROME"}, 1194 device.capabilities.printer.color = {
1068 {"type": "STANDARD_COLOR"} 1195 "option": [
1069 ] 1196 {"is_default": true, "type": "STANDARD_MONOCHROME"},
1070 }; 1197 {"type": "STANDARD_COLOR"}
1071 this.setCapabilities(device); 1198 ]
1072 1199 };
1073 checkSectionVisible($('color-settings'), true); 1200 this.setCapabilities(device);
1074 expectEquals( 1201
1075 'bw', $('color-settings').querySelector('.color-settings-select').value); 1202 checkSectionVisible($('color-settings'), true);
1076 1203 expectEquals(
1077 this.waitForAnimationToEnd('more-settings'); 1204 'bw',
1205 $('color-settings').querySelector('.color-settings-select').value);
1206
1207 this.waitForAnimationToEnd('more-settings');
1208 }.bind(this));
1078 }); 1209 });
1079 1210
1080 // Test that the color settings, two options, both custom, defaults to color. 1211 // Test that the color settings, two options, both custom, defaults to color.
1081 TEST_F('PrintPreviewWebUITest', 1212 TEST_F('PrintPreviewWebUITest',
1082 'TestColorSettingsBothCustomDefaultColor', function() { 1213 'TestColorSettingsBothCustomDefaultColor', function() {
1083 this.setInitialSettings(); 1214 this.setInitialSettings();
1084 this.setLocalDestinations(); 1215 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1085 1216 function() {
1086 var device = getCddTemplate("FooDevice"); 1217 this.setLocalDestinations();
1087 device.capabilities.printer.color = { 1218
1088 "option": [ 1219 var device = getCddTemplate("FooDevice");
1089 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"}, 1220 device.capabilities.printer.color = {
1090 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"} 1221 "option": [
1091 ] 1222 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"},
1092 }; 1223 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"}
1093 this.setCapabilities(device); 1224 ]
1094 1225 };
1095 checkSectionVisible($('color-settings'), true); 1226 this.setCapabilities(device);
1096 expectEquals( 1227
1097 'color', 1228 checkSectionVisible($('color-settings'), true);
1098 $('color-settings').querySelector('.color-settings-select').value); 1229 expectEquals(
1099 1230 'color',
1100 this.waitForAnimationToEnd('more-settings'); 1231 $('color-settings').querySelector('.color-settings-select').value);
1232
1233 this.waitForAnimationToEnd('more-settings');
1234 }.bind(this));
1101 }); 1235 });
1102 1236
1103 // Test to verify that duplex settings are set according to the printer 1237 // Test to verify that duplex settings are set according to the printer
1104 // capabilities. 1238 // capabilities.
1105 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() { 1239 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
1106 this.setInitialSettings(); 1240 this.setInitialSettings();
1107 this.setLocalDestinations(); 1241 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1108 this.setCapabilities(getCddTemplate("FooDevice")); 1242 function() {
1109 1243 this.setLocalDestinations();
1110 var otherOptions = $('other-options-settings'); 1244 this.setCapabilities(getCddTemplate("FooDevice"));
1111 checkSectionVisible(otherOptions, true); 1245
1112 duplexContainer = otherOptions.querySelector('#duplex-container'); 1246 var otherOptions = $('other-options-settings');
1113 expectFalse(duplexContainer.hidden); 1247 checkSectionVisible(otherOptions, true);
1114 expectFalse(duplexContainer.querySelector('.checkbox').checked); 1248 duplexContainer = otherOptions.querySelector('#duplex-container');
1115 1249 expectFalse(duplexContainer.hidden);
1116 this.waitForAnimationToEnd('more-settings'); 1250 expectFalse(duplexContainer.querySelector('.checkbox').checked);
1251
1252 this.waitForAnimationToEnd('more-settings');
1253 }.bind(this));
1117 }); 1254 });
1118 1255
1119 // Test to verify that duplex settings are set according to the printer 1256 // Test to verify that duplex settings are set according to the printer
1120 // capabilities. 1257 // capabilities.
1121 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() { 1258 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
1122 this.setInitialSettings(); 1259 this.setInitialSettings();
1123 this.setLocalDestinations(); 1260 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1124 var device = getCddTemplate("FooDevice"); 1261 function() {
1125 delete device.capabilities.printer.duplex; 1262 this.setLocalDestinations();
1126 this.setCapabilities(device); 1263 var device = getCddTemplate("FooDevice");
1127 1264 delete device.capabilities.printer.duplex;
1128 // Check that it is collapsed. 1265 this.setCapabilities(device);
1129 var otherOptions = $('other-options-settings'); 1266
1130 checkSectionVisible(otherOptions, false); 1267 // Check that it is collapsed.
1131 1268 var otherOptions = $('other-options-settings');
1132 this.expandMoreSettings(); 1269 checkSectionVisible(otherOptions, false);
1133 1270
1134 // Now it should be visible. 1271 this.expandMoreSettings();
1135 checkSectionVisible(otherOptions, true); 1272
1136 expectTrue(otherOptions.querySelector('#duplex-container').hidden); 1273 // Now it should be visible.
1137 1274 checkSectionVisible(otherOptions, true);
1138 this.waitForAnimationToEnd('more-settings'); 1275 expectTrue(otherOptions.querySelector('#duplex-container').hidden);
1276
1277 this.waitForAnimationToEnd('more-settings');
1278 }.bind(this));
1139 }); 1279 });
1140 1280
1141 // Test that changing the selected printer updates the preview. 1281 // Test that changing the selected printer updates the preview.
1142 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { 1282 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
1143 this.setInitialSettings(); 1283 this.setInitialSettings();
1144 this.setLocalDestinations(); 1284 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1145 this.setCapabilities(getCddTemplate("FooDevice")); 1285 function() {
1146 1286 this.setLocalDestinations();
1147 var previewGenerator = mock(print_preview.PreviewGenerator); 1287 this.setCapabilities(getCddTemplate("FooDevice"));
1148 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy(); 1288
1149 1289 var previewGenerator = mock(print_preview.PreviewGenerator);
1150 // The number of settings that can change due to a change in the destination 1290 this.printPreview_.previewArea_.previewGenerator_ =
1151 // that will therefore dispatch ticket item change events. 1291 previewGenerator.proxy();
1152 previewGenerator.expects(exactly(9)).requestPreview(); 1292
1153 1293 // The number of settings that can change due to a change in the
1154 var barDestination = 1294 // destination that will therefore dispatch ticket item change events.
1155 printPreview.destinationStore_.destinations().find(function(d) { 1295 previewGenerator.expects(exactly(9)).requestPreview();
1156 return d.id == 'BarDevice'; 1296
1157 }); 1297 var barDestination =
1158 1298 this.printPreview_.destinationStore_.destinations().find(
1159 printPreview.destinationStore_.selectDestination(barDestination); 1299 function(d) {
1160 1300 return d.id == 'BarDevice';
1161 var device = getCddTemplate("BarDevice"); 1301 });
1162 device.capabilities.printer.color = { 1302
1163 "option": [ 1303 this.printPreview_.destinationStore_.selectDestination(barDestination);
1164 {"is_default": true, "type": "STANDARD_MONOCHROME"} 1304
1165 ] 1305 var device = getCddTemplate("BarDevice");
1166 }; 1306 device.capabilities.printer.color = {
1167 this.setCapabilities(device); 1307 "option": [
1168 1308 {"is_default": true, "type": "STANDARD_MONOCHROME"}
1169 this.waitForAnimationToEnd('more-settings'); 1309 ]
1310 };
1311 this.setCapabilities(device);
1312
1313 this.waitForAnimationToEnd('more-settings');
1314 }.bind(this));
1170 }); 1315 });
1171 1316
1172 // Test that error message is displayed when plugin doesn't exist. 1317 // Test that error message is displayed when plugin doesn't exist.
1173 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() { 1318 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
1174 var previewAreaEl = $('preview-area'); 1319 this.setInitialSettings();
1175 1320 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1176 var loadingMessageEl = 1321 function() {
1177 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0]; 1322 var previewAreaEl = $('preview-area');
1178 expectTrue(loadingMessageEl.hidden); 1323
1179 1324 var loadingMessageEl =
1180 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( 1325 previewAreaEl.
1181 'preview-area-preview-failed-message')[0]; 1326 getElementsByClassName('preview-area-loading-message')[0];
1182 expectTrue(previewFailedMessageEl.hidden); 1327 expectTrue(loadingMessageEl.hidden);
1183 1328
1184 var printFailedMessageEl = 1329 var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
1185 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0]; 1330 'preview-area-preview-failed-message')[0];
1186 expectTrue(printFailedMessageEl.hidden); 1331 expectTrue(previewFailedMessageEl.hidden);
1187 1332
1188 var customMessageEl = 1333 var printFailedMessageEl =
1189 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; 1334 previewAreaEl.
1190 expectFalse(customMessageEl.hidden); 1335 getElementsByClassName('preview-area-print-failed')[0];
1191 1336 expectTrue(printFailedMessageEl.hidden);
1192 testDone(); 1337
1338 var customMessageEl =
1339 previewAreaEl.
1340 getElementsByClassName('preview-area-custom-message')[0];
1341 expectFalse(customMessageEl.hidden);
1342
1343 testDone();
1344 });
1193 }); 1345 });
1194 1346
1195 // Test custom localized paper names. 1347 // Test custom localized paper names.
1196 TEST_F('PrintPreviewWebUITest', 'TestCustomPaperNames', function() { 1348 TEST_F('PrintPreviewWebUITest', 'TestCustomPaperNames', function() {
1197 this.setInitialSettings(); 1349 this.setInitialSettings();
1198 this.setLocalDestinations(); 1350 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1199 1351 function() {
1200 var customLocalizedMediaName = 'Vendor defined localized media name'; 1352 this.setLocalDestinations();
1201 var customMediaName = 'Vendor defined media name'; 1353
1202 1354 var customLocalizedMediaName = 'Vendor defined localized media name';
1203 var device = getCddTemplate("FooDevice"); 1355 var customMediaName = 'Vendor defined media name';
1204 device.capabilities.printer.media_size = { 1356
1205 option: [ 1357 var device = getCddTemplate("FooDevice");
1206 { name: 'CUSTOM', 1358 device.capabilities.printer.media_size = {
1207 width_microns: 15900, 1359 option: [
1208 height_microns: 79400, 1360 { name: 'CUSTOM',
1209 is_default: true, 1361 width_microns: 15900,
1210 custom_display_name_localized: [ 1362 height_microns: 79400,
1211 { locale: navigator.language, 1363 is_default: true,
1212 value: customLocalizedMediaName 1364 custom_display_name_localized: [
1213 } 1365 { locale: navigator.language,
1214 ] 1366 value: customLocalizedMediaName
1215 }, 1367 }
1216 { name: 'CUSTOM', 1368 ]
1217 width_microns: 15900, 1369 },
1218 height_microns: 79400, 1370 { name: 'CUSTOM',
1219 custom_display_name: customMediaName 1371 width_microns: 15900,
1220 } 1372 height_microns: 79400,
1221 ] 1373 custom_display_name: customMediaName
1222 }; 1374 }
1223 1375 ]
1224 this.setCapabilities(device); 1376 };
1225 1377
1226 this.expandMoreSettings(); 1378 this.setCapabilities(device);
1227 1379
1228 checkSectionVisible($('media-size-settings'), true); 1380 this.expandMoreSettings();
1229 var mediaSelect = $('media-size-settings').querySelector('.settings-select'); 1381
1230 // Check the default media item. 1382 checkSectionVisible($('media-size-settings'), true);
1231 expectEquals( 1383 var mediaSelect =
1232 customLocalizedMediaName, 1384 $('media-size-settings').querySelector('.settings-select');
1233 mediaSelect.options[mediaSelect.selectedIndex].text); 1385 // Check the default media item.
1234 // Check the other media item. 1386 expectEquals(
1235 expectEquals( 1387 customLocalizedMediaName,
1236 customMediaName, 1388 mediaSelect.options[mediaSelect.selectedIndex].text);
1237 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text); 1389 // Check the other media item.
1238 1390 expectEquals(
1239 this.waitForAnimationToEnd('more-settings'); 1391 customMediaName,
1392 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text);
1393
1394 this.waitForAnimationToEnd('more-settings');
1395 }.bind(this));
1240 }); 1396 });
1241 1397
1242 function getCddTemplateWithAdvancedSettings(printerId) { 1398 function getCddTemplateWithAdvancedSettings(printerId) {
1243 return { 1399 return {
1244 printerId: printerId, 1400 printerId: printerId,
1245 capabilities: { 1401 capabilities: {
1246 version: '1.0', 1402 version: '1.0',
1247 printer: { 1403 printer: {
1248 supported_content_type: [{content_type: 'application/pdf'}], 1404 supported_content_type: [{content_type: 'application/pdf'}],
1249 vendor_capability: 1405 vendor_capability:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 // testPluginCompatibility() being set to always return false. Enable button 1464 // testPluginCompatibility() being set to always return false. Enable button
1309 // to send click event. 1465 // to send click event.
1310 advancedOptionsSettingsButton.disabled = false; 1466 advancedOptionsSettingsButton.disabled = false;
1311 advancedOptionsSettingsButton.click(); 1467 advancedOptionsSettingsButton.click();
1312 } 1468 }
1313 1469
1314 // Test advanced settings with 1 capability (should not display settings search 1470 // Test advanced settings with 1 capability (should not display settings search
1315 // box). 1471 // box).
1316 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings1Option', function() { 1472 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings1Option', function() {
1317 var device = getCddTemplateWithAdvancedSettings("FooDevice"); 1473 var device = getCddTemplateWithAdvancedSettings("FooDevice");
1318 this.setupAdvancedSettingsTest(device); 1474 this.accessibilityIssuesAreErrors = false;
1475 this.setInitialSettings();
1476 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1477 function() {
1478 this.setupAdvancedSettingsTest(device);
1319 1479
1320 // Open the advanced settings overlay. 1480 // Open the advanced settings overlay.
1321 openAdvancedSettings(); 1481 openAdvancedSettings();
1322 1482
1323 // Check that advanced settings close button is now visible, 1483 // Check that advanced settings close button is now visible,
1324 // but not the search box (only 1 capability). 1484 // but not the search box (only 1 capability).
1325 var advancedSettingsCloseButton = $('advanced-settings'). 1485 var advancedSettingsCloseButton = $('advanced-settings').
1326 querySelector('.close-button'); 1486 querySelector('.close-button');
1327 checkElementDisplayed(advancedSettingsCloseButton, true); 1487 checkElementDisplayed(advancedSettingsCloseButton, true);
1328 checkElementDisplayed($('advanced-settings'). 1488 checkElementDisplayed($('advanced-settings').
1329 querySelector('.search-box-area'), false); 1489 querySelector('.search-box-area'), false);
1330 1490
1331 this.waitForAnimationToEnd('more-settings'); 1491 this.waitForAnimationToEnd('more-settings');
1492 }.bind(this));
1332 }); 1493 });
1333 1494
1334 1495
1335 // Test advanced settings with 2 capabilities (should have settings search box). 1496 // Test advanced settings with 2 capabilities (should have settings search box).
1336 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings2Options', function() { 1497 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings2Options', function() {
1337 var device = getCddTemplateWithAdvancedSettings("FooDevice"); 1498 var device = getCddTemplateWithAdvancedSettings("FooDevice");
1338 // Add new capability. 1499 // Add new capability.
1339 device.capabilities.printer.vendor_capability.push({ 1500 device.capabilities.printer.vendor_capability.push({
1340 display_name: 'Paper Type', 1501 display_name: 'Paper Type',
1341 id: 'Paper Type', 1502 id: 'Paper Type',
1342 type: 'SELECT', 1503 type: 'SELECT',
1343 select_cap: { 1504 select_cap: {
1344 option: [ 1505 option: [
1345 {display_name: 'Standard', value: 0, is_default: true}, 1506 {display_name: 'Standard', value: 0, is_default: true},
1346 {display_name: 'Recycled', value: 1}, 1507 {display_name: 'Recycled', value: 1},
1347 {display_name: 'Special', value: 2} 1508 {display_name: 'Special', value: 2}
1348 ] 1509 ]
1349 } 1510 }
1350 }); 1511 });
1351 this.setupAdvancedSettingsTest(device); 1512 this.accessibilityIssuesAreErrors = false;
1513 this.setInitialSettings();
1514 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1515 function() {
1516 this.setupAdvancedSettingsTest(device);
1352 1517
1353 // Open the advanced settings overlay. 1518 // Open the advanced settings overlay.
1354 openAdvancedSettings(); 1519 openAdvancedSettings();
1355 1520
1356 // Check advanced settings is visible and that the search box now 1521 // Check advanced settings is visible and that the search box now
1357 // appears. 1522 // appears.
1358 var advancedSettingsCloseButton = $('advanced-settings'). 1523 var advancedSettingsCloseButton = $('advanced-settings').
1359 querySelector('.close-button'); 1524 querySelector('.close-button');
1360 checkElementDisplayed(advancedSettingsCloseButton, true); 1525 checkElementDisplayed(advancedSettingsCloseButton, true);
1361 checkElementDisplayed($('advanced-settings'). 1526 checkElementDisplayed($('advanced-settings').
1362 querySelector('.search-box-area'), true); 1527 querySelector('.search-box-area'), true);
1363 1528
1364 this.waitForAnimationToEnd('more-settings'); 1529 this.waitForAnimationToEnd('more-settings');
1530 }.bind(this));
1365 }); 1531 });
1366 1532
1367 // Test that initialization with saved destination only issues one call 1533 // Test that initialization with saved destination only issues one call
1368 // to startPreview. 1534 // to startPreview.
1369 TEST_F('PrintPreviewWebUITest', 'TestInitIssuesOneRequest', function() { 1535 TEST_F('PrintPreviewWebUITest', 'TestInitIssuesOneRequest', function() {
1536 this.createPrintPreview();
1370 // Load in a bunch of recent destinations with non null capabilities. 1537 // Load in a bunch of recent destinations with non null capabilities.
1371 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; 1538 var origin = cr.isChromeOS ? 'chrome_os' : 'local';
1372 var initSettings = { 1539 var initSettings = {
1373 version: 2, 1540 version: 2,
1374 recentDestinations: [1, 2, 3].map(function(i) { 1541 recentDestinations: [1, 2, 3].map(function(i) {
1375 return { 1542 return {
1376 id: 'ID' + i, origin: origin, account: '', 1543 id: 'ID' + i, origin: origin, account: '',
1377 capabilities: getCddTemplate('ID' + i), name: '', 1544 capabilities: getCddTemplate('ID' + i), name: '',
1378 extensionId: '', extensionName: '' 1545 extensionId: '', extensionName: ''
1379 }; 1546 };
1380 }), 1547 }),
1381 }; 1548 };
1382 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(initSettings); 1549 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(initSettings);
1383 this.setCapabilities(getCddTemplate('ID1')); 1550 this.setCapabilities(getCddTemplate('ID1'));
1384 this.setCapabilities(getCddTemplate('ID2')); 1551 this.setCapabilities(getCddTemplate('ID2'));
1385 this.setCapabilities(getCddTemplate('ID3')); 1552 this.setCapabilities(getCddTemplate('ID3'));
1386 1553
1387 // Use a real preview generator. 1554 // Use a real preview generator.
1388 printPreview.previewArea_.previewGenerator_ = 1555 this.printPreview_.previewArea_.previewGenerator_ =
1389 new print_preview.PreviewGenerator(printPreview.destinationStore_, 1556 new print_preview.PreviewGenerator(this.printPreview_.destinationStore_,
1390 printPreview.printTicketStore_, this.nativeLayer_, 1557 this.printPreview_.printTicketStore_, this.nativeLayer_,
1391 printPreview.documentInfo_); 1558 this.printPreview_.documentInfo_);
1392 1559
1393 // Preview generator starts out with inFlightRequestId_ == -1. The id 1560 // Preview generator starts out with inFlightRequestId_ == -1. The id
1394 // increments by 1 for each startGetPreview call it makes. It should only 1561 // increments by 1 for each startGetPreview call it makes. It should only
1395 // make one such call during initialization or there will be a race; see 1562 // make one such call during initialization or there will be a race; see
1396 // crbug.com/666595 1563 // crbug.com/666595
1397 expectEquals( 1564 expectEquals(
1398 -1, 1565 -1,
1399 printPreview.previewArea_.previewGenerator_.inFlightRequestId_); 1566 this.printPreview_.previewArea_.previewGenerator_.inFlightRequestId_);
1400 this.setInitialSettings(); 1567 this.setInitialSettings();
1401 expectEquals( 1568 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1402 0, 1569 function() {
1403 printPreview.previewArea_.previewGenerator_.inFlightRequestId_); 1570 expectEquals(
1404 testDone(); 1571 0,
1572 this.printPreview_.previewArea_.previewGenerator_.
1573 inFlightRequestId_);
1574 testDone();
1575 }.bind(this));
1405 }); 1576 });
1406 1577
1407 // Test that invalid settings errors disable the print preview and display 1578 // Test that invalid settings errors disable the print preview and display
1408 // an error and that the preview dialog can be recovered by selecting a 1579 // an error and that the preview dialog can be recovered by selecting a
1409 // new destination. 1580 // new destination.
1410 TEST_F('PrintPreviewWebUITest', 'TestInvalidSettingsError', function() { 1581 TEST_F('PrintPreviewWebUITest', 'TestInvalidSettingsError', function() {
1411 // Setup 1582 // Setup
1412 this.setInitialSettings(); 1583 this.setInitialSettings();
1413 this.setLocalDestinations(); 1584 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1414 this.setCapabilities(getCddTemplate("FooDevice")); 1585 function() {
1586 this.setLocalDestinations();
1587 this.setCapabilities(getCddTemplate("FooDevice"));
1415 1588
1416 // Manually enable the print header. This is needed since there is no 1589 // Manually enable the print header. This is needed since there is no
1417 // plugin during test, so it will be set as disabled normally. 1590 // plugin during test, so it will be set as disabled normally.
1418 printPreview.printHeader_.isEnabled = true; 1591 this.printPreview_.printHeader_.isEnabled = true;
1419 1592
1420 // There will be an error message in the preview area since the plugin is 1593 // There will be an error message in the preview area since the plugin
1421 // not running. However, it should not be the invalid settings error. 1594 // is not running. However, it should not be the invalid settings error.
1422 var previewAreaEl = $('preview-area'); 1595 var previewAreaEl = $('preview-area');
1423 var customMessageEl = 1596 var customMessageEl =
1424 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; 1597 previewAreaEl.
1425 expectFalse(customMessageEl.hidden); 1598 getElementsByClassName('preview-area-custom-message')[0];
1426 var expectedMessageStart = 'The selected printer is not available or not ' + 1599 expectFalse(customMessageEl.hidden);
1427 'installed correctly.' 1600 var expectedMessageStart = 'The selected printer is not available or '
1428 expectFalse(customMessageEl.textContent.includes(expectedMessageStart)); 1601 + 'not installed correctly.'
1602 expectFalse(customMessageEl.textContent.includes(expectedMessageStart));
1429 1603
1430 // Verify that the print button is enabled. 1604 // Verify that the print button is enabled.
1431 var printHeader = $('print-header'); 1605 var printHeader = $('print-header');
1432 var printButton = printHeader.querySelector('button.print'); 1606 var printButton = printHeader.querySelector('button.print');
1433 checkElementDisplayed(printButton, true); 1607 checkElementDisplayed(printButton, true);
1434 expectFalse(printButton.disabled); 1608 expectFalse(printButton.disabled);
1435 1609
1436 // Report invalid settings error. 1610 // Report invalid settings error.
1437 this.dispatchInvalidSettings(); 1611 this.dispatchInvalidSettings();
1438 1612
1439 // Should be in an error state, print button disabled, invalid custom error 1613 // Should be in an error state, print button disabled, invalid custom
1440 // message shown. 1614 // error message shown.
1441 expectFalse(customMessageEl.hidden); 1615 expectFalse(customMessageEl.hidden);
1442 expectTrue(customMessageEl.textContent.includes(expectedMessageStart)); 1616 expectTrue(customMessageEl.textContent.includes(expectedMessageStart));
1443 expectTrue(printButton.disabled); 1617 expectTrue(printButton.disabled);
1444 1618
1445 // Select a new destination 1619 // Select a new destination
1446 var barDestination = 1620 var barDestination =
1447 printPreview.destinationStore_.destinations().find(function(d) { 1621 this.printPreview_.destinationStore_.destinations().find(
1448 return d.id == 'BarDevice'; 1622 function(d) {
1449 }); 1623 return d.id == 'BarDevice';
1624 });
1450 1625
1451 printPreview.destinationStore_.selectDestination(barDestination); 1626 this.printPreview_.destinationStore_.selectDestination(barDestination);
1452 1627
1453 // Dispatch events indicating capabilities were fetched and new preview has 1628 // Dispatch events indicating capabilities were fetched and new preview
1454 // loaded. 1629 // has loaded.
1455 this.setCapabilities(getCddTemplate("BarDevice")); 1630 this.setCapabilities(getCddTemplate("BarDevice"));
1456 this.dispatchPreviewDone(); 1631 this.dispatchPreviewDone();
1457 1632
1458 // Has active print button and successfully "prints", indicating recovery 1633 // Has active print button and successfully "prints", indicating
1459 // from error state. 1634 // recovery from error state.
1460 expectFalse(printButton.disabled); 1635 expectFalse(printButton.disabled);
1461 expectFalse(this.hasPrinted()); 1636 expectFalse(this.hasPrinted());
1462 printButton.click(); 1637 printButton.click();
1463 expectTrue(this.hasPrinted()); 1638 expectTrue(this.hasPrinted());
1464 testDone(); 1639 testDone();
1640 }.bind(this));
1465 }); 1641 });
1466 1642
1467 // Test the preview generator to make sure the generate draft parameter is set 1643 // Test the preview generator to make sure the generate draft parameter is set
1468 // correctly. It should be false if the only change is the page range. 1644 // correctly. It should be false if the only change is the page range.
1469 TEST_F('PrintPreviewWebUITest', 'TestGenerateDraft', function() { 1645 TEST_F('PrintPreviewWebUITest', 'TestGenerateDraft', function() {
1646 this.createPrintPreview();
1647
1470 // Use a real preview generator. 1648 // Use a real preview generator.
1471 printPreview.previewArea_.previewGenerator_ = 1649 this.printPreview_.previewArea_.previewGenerator_ =
1472 new print_preview.PreviewGenerator(printPreview.destinationStore_, 1650 new print_preview.PreviewGenerator(this.printPreview_.destinationStore_,
1473 printPreview.printTicketStore_, this.nativeLayer_, 1651 this.printPreview_.printTicketStore_, this.nativeLayer_,
1474 printPreview.documentInfo_); 1652 this.printPreview_.documentInfo_);
1475 1653
1476 this.setInitialSettings(); 1654 this.setInitialSettings();
1477 this.setLocalDestinations(); 1655 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1478 this.setCapabilities(getCddTemplate("FooDevice")); 1656 function() {
1657 this.setLocalDestinations();
1658 this.setCapabilities(getCddTemplate("FooDevice"));
1479 1659
1480 // The first request should generate draft because there was no previous print 1660 // The first request should generate draft because there was no
1481 // preview draft. 1661 // previous print preview draft.
1482 expectTrue(this.generateDraft()); 1662 expectTrue(this.generateDraft());
1483 1663
1484 // Change the page range - no new draft needed. 1664 // Change the page range - no new draft needed.
1485 printPreview.printTicketStore_.pageRange.updateValue("2"); 1665 this.printPreview_.printTicketStore_.pageRange.updateValue("2");
1486 expectFalse(this.generateDraft()); 1666 expectFalse(this.generateDraft());
1487 1667
1488 // Change the margin type - need to regenerate again. 1668 // Change the margin type - need to regenerate again.
1489 printPreview.printTicketStore_.marginsType.updateValue( 1669 this.printPreview_.printTicketStore_.marginsType.updateValue(
1490 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); 1670 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS);
1491 expectTrue(this.generateDraft()); 1671 expectTrue(this.generateDraft());
1492 1672
1493 testDone(); 1673 testDone();
1674 }.bind(this));
1494 }); 1675 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698