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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/settings/usb_devices_tests.js
diff --git a/chrome/test/data/webui/settings/usb_devices_tests.js b/chrome/test/data/webui/settings/usb_devices_tests.js
index 9acf92900f68ea629f39326e4bfef6416fabc250..74742ce60f1e677ca130c19fef456a21edc696cc 100644
--- a/chrome/test/data/webui/settings/usb_devices_tests.js
+++ b/chrome/test/data/webui/settings/usb_devices_tests.js
@@ -3,147 +3,142 @@
// found in the LICENSE file.
/** @fileoverview Suite of tests for usb_devices. */
-cr.define('usb_devices', function() {
- function registerTests() {
- suite('UsbDevices', function() {
- /**
- * A dummy usb-devices element created before each test.
- * @type {UsbDevices}
- */
- var testElement;
-
- /**
- * The mock proxy object to use during test.
- * @type {TestSiteSettingsPrefsBrowserProxy}
- */
- var browserProxy = null;
-
- /**
- * An example USB device entry list.
- * @type {!Array<UsbDeviceEntry>}
- */
- var deviceList = [
- {
- embeddingOrigin: 'device-1-embedding-origin',
- object: {
- name: 'device-1',
- "product-id": 1,
- "serial-number": "device-1-sn",
- "vendor-id": 1
- },
- objectName: 'device-1',
- origin: 'device-1-origin',
- setting: 'device-1-settings',
- source: 'device-1-source'
- }, {
- embeddingOrigin: 'device-2-embedding-origin',
- object: {
- name: 'device-2',
- "product-id": 2,
- "serial-number": "device-2-sn",
- "vendor-id": 2
- },
- objectName: 'device-2',
- origin: 'device-2-origin',
- setting: 'device-2-settings',
- source: 'device-2-source'
- }
- ];
-
- setup(function() {
- browserProxy = new TestSiteSettingsPrefsBrowserProxy();
- settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
- });
-
- teardown(function() {
- testElement.remove();
- testElement = null;
- });
-
- /** @return {!Promise} */
- function initPage() {
- browserProxy.reset();
- PolymerTest.clearBody();
- testElement = document.createElement('usb-devices');
- document.body.appendChild(testElement);
- return browserProxy.whenCalled('fetchUsbDevices').then(function(){
- Polymer.dom.flush();
- });
- }
-
- test('empty devices list', function() {
- return initPage().then(function(){
- var listItems = testElement.root.querySelectorAll('.list-item');
- assertEquals(0, listItems.length);
- });
- });
+suite('UsbDevices', function() {
+ /**
+ * A dummy usb-devices element created before each test.
+ * @type {UsbDevices}
+ */
+ var testElement;
+
+ /**
+ * The mock proxy object to use during test.
+ * @type {TestSiteSettingsPrefsBrowserProxy}
+ */
+ var browserProxy = null;
+
+ /**
+ * An example USB device entry list.
+ * @type {!Array<UsbDeviceEntry>}
+ */
+ var deviceList = [
+ {
+ embeddingOrigin: 'device-1-embedding-origin',
+ object: {
+ name: 'device-1',
+ 'product-id': 1,
+ 'serial-number': 'device-1-sn',
+ 'vendor-id': 1
+ },
+ objectName: 'device-1',
+ origin: 'device-1-origin',
+ setting: 'device-1-settings',
+ source: 'device-1-source'
+ },
+ {
+ embeddingOrigin: 'device-2-embedding-origin',
+ object: {
+ name: 'device-2',
+ 'product-id': 2,
+ 'serial-number': 'device-2-sn',
+ 'vendor-id': 2
+ },
+ objectName: 'device-2',
+ origin: 'device-2-origin',
+ setting: 'device-2-settings',
+ source: 'device-2-source'
+ }
+ ];
+
+ setup(function() {
+ browserProxy = new TestSiteSettingsPrefsBrowserProxy();
+ settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
+ });
+
+ teardown(function() {
+ testElement.remove();
+ testElement = null;
+ });
+
+ /** @return {!Promise} */
+ function initPage() {
+ browserProxy.reset();
+ PolymerTest.clearBody();
+ testElement = document.createElement('usb-devices');
+ document.body.appendChild(testElement);
+ return browserProxy.whenCalled('fetchUsbDevices').then(function() {
+ Polymer.dom.flush();
+ });
+ }
- test('non-empty device list', function() {
- browserProxy.setUsbDevices(deviceList);
+ test('empty devices list', function() {
+ return initPage().then(function() {
+ var listItems = testElement.root.querySelectorAll('.list-item');
+ assertEquals(0, listItems.length);
+ });
+ });
- return initPage().then(function() {
- var listItems = testElement.root.querySelectorAll('.list-item');
- assertEquals(deviceList.length, listItems.length);
- });
- });
+ test('non-empty device list', function() {
+ browserProxy.setUsbDevices(deviceList);
- test('non-empty device list has working menu buttons', function() {
- browserProxy.setUsbDevices(deviceList);
+ return initPage().then(function() {
+ var listItems = testElement.root.querySelectorAll('.list-item');
+ assertEquals(deviceList.length, listItems.length);
+ });
+ });
- return initPage().then(function() {
- var menuButton = testElement.$$('paper-icon-button');
- assertTrue(!!menuButton);
- MockInteractions.tap(menuButton);
- var dialog = testElement.$$('dialog[is=cr-action-menu]');
- assertTrue(dialog.open);
- });
- });
+ test('non-empty device list has working menu buttons', function() {
+ browserProxy.setUsbDevices(deviceList);
+ return initPage().then(function() {
+ var menuButton = testElement.$$('paper-icon-button');
+ assertTrue(!!menuButton);
+ MockInteractions.tap(menuButton);
+ var dialog = testElement.$$('dialog[is=cr-action-menu]');
+ assertTrue(dialog.open);
+ });
+ });
+
+ /**
+ * A reusable function to test removing different devices.
+ * @param {!number} indexToRemove index of devices to be removed.
+ * @return {!Promise}
+ */
+ function testRemovalFlow(indexToRemove) {
+ /**
+ * Test whether or not clicking remove-button sends the correct
+ * parameters to the browserProxy.removeUsbDevice() function.
+ */
+ var menuButton =
+ testElement.root.querySelectorAll('paper-icon-button')[indexToRemove];
+ var removeButton = testElement.$.removeButton;
+ MockInteractions.tap(menuButton);
+ MockInteractions.tap(removeButton);
+ return browserProxy.whenCalled('removeUsbDevice').then(function(args) {
/**
- * A reusable function to test removing different devices.
- * @param {!number} indexToRemove index of devices to be removed.
- * @return {!Promise}
+ * removeUsbDevice() is expected to be called with arguments as
+ * [origin, embeddingOrigin, object].
*/
- function testRemovalFlow(indexToRemove){
- /**
- * Test whether or not clicking remove-button sends the correct
- * parameters to the browserProxy.removeUsbDevice() function.
- */
- var menuButton = testElement.root
- .querySelectorAll('paper-icon-button')[indexToRemove];
- var removeButton = testElement.$.removeButton;
- MockInteractions.tap(menuButton);
- MockInteractions.tap(removeButton);
- return browserProxy.whenCalled('removeUsbDevice').then(function(args){
- /**
- * removeUsbDevice() is expected to be called with arguments as
- * [origin, embeddingOrigin, object].
- */
- assertEquals(deviceList[indexToRemove].origin, args[0]);
- assertEquals(deviceList[indexToRemove].embeddingOrigin, args[1]);
- assertEquals(deviceList[indexToRemove].object, args[2]);
-
- var dialog = testElement.$$('dialog[is=cr-action-menu]');
- assertFalse(dialog.open);
- });
- }
+ assertEquals(deviceList[indexToRemove].origin, args[0]);
+ assertEquals(deviceList[indexToRemove].embeddingOrigin, args[1]);
+ assertEquals(deviceList[indexToRemove].object, args[2]);
- test('try removing items using remove button', function() {
- browserProxy.setUsbDevices(deviceList);
+ var dialog = testElement.$$('dialog[is=cr-action-menu]');
+ assertFalse(dialog.open);
+ });
+ }
+
+ test('try removing items using remove button', function() {
+ browserProxy.setUsbDevices(deviceList);
- var self = this;
+ var self = this;
- return initPage().then(function(){
+ return initPage()
+ .then(function() {
return testRemovalFlow(0);
- }).then(function(){
+ })
+ .then(function() {
browserProxy.reset();
return testRemovalFlow(1);
});
- });
- });
- }
-
- return {
- registerTests: registerTests,
- };
+ });
});

Powered by Google App Engine
This is Rietveld 408576698