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

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

Issue 2862463002: [MD settings] split up site settings tests (Closed)
Patch Set: mocha grep 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 /** @fileoverview Suite of tests for usb_devices. */ 5 /** @fileoverview Suite of tests for usb_devices. */
6 cr.define('usb_devices', function() { 6 suite('UsbDevices', function() {
7 function registerTests() { 7 /**
8 suite('UsbDevices', function() { 8 * A dummy usb-devices element created before each test.
9 * @type {UsbDevices}
10 */
11 var testElement;
12
13 /**
14 * The mock proxy object to use during test.
15 * @type {TestSiteSettingsPrefsBrowserProxy}
16 */
17 var browserProxy = null;
18
19 /**
20 * An example USB device entry list.
21 * @type {!Array<UsbDeviceEntry>}
22 */
23 var deviceList = [
24 {
25 embeddingOrigin: 'device-1-embedding-origin',
26 object: {
27 name: 'device-1',
28 'product-id': 1,
29 'serial-number': 'device-1-sn',
30 'vendor-id': 1
31 },
32 objectName: 'device-1',
33 origin: 'device-1-origin',
34 setting: 'device-1-settings',
35 source: 'device-1-source'
36 },
37 {
38 embeddingOrigin: 'device-2-embedding-origin',
39 object: {
40 name: 'device-2',
41 'product-id': 2,
42 'serial-number': 'device-2-sn',
43 'vendor-id': 2
44 },
45 objectName: 'device-2',
46 origin: 'device-2-origin',
47 setting: 'device-2-settings',
48 source: 'device-2-source'
49 }
50 ];
51
52 setup(function() {
53 browserProxy = new TestSiteSettingsPrefsBrowserProxy();
54 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
55 });
56
57 teardown(function() {
58 testElement.remove();
59 testElement = null;
60 });
61
62 /** @return {!Promise} */
63 function initPage() {
64 browserProxy.reset();
65 PolymerTest.clearBody();
66 testElement = document.createElement('usb-devices');
67 document.body.appendChild(testElement);
68 return browserProxy.whenCalled('fetchUsbDevices').then(function() {
69 Polymer.dom.flush();
70 });
71 }
72
73 test('empty devices list', function() {
74 return initPage().then(function() {
75 var listItems = testElement.root.querySelectorAll('.list-item');
76 assertEquals(0, listItems.length);
77 });
78 });
79
80 test('non-empty device list', function() {
81 browserProxy.setUsbDevices(deviceList);
82
83 return initPage().then(function() {
84 var listItems = testElement.root.querySelectorAll('.list-item');
85 assertEquals(deviceList.length, listItems.length);
86 });
87 });
88
89 test('non-empty device list has working menu buttons', function() {
90 browserProxy.setUsbDevices(deviceList);
91
92 return initPage().then(function() {
93 var menuButton = testElement.$$('paper-icon-button');
94 assertTrue(!!menuButton);
95 MockInteractions.tap(menuButton);
96 var dialog = testElement.$$('dialog[is=cr-action-menu]');
97 assertTrue(dialog.open);
98 });
99 });
100
101 /**
102 * A reusable function to test removing different devices.
103 * @param {!number} indexToRemove index of devices to be removed.
104 * @return {!Promise}
105 */
106 function testRemovalFlow(indexToRemove) {
107 /**
108 * Test whether or not clicking remove-button sends the correct
109 * parameters to the browserProxy.removeUsbDevice() function.
110 */
111 var menuButton =
112 testElement.root.querySelectorAll('paper-icon-button')[indexToRemove];
113 var removeButton = testElement.$.removeButton;
114 MockInteractions.tap(menuButton);
115 MockInteractions.tap(removeButton);
116 return browserProxy.whenCalled('removeUsbDevice').then(function(args) {
9 /** 117 /**
10 * A dummy usb-devices element created before each test. 118 * removeUsbDevice() is expected to be called with arguments as
11 * @type {UsbDevices} 119 * [origin, embeddingOrigin, object].
12 */ 120 */
13 var testElement; 121 assertEquals(deviceList[indexToRemove].origin, args[0]);
122 assertEquals(deviceList[indexToRemove].embeddingOrigin, args[1]);
123 assertEquals(deviceList[indexToRemove].object, args[2]);
14 124
15 /** 125 var dialog = testElement.$$('dialog[is=cr-action-menu]');
16 * The mock proxy object to use during test. 126 assertFalse(dialog.open);
17 * @type {TestSiteSettingsPrefsBrowserProxy} 127 });
18 */ 128 }
19 var browserProxy = null;
20 129
21 /** 130 test('try removing items using remove button', function() {
22 * An example USB device entry list. 131 browserProxy.setUsbDevices(deviceList);
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 132
53 setup(function() { 133 var self = this;
54 browserProxy = new TestSiteSettingsPrefsBrowserProxy();
55 settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
56 });
57 134
58 teardown(function() { 135 return initPage()
59 testElement.remove(); 136 .then(function() {
60 testElement = null;
61 });
62
63 /** @return {!Promise} */
64 function initPage() {
65 browserProxy.reset();
66 PolymerTest.clearBody();
67 testElement = document.createElement('usb-devices');
68 document.body.appendChild(testElement);
69 return browserProxy.whenCalled('fetchUsbDevices').then(function(){
70 Polymer.dom.flush();
71 });
72 }
73
74 test('empty devices list', function() {
75 return initPage().then(function(){
76 var listItems = testElement.root.querySelectorAll('.list-item');
77 assertEquals(0, listItems.length);
78 });
79 });
80
81 test('non-empty device list', function() {
82 browserProxy.setUsbDevices(deviceList);
83
84 return initPage().then(function() {
85 var listItems = testElement.root.querySelectorAll('.list-item');
86 assertEquals(deviceList.length, listItems.length);
87 });
88 });
89
90 test('non-empty device list has working menu buttons', function() {
91 browserProxy.setUsbDevices(deviceList);
92
93 return initPage().then(function() {
94 var menuButton = testElement.$$('paper-icon-button');
95 assertTrue(!!menuButton);
96 MockInteractions.tap(menuButton);
97 var dialog = testElement.$$('dialog[is=cr-action-menu]');
98 assertTrue(dialog.open);
99 });
100 });
101
102 /**
103 * A reusable function to test removing different devices.
104 * @param {!number} indexToRemove index of devices to be removed.
105 * @return {!Promise}
106 */
107 function testRemovalFlow(indexToRemove){
108 /**
109 * Test whether or not clicking remove-button sends the correct
110 * parameters to the browserProxy.removeUsbDevice() function.
111 */
112 var menuButton = testElement.root
113 .querySelectorAll('paper-icon-button')[indexToRemove];
114 var removeButton = testElement.$.removeButton;
115 MockInteractions.tap(menuButton);
116 MockInteractions.tap(removeButton);
117 return browserProxy.whenCalled('removeUsbDevice').then(function(args){
118 /**
119 * removeUsbDevice() is expected to be called with arguments as
120 * [origin, embeddingOrigin, object].
121 */
122 assertEquals(deviceList[indexToRemove].origin, args[0]);
123 assertEquals(deviceList[indexToRemove].embeddingOrigin, args[1]);
124 assertEquals(deviceList[indexToRemove].object, args[2]);
125
126 var dialog = testElement.$$('dialog[is=cr-action-menu]');
127 assertFalse(dialog.open);
128 });
129 }
130
131 test('try removing items using remove button', function() {
132 browserProxy.setUsbDevices(deviceList);
133
134 var self = this;
135
136 return initPage().then(function(){
137 return testRemovalFlow(0); 137 return testRemovalFlow(0);
138 }).then(function(){ 138 })
139 .then(function() {
139 browserProxy.reset(); 140 browserProxy.reset();
140 return testRemovalFlow(1); 141 return testRemovalFlow(1);
141 }); 142 });
142 }); 143 });
143 });
144 }
145
146 return {
147 registerTests: registerTests,
148 };
149 }); 144 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698