| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var ROOT_PATH = '../../../../'; |
| 6 |
| 7 GEN_INCLUDE( |
| 8 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']); |
| 9 |
| 10 /** |
| 11 * Test fixture for DestinationSearch of Print Preview. |
| 12 * @constructor |
| 13 * @extends {PolymerTest} |
| 14 */ |
| 15 function PrintPreviewDestinationSearchTest() {} |
| 16 |
| 17 PrintPreviewDestinationSearchTest.prototype = { |
| 18 __proto__: PolymerTest.prototype, |
| 19 |
| 20 /** @override */ |
| 21 browsePreload: 'chrome://print', |
| 22 |
| 23 /** @override */ |
| 24 runAccessibilityChecks: false, |
| 25 |
| 26 /** @override */ |
| 27 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), |
| 28 }; |
| 29 |
| 30 TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() { |
| 31 var self = this; |
| 32 |
| 33 suite('DestinationSearchTest', function() { |
| 34 var root_; |
| 35 |
| 36 var destinationSearch_; |
| 37 var nativeLayer_; |
| 38 var invitationStore_; |
| 39 var destinationStore_; |
| 40 var userInfo_; |
| 41 |
| 42 function getCaps() { |
| 43 return { |
| 44 'printer': { |
| 45 'color': { |
| 46 'option': [{ |
| 47 'is_default': true, |
| 48 'type': 'STANDARD_MONOCHROME', |
| 49 'vendor_id': '13' |
| 50 }] |
| 51 }, |
| 52 'copies': {}, |
| 53 'duplex': { |
| 54 'option': [ |
| 55 {'type': 'NO_DUPLEX'}, {'is_default': true, 'type': 'LONG_EDGE'}, |
| 56 {'type': 'SHORT_EDGE'} |
| 57 ] |
| 58 }, |
| 59 'media_size': { |
| 60 'option': [ |
| 61 { |
| 62 'custom_display_name': 'na letter', |
| 63 'height_microns': 279400, |
| 64 'is_default': true, |
| 65 'name': 'NA_LETTER', |
| 66 'vendor_id': 'na_letter_8.5x11in', |
| 67 'width_microns': 215900 |
| 68 }, |
| 69 { |
| 70 'custom_display_name': 'na legal', |
| 71 'height_microns': 355600, |
| 72 'name': 'NA_LEGAL', |
| 73 'vendor_id': 'na_legal_8.5x14in', |
| 74 'width_microns': 215900 |
| 75 } |
| 76 ] |
| 77 }, |
| 78 'page_orientation': { |
| 79 'option': [ |
| 80 {'is_default': true, 'type': 'PORTRAIT'}, {'type': 'LANDSCAPE'}, |
| 81 {'type': 'AUTO'} |
| 82 ] |
| 83 }, |
| 84 'supported_content_type': [{'content_type': 'application/pdf'}] |
| 85 }, |
| 86 'version': '1.0' |
| 87 }; |
| 88 }; |
| 89 |
| 90 function waitForEvent(element, eventName) { |
| 91 return new Promise(function(resolve) { |
| 92 var listener = function(e) { |
| 93 resolve(); |
| 94 element.removeEventListener(eventName, listener); |
| 95 }; |
| 96 |
| 97 element.addEventListener(eventName, listener); |
| 98 }); |
| 99 }; |
| 100 |
| 101 function requestSetup(destId, nativeLayerMock, destinationSearch) { |
| 102 var dest = new print_preview.Destination(destId, |
| 103 print_preview.Destination.Type.LOCAL, |
| 104 print_preview.Destination.Origin.CROS, |
| 105 "displayName", |
| 106 print_preview.Destination.ConnectionStatus.ONLINE); |
| 107 |
| 108 nativeLayerMock.expects(once()).setupPrinter(destId); |
| 109 destinationSearch.handleOnDestinationSelect_(dest); |
| 110 }; |
| 111 |
| 112 setup(function() { |
| 113 Mock4JS.clearMocksToVerify(); |
| 114 |
| 115 nativeLayer_ = mock(print_preview.NativeLayer); |
| 116 nativeLayer_.expects(atLeastOnce()) |
| 117 .addEventListener(ANYTHING, ANYTHING, ANYTHING); |
| 118 |
| 119 invitationStore_ = new print_preview.InvitationStore(); |
| 120 destinationStore_ = new print_preview.DestinationStore( |
| 121 nativeLayer_.proxy(), new print_preview.UserInfo(), |
| 122 new print_preview.AppState()); |
| 123 userInfo_ = new print_preview.UserInfo(); |
| 124 |
| 125 destinationSearch_ = new print_preview.DestinationSearch( |
| 126 destinationStore_, invitationStore_, userInfo_); |
| 127 destinationSearch_.decorate($('destination-search')); |
| 128 }); |
| 129 |
| 130 teardown(function() { |
| 131 Mock4JS.verifyAllMocks(); |
| 132 }); |
| 133 |
| 134 test('DestinationSelected', function() { |
| 135 var destId = "001122DEADBEEF"; |
| 136 requestSetup(destId, nativeLayer_, destinationSearch_); |
| 137 }); |
| 138 |
| 139 test('ReceiveSuccessfulSetup', function() { |
| 140 var destId = "00112233DEADBEEF"; |
| 141 requestSetup(destId, nativeLayer_, destinationSearch_); |
| 142 |
| 143 evt = new Event(print_preview.NativeLayer.EventType.PRINTER_SETUP); |
| 144 evt.printerId = destId; |
| 145 evt.capabilities = getCaps(); |
| 146 evt.success = true; |
| 147 |
| 148 waiter = waitForEvent( |
| 149 destinationStore_, |
| 150 print_preview.DestinationStore.EventType.DESTINATION_SELECT); |
| 151 |
| 152 destinationStore_.handleCrosDestinationResolved_(evt); |
| 153 |
| 154 // wait for event propogation to complete. |
| 155 return waiter.then(function() { |
| 156 // after setup succeeds, the destination should be selected. |
| 157 assertNotEquals(null, destinationStore_.selectedDestination); |
| 158 assertEquals(destId, destinationStore_.selectedDestination.id); |
| 159 }); |
| 160 }); |
| 161 |
| 162 test('ReceiveFailedSetup', function() { |
| 163 var destId = '00112233DEADBEEF'; |
| 164 requestSetup(destId, nativeLayer_, destinationSearch_); |
| 165 |
| 166 evt = new Event(print_preview.NativeLayer.EventType.PRINTER_SETUP); |
| 167 evt.printerId = destId; |
| 168 evt.capabilities = null; |
| 169 evt.success = false; |
| 170 |
| 171 waiter = waitForEvent( |
| 172 destinationStore_, |
| 173 print_preview.DestinationStore.EventType.PRINTER_CONFIGURED); |
| 174 |
| 175 destinationStore_.handleCrosDestinationResolved_(evt); |
| 176 |
| 177 return waiter.then(function() { |
| 178 assertEquals(null, destinationStore_.selectedDestination); |
| 179 }); |
| 180 }); |
| 181 }); |
| 182 |
| 183 mocha.run(); |
| 184 }); |
| OLD | NEW |