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

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

Issue 601083004: Enable a11y audit for chrome://print and fix failing tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Debugging Failures Created 6 years, 2 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 /** 5 /**
6 * Test fixture for print preview WebUI testing. 6 * Test fixture for print preview WebUI testing.
7 * @constructor 7 * @constructor
8 * @extends {testing.Test} 8 * @extends {testing.Test}
9 */ 9 */
10 function PrintPreviewWebUITest() { 10 function PrintPreviewWebUITest() {
(...skipping 17 matching lines...) Expand all
28 */ 28 */
29 PrintPreviewWebUITest.FOO_INDEX = 1; 29 PrintPreviewWebUITest.FOO_INDEX = 1;
30 30
31 /** 31 /**
32 * Index of the Bar printer. 32 * Index of the Bar printer.
33 * @type {number} 33 * @type {number}
34 * @const 34 * @const
35 */ 35 */
36 PrintPreviewWebUITest.BAR_INDEX = 2; 36 PrintPreviewWebUITest.BAR_INDEX = 2;
37 37
38 PrintPreviewWebUITest.TIMEOUT = 500;
39
38 PrintPreviewWebUITest.prototype = { 40 PrintPreviewWebUITest.prototype = {
39 __proto__: testing.Test.prototype, 41 __proto__: testing.Test.prototype,
40 42
41 /** 43 /**
42 * Browse to the sample page, cause print preview & call preLoad(). 44 * Browse to the sample page, cause print preview & call preLoad().
43 * @type {string} 45 * @type {string}
44 * @override 46 * @override
45 */ 47 */
46 browsePrintPreload: 'print_preview_hello_world_test.html', 48 browsePrintPreload: 'print_preview_hello_world_test.html',
47 49
50 /** @override */
51 runAccessibilityChecks: true,
52
53 /** @override */
54 accessibilityIssuesAreErrors: true,
55
56 /** @override */
57 isAsync: true,
58
48 /** 59 /**
49 * Stub out low-level functionality like the NativeLayer and 60 * Stub out low-level functionality like the NativeLayer and
50 * CloudPrintInterface. 61 * CloudPrintInterface.
51 * @this {PrintPreviewWebUITest} 62 * @this {PrintPreviewWebUITest}
52 * @override 63 * @override
53 */ 64 */
54 preLoad: function() { 65 preLoad: function() {
55 window.addEventListener('DOMContentLoaded', function() { 66 window.addEventListener('DOMContentLoaded', function() {
56 function NativeLayerStub() { 67 function NativeLayerStub() {
57 cr.EventTarget.call(this); 68 cr.EventTarget.call(this);
(...skipping 22 matching lines...) Expand all
80 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub; 91 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub;
81 cloudprint.CloudPrintInterface.EventType = oldCpInterfaceEventType; 92 cloudprint.CloudPrintInterface.EventType = oldCpInterfaceEventType;
82 93
83 print_preview.PreviewArea.prototype.getPluginType_ = 94 print_preview.PreviewArea.prototype.getPluginType_ =
84 function() { 95 function() {
85 return print_preview.PreviewArea.PluginType_.NONE; 96 return print_preview.PreviewArea.PluginType_.NONE;
86 }; 97 };
87 }.bind(this)); 98 }.bind(this));
88 }, 99 },
89 100
90 setUpPreview: function() { 101 setUpPreview: function() {
Dan Beam 2014/10/15 21:37:31 rename to setUp, add /** @override */ and remove a
hcarmona 2014/10/17 01:35:53 Can't do this because not all tests need to call s
91 var initialSettingsSetEvent = 102 var initialSettingsSetEvent =
92 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); 103 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
93 initialSettingsSetEvent.initialSettings = this.initialSettings_; 104 initialSettingsSetEvent.initialSettings = this.initialSettings_;
94 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); 105 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
95 106
96 var localDestsSetEvent = 107 var localDestsSetEvent =
97 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); 108 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
98 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; 109 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
99 this.nativeLayer_.dispatchEvent(localDestsSetEvent); 110 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
100 }, 111 },
101 112
113 waitForTransitionEvents: function(expectedTransitions) {
114 // add a listener for the transition end event
115 document.addEventListener('webkitTransitionEnd', function finishTest(e) {
116 if (--expectedTransitions <= 0) {
117 // end the test once all expected transitions are done
Dan Beam 2014/10/15 21:37:31 why not when a specific transition ends, e.g. e
hcarmona 2014/10/17 01:35:53 Done.
118 console.log('transitions done');
119 testDone();
120 }
121 else {
122 // If more transitions are expected, make sure they will happen
123 // because the webkitTransitionEnd event is sometimes flaky.
124 console.log('transitions remain: ' + expectedTransitions);
125 ensureTransitionEndEvent(document, PrintPreviewWebUITest.TIMEOUT);
Dan Beam 2014/10/15 21:39:19 we should not have to do this
hcarmona 2014/10/17 01:35:53 Acknowledged.
126 }
127 });
128
129 // Event is not thrown if there is no draw event. This will ensure that
130 // the event is thrown to keep test from waiting forever.
131 ensureTransitionEndEvent(document, PrintPreviewWebUITest.TIMEOUT);
132 },
133
102 /** 134 /**
103 * Generate a real C++ class; don't typedef. 135 * Generate a real C++ class; don't typedef.
104 * @type {?string} 136 * @type {?string}
105 * @override 137 * @override
106 */ 138 */
107 typedefCppFixture: null, 139 typedefCppFixture: null,
108 140
109 /** 141 /**
110 * @this {PrintPreviewWebUITest} 142 * @this {PrintPreviewWebUITest}
111 * @override 143 * @override
(...skipping 20 matching lines...) Expand all
132 { printerName: 'BarName', deviceName: 'BarDevice' } 164 { printerName: 'BarName', deviceName: 'BarDevice' }
133 ]; 165 ];
134 this.nativeLayer_ = printPreview.nativeLayer_; 166 this.nativeLayer_ = printPreview.nativeLayer_;
135 } 167 }
136 }; 168 };
137 169
138 GEN('#include "chrome/test/data/webui/print_preview.h"'); 170 GEN('#include "chrome/test/data/webui/print_preview.h"');
139 171
140 // Test some basic assumptions about the print preview WebUI. 172 // Test some basic assumptions about the print preview WebUI.
141 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { 173 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
142 var initialSettingsSetEvent = 174 this.setUpPreview();
143 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
144 initialSettingsSetEvent.initialSettings = this.initialSettings_;
145 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
146
147 var localDestsSetEvent =
148 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
149 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
150 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
151 175
152 var recentList = $('destination-search').querySelector('.recent-list ul'); 176 var recentList = $('destination-search').querySelector('.recent-list ul');
153 var localList = $('destination-search').querySelector('.local-list ul'); 177 var localList = $('destination-search').querySelector('.local-list ul');
154 assertNotEquals(null, recentList); 178 assertNotEquals(null, recentList);
155 assertEquals(1, recentList.childNodes.length); 179 assertEquals(1, recentList.childNodes.length);
156 assertEquals('FooName', 180 assertEquals('FooName',
157 recentList.childNodes.item(0).querySelector( 181 recentList.childNodes.item(0).querySelector(
158 '.destination-list-item-name').textContent); 182 '.destination-list-item-name').textContent);
159 183
160 assertNotEquals(null, localList); 184 assertNotEquals(null, localList);
161 assertEquals(3, localList.childNodes.length); 185 assertEquals(3, localList.childNodes.length);
162 assertEquals('Save as PDF', 186 assertEquals('Save as PDF',
163 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). 187 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX).
164 querySelector('.destination-list-item-name').textContent); 188 querySelector('.destination-list-item-name').textContent);
165 assertEquals('FooName', 189 assertEquals('FooName',
166 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). 190 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
167 querySelector('.destination-list-item-name').textContent); 191 querySelector('.destination-list-item-name').textContent);
168 assertEquals('BarName', 192 assertEquals('BarName',
169 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). 193 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
170 querySelector('.destination-list-item-name').textContent); 194 querySelector('.destination-list-item-name').textContent);
195 testDone();
171 }); 196 });
172 197
173 // Test that the printer list is structured correctly after calling 198 // Test that the printer list is structured correctly after calling
174 // addCloudPrinters with an empty list. 199 // addCloudPrinters with an empty list.
175 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { 200 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
176 var initialSettingsSetEvent = 201 this.setUpPreview();
177 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
178 initialSettingsSetEvent.initialSettings = this.initialSettings_;
179 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
180
181 var localDestsSetEvent =
182 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
183 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
184 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
185 202
186 var cloudPrintEnableEvent = 203 var cloudPrintEnableEvent =
187 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); 204 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE);
188 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; 205 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url';
189 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent); 206 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent);
190 207
191 var searchDoneEvent = 208 var searchDoneEvent =
192 new Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE); 209 new Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE);
193 searchDoneEvent.printers = []; 210 searchDoneEvent.printers = [];
194 searchDoneEvent.isRecent = true; 211 searchDoneEvent.isRecent = true;
(...skipping 17 matching lines...) Expand all
212 querySelector('.destination-list-item-name').textContent); 229 querySelector('.destination-list-item-name').textContent);
213 assertEquals('FooName', 230 assertEquals('FooName',
214 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). 231 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
215 querySelector('.destination-list-item-name').textContent); 232 querySelector('.destination-list-item-name').textContent);
216 assertEquals('BarName', 233 assertEquals('BarName',
217 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). 234 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
218 querySelector('.destination-list-item-name').textContent); 235 querySelector('.destination-list-item-name').textContent);
219 236
220 assertNotEquals(null, cloudList); 237 assertNotEquals(null, cloudList);
221 assertEquals(0, cloudList.childNodes.length); 238 assertEquals(0, cloudList.childNodes.length);
239 testDone();
222 }); 240 });
223 241
224 /** 242 /**
225 * Verify that |section| visibility matches |visible|. 243 * Verify that |section| visibility matches |visible|.
226 * @param {HTMLDivElement} section The section to check. 244 * @param {HTMLDivElement} section The section to check.
227 * @param {boolean} visible The expected state of visibility. 245 * @param {boolean} visible The expected state of visibility.
228 */ 246 */
229 function checkSectionVisible(section, visible) { 247 function checkSectionVisible(section, visible) {
230 assertNotEquals(null, section); 248 assertNotEquals(null, section);
231 expectEquals( 249 expectEquals(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // Test that disabled settings hide the disabled sections. 303 // Test that disabled settings hide the disabled sections.
286 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKiosMode', 304 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKiosMode',
287 function() { 305 function() {
288 var initialSettingsSetEvent = 306 var initialSettingsSetEvent =
289 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); 307 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
290 initialSettingsSetEvent.initialSettings = this.initialSettings_; 308 initialSettingsSetEvent.initialSettings = this.initialSettings_;
291 initialSettingsSetEvent.initialSettings.isInAppKioskMode_ = true; 309 initialSettingsSetEvent.initialSettings.isInAppKioskMode_ = true;
292 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); 310 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
293 311
294 checkElementDisplayed($('system-dialog-link'), false); 312 checkElementDisplayed($('system-dialog-link'), false);
313 testDone();
295 }); 314 });
296 315
297 // Test that disabled settings hide the disabled sections. 316 // Test that disabled settings hide the disabled sections.
298 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { 317 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
299 checkSectionVisible($('layout-settings'), false); 318 checkSectionVisible($('layout-settings'), false);
300 checkSectionVisible($('color-settings'), false); 319 checkSectionVisible($('color-settings'), false);
301 checkSectionVisible($('copies-settings'), false); 320 checkSectionVisible($('copies-settings'), false);
302 321 this.setUpPreview();
303 var initialSettingsSetEvent =
304 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
305 initialSettingsSetEvent.initialSettings = this.initialSettings_;
306 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
307
308 var localDestsSetEvent =
309 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
310 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
311 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
312 322
313 var capsSetEvent = 323 var capsSetEvent =
314 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 324 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
315 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 325 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
316 capsSetEvent.settingsInfo.capabilities.printer.color = { 326 capsSetEvent.settingsInfo.capabilities.printer.color = {
317 "option": [ 327 "option": [
318 {"is_default": true, "type": "STANDARD_COLOR"} 328 {"is_default": true, "type": "STANDARD_COLOR"}
319 ] 329 ]
320 }; 330 };
321 delete capsSetEvent.settingsInfo.capabilities.printer.copies; 331 delete capsSetEvent.settingsInfo.capabilities.printer.copies;
322 this.nativeLayer_.dispatchEvent(capsSetEvent); 332 this.nativeLayer_.dispatchEvent(capsSetEvent);
323 333
324 checkSectionVisible($('layout-settings'), true); 334 checkSectionVisible($('layout-settings'), true);
325 checkSectionVisible($('color-settings'), false); 335 checkSectionVisible($('color-settings'), false);
326 checkSectionVisible($('copies-settings'), false); 336 checkSectionVisible($('copies-settings'), false);
337 testDone();
327 }); 338 });
328 339
329 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the 340 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the
330 // fit to page option. 341 // fit to page option.
331 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() { 342 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() {
332 // Add PDF printer. 343 // Add PDF printer.
333 this.initialSettings_.isDocumentModifiable_ = false; 344 this.initialSettings_.isDocumentModifiable_ = false;
334 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF'; 345 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF';
335 346
336 var initialSettingsSetEvent = 347 var initialSettingsSetEvent =
(...skipping 29 matching lines...) Expand all
366 } 377 }
367 ] 378 ]
368 } 379 }
369 } 380 }
370 } 381 }
371 }; 382 };
372 this.nativeLayer_.dispatchEvent(capsSetEvent); 383 this.nativeLayer_.dispatchEvent(capsSetEvent);
373 384
374 checkSectionVisible($('other-options-settings'), false); 385 checkSectionVisible($('other-options-settings'), false);
375 checkSectionVisible($('media-size-settings'), false); 386 checkSectionVisible($('media-size-settings'), false);
387 testDone();
376 }); 388 });
377 389
378 // When the source is 'HTML', we always hide the fit to page option and show 390 // When the source is 'HTML', we always hide the fit to page option and show
379 // media size option. 391 // media size option.
380 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() { 392 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() {
381 var initialSettingsSetEvent = 393 this.setUpPreview();
382 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
383 initialSettingsSetEvent.initialSettings = this.initialSettings_;
384 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
385
386 var localDestsSetEvent =
387 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
388 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
389 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
390 394
391 var capsSetEvent = 395 var capsSetEvent =
392 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 396 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
393 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 397 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
394 this.nativeLayer_.dispatchEvent(capsSetEvent); 398 this.nativeLayer_.dispatchEvent(capsSetEvent);
395 399
396 var moreSettingsDiv = $('more-settings'); 400 var moreSettingsDiv = $('more-settings');
397 var mediaSizeDiv = $('media-size-settings'); 401 var mediaSizeDiv = $('media-size-settings');
398 var otherOptionsDiv = $('other-options-settings'); 402 var otherOptionsDiv = $('other-options-settings');
399 var fitToPageEl = otherOptionsDiv.querySelector('.fit-to-page-container'); 403 var fitToPageEl = otherOptionsDiv.querySelector('.fit-to-page-container');
400 404
401 // Check that options are collapsed (section is visible, because duplex is 405 // Check that options are collapsed (section is visible, because duplex is
402 // available). 406 // available).
403 checkSectionVisible(otherOptionsDiv, true); 407 checkSectionVisible(otherOptionsDiv, true);
404 checkElementDisplayed(fitToPageEl, false); 408 checkElementDisplayed(fitToPageEl, false);
405 checkSectionVisible(mediaSizeDiv, false); 409 checkSectionVisible(mediaSizeDiv, false);
406 // Expand it. 410 // Expand it.
407 checkSectionVisible(moreSettingsDiv, true); 411 checkSectionVisible(moreSettingsDiv, true);
408 moreSettingsDiv.click(); 412 moreSettingsDiv.click();
409 413
410 checkElementDisplayed(fitToPageEl, false); 414 checkElementDisplayed(fitToPageEl, false);
411 checkSectionVisible(mediaSizeDiv, true); 415 checkSectionVisible(mediaSizeDiv, true);
416
417 this.waitForTransitionEvents(1);
412 }); 418 });
413 419
414 // When the source is "PDF", depending on the selected destination printer, we 420 // When the source is "PDF", depending on the selected destination printer, we
415 // show/hide the fit to page option and hide media size selection. 421 // show/hide the fit to page option and hide media size selection.
416 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() { 422 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() {
417 this.initialSettings_.isDocumentModifiable_ = false; 423 this.initialSettings_.isDocumentModifiable_ = false;
418 424 this.setUpPreview();
419 var initialSettingsSetEvent =
420 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
421 initialSettingsSetEvent.initialSettings = this.initialSettings_;
422 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
423
424 var localDestsSetEvent =
425 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
426 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
427 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
428 425
429 var capsSetEvent = 426 var capsSetEvent =
430 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 427 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
431 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 428 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
432 this.nativeLayer_.dispatchEvent(capsSetEvent); 429 this.nativeLayer_.dispatchEvent(capsSetEvent);
433 430
434 var otherOptionsDiv = $('other-options-settings'); 431 var otherOptionsDiv = $('other-options-settings');
435 432
436 checkSectionVisible(otherOptionsDiv, true); 433 checkSectionVisible(otherOptionsDiv, true);
437 checkElementDisplayed( 434 checkElementDisplayed(
438 otherOptionsDiv.querySelector('.fit-to-page-container'), true); 435 otherOptionsDiv.querySelector('.fit-to-page-container'), true);
439 expectTrue( 436 expectTrue(
440 otherOptionsDiv.querySelector('.fit-to-page-checkbox').checked); 437 otherOptionsDiv.querySelector('.fit-to-page-checkbox').checked);
441 checkSectionVisible($('media-size-settings'), true); 438 checkSectionVisible($('media-size-settings'), true);
439 testDone();
Dan Beam 2014/10/15 21:37:31 function PrintPreviewWebUIAsyncTest() {} PrintPre
Dan Beam 2014/10/15 21:39:18 (so you don't have to put all these useless testDo
hcarmona 2014/10/17 01:35:53 Acknowledged.
hcarmona 2014/10/17 01:35:53 Done.
442 }); 440 });
443 441
444 // When the print scaling is disabled for the source "PDF", we show the fit 442 // When the print scaling is disabled for the source "PDF", we show the fit
445 // to page option but the state is unchecked by default. 443 // to page option but the state is unchecked by default.
446 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() { 444 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() {
447 this.initialSettings_.isDocumentModifiable_ = false; 445 this.initialSettings_.isDocumentModifiable_ = false;
448 446 this.setUpPreview();
449 var initialSettingsSetEvent =
450 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
451 initialSettingsSetEvent.initialSettings = this.initialSettings_;
452 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
453
454 var localDestsSetEvent =
455 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
456 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
457 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
458 447
459 var capsSetEvent = 448 var capsSetEvent =
460 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 449 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
461 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 450 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
462 this.nativeLayer_.dispatchEvent(capsSetEvent); 451 this.nativeLayer_.dispatchEvent(capsSetEvent);
463 452
464 // Indicate that the PDF does not support scaling by default. 453 // Indicate that the PDF does not support scaling by default.
465 cr.dispatchSimpleEvent( 454 cr.dispatchSimpleEvent(
466 this.nativeLayer_, print_preview.NativeLayer.EventType.DISABLE_SCALING); 455 this.nativeLayer_, print_preview.NativeLayer.EventType.DISABLE_SCALING);
467 456
468 var otherOptionsDiv = $('other-options-settings'); 457 var otherOptionsDiv = $('other-options-settings');
469 458
470 checkSectionVisible(otherOptionsDiv, true); 459 checkSectionVisible(otherOptionsDiv, true);
471 460
472 checkElementDisplayed( 461 checkElementDisplayed(
473 otherOptionsDiv.querySelector('.fit-to-page-container'), true); 462 otherOptionsDiv.querySelector('.fit-to-page-container'), true);
474 expectFalse( 463 expectFalse(
475 otherOptionsDiv.querySelector('.fit-to-page-checkbox').checked); 464 otherOptionsDiv.querySelector('.fit-to-page-checkbox').checked);
465 testDone();
476 }); 466 });
477 467
478 // Make sure that custom margins controls are properly set up. 468 // Make sure that custom margins controls are properly set up.
479 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() { 469 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() {
480 var initialSettingsSetEvent = 470 this.setUpPreview();
481 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
482 initialSettingsSetEvent.initialSettings = this.initialSettings_;
483 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
484
485 var localDestsSetEvent =
486 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
487 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
488 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
489 471
490 var capsSetEvent = 472 var capsSetEvent =
491 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 473 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
492 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 474 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
493 this.nativeLayer_.dispatchEvent(capsSetEvent); 475 this.nativeLayer_.dispatchEvent(capsSetEvent);
494 476
495 printPreview.printTicketStore_.marginsType.updateValue( 477 printPreview.printTicketStore_.marginsType.updateValue(
496 print_preview.ticket_items.MarginsType.Value.CUSTOM); 478 print_preview.ticket_items.MarginsType.Value.CUSTOM);
497 479
498 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { 480 ['left', 'top', 'right', 'bottom'].forEach(function(margin) {
499 var control = $('preview-area').querySelector('.margin-control-' + margin); 481 var control = $('preview-area').querySelector('.margin-control-' + margin);
500 assertNotEquals(null, control); 482 assertNotEquals(null, control);
501 var input = control.querySelector('.margin-control-textbox'); 483 var input = control.querySelector('.margin-control-textbox');
502 assertTrue(input.hasAttribute('aria-label')); 484 assertTrue(input.hasAttribute('aria-label'));
503 assertNotEquals('undefined', input.getAttribute('aria-label')); 485 assertNotEquals('undefined', input.getAttribute('aria-label'));
504 }); 486 });
487 testDone();
505 }); 488 });
506 489
507 // Page layout has zero margins. Hide header and footer option. 490 // Page layout has zero margins. Hide header and footer option.
508 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter', 491 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
509 function() { 492 function() {
510 var initialSettingsSetEvent = 493 this.setUpPreview();
511 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
512 initialSettingsSetEvent.initialSettings = this.initialSettings_;
513 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
514
515 var localDestsSetEvent =
516 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
517 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
518 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
519 494
520 var capsSetEvent = 495 var capsSetEvent =
521 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 496 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
522 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 497 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
523 this.nativeLayer_.dispatchEvent(capsSetEvent); 498 this.nativeLayer_.dispatchEvent(capsSetEvent);
524 499
525 var moreSettingsDiv = $('more-settings'); 500 var moreSettingsDiv = $('more-settings');
526 var otherOptionsDiv = $('other-options-settings'); 501 var otherOptionsDiv = $('other-options-settings');
527 var headerFooterEl = 502 var headerFooterEl =
528 otherOptionsDiv.querySelector('.header-footer-container'); 503 otherOptionsDiv.querySelector('.header-footer-container');
529 504
530 // Check that options are collapsed (section is visible, because duplex is 505 // Check that options are collapsed (section is visible, because duplex is
531 // available). 506 // available).
532 checkSectionVisible(otherOptionsDiv, true); 507 checkSectionVisible(otherOptionsDiv, true);
533 checkElementDisplayed(headerFooterEl, false); 508 checkElementDisplayed(headerFooterEl, false);
534 // Expand it. 509 // Expand it.
535 checkSectionVisible(moreSettingsDiv, true); 510 checkSectionVisible(moreSettingsDiv, true);
536 moreSettingsDiv.click(); 511 moreSettingsDiv.click();
537 512
538 checkElementDisplayed(headerFooterEl, true); 513 checkElementDisplayed(headerFooterEl, true);
539 514
540 printPreview.printTicketStore_.marginsType.updateValue( 515 printPreview.printTicketStore_.marginsType.updateValue(
541 print_preview.ticket_items.MarginsType.Value.CUSTOM); 516 print_preview.ticket_items.MarginsType.Value.CUSTOM);
542 printPreview.printTicketStore_.customMargins.updateValue( 517 printPreview.printTicketStore_.customMargins.updateValue(
543 new print_preview.Margins(0, 0, 0, 0)); 518 new print_preview.Margins(0, 0, 0, 0));
544 519
545 checkElementDisplayed(headerFooterEl, false); 520 checkElementDisplayed(headerFooterEl, false);
521
522 this.waitForTransitionEvents(4);
546 }); 523 });
547 524
548 // Page layout has half-inch margins. Show header and footer option. 525 // Page layout has half-inch margins. Show header and footer option.
549 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter', 526 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter',
550 function() { 527 function() {
551 var initialSettingsSetEvent = 528 this.setUpPreview();
552 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
553 initialSettingsSetEvent.initialSettings = this.initialSettings_;
554 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
555
556 var localDestsSetEvent =
557 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
558 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
559 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
560
561 var capsSetEvent = 529 var capsSetEvent =
562 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 530 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
563 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 531 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
564 this.nativeLayer_.dispatchEvent(capsSetEvent); 532 this.nativeLayer_.dispatchEvent(capsSetEvent);
565 533
566 var moreSettingsDiv = $('more-settings'); 534 var moreSettingsDiv = $('more-settings');
567 var otherOptionsDiv = $('other-options-settings'); 535 var otherOptionsDiv = $('other-options-settings');
568 var headerFooterEl = 536 var headerFooterEl =
569 otherOptionsDiv.querySelector('.header-footer-container'); 537 otherOptionsDiv.querySelector('.header-footer-container');
570 538
571 // Check that options are collapsed (section is visible, because duplex is 539 // Check that options are collapsed (section is visible, because duplex is
572 // available). 540 // available).
573 checkSectionVisible(otherOptionsDiv, true); 541 checkSectionVisible(otherOptionsDiv, true);
574 checkElementDisplayed(headerFooterEl, false); 542 checkElementDisplayed(headerFooterEl, false);
575 // Expand it. 543 // Expand it.
576 checkSectionVisible(moreSettingsDiv, true); 544 checkSectionVisible(moreSettingsDiv, true);
577 moreSettingsDiv.click(); 545 moreSettingsDiv.click();
578 546
579 checkElementDisplayed(headerFooterEl, true); 547 checkElementDisplayed(headerFooterEl, true);
580 548
581 printPreview.printTicketStore_.marginsType.updateValue( 549 printPreview.printTicketStore_.marginsType.updateValue(
582 print_preview.ticket_items.MarginsType.Value.CUSTOM); 550 print_preview.ticket_items.MarginsType.Value.CUSTOM);
583 printPreview.printTicketStore_.customMargins.updateValue( 551 printPreview.printTicketStore_.customMargins.updateValue(
584 new print_preview.Margins(36, 36, 36, 36)); 552 new print_preview.Margins(36, 36, 36, 36));
585 553
586 checkElementDisplayed(headerFooterEl, true); 554 checkElementDisplayed(headerFooterEl, true);
555
556 this.waitForTransitionEvents(4);
587 }); 557 });
588 558
589 // Page layout has zero top and bottom margins. Hide header and footer option. 559 // Page layout has zero top and bottom margins. Hide header and footer option.
590 TEST_F('PrintPreviewWebUITest', 560 TEST_F('PrintPreviewWebUITest',
591 'ZeroTopAndBottomMarginsHideHeaderFooter', 561 'ZeroTopAndBottomMarginsHideHeaderFooter',
592 function() { 562 function() {
593 var initialSettingsSetEvent = 563 this.setUpPreview();
594 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
595 initialSettingsSetEvent.initialSettings = this.initialSettings_;
596 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
597
598 var localDestsSetEvent =
599 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
600 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
601 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
602 564
603 var capsSetEvent = 565 var capsSetEvent =
604 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 566 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
605 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 567 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
606 this.nativeLayer_.dispatchEvent(capsSetEvent); 568 this.nativeLayer_.dispatchEvent(capsSetEvent);
607 569
608 var moreSettingsDiv = $('more-settings'); 570 var moreSettingsDiv = $('more-settings');
609 var otherOptionsDiv = $('other-options-settings'); 571 var otherOptionsDiv = $('other-options-settings');
610 var headerFooterEl = 572 var headerFooterEl =
611 otherOptionsDiv.querySelector('.header-footer-container'); 573 otherOptionsDiv.querySelector('.header-footer-container');
612 574
613 // Check that options are collapsed (section is visible, because duplex is 575 // Check that options are collapsed (section is visible, because duplex is
614 // available). 576 // available).
615 checkSectionVisible(otherOptionsDiv, true); 577 checkSectionVisible(otherOptionsDiv, true);
616 checkElementDisplayed(headerFooterEl, false); 578 checkElementDisplayed(headerFooterEl, false);
617 // Expand it. 579 // Expand it.
618 checkSectionVisible(moreSettingsDiv, true); 580 checkSectionVisible(moreSettingsDiv, true);
619 moreSettingsDiv.click(); 581 moreSettingsDiv.click();
620 582
621 checkElementDisplayed(headerFooterEl, true); 583 checkElementDisplayed(headerFooterEl, true);
622 584
623 printPreview.printTicketStore_.marginsType.updateValue( 585 printPreview.printTicketStore_.marginsType.updateValue(
624 print_preview.ticket_items.MarginsType.Value.CUSTOM); 586 print_preview.ticket_items.MarginsType.Value.CUSTOM);
625 printPreview.printTicketStore_.customMargins.updateValue( 587 printPreview.printTicketStore_.customMargins.updateValue(
626 new print_preview.Margins(0, 36, 0, 36)); 588 new print_preview.Margins(0, 36, 0, 36));
627 589
628 checkElementDisplayed(headerFooterEl, false); 590 checkElementDisplayed(headerFooterEl, false);
591
592 this.waitForTransitionEvents(4);
629 }); 593 });
630 594
631 // Page layout has zero top and half-inch bottom margin. Show header and footer 595 // Page layout has zero top and half-inch bottom margin. Show header and footer
632 // option. 596 // option.
633 TEST_F('PrintPreviewWebUITest', 597 TEST_F('PrintPreviewWebUITest',
634 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter', 598 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
635 function() { 599 function() {
636 var initialSettingsSetEvent = 600 this.setUpPreview();
637 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
638 initialSettingsSetEvent.initialSettings = this.initialSettings_;
639 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
640
641 var localDestsSetEvent =
642 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
643 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
644 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
645 601
646 var capsSetEvent = 602 var capsSetEvent =
647 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 603 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
648 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 604 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
649 this.nativeLayer_.dispatchEvent(capsSetEvent); 605 this.nativeLayer_.dispatchEvent(capsSetEvent);
650 606
651 var moreSettingsDiv = $('more-settings'); 607 var moreSettingsDiv = $('more-settings');
652 var otherOptionsDiv = $('other-options-settings'); 608 var otherOptionsDiv = $('other-options-settings');
653 var headerFooterEl = 609 var headerFooterEl =
654 otherOptionsDiv.querySelector('.header-footer-container'); 610 otherOptionsDiv.querySelector('.header-footer-container');
655 611
656 // Check that options are collapsed (section is visible, because duplex is 612 // Check that options are collapsed (section is visible, because duplex is
657 // available). 613 // available).
658 checkSectionVisible(otherOptionsDiv, true); 614 checkSectionVisible(otherOptionsDiv, true);
659 checkElementDisplayed(headerFooterEl, false); 615 checkElementDisplayed(headerFooterEl, false);
660 // Expand it. 616 // Expand it.
661 checkSectionVisible(moreSettingsDiv, true); 617 checkSectionVisible(moreSettingsDiv, true);
662 moreSettingsDiv.click(); 618 moreSettingsDiv.click();
663 619
664 checkElementDisplayed(headerFooterEl, true); 620 checkElementDisplayed(headerFooterEl, true);
665 621
666 printPreview.printTicketStore_.marginsType.updateValue( 622 printPreview.printTicketStore_.marginsType.updateValue(
667 print_preview.ticket_items.MarginsType.Value.CUSTOM); 623 print_preview.ticket_items.MarginsType.Value.CUSTOM);
668 printPreview.printTicketStore_.customMargins.updateValue( 624 printPreview.printTicketStore_.customMargins.updateValue(
669 new print_preview.Margins(0, 36, 36, 36)); 625 new print_preview.Margins(0, 36, 36, 36));
670 626
671 checkElementDisplayed(headerFooterEl, true); 627 checkElementDisplayed(headerFooterEl, true);
628 this.waitForTransitionEvents(4);
672 }); 629 });
673 630
674 // Test that the color settings, one option, standard monochrome. 631 // Test that the color settings, one option, standard monochrome.
675 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() { 632 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() {
676 this.setUpPreview(); 633 this.setUpPreview();
677 634
678 // Only one option, standard monochrome. 635 // Only one option, standard monochrome.
679 var capsSetEvent = 636 var capsSetEvent =
680 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 637 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
681 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 638 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
682 capsSetEvent.settingsInfo.capabilities.printer.color = { 639 capsSetEvent.settingsInfo.capabilities.printer.color = {
683 "option": [ 640 "option": [
684 {"is_default": true, "type": "STANDARD_MONOCHROME"} 641 {"is_default": true, "type": "STANDARD_MONOCHROME"}
685 ] 642 ]
686 }; 643 };
687 this.nativeLayer_.dispatchEvent(capsSetEvent); 644 this.nativeLayer_.dispatchEvent(capsSetEvent);
688 645
689 checkSectionVisible($('color-settings'), false); 646 checkSectionVisible($('color-settings'), false);
647 testDone();
690 }); 648 });
691 649
692 // Test that the color settings, one option, custom monochrome. 650 // Test that the color settings, one option, custom monochrome.
693 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome', 651 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome',
694 function() { 652 function() {
695 this.setUpPreview(); 653 this.setUpPreview();
696 654
697 // Only one option, standard monochrome. 655 // Only one option, standard monochrome.
698 var capsSetEvent = 656 var capsSetEvent =
699 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 657 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
700 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 658 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
701 capsSetEvent.settingsInfo.capabilities.printer.color = { 659 capsSetEvent.settingsInfo.capabilities.printer.color = {
702 "option": [ 660 "option": [
703 {"is_default": true, "type": "CUSTOM_MONOCHROME", "vendor_id": "42"} 661 {"is_default": true, "type": "CUSTOM_MONOCHROME", "vendor_id": "42"}
704 ] 662 ]
705 }; 663 };
706 this.nativeLayer_.dispatchEvent(capsSetEvent); 664 this.nativeLayer_.dispatchEvent(capsSetEvent);
707 665
708 checkSectionVisible($('color-settings'), false); 666 checkSectionVisible($('color-settings'), false);
667 testDone();
709 }); 668 });
710 669
711 // Test that the color settings, one option, standard color. 670 // Test that the color settings, one option, standard color.
712 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() { 671 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() {
713 this.setUpPreview(); 672 this.setUpPreview();
714 673
715 var capsSetEvent = 674 var capsSetEvent =
716 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 675 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
717 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 676 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
718 capsSetEvent.settingsInfo.capabilities.printer.color = { 677 capsSetEvent.settingsInfo.capabilities.printer.color = {
719 "option": [ 678 "option": [
720 {"is_default": true, "type": "STANDARD_COLOR"} 679 {"is_default": true, "type": "STANDARD_COLOR"}
721 ] 680 ]
722 }; 681 };
723 this.nativeLayer_.dispatchEvent(capsSetEvent); 682 this.nativeLayer_.dispatchEvent(capsSetEvent);
724 683
725 checkSectionVisible($('color-settings'), false); 684 checkSectionVisible($('color-settings'), false);
685 testDone();
726 }); 686 });
727 687
728 // Test that the color settings, one option, custom color. 688 // Test that the color settings, one option, custom color.
729 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() { 689 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() {
730 this.setUpPreview(); 690 this.setUpPreview();
731 691
732 var capsSetEvent = 692 var capsSetEvent =
733 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 693 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
734 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 694 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
735 capsSetEvent.settingsInfo.capabilities.printer.color = { 695 capsSetEvent.settingsInfo.capabilities.printer.color = {
736 "option": [ 696 "option": [
737 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"} 697 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"}
738 ] 698 ]
739 }; 699 };
740 this.nativeLayer_.dispatchEvent(capsSetEvent); 700 this.nativeLayer_.dispatchEvent(capsSetEvent);
741 701
742 checkSectionVisible($('color-settings'), false); 702 checkSectionVisible($('color-settings'), false);
703 testDone();
743 }); 704 });
744 705
745 // Test that the color settings, two options, both standard, defaults to color. 706 // Test that the color settings, two options, both standard, defaults to color.
746 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor', 707 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor',
747 function() { 708 function() {
748 this.setUpPreview(); 709 this.setUpPreview();
749 710
750 var capsSetEvent = 711 var capsSetEvent =
751 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 712 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
752 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 713 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
753 capsSetEvent.settingsInfo.capabilities.printer.color = { 714 capsSetEvent.settingsInfo.capabilities.printer.color = {
754 "option": [ 715 "option": [
755 {"type": "STANDARD_MONOCHROME"}, 716 {"type": "STANDARD_MONOCHROME"},
756 {"is_default": true, "type": "STANDARD_COLOR"} 717 {"is_default": true, "type": "STANDARD_COLOR"}
757 ] 718 ]
758 }; 719 };
759 this.nativeLayer_.dispatchEvent(capsSetEvent); 720 this.nativeLayer_.dispatchEvent(capsSetEvent);
760 721
761 checkSectionVisible($('color-settings'), true); 722 checkSectionVisible($('color-settings'), true);
762 expectEquals( 723 expectEquals(
763 'color', 724 'color',
764 $('color-settings').querySelector('.color-settings-select').value); 725 $('color-settings').querySelector('.color-settings-select').value);
726 testDone();
765 }); 727 });
766 728
767 // Test that the color settings, two options, both standard, defaults to 729 // Test that the color settings, two options, both standard, defaults to
768 // monochrome. 730 // monochrome.
769 TEST_F('PrintPreviewWebUITest', 731 TEST_F('PrintPreviewWebUITest',
770 'TestColorSettingsBothStandardDefaultMonochrome', function() { 732 'TestColorSettingsBothStandardDefaultMonochrome', function() {
771 this.setUpPreview(); 733 this.setUpPreview();
772 734
773 var capsSetEvent = 735 var capsSetEvent =
774 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 736 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
775 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 737 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
776 capsSetEvent.settingsInfo.capabilities.printer.color = { 738 capsSetEvent.settingsInfo.capabilities.printer.color = {
777 "option": [ 739 "option": [
778 {"is_default": true, "type": "STANDARD_MONOCHROME"}, 740 {"is_default": true, "type": "STANDARD_MONOCHROME"},
779 {"type": "STANDARD_COLOR"} 741 {"type": "STANDARD_COLOR"}
780 ] 742 ]
781 }; 743 };
782 this.nativeLayer_.dispatchEvent(capsSetEvent); 744 this.nativeLayer_.dispatchEvent(capsSetEvent);
783 745
784 checkSectionVisible($('color-settings'), true); 746 checkSectionVisible($('color-settings'), true);
785 expectEquals( 747 expectEquals(
786 'bw', $('color-settings').querySelector('.color-settings-select').value); 748 'bw', $('color-settings').querySelector('.color-settings-select').value);
749 testDone();
787 }); 750 });
788 751
789 // Test that the color settings, two options, both custom, defaults to color. 752 // Test that the color settings, two options, both custom, defaults to color.
790 TEST_F('PrintPreviewWebUITest', 753 TEST_F('PrintPreviewWebUITest',
791 'TestColorSettingsBothCustomDefaultColor', function() { 754 'TestColorSettingsBothCustomDefaultColor', function() {
792 this.setUpPreview(); 755 this.setUpPreview();
793 756
794 var capsSetEvent = 757 var capsSetEvent =
795 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 758 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
796 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 759 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
797 capsSetEvent.settingsInfo.capabilities.printer.color = { 760 capsSetEvent.settingsInfo.capabilities.printer.color = {
798 "option": [ 761 "option": [
799 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"}, 762 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"},
800 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"} 763 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"}
801 ] 764 ]
802 }; 765 };
803 this.nativeLayer_.dispatchEvent(capsSetEvent); 766 this.nativeLayer_.dispatchEvent(capsSetEvent);
804 767
805 checkSectionVisible($('color-settings'), true); 768 checkSectionVisible($('color-settings'), true);
806 expectEquals( 769 expectEquals(
807 'color', 770 'color',
808 $('color-settings').querySelector('.color-settings-select').value); 771 $('color-settings').querySelector('.color-settings-select').value);
772 testDone();
809 }); 773 });
810 774
811 // Test to verify that duplex settings are set according to the printer 775 // Test to verify that duplex settings are set according to the printer
812 // capabilities. 776 // capabilities.
813 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() { 777 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
814 var initialSettingsSetEvent = 778 this.setUpPreview();
815 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
816 initialSettingsSetEvent.initialSettings = this.initialSettings_;
817 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
818
819 var localDestsSetEvent =
820 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
821 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
822 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
823 779
824 var otherOptionsDiv = $('other-options-settings'); 780 var otherOptionsDiv = $('other-options-settings');
825 var duplexDiv = otherOptionsDiv.querySelector('.duplex-container'); 781 var duplexDiv = otherOptionsDiv.querySelector('.duplex-container');
826 var duplexCheckbox = otherOptionsDiv.querySelector('.duplex-checkbox'); 782 var duplexCheckbox = otherOptionsDiv.querySelector('.duplex-checkbox');
827 783
828 var capsSetEvent = 784 var capsSetEvent =
829 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 785 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
830 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 786 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
831 this.nativeLayer_.dispatchEvent(capsSetEvent); 787 this.nativeLayer_.dispatchEvent(capsSetEvent);
832 788
833 checkSectionVisible(otherOptionsDiv, true); 789 checkSectionVisible(otherOptionsDiv, true);
834 expectFalse(duplexDiv.hidden); 790 expectFalse(duplexDiv.hidden);
835 expectFalse(duplexCheckbox.checked); 791 expectFalse(duplexCheckbox.checked);
792 testDone();
836 }); 793 });
837 794
838 // Test to verify that duplex settings are set according to the printer 795 // Test to verify that duplex settings are set according to the printer
839 // capabilities. 796 // capabilities.
840 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() { 797 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
841 var initialSettingsSetEvent = 798 this.setUpPreview();
842 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
843 initialSettingsSetEvent.initialSettings = this.initialSettings_;
844 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
845
846 var localDestsSetEvent =
847 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
848 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
849 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
850 799
851 var moreSettingsDiv = $('more-settings'); 800 var moreSettingsDiv = $('more-settings');
852 var otherOptionsDiv = $('other-options-settings'); 801 var otherOptionsDiv = $('other-options-settings');
853 var duplexDiv = otherOptionsDiv.querySelector('.duplex-container'); 802 var duplexDiv = otherOptionsDiv.querySelector('.duplex-container');
854 803
855 var capsSetEvent = 804 var capsSetEvent =
856 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 805 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
857 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 806 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
858 delete capsSetEvent.settingsInfo.capabilities.printer.duplex; 807 delete capsSetEvent.settingsInfo.capabilities.printer.duplex;
859 this.nativeLayer_.dispatchEvent(capsSetEvent); 808 this.nativeLayer_.dispatchEvent(capsSetEvent);
860 809
861 // Check that it is collapsed. 810 // Check that it is collapsed.
862 checkSectionVisible(otherOptionsDiv, false); 811 checkSectionVisible(otherOptionsDiv, false);
863 // Expand it. 812 // Expand it.
864 checkSectionVisible(moreSettingsDiv, true); 813 checkSectionVisible(moreSettingsDiv, true);
865 moreSettingsDiv.click(); 814 moreSettingsDiv.click();
866 // Now it should be visible. 815 // Now it should be visible.
867 checkSectionVisible(otherOptionsDiv, true); 816 checkSectionVisible(otherOptionsDiv, true);
868 expectTrue(duplexDiv.hidden); 817 expectTrue(duplexDiv.hidden);
818
819 this.waitForTransitionEvents(1);
869 }); 820 });
870 821
871 // Test that changing the selected printer updates the preview. 822 // Test that changing the selected printer updates the preview.
872 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { 823 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
873 824 this.setUpPreview();
874 var initialSettingsSetEvent =
875 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
876 initialSettingsSetEvent.initialSettings = this.initialSettings_;
877 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
878
879 var localDestsSetEvent =
880 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
881 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
882 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
883 825
884 var capsSetEvent = 826 var capsSetEvent =
885 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 827 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
886 capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); 828 capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
887 this.nativeLayer_.dispatchEvent(capsSetEvent); 829 this.nativeLayer_.dispatchEvent(capsSetEvent);
888 830
889 var previewGenerator = mock(print_preview.PreviewGenerator); 831 var previewGenerator = mock(print_preview.PreviewGenerator);
890 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy(); 832 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy();
891 previewGenerator.expects(exactly(6)).requestPreview(); 833 previewGenerator.expects(exactly(6)).requestPreview();
892 834
(...skipping 10 matching lines...) Expand all
903 845
904 var capsSetEvent = 846 var capsSetEvent =
905 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 847 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
906 capsSetEvent.settingsInfo = getCddTemplate("BarDevice"); 848 capsSetEvent.settingsInfo = getCddTemplate("BarDevice");
907 capsSetEvent.settingsInfo.capabilities.printer.color = { 849 capsSetEvent.settingsInfo.capabilities.printer.color = {
908 "option": [ 850 "option": [
909 {"is_default": true, "type": "STANDARD_MONOCHROME"} 851 {"is_default": true, "type": "STANDARD_MONOCHROME"}
910 ] 852 ]
911 }; 853 };
912 this.nativeLayer_.dispatchEvent(capsSetEvent); 854 this.nativeLayer_.dispatchEvent(capsSetEvent);
855 testDone();
913 }); 856 });
914 857
915 // Test that error message is displayed when plugin doesn't exist. 858 // Test that error message is displayed when plugin doesn't exist.
916 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() { 859 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
917 var previewAreaEl = $('preview-area'); 860 var previewAreaEl = $('preview-area');
918 861
919 var loadingMessageEl = 862 var loadingMessageEl =
920 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0]; 863 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0];
921 expectEquals(true, loadingMessageEl.hidden); 864 expectEquals(true, loadingMessageEl.hidden);
922 865
923 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( 866 var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
924 'preview-area-preview-failed-message')[0]; 867 'preview-area-preview-failed-message')[0];
925 expectEquals(true, previewFailedMessageEl.hidden); 868 expectEquals(true, previewFailedMessageEl.hidden);
926 869
927 var printFailedMessageEl = 870 var printFailedMessageEl =
928 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0]; 871 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0];
929 expectEquals(true, printFailedMessageEl.hidden); 872 expectEquals(true, printFailedMessageEl.hidden);
930 873
931 var customMessageEl = 874 var customMessageEl =
932 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; 875 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0];
933 expectEquals(false, customMessageEl.hidden); 876 expectEquals(false, customMessageEl.hidden);
877 testDone();
934 }); 878 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698