| Index: chrome/test/data/webui/bluetooth_internals_browsertest.js
|
| diff --git a/chrome/test/data/webui/bluetooth_internals_browsertest.js b/chrome/test/data/webui/bluetooth_internals_browsertest.js
|
| index d68f2e729b15561639dc4e6590631976b308b9d9..50eacf64fabc5ccb89334a214bfaa514da239ccd 100644
|
| --- a/chrome/test/data/webui/bluetooth_internals_browsertest.js
|
| +++ b/chrome/test/data/webui/bluetooth_internals_browsertest.js
|
| @@ -53,12 +53,12 @@ BluetoothInternalsTest.prototype = {
|
| 'mojo/public/js/bindings',
|
| ]).then(function([frameInterfaces, adapter, device, bindings]) {
|
| /**
|
| - * A test adapter factory proxy for the chrome://bluetooth-internals
|
| - * page.
|
| - *
|
| - * @constructor
|
| - * @extends {TestBrowserProxyBase}
|
| - */
|
| + * A test adapter factory proxy for the chrome://bluetooth-internals
|
| + * page.
|
| + *
|
| + * @constructor
|
| + * @extends {TestBrowserProxyBase}
|
| + */
|
| var TestAdapterFactoryProxy = function() {
|
| settings.TestBrowserProxy.call(this, [
|
| 'getAdapter',
|
| @@ -83,11 +83,10 @@ BluetoothInternalsTest.prototype = {
|
| };
|
|
|
| /**
|
| - * A test adapter proxy for the chrome://bluetooth-internals page.
|
| - *
|
| - * @constructor
|
| - * @extends {TestBrowserProxyBase}
|
| - */
|
| + * A test adapter proxy for the chrome://bluetooth-internals page.
|
| + * @constructor
|
| + * @extends {TestBrowserProxyBase}
|
| + */
|
| var TestAdapterProxy = function() {
|
| settings.TestBrowserProxy.call(this, [
|
| 'getInfo',
|
| @@ -95,13 +94,25 @@ BluetoothInternalsTest.prototype = {
|
| 'setClient',
|
| ]);
|
|
|
| + this.deviceProxyMap = new Map();
|
| this.adapterInfo_ = null;
|
| this.devices_ = [];
|
| + this.connectResult_ = adapter.AdapterInfo.SUCCESS;
|
| };
|
|
|
| TestAdapterProxy.prototype = {
|
| __proto__: settings.TestBrowserProxy.prototype,
|
|
|
| + connectToDevice: function(address) {
|
| + assert(this.deviceProxyMap.has(address), 'Device does not exist');
|
| +
|
| + return Promise.resolve({
|
| + result: this.connectResult_,
|
| + device: this.deviceProxyMap.get(
|
| + address).binding.createInterfacePtrAndBind(),
|
| + });
|
| + },
|
| +
|
| getInfo: function() {
|
| this.methodCalled('getInfo');
|
| return Promise.resolve({info: this.adapterInfo_});
|
| @@ -120,11 +131,60 @@ BluetoothInternalsTest.prototype = {
|
| this.adapterInfo_ = adapterInfo;
|
| },
|
|
|
| + setTestConnectResult: function(connectResult) {
|
| + this.connectResult_ = connectResult;
|
| + },
|
| +
|
| setTestDevices: function(devices) {
|
| this.devices_ = devices;
|
| - }
|
| + this.devices_.forEach(function(device) {
|
| + this.deviceProxyMap.set(
|
| + device.address, new TestDeviceProxy(device));
|
| + }, this);
|
| + },
|
| };
|
|
|
| + /**
|
| + * A test Device proxy for the chrome://bluetooth-internals
|
| + * page. Proxies are generated by a TestAdapterProxy which provides
|
| + * the DeviceInfo.
|
| + * @constructor
|
| + * @extends {TestBrowserProxyBase}
|
| + * @param {!device.DeviceInfo} info
|
| + */
|
| + var TestDeviceProxy = function(info) {
|
| + settings.TestBrowserProxy.call(this, [
|
| + 'getInfo',
|
| + 'getServices',
|
| + ]);
|
| +
|
| + this.binding = new bindings.Binding(device.Device, this);
|
| + this.info_ = info;
|
| + this.services_ = [];
|
| + }
|
| +
|
| + TestDeviceProxy.prototype = {
|
| + __proto__: settings.TestBrowserProxy.prototype,
|
| +
|
| + disconnect: function() {
|
| + this.binding.close();
|
| + },
|
| +
|
| + getInfo: function() {
|
| + this.methodCalled('getInfo');
|
| + return Promise.resolve({info: this.info_});
|
| + },
|
| +
|
| + getServices: function() {
|
| + this.methodCalled('getServices');
|
| + return Promise.resolve({services: this.services_});
|
| + },
|
| +
|
| + setTestServices: function(services) {
|
| + this.services_ = services;
|
| + },
|
| + }
|
| +
|
| frameInterfaces.addInterfaceOverrideForTesting(
|
| adapter.AdapterFactory.name, function(handle) {
|
| this.adapterFactory = new TestAdapterFactoryProxy();
|
| @@ -137,6 +197,14 @@ BluetoothInternalsTest.prototype = {
|
| this.adapterFactory.adapter.setTestAdapter(
|
| this.fakeAdapterInfo());
|
|
|
| + this.adapterFactory.adapter.deviceProxyMap.forEach(
|
| + function(deviceProxy) {
|
| + deviceProxy.setTestServices([
|
| + this.fakeServiceInfo1(),
|
| + this.fakeServiceInfo2(),
|
| + ])
|
| + }, this);
|
| +
|
| this.setupResolver.resolve();
|
| }.bind(this));
|
|
|
| @@ -200,6 +268,28 @@ BluetoothInternalsTest.prototype = {
|
| name_for_display: "CCC",
|
| };
|
| },
|
| +
|
| + /**
|
| + * Returns a copy of fake service info object (variant 1).
|
| + * @return {!Object}
|
| + */
|
| + fakeServiceInfo1: function() {
|
| + return {
|
| + uuid: '00002a05-0000-1000-8000-00805f9b34fb',
|
| + is_primary: true,
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * Returns a copy of fake service info object (variant 2).
|
| + * @return {!Object}
|
| + */
|
| + fakeServiceInfo2: function() {
|
| + return {
|
| + uuid: '0000180d-0000-1000-8000-00805f9b34fb',
|
| + is_primary: true,
|
| + }
|
| + },
|
| };
|
|
|
| TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() {
|
| @@ -209,11 +299,14 @@ TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() {
|
| var adapterFieldSet = null;
|
| var deviceTable = null;
|
| var sidebarNode = null;
|
| + var pageNames = ['adapter', 'devices'];
|
|
|
| var fakeAdapterInfo = this.fakeAdapterInfo;
|
| var fakeDeviceInfo1 = this.fakeDeviceInfo1;
|
| var fakeDeviceInfo2 = this.fakeDeviceInfo2;
|
| var fakeDeviceInfo3 = this.fakeDeviceInfo3;
|
| + var fakeServiceInfo1 = this.fakeServiceInfo1;
|
| + var fakeServiceInfo2 = this.fakeServiceInfo2;
|
|
|
| // Before tests are run, make sure setup completes.
|
| var setupPromise = this.setupResolver.promise.then(function() {
|
| @@ -241,13 +334,28 @@ TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() {
|
| devices.splice(0, devices.length);
|
| adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo1());
|
| adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo2());
|
| +
|
| });
|
|
|
| teardown(function() {
|
| adapterFactory.reset();
|
| sidebarObj.close();
|
| snackbar.Snackbar.dismiss(true);
|
| +
|
| + adapterFactory.adapter.deviceProxyMap.forEach(function(deviceProxy) {
|
| + deviceProxy.reset();
|
| + });
|
| +
|
| PageManager.registeredPages['adapter'].setAdapterInfo(fakeAdapterInfo());
|
| +
|
| + for (var pageName in PageManager.registeredPages) {
|
| + var page = PageManager.registeredPages[pageName];
|
| +
|
| + if (pageNames.indexOf(pageName) < 0) {
|
| + page.pageDiv.parentNode.removeChild(page.pageDiv);
|
| + PageManager.unregister(page);
|
| + }
|
| + }
|
| });
|
|
|
| /**
|
| @@ -417,7 +525,7 @@ TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() {
|
| var sidebarItems = Array.from(
|
| sidebarNode.querySelectorAll('.sidebar-content li'));
|
|
|
| - ['adapter', 'devices'].forEach(function(pageName) {
|
| + pageNames.forEach(function(pageName) {
|
| expectTrue(sidebarItems.some(function(item) {
|
| return item.dataset.pageName === pageName;
|
| }));
|
| @@ -600,6 +708,97 @@ TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() {
|
| adapterBroker.adapterClient_.discoveringChanged(adapterInfo.discovering);
|
| checkAdapterFieldSet(adapterInfo);
|
| });
|
| +
|
| + /** Device Details Page Tests */
|
| +
|
| + /**
|
| + * Checks DeviceDetailsPage status fieldset.
|
| + * @param {!HTMLElement} detailsPage
|
| + * @param {!Object} deviceInfo
|
| + */
|
| + function checkDeviceDetailsFieldSet(detailsPage, deviceInfo) {
|
| + [
|
| + 'name',
|
| + 'address',
|
| + 'is_gatt_connected',
|
| + 'rssi.value',
|
| + 'services.length',
|
| + ].forEach(function(propName){
|
| + var valueCell = detailsPage.querySelector(
|
| + 'fieldset [data-field="' + propName + '"]');
|
| +
|
| + var parts = propName.split('.');
|
| + var value = deviceInfo;
|
| +
|
| + while (value != null && parts.length > 0) {
|
| + var part = parts.shift();
|
| + value = value[part];
|
| + }
|
| +
|
| + if (propName == 'is_gatt_connected')
|
| + value = value ? 'Connected' : 'Not Connected';
|
| +
|
| + if (typeof(value) === 'boolean') {
|
| + expectEquals(value, valueCell.classList.contains('checked'));
|
| + } else if (typeof(value) === 'string') {
|
| + expectEquals(value, valueCell.textContent);
|
| + } else {
|
| + assert('boolean or string type expected but got ' + typeof(value));
|
| + }
|
| + });
|
| + }
|
| +
|
| + test('DeviceDetailsPage_NewDelete', function() {
|
| + var device = devices.item(0);
|
| +
|
| + var deviceInspectLink = $(device.address).querySelector(
|
| + '[is="action-link"]');
|
| +
|
| + var deviceDetailsPageId = 'devices/' + device.address.toLowerCase();
|
| +
|
| + deviceInspectLink.click();
|
| + expectEquals("#" + deviceDetailsPageId, window.location.hash);
|
| +
|
| + var detailsPage = $(deviceDetailsPageId);
|
| + assertTrue(!!detailsPage);
|
| +
|
| + return adapterFactory.adapter.deviceProxyMap.get(
|
| + device.address).whenCalled('getServices').then(function() {
|
| + // At this point, the device details page should be fully loaded.
|
| + checkDeviceDetailsFieldSet(detailsPage, device);
|
| +
|
| + detailsPage.querySelector('.forget-btn').click();
|
| + expectEquals('#devices', window.location.hash);
|
| + detailsPage = $(deviceDetailsPageId);
|
| + expectFalse(!!detailsPage);
|
| + });
|
| + });
|
| +
|
| + test('DeviceDetailsPage_NewDelete_FromDevicesPage', function() {
|
| + var device = devices.item(0);
|
| + var deviceDetailsPageId = 'devices/' + device.address.toLowerCase();
|
| +
|
| + var deviceLinks = $(device.address).querySelectorAll(
|
| + '[is="action-link"]');
|
| +
|
| + // First link is 'Inspect'.
|
| + deviceLinks[0].click();
|
| + expectEquals("#" + deviceDetailsPageId, window.location.hash);
|
| +
|
| + var detailsPage = $(deviceDetailsPageId);
|
| + assertTrue(!!detailsPage);
|
| +
|
| + return adapterFactory.adapter.deviceProxyMap.get(
|
| + device.address).whenCalled('getServices').then(function() {
|
| + checkDeviceDetailsFieldSet(detailsPage, device);
|
| +
|
| + // Second link is 'Forget'.
|
| + deviceLinks[1].click();
|
| + expectEquals('#devices', window.location.hash);
|
| + detailsPage = $(deviceDetailsPageId);
|
| + expectFalse(!!detailsPage);
|
| + });
|
| + });
|
| });
|
|
|
| // Run all registered tests.
|
|
|