| OLD | NEW |
| 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() { |
| 11 testing.Test.call(this); | 11 testing.Test.call(this); |
| 12 this.nativeLayer_ = null; | 12 this.nativeLayer_ = null; |
| 13 this.initialSettings_ = null; | 13 this.initialSettings_ = null; |
| 14 this.localDestinationInfos_ = null; | 14 this.localDestinationInfos_ = null; |
| 15 } | 15 } |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Index of the "Save as PDF" printer. |
| 19 * @type {number} |
| 20 * @const |
| 21 */ |
| 22 PrintPreviewWebUITest.PDF_INDEX = 0; |
| 23 |
| 24 /** |
| 18 * Index of the Foo printer. | 25 * Index of the Foo printer. |
| 19 * @type {number} | 26 * @type {number} |
| 20 * @const | 27 * @const |
| 21 */ | 28 */ |
| 22 PrintPreviewWebUITest.FOO_INDEX = 0; | 29 PrintPreviewWebUITest.FOO_INDEX = 1; |
| 23 | 30 |
| 24 /** | 31 /** |
| 25 * Index of the Bar printer. | 32 * Index of the Bar printer. |
| 26 * @type {number} | 33 * @type {number} |
| 27 * @const | 34 * @const |
| 28 */ | 35 */ |
| 29 PrintPreviewWebUITest.BAR_INDEX = 1; | 36 PrintPreviewWebUITest.BAR_INDEX = 2; |
| 30 | 37 |
| 31 PrintPreviewWebUITest.prototype = { | 38 PrintPreviewWebUITest.prototype = { |
| 32 __proto__: testing.Test.prototype, | 39 __proto__: testing.Test.prototype, |
| 33 | 40 |
| 34 /** | 41 /** |
| 35 * Browse to the sample page, cause print preview & call preLoad(). | 42 * Browse to the sample page, cause print preview & call preLoad(). |
| 36 * @type {string} | 43 * @type {string} |
| 37 * @override | 44 * @override |
| 38 */ | 45 */ |
| 39 browsePrintPreload: 'print_preview_hello_world_test.html', | 46 browsePrintPreload: 'print_preview_hello_world_test.html', |
| 40 | 47 |
| 41 /** | 48 /** |
| 42 * Stub out low-level functionality like the NativeLayer and | 49 * Stub out low-level functionality like the NativeLayer and |
| 43 * CloudPrintInterface. | 50 * CloudPrintInterface. |
| 44 * @this {PrintPreviewWebUITest} | 51 * @this {PrintPreviewWebUITest} |
| 45 * @override | 52 * @override |
| 46 */ | 53 */ |
| 47 preLoad: function() { | 54 preLoad: function() { |
| 48 window.addEventListener('DOMContentLoaded', function() { | 55 window.addEventListener('DOMContentLoaded', function() { |
| 49 function NativeLayerStub() { | 56 function NativeLayerStub() { |
| 50 cr.EventTarget.call(this); | 57 cr.EventTarget.call(this); |
| 51 } | 58 } |
| 52 NativeLayerStub.prototype = { | 59 NativeLayerStub.prototype = { |
| 53 __proto__: cr.EventTarget.prototype, | 60 __proto__: cr.EventTarget.prototype, |
| 54 startGetInitialSettings: function() {}, | 61 startGetInitialSettings: function() {}, |
| 55 startGetLocalDestinations: function() {}, | 62 startGetLocalDestinations: function() {}, |
| 56 startGetLocalDestinationCapabilities: function(destinationId) {} | 63 startGetLocalDestinationCapabilities: function(destinationId) {} |
| 57 }; | 64 }; |
| 58 | 65 var oldNativeLayerEventType = print_preview.NativeLayer.EventType; |
| 59 this.nativeLayer_ = new NativeLayerStub(); | 66 var oldDuplexMode = print_preview.NativeLayer.DuplexMode; |
| 60 printPreview.nativeLayer_ = this.nativeLayer_; | 67 print_preview.NativeLayer = NativeLayerStub; |
| 68 print_preview.NativeLayer.EventType = oldNativeLayerEventType; |
| 69 print_preview.NativeLayer.DuplexMode = oldDuplexMode; |
| 61 | 70 |
| 62 function CloudPrintInterfaceStub() { | 71 function CloudPrintInterfaceStub() { |
| 63 cr.EventTarget.call(this); | 72 cr.EventTarget.call(this); |
| 64 } | 73 } |
| 65 CloudPrintInterfaceStub.prototype = { | 74 CloudPrintInterfaceStub.prototype = { |
| 66 __proto__: cr.EventTarget.prototype, | 75 __proto__: cr.EventTarget.prototype, |
| 67 search: function(isRecent) {} | 76 search: function(isRecent) {} |
| 68 }; | 77 }; |
| 69 var oldCpInterfaceEventType = cloudprint.CloudPrintInterface.EventType; | 78 var oldCpInterfaceEventType = cloudprint.CloudPrintInterface.EventType; |
| 70 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub; | 79 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 99 true /*isDocumentModifiable*/, | 108 true /*isDocumentModifiable*/, |
| 100 0 /*marginsType*/, | 109 0 /*marginsType*/, |
| 101 null /*customMargins*/, | 110 null /*customMargins*/, |
| 102 true /*isDuplexEnabled*/, | 111 true /*isDuplexEnabled*/, |
| 103 false /*isHeaderFooterEnabled*/, | 112 false /*isHeaderFooterEnabled*/, |
| 104 'FooDevice' /*initialDestinationId*/); | 113 'FooDevice' /*initialDestinationId*/); |
| 105 this.localDestinationInfos_ = [ | 114 this.localDestinationInfos_ = [ |
| 106 { printerName: 'FooName', deviceName: 'FooDevice' }, | 115 { printerName: 'FooName', deviceName: 'FooDevice' }, |
| 107 { printerName: 'BarName', deviceName: 'BarDevice' } | 116 { printerName: 'BarName', deviceName: 'BarDevice' } |
| 108 ]; | 117 ]; |
| 118 this.nativeLayer_ = printPreview.nativeLayer_; |
| 109 } | 119 } |
| 110 }; | 120 }; |
| 111 | 121 |
| 112 GEN('#include "chrome/test/data/webui/print_preview.h"'); | 122 GEN('#include "chrome/test/data/webui/print_preview.h"'); |
| 113 | 123 |
| 114 // Test some basic assumptions about the print preview WebUI. | 124 // Test some basic assumptions about the print preview WebUI. |
| 115 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { | 125 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { |
| 116 var initialSettingsSetEvent = | 126 var initialSettingsSetEvent = |
| 117 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 127 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
| 118 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 128 initialSettingsSetEvent.initialSettings = this.initialSettings_; |
| 119 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | 129 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
| 120 | 130 |
| 121 var localDestsSetEvent = | 131 var localDestsSetEvent = |
| 122 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | 132 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
| 123 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | 133 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
| 124 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | 134 this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
| 125 | 135 |
| 126 var printerList = $('destination-settings'). | 136 var recentList = $('destination-search').querySelector( |
| 127 getElementsByClassName('destination-settings-select')[0]; | 137 '.destination-search-recent-list ' + |
| 128 assertNotEquals(null, printerList); | 138 '.destination-list-destination-list-item-container'); |
| 129 assertGE(printerList.options.length, 2); | 139 var localList = $('destination-search').querySelector( |
| 130 expectEquals(PrintPreviewWebUITest.FOO_INDEX, printerList.selectedIndex); | 140 '.destination-search-local-list ' + |
| 131 expectEquals('FooName', | 141 '.destination-list-destination-list-item-container'); |
| 132 printerList.options[PrintPreviewWebUITest.FOO_INDEX].text, | 142 assertNotEquals(null, recentList); |
| 133 'fooIndex=' + PrintPreviewWebUITest.FOO_INDEX); | 143 assertEquals(1, recentList.childNodes.length); |
| 134 expectEquals('FooDevice', | 144 assertEquals('FooName', |
| 135 printerList.options[PrintPreviewWebUITest.FOO_INDEX].value, | 145 recentList.childNodes.item(0).querySelector( |
| 136 'fooIndex=' + PrintPreviewWebUITest.FOO_INDEX); | 146 '.destination-list-item-name').textContent); |
| 137 expectEquals('BarName', | 147 |
| 138 printerList.options[PrintPreviewWebUITest.BAR_INDEX].text, | 148 assertNotEquals(null, localList); |
| 139 'barIndex=' + PrintPreviewWebUITest.BAR_INDEX); | 149 assertEquals(3, localList.childNodes.length); |
| 140 expectEquals('BarDevice', | 150 assertEquals('Save as PDF', |
| 141 printerList.options[PrintPreviewWebUITest.BAR_INDEX].value, | 151 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). |
| 142 'barIndex=' + PrintPreviewWebUITest.BAR_INDEX); | 152 querySelector('.destination-list-item-name').textContent); |
| 153 assertEquals('FooName', |
| 154 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). |
| 155 querySelector('.destination-list-item-name').textContent); |
| 156 assertEquals('BarName', |
| 157 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). |
| 158 querySelector('.destination-list-item-name').textContent); |
| 143 }); | 159 }); |
| 144 | 160 |
| 145 // Test that the printer list is structured correctly after calling | 161 // Test that the printer list is structured correctly after calling |
| 146 // addCloudPrinters with an empty list. | 162 // addCloudPrinters with an empty list. |
| 147 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { | 163 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { |
| 148 var initialSettingsSetEvent = | 164 var initialSettingsSetEvent = |
| 149 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 165 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
| 150 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 166 initialSettingsSetEvent.initialSettings = this.initialSettings_; |
| 151 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | 167 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
| 152 | 168 |
| 153 var localDestsSetEvent = | 169 var localDestsSetEvent = |
| 154 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | 170 new cr.Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
| 155 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | 171 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
| 156 this.nativeLayer_.dispatchEvent(localDestsSetEvent); | 172 this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
| 157 | 173 |
| 158 var cloudPrintEnableEvent = | 174 var cloudPrintEnableEvent = |
| 159 new cr.Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); | 175 new cr.Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); |
| 160 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; | 176 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; |
| 161 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent); | 177 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent); |
| 162 | 178 |
| 163 var searchDoneEvent = | 179 var searchDoneEvent = |
| 164 new cr.Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE); | 180 new cr.Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE); |
| 165 searchDoneEvent.printers = []; | 181 searchDoneEvent.printers = []; |
| 166 searchDoneEvent.isRecent = true; | 182 searchDoneEvent.isRecent = true; |
| 167 searchDoneEvent.email = 'foo@chromium.org'; | 183 searchDoneEvent.email = 'foo@chromium.org'; |
| 168 printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent); | 184 printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent); |
| 169 | 185 |
| 170 var printerList = $('destination-settings'). | 186 var recentList = $('destination-search').querySelector( |
| 171 getElementsByClassName('destination-settings-select')[0]; | 187 '.destination-search-recent-list ' + |
| 172 assertNotEquals(null, printerList); | 188 '.destination-list-destination-list-item-container'); |
| 173 assertGE(printerList.options.length, 2); | 189 var localList = $('destination-search').querySelector( |
| 174 expectEquals(PrintPreviewWebUITest.FOO_INDEX, printerList.selectedIndex); | 190 '.destination-search-local-list ' + |
| 175 expectEquals('FooName', | 191 '.destination-list-destination-list-item-container'); |
| 176 printerList.options[PrintPreviewWebUITest.FOO_INDEX].text, | 192 var cloudList = $('destination-search').querySelector( |
| 177 'fooIndex=' + PrintPreviewWebUITest.FOO_INDEX); | 193 '.destination-search-cloud-list ' + |
| 178 expectEquals('FooDevice', | 194 '.destination-list-destination-list-item-container'); |
| 179 printerList.options[PrintPreviewWebUITest.FOO_INDEX].value, | 195 |
| 180 'fooIndex=' + PrintPreviewWebUITest.FOO_INDEX); | 196 assertNotEquals(null, recentList); |
| 181 expectEquals('BarName', | 197 assertEquals(1, recentList.childNodes.length); |
| 182 printerList.options[PrintPreviewWebUITest.BAR_INDEX].text, | 198 assertEquals('FooName', |
| 183 'barIndex=' + PrintPreviewWebUITest.BAR_INDEX); | 199 recentList.childNodes.item(0).querySelector( |
| 184 expectEquals('BarDevice', | 200 '.destination-list-item-name').textContent); |
| 185 printerList.options[PrintPreviewWebUITest.BAR_INDEX].value, | 201 |
| 186 'barIndex=' + PrintPreviewWebUITest.BAR_INDEX); | 202 assertNotEquals(null, localList); |
| 203 assertEquals(3, localList.childNodes.length); |
| 204 assertEquals('Save as PDF', |
| 205 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX). |
| 206 querySelector('.destination-list-item-name').textContent); |
| 207 assertEquals('FooName', |
| 208 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX). |
| 209 querySelector('.destination-list-item-name').textContent); |
| 210 assertEquals('BarName', |
| 211 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). |
| 212 querySelector('.destination-list-item-name').textContent); |
| 213 |
| 214 assertNotEquals(null, cloudList); |
| 215 assertEquals(0, cloudList.childNodes.length); |
| 187 }); | 216 }); |
| 188 | 217 |
| 189 /** | 218 /** |
| 190 * Verify that |section| visibility matches |visible|. | 219 * Verify that |section| visibility matches |visible|. |
| 191 * @param {HTMLDivElement} section The section to check. | 220 * @param {HTMLDivElement} section The section to check. |
| 192 * @param {boolean} visible The expected state of visibility. | 221 * @param {boolean} visible The expected state of visibility. |
| 193 */ | 222 */ |
| 194 function checkSectionVisible(section, visible) { | 223 function checkSectionVisible(section, visible) { |
| 195 assertNotEquals(null, section); | 224 assertNotEquals(null, section); |
| 196 expectEquals( | 225 expectEquals( |
| 197 visible, section.classList.contains('visible'), 'section=' + section.id); | 226 visible, section.classList.contains('visible'), 'section=' + section.id); |
| 198 } | 227 } |
| 199 | 228 |
| 200 function checkElementDisplayed(el, isDisplayed) { | 229 function checkElementDisplayed(el, isDisplayed) { |
| 201 assertNotEquals(null, el); | 230 assertNotEquals(null, el); |
| 202 expectEquals(isDisplayed, el.style.display != 'none'); | 231 expectEquals(isDisplayed, !el.hidden); |
| 203 } | 232 } |
| 204 | 233 |
| 205 // Test that disabled settings hide the disabled sections. | 234 // Test that disabled settings hide the disabled sections. |
| 206 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { | 235 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { |
| 207 var initialSettingsSetEvent = | 236 var initialSettingsSetEvent = |
| 208 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); | 237 new cr.Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
| 209 initialSettingsSetEvent.initialSettings = this.initialSettings_; | 238 initialSettingsSetEvent.initialSettings = this.initialSettings_; |
| 210 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); | 239 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
| 211 | 240 |
| 212 var localDestsSetEvent = | 241 var localDestsSetEvent = |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 }; | 747 }; |
| 719 this.nativeLayer_.dispatchEvent(capsSetEvent); | 748 this.nativeLayer_.dispatchEvent(capsSetEvent); |
| 720 }); | 749 }); |
| 721 | 750 |
| 722 // Test that error message is displayed when plugin doesn't exist. | 751 // Test that error message is displayed when plugin doesn't exist. |
| 723 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() { | 752 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() { |
| 724 var previewAreaEl = $('preview-area'); | 753 var previewAreaEl = $('preview-area'); |
| 725 | 754 |
| 726 var loadingMessageEl = | 755 var loadingMessageEl = |
| 727 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0]; | 756 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0]; |
| 728 expectEquals('none', loadingMessageEl.style.display); | 757 expectEquals(true, loadingMessageEl.hidden); |
| 729 | 758 |
| 730 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( | 759 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( |
| 731 'preview-area-preview-failed-message')[0]; | 760 'preview-area-preview-failed-message')[0]; |
| 732 expectEquals('none', previewFailedMessageEl.style.display); | 761 expectEquals(true, previewFailedMessageEl.hidden); |
| 733 | 762 |
| 734 var printFailedMessageEl = | 763 var printFailedMessageEl = |
| 735 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0]; | 764 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0]; |
| 736 expectEquals('none', printFailedMessageEl.style.display); | 765 expectEquals(true, printFailedMessageEl.hidden); |
| 737 | 766 |
| 738 var customMessageEl = | 767 var customMessageEl = |
| 739 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; | 768 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; |
| 740 expectEquals('', customMessageEl.style.display); | 769 expectEquals(false, customMessageEl.hidden); |
| 741 }); | 770 }); |
| OLD | NEW |