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

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: add annotation to fix closure_compiler 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() {
dpapad 2016/11/08 01:53:49 Nit: UsbDevices
scottchen 2016/11/09 19:20:56 Done.
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 return initPage();
dpapad 2016/11/08 01:53:49 Can we remove this call? Every test is calling ini
scottchen 2016/11/09 19:20:57 Done.
63 });
64
65 teardown(function() {
66 testElement.remove();
67 testElement = null;
68 });
69
70 /** @return {!Promise} */
71 function initPage() {
72 browserProxy.reset();
73 PolymerTest.clearBody();
74 testElement = document.createElement('usb-devices');
75 document.body.appendChild(testElement);
76 return browserProxy.whenCalled('fetchUsbDevices');
77 }
78
79 test('empty devices list', function() {
80 return initPage().then(function(){
81 var devices = testElement.devices;
82 assertTrue(!!devices);
dpapad 2016/11/08 01:53:49 This tests that |devices| is populated, but it's n
scottchen 2016/11/09 19:20:57 Done.
83 assertEquals(0, devices.length);
84 });
85 });
86
87 test('non-empty device list', function() {
88 browserProxy.setUsbDevices(deviceList);
89
90 return initPage().then(function() {
91 var devices = testElement.devices;
92 assertTrue(!!devices);
93 assertEquals(deviceList.length, devices.length);
94 });
95 });
96
97
98 test('non-empty device list creates dialog menu correctly', function() {
99 browserProxy.setUsbDevices(deviceList);
100
101 return initPage().then(function() {
102 Polymer.dom.flush();
103 var dialog = testElement.$$('dialog');
104
105 assertTrue(!!dialog);
106 assertFalse(dialog.hasAttribute('open'));
107
108 var removeButton = testElement.$["remove-button"];
109 assertTrue(!!removeButton);
110 });
111 });
112
113 test('non-empty device list has working menu buttons', function() {
114 browserProxy.setUsbDevices(deviceList);
115
116 return initPage().then(function() {
117 Polymer.dom.flush();
118
119 var menuButton = testElement.$$('paper-icon-button');
120 assertTrue(!!menuButton);
121
122 MockInteractions.tap(menuButton);
123
124 var dialog = testElement.$$('dialog');
125 assertTrue(dialog.hasAttribute('open'));
126 });
127 });
128
129 test('remove first item from list using remove button', function() {
130 browserProxy.setUsbDevices(deviceList);
131
132 return initPage().then(function() {
133 Polymer.dom.flush();
134
135 /**
136 * To test whether remove button removes an item, we first
137 * tap the menu button to indicate which device to remove, then
138 * check that device count goes down.
139 */
140 assertEquals(deviceList.length, testElement.devices.length);
141
142 var menuButton = testElement.$$('paper-icon-button');
143 MockInteractions.tap(menuButton);
144 var removeButton = testElement.$["remove-button"];
145 MockInteractions.tap(removeButton);
146
147 // Check length is one less than original fixture
148 assertEquals(deviceList.length - 1, testElement.devices.length);
149 // Check second device in original fixture becomes the first device
150 assertEquals(deviceList[1], testElement.devices[0]);
151 });
152 });
153
154 test('remove second item from list using remove button', function() {
155 browserProxy.setUsbDevices(deviceList);
156
157 return initPage().then(function() {
158 Polymer.dom.flush();
159
160 /**
161 * To test whether remove button removes an item, we first
162 * tap the menu button to indicate which device to remove, then
163 * check that device count goes down.
164 */
165 assertEquals(deviceList.length, testElement.devices.length);
166
167 var menuButton = testElement.root
168 .querySelectorAll('paper-icon-button')[1];
169 var removeButton = testElement.$["remove-button"];
170 MockInteractions.tap(menuButton);
171 MockInteractions.tap(removeButton);
172
173 // Check length is one less than original fixture
174 assertEquals(deviceList.length - 1, testElement.devices.length);
175 // Check first device in original fixture is still the first device
176 assertEquals(deviceList[0], testElement.devices[0]);
177 });
178 });
179 });
180 }
181
182 return {
183 registerTests: registerTests,
184 };
185 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698