Chromium Code Reviews| OLD | NEW |
|---|---|
| (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').then(function(){ | |
| 76 Polymer.dom.flush(); | |
| 77 }); | |
| 78 } | |
| 79 | |
| 80 test('empty devices list', function() { | |
| 81 return initPage().then(function(){ | |
| 82 var listItems = testElement.root.querySelectorAll('.list-item'); | |
| 83 assertEquals(0, listItems.length); | |
| 84 }); | |
| 85 }); | |
| 86 | |
| 87 test('non-empty device list', function() { | |
| 88 browserProxy.setUsbDevices(deviceList); | |
| 89 | |
| 90 return initPage().then(function() { | |
| 91 var listItems = testElement.root.querySelectorAll('.list-item'); | |
| 92 assertEquals(deviceList.length, listItems.length); | |
| 93 }); | |
| 94 }); | |
| 95 | |
| 96 test('non-empty device list has working menu buttons', function() { | |
| 97 browserProxy.setUsbDevices(deviceList); | |
| 98 | |
| 99 return initPage().then(function() { | |
| 100 var menuButton = testElement.$$('paper-icon-button'); | |
| 101 assertTrue(!!menuButton); | |
|
dpapad
2016/11/10 20:28:36
Add an assertion here that the dialog is initially
| |
| 102 MockInteractions.tap(menuButton); | |
| 103 var dialog = testElement.$$('dialog[is=cr-action-menu]'); | |
| 104 assertTrue(dialog.open); | |
| 105 }); | |
| 106 }); | |
| 107 | |
| 108 /** | |
| 109 * A reusable function to test removing different devices. | |
| 110 * @param {!number} indexToRemove index of devices to be removed. | |
| 111 * @return {!Promise} | |
| 112 */ | |
| 113 function testRemovalFlow(indexToRemove){ | |
| 114 /** | |
| 115 * Test whether or not clicking remove-button sends the correct | |
| 116 * parameters to the browserProxy.removeUsbDevice() function. | |
| 117 */ | |
| 118 var menuButton = testElement.root | |
| 119 .querySelectorAll('paper-icon-button')[indexToRemove]; | |
|
dpapad
2016/11/10 20:28:35
Nit: Per styleguide at https://google.github.io/st
| |
| 120 var removeButton = testElement.$.removeButton; | |
| 121 MockInteractions.tap(menuButton); | |
| 122 MockInteractions.tap(removeButton); | |
| 123 return browserProxy.whenCalled('removeUsbDevice').then(function(args){ | |
| 124 /** | |
| 125 * removeUsbDevice() is expected to be called with arguments as | |
| 126 * [origin, embeddingOrigin, object]. | |
| 127 */ | |
| 128 assertEquals(deviceList[indexToRemove].origin, args[0]); | |
| 129 assertEquals(deviceList[indexToRemove].embeddingOrigin, args[1]); | |
| 130 assertEquals(deviceList[indexToRemove].object, args[2]); | |
| 131 | |
| 132 var dialog = testElement.$$('dialog[is=cr-action-menu]'); | |
| 133 assertFalse(dialog.open); | |
| 134 }); | |
| 135 } | |
| 136 | |
| 137 test('try removing items using remove button', function() { | |
| 138 browserProxy.setUsbDevices(deviceList); | |
| 139 | |
| 140 var self = this; | |
|
dpapad
2016/11/10 20:28:36
Don't see any uses of self. Maybe remove?
| |
| 141 | |
| 142 return initPage().then(function(){ | |
| 143 return testRemovalFlow(0); | |
| 144 }).then(function(){ | |
| 145 browserProxy.reset(); | |
| 146 return testRemovalFlow(1); | |
| 147 }); | |
| 148 }); | |
| 149 }); | |
| 150 } | |
| 151 | |
| 152 return { | |
| 153 registerTests: registerTests, | |
| 154 }; | |
| 155 }); | |
| OLD | NEW |