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

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

Issue 2893003003: Print Preview: Merge NativeLayerStubs for tests (Closed)
Patch Set: Remove extra variable 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 2016 The Chromium Authors. All rights reserved. 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 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 var ROOT_PATH = '../../../../'; 5 var ROOT_PATH = '../../../../../';
6 6
7 GEN_INCLUDE( 7 GEN_INCLUDE(
8 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']); 8 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']);
9 9
10 /** 10 /**
11 * Test fixture for DestinationSearch of Print Preview. 11 * Test fixture for DestinationSearch of Print Preview.
12 * @constructor 12 * @constructor
13 * @extends {PolymerTest} 13 * @extends {PolymerTest}
14 */ 14 */
15 function PrintPreviewDestinationSearchTest() {} 15 function PrintPreviewDestinationSearchTest() {}
16 16
17 PrintPreviewDestinationSearchTest.prototype = { 17 PrintPreviewDestinationSearchTest.prototype = {
18 __proto__: PolymerTest.prototype, 18 __proto__: PolymerTest.prototype,
19 19
20 /** @override */ 20 /** @override */
21 browsePreload: 'chrome://print', 21 browsePreload: 'chrome://print',
22 22
23 /** @override */ 23 /** @override */
24 runAccessibilityChecks: false, 24 runAccessibilityChecks: false,
25 25
26 /** @override */ 26 /** @override */
27 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([ 27 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([
28 ROOT_PATH + 'chrome/test/data/webui/settings/test_browser_proxy.js', 28 ROOT_PATH + 'chrome/test/data/webui/settings/test_browser_proxy.js',
29 'native_layer_stub.js',
29 ]), 30 ]),
30 31
31 }; 32 };
32 33
33 TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() { 34 TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() {
34 var self = this; 35 var self = this;
35 36
36 suite('DestinationSearchTest', function() { 37 suite('DestinationSearchTest', function() {
37 var root_; 38 var root_;
38 39
39 var destinationSearch_; 40 var destinationSearch_;
40 var nativeLayer_; 41 var nativeLayer_;
41 var invitationStore_; 42 var invitationStore_;
42 var destinationStore_; 43 var destinationStore_;
43 var userInfo_; 44 var userInfo_;
44 45
45 /**
46 * Test version of the native layer.
47 * TODO (rbpotter): Merge this with NativeLayerStub() from print_preview.js
48 * and put into a separate file.
49 * @constructor
50 * @extends {settings.TestBrowserProxy}
51 */
52 function NativeLayerStub() {
53 settings.TestBrowserProxy.call(this, [ 'setupPrinter' ]);
54 this.destinationToWatch_ = '';
55 this.eventTarget_ = mock(cr.EventTarget);
56 this.getLocalDestinationCapabilitiesCallCount_ = 0;
57 this.setupPrinterResponse_ = null;
58 this.shouldReject_ = false;
59 }
60
61 NativeLayerStub.prototype = {
62 __proto__: settings.TestBrowserProxy.prototype,
63 didGetCapabilitiesOnce: function(destinationId) {
64 return (destinationId == this.destinationToWatch_ &&
65 this.getLocalDestinationCapabilitiesCallCount_ == 1);
66 },
67 getEventTarget: function() { return this.eventTarget_; },
68 setDestinationToWatch: function(destinationId) {
69 this.destinationToWatch_ = destinationId;
70 this.getLocalDestinationCapabilitiesCallCount_ = 0;
71 },
72 setSetupPrinterResponse: function(reject, response) {
73 this.shouldReject_ = reject;
74 this.setupPrinterResponse_ = response;
75 },
76 setupPrinter: function(printerId) {
77 this.methodCalled('setupPrinter', printerId);
78 return this.shouldReject_ ?
79 Promise.reject(this.setupPrinterResponse_) :
80 Promise.resolve(this.setupPrinterResponse_);
81 },
82 startGetLocalDestinationCapabilities: function(destinationId) {
83 if (destinationId == this.destinationToWatch_)
84 this.getLocalDestinationCapabilitiesCallCount_++;
85 },
86 };
87 NativeLayerStub.EventType = print_preview.NativeLayer.EventType;
88
89 function getCaps() { 46 function getCaps() {
90 return { 47 return {
91 'printer': { 48 'printer': {
92 'color': { 49 'color': {
93 'option': [{ 50 'option': [{
94 'is_default': true, 51 'is_default': true,
95 'type': 'STANDARD_MONOCHROME', 52 'type': 'STANDARD_MONOCHROME',
96 'vendor_id': '13' 53 'vendor_id': '13'
97 }] 54 }]
98 }, 55 },
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // Select destination. 143 // Select destination.
187 if (cr.isChromeOS) { 144 if (cr.isChromeOS) {
188 destinationSearch.handleConfigureDestination_(dest); 145 destinationSearch.handleConfigureDestination_(dest);
189 } else { 146 } else {
190 destinationSearch.handleOnDestinationSelect_(dest); 147 destinationSearch.handleOnDestinationSelect_(dest);
191 } 148 }
192 }; 149 };
193 150
194 setup(function() { 151 setup(function() {
195 Mock4JS.clearMocksToVerify(); 152 Mock4JS.clearMocksToVerify();
196 nativeLayer_ = new NativeLayerStub(); 153 nativeLayer_ = new print_preview.NativeLayerStub();
197 var nativeLayerEventTarget = nativeLayer_.getEventTarget(); 154 var nativeLayerEventTarget = mock(cr.EventTarget);
155 nativeLayer_.setEventTarget(nativeLayerEventTarget.proxy());
198 nativeLayerEventTarget.expects(atLeastOnce()) 156 nativeLayerEventTarget.expects(atLeastOnce())
199 .addEventListener(ANYTHING, ANYTHING, ANYTHING); 157 .addEventListener(ANYTHING, ANYTHING, ANYTHING);
200 158
201 invitationStore_ = new print_preview.InvitationStore(); 159 invitationStore_ = new print_preview.InvitationStore();
202 var nativeLayerProxy = nativeLayer_;
203 nativeLayerProxy.eventTarget_ = nativeLayerEventTarget.proxy();
204 destinationStore_ = new print_preview.DestinationStore( 160 destinationStore_ = new print_preview.DestinationStore(
205 nativeLayerProxy, new print_preview.UserInfo(), 161 nativeLayer_, new print_preview.UserInfo(),
206 new print_preview.AppState()); 162 new print_preview.AppState());
207 userInfo_ = new print_preview.UserInfo(); 163 userInfo_ = new print_preview.UserInfo();
208 164
209 destinationSearch_ = new print_preview.DestinationSearch( 165 destinationSearch_ = new print_preview.DestinationSearch(
210 destinationStore_, invitationStore_, userInfo_); 166 destinationStore_, invitationStore_, userInfo_);
211 destinationSearch_.decorate($('destination-search')); 167 destinationSearch_.decorate($('destination-search'));
212 }); 168 });
213 169
214 teardown(function() { 170 teardown(function() {
215 Mock4JS.verifyAllMocks(); 171 Mock4JS.verifyAllMocks();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 // Simulate a click. 262 // Simulate a click.
307 dest.onActivate_(); 263 dest.onActivate_();
308 264
309 // Verify that the destination has been selected. 265 // Verify that the destination has been selected.
310 assertEquals(printerId, destinationStore_.selectedDestination.id); 266 assertEquals(printerId, destinationStore_.selectedDestination.id);
311 }); 267 });
312 }); 268 });
313 269
314 mocha.run(); 270 mocha.run();
315 }); 271 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698