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

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

Issue 2606043004: Perform printer setup on Chrome OS before selecting printer. (Closed)
Patch Set: fix nits Created 3 years, 11 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
« no previous file with comments | « chrome/test/data/webui/print_preview.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 var resolver = new PromiseResolver();
109 nativeLayerMock.expects(once()).setupPrinter(destId).
110 will(returnValue(resolver.promise));
111 destinationSearch.handleOnDestinationSelect_(dest);
112 return resolver;
113 };
114
115 function resolveSetup(resolver, printerId, success, capabilities) {
116 var response = {
117 printerId: printerId,
118 capabilities: capabilities,
119 success: success
120 };
121
122 resolver.resolve(response);
123 }
124
125 setup(function() {
126 Mock4JS.clearMocksToVerify();
127
128 nativeLayer_ = mock(print_preview.NativeLayer);
129 nativeLayer_.expects(atLeastOnce())
130 .addEventListener(ANYTHING, ANYTHING, ANYTHING);
131
132 invitationStore_ = new print_preview.InvitationStore();
133 destinationStore_ = new print_preview.DestinationStore(
134 nativeLayer_.proxy(), new print_preview.UserInfo(),
135 new print_preview.AppState());
136 userInfo_ = new print_preview.UserInfo();
137
138 destinationSearch_ = new print_preview.DestinationSearch(
139 destinationStore_, invitationStore_, userInfo_);
140 destinationSearch_.decorate($('destination-search'));
141 });
142
143 teardown(function() {
144 Mock4JS.verifyAllMocks();
145 });
146
147 test('ResolutionFails', function() {
148 var destId = "001122DEADBEEF";
149 var resolver = requestSetup(destId, nativeLayer_, destinationSearch_);
150 resolver.reject(destId);
151 });
152
153 test('ReceiveSuccessfulSetup', function() {
154 var destId = "00112233DEADBEEF";
155 var resolver = requestSetup(destId, nativeLayer_, destinationSearch_);
156
157 waiter = waitForEvent(
158 destinationStore_,
159 print_preview.DestinationStore.EventType.DESTINATION_SELECT);
160
161 resolveSetup(resolver, destId, true, getCaps());
162
163 // wait for event propogation to complete.
164 return waiter.then(function() {
165 // after setup succeeds, the destination should be selected.
166 assertNotEquals(null, destinationStore_.selectedDestination);
167 assertEquals(destId, destinationStore_.selectedDestination.id);
168 });
169 });
170
171 test('ReceiveFailedSetup', function() {
172 var destId = '00112233DEADBEEF';
173 var resolver = requestSetup(destId, nativeLayer_, destinationSearch_);
174
175 waiter = waitForEvent(
176 destinationStore_,
177 print_preview.DestinationStore.EventType.PRINTER_CONFIGURED);
178
179 resolveSetup(resolver, destId, false, null);
180
181 return waiter.then(function() {
182 assertEquals(null, destinationStore_.selectedDestination);
183 });
184 });
185 });
186
187 mocha.run();
188 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/print_preview.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698