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

Side by Side Diff: chrome/test/data/webui/settings/usb_devices_tests.js

Issue 2480843003: change site-settings -> usb-device to use cr-action-menu instead of paper-menu (Closed)
Patch Set: fix up usb-device tests as comments recommended on previous patches Created 4 years, 1 month 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
(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 /** @fileoverview Suite of tests for usb_devices. */
6 cr.define('usb_devices', function() {
7 function registerTests() {
8 suite('UsbDevices', function() {
9 /**
10 * A dummy usb-devices element created before each test.
11 * @type {UsbDeviceEntry}
12 */
13 var testElement;
14
15 /**
16 * The mock proxy object to use during test.
17 * @type {TestSiteSettingsPrefsBrowserProxy}
18 */
19 var browserProxy = null;
20
21 /**
22 * An example USB device entry list.
23 * @type {!Array<UsbDeviceEntry>}
24 */
25 var deviceList = [
26 {
27 embeddingOrigin: 'device-1-embedding-origin',
28 object: {
29 name: 'device-1',
30 "product-id": 1,
31 "serial-number": "device-1-sn",
32 "vendor-id": 1
33 },
34 objectName: 'device-1',
35 origin: 'device-1-origin',
36 setting: 'device-1-settings',
37 source: 'device-1-source'
38 }, {
39 embeddingOrigin: 'device-2-embedding-origin',
40 object: {
41 name: 'device-2',
42 "product-id": 2,
43 "serial-number": "device-2-sn",
44 "vendor-id": 2
45 },
46 objectName: 'device-2',
47 origin: 'device-2-origin',
48 setting: 'device-2-settings',
49 source: 'device-2-source'
50 }
51 ];
52
53 // Import necessary html before running suite.
54 suiteSetup(function() {
55 return PolymerTest.importHtml(
56 'chrome://md-settings/site_settings/usb_devices.html');
57 });
58
59 setup(function() {
60 browserProxy = new TestSiteSettingsPrefsBrowserProxy();
61 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
62 });
63
64 teardown(function() {
65 testElement.remove();
66 testElement = null;
67 });
68
69 /** @return {!Promise} */
70 function initPage() {
71 browserProxy.reset();
72 PolymerTest.clearBody();
73 testElement = document.createElement('usb-devices');
74 document.body.appendChild(testElement);
75 return browserProxy.whenCalled('fetchUsbDevices');
dpapad 2016/11/09 20:32:09 Polymer.dom.flush() is called after every initPage
scottchen 2016/11/10 06:08:21 Done.
76 }
77
78 test('empty devices list', function() {
79 return initPage().then(function(){
80 Polymer.dom.flush();
81 var listItems = testElement.root.querySelectorAll('.list-item');
82 assertEquals(0, listItems.length);
83 });
84 });
85
86 test('non-empty device list', function() {
87 browserProxy.setUsbDevices(deviceList);
88
89 return initPage().then(function() {
90 Polymer.dom.flush();
91 var listItems = testElement.root.querySelectorAll('.list-item');
92 assertEquals(deviceList.length, listItems.length);
93 });
94 });
95
96
97 test('non-empty device list creates dialog menu correctly', function() {
dpapad 2016/11/09 20:32:09 I don't think this test is adding much value. the
scottchen 2016/11/10 06:08:21 Done.
98 browserProxy.setUsbDevices(deviceList);
99
100 return initPage().then(function() {
101 Polymer.dom.flush();
102 var dialog = testElement.$$('dialog');
dpapad 2016/11/09 20:32:09 Let's be specific about what kind of dialog we loo
scottchen 2016/11/10 06:08:21 Done.
103
104 assertTrue(!!dialog);
105 assertFalse(dialog.hasAttribute('open'));
106
107 var removeButton = testElement.$["remove-button"];
108 assertTrue(!!removeButton);
109 });
110 });
111
112 test('non-empty device list has working menu buttons', function() {
113 browserProxy.setUsbDevices(deviceList);
114
115 return initPage().then(function() {
116 Polymer.dom.flush();
117
118 var menuButton = testElement.$$('paper-icon-button');
119 assertTrue(!!menuButton);
120
121 MockInteractions.tap(menuButton);
122
123 var dialog = testElement.$$('dialog');
124 assertTrue(dialog.hasAttribute('open'));
dpapad 2016/11/09 20:32:09 Nit: I think this would also work assertTrue(dial
scottchen 2016/11/10 06:08:21 Done.
125 });
126 });
127
128 test('try removing items using remove button', function() {
dpapad 2016/11/09 20:32:09 Given that we are not actually removing anything d
scottchen 2016/11/10 06:08:21 - I think the previous test is to test the menu bu
dpapad 2016/11/10 17:35:09 OK, that makes sense.
129 browserProxy.setUsbDevices(deviceList);
130
131 var self = this;
132
133 /**
134 * A reusable function to test removing different devices.
135 * @param {!number} indexToRemove index of devices to be removed.
136 * @return {!Promise}
137 */
138 function testRemovalFlow(indexToRemove){
dpapad 2016/11/10 17:35:09 Probably more readable if you move this helper fun
scottchen 2016/11/10 19:58:00 Done.
139 return initPage().then(function() {
140 Polymer.dom.flush();
141
142 /**
143 * Test whether or not clicking remove-button sends the correct
144 * parameters to the browserProxy.removeUsbDevice() function.
145 */
146 var menuButton = testElement.root
147 .querySelectorAll('paper-icon-button')[indexToRemove];
148 var removeButton = testElement.$["remove-button"];
149 MockInteractions.tap(menuButton);
150 MockInteractions.tap(removeButton);
151 return browserProxy.whenCalled('removeUsbDevice');
152 }).then(function(args){
153 /**
154 * removeUsbDevice() is expected to be called with arguments as
155 * [origin, embeddingOrigin, object].
156 */
157 assertEquals(deviceList[indexToRemove].origin, args[0]);
158 assertEquals(deviceList[indexToRemove].embeddingOrigin, args[1]);
159 assertEquals(deviceList[indexToRemove].object, args[2]);
160 });
161 }
162
163 return testRemovalFlow(0).then(function(){
164 return testRemovalFlow(1);
165 });
166 });
167 });
168 }
169
170 return {
171 registerTests: registerTests,
172 };
173 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698