Commit c01616be authored by dpapad's avatar dpapad Committed by Commit Bot

WebUI: Convert TestBrowserProxy and remaining subclasses to ES6 class syntax.

Bug: None
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Icab535f6157bd313cb2fe95ad0a54dd11e6e2da9
Reviewed-on: https://chromium-review.googlesource.com/596682Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491447}
parent d676a966
...@@ -55,12 +55,10 @@ BluetoothInternalsTest.prototype = { ...@@ -55,12 +55,10 @@ BluetoothInternalsTest.prototype = {
/** /**
* A test adapter factory proxy for the chrome://bluetooth-internals * A test adapter factory proxy for the chrome://bluetooth-internals
* page. * page.
*
* @constructor
* @extends {TestBrowserProxy}
*/ */
var TestAdapterFactoryProxy = function() { class TestAdapterFactoryProxy extends TestBrowserProxy {
TestBrowserProxy.call(this, [ constructor() {
super([
'getAdapter', 'getAdapter',
]); ]);
...@@ -68,11 +66,9 @@ BluetoothInternalsTest.prototype = { ...@@ -68,11 +66,9 @@ BluetoothInternalsTest.prototype = {
this.adapter = new TestAdapterProxy(); this.adapter = new TestAdapterProxy();
this.adapterBinding_ = new bindings.Binding(adapter.Adapter, this.adapterBinding_ = new bindings.Binding(adapter.Adapter,
this.adapter); this.adapter);
}; }
TestAdapterFactoryProxy.prototype = { getAdapter() {
__proto__: TestBrowserProxy.prototype,
getAdapter: function() {
this.methodCalled('getAdapter'); this.methodCalled('getAdapter');
// Create message pipe bound to TestAdapter. // Create message pipe bound to TestAdapter.
...@@ -80,15 +76,14 @@ BluetoothInternalsTest.prototype = { ...@@ -80,15 +76,14 @@ BluetoothInternalsTest.prototype = {
adapter: this.adapterBinding_.createInterfacePtrAndBind(), adapter: this.adapterBinding_.createInterfacePtrAndBind(),
}); });
} }
}; }
/** /**
* A test adapter proxy for the chrome://bluetooth-internals page. * A test adapter proxy for the chrome://bluetooth-internals page.
* @constructor
* @extends {TestBrowserProxy}
*/ */
var TestAdapterProxy = function() { class TestAdapterProxy extends TestBrowserProxy {
TestBrowserProxy.call(this, [ constructor() {
super([
'getInfo', 'getInfo',
'getDevices', 'getDevices',
'setClient', 'setClient',
...@@ -98,12 +93,9 @@ BluetoothInternalsTest.prototype = { ...@@ -98,12 +93,9 @@ BluetoothInternalsTest.prototype = {
this.adapterInfo_ = null; this.adapterInfo_ = null;
this.devices_ = []; this.devices_ = [];
this.connectResult_ = adapter.AdapterInfo.SUCCESS; this.connectResult_ = adapter.AdapterInfo.SUCCESS;
}; }
TestAdapterProxy.prototype = {
__proto__: TestBrowserProxy.prototype,
connectToDevice: function(address) { connectToDevice(address) {
assert(this.deviceProxyMap.has(address), 'Device does not exist'); assert(this.deviceProxyMap.has(address), 'Device does not exist');
return Promise.resolve({ return Promise.resolve({
...@@ -111,49 +103,48 @@ BluetoothInternalsTest.prototype = { ...@@ -111,49 +103,48 @@ BluetoothInternalsTest.prototype = {
device: this.deviceProxyMap.get( device: this.deviceProxyMap.get(
address).binding.createInterfacePtrAndBind(), address).binding.createInterfacePtrAndBind(),
}); });
}, }
getInfo: function() { getInfo() {
this.methodCalled('getInfo'); this.methodCalled('getInfo');
return Promise.resolve({info: this.adapterInfo_}); return Promise.resolve({info: this.adapterInfo_});
}, }
getDevices: function() { getDevices() {
this.methodCalled('getDevices'); this.methodCalled('getDevices');
return Promise.resolve({devices: this.devices_}); return Promise.resolve({devices: this.devices_});
}, }
setClient: function(client) { setClient(client) {
this.methodCalled('setClient', client); this.methodCalled('setClient', client);
}, }
setTestAdapter: function(adapterInfo) { setTestAdapter(adapterInfo) {
this.adapterInfo_ = adapterInfo; this.adapterInfo_ = adapterInfo;
}, }
setTestConnectResult: function(connectResult) { setTestConnectResult(connectResult) {
this.connectResult_ = connectResult; this.connectResult_ = connectResult;
}, }
setTestDevices: function(devices) { setTestDevices(devices) {
this.devices_ = devices; this.devices_ = devices;
this.devices_.forEach(function(device) { this.devices_.forEach(function(device) {
this.deviceProxyMap.set( this.deviceProxyMap.set(
device.address, new TestDeviceProxy(device)); device.address, new TestDeviceProxy(device));
}, this); }, this);
}, }
}; }
/** /**
* A test Device proxy for the chrome://bluetooth-internals * A test Device proxy for the chrome://bluetooth-internals
* page. Proxies are generated by a TestAdapterProxy which provides * page. Proxies are generated by a TestAdapterProxy which provides
* the DeviceInfo. * the DeviceInfo.
* @constructor
* @extends {TestBrowserProxy}
* @param {!device.DeviceInfo} info * @param {!device.DeviceInfo} info
*/ */
var TestDeviceProxy = function(info) { class TestDeviceProxy extends TestBrowserProxy {
TestBrowserProxy.call(this, [ constructor(info) {
super([
'getInfo', 'getInfo',
'getServices', 'getServices',
]); ]);
...@@ -163,26 +154,23 @@ BluetoothInternalsTest.prototype = { ...@@ -163,26 +154,23 @@ BluetoothInternalsTest.prototype = {
this.services_ = []; this.services_ = [];
} }
TestDeviceProxy.prototype = { disconnect() {
__proto__: TestBrowserProxy.prototype,
disconnect: function() {
this.binding.close(); this.binding.close();
}, }
getInfo: function() { getInfo() {
this.methodCalled('getInfo'); this.methodCalled('getInfo');
return Promise.resolve({info: this.info_}); return Promise.resolve({info: this.info_});
}, }
getServices: function() { getServices() {
this.methodCalled('getServices'); this.methodCalled('getServices');
return Promise.resolve({services: this.services_}); return Promise.resolve({services: this.services_});
}, }
setTestServices: function(services) { setTestServices(services) {
this.services_ = services; this.services_ = services;
}, }
} }
frameInterfaces.addInterfaceOverrideForTesting( frameInterfaces.addInterfaceOverrideForTesting(
...@@ -207,7 +195,6 @@ BluetoothInternalsTest.prototype = { ...@@ -207,7 +195,6 @@ BluetoothInternalsTest.prototype = {
this.setupResolver.resolve(); this.setupResolver.resolve();
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
}.bind(this); }.bind(this);
}, },
......
...@@ -4,13 +4,11 @@ ...@@ -4,13 +4,11 @@
/** /**
* The mock signin.ProfileBrowserProxy. * The mock signin.ProfileBrowserProxy.
*
* @constructor
* @implements {signin.ProfileBrowserProxy} * @implements {signin.ProfileBrowserProxy}
* @extends {TestBrowserProxy}
*/ */
var TestProfileBrowserProxy = function() { class TestProfileBrowserProxy extends TestBrowserProxy {
TestBrowserProxy.call(this, [ constructor() {
super([
'getAvailableIcons', 'getAvailableIcons',
'getSignedInUsers', 'getSignedInUsers',
'launchGuestUser', 'launchGuestUser',
...@@ -36,73 +34,76 @@ var TestProfileBrowserProxy = function() { ...@@ -36,73 +34,76 @@ var TestProfileBrowserProxy = function() {
/** @private {boolean} */ /** @private {boolean} */
this.allProfilesLocked_ = false; this.allProfilesLocked_ = false;
}; }
TestProfileBrowserProxy.prototype = {
__proto__: TestBrowserProxy.prototype,
/** /**
* @param {!Array<!AvatarIcon>} icons * @param {!Array<!AvatarIcon>} icons
*/ */
setIcons: function(icons) { setIcons(icons) {
this.icons_ = icons; this.icons_ = icons;
}, }
/** /**
* @param {!Array<SignedInUser>} signedInUsers * @param {!Array<SignedInUser>} signedInUsers
*/ */
setSignedInUsers: function(signedInUsers) { setSignedInUsers(signedInUsers) {
this.signedInUsers_ = signedInUsers; this.signedInUsers_ = signedInUsers;
}, }
/** /**
* @param {!ProfileInfo} profileInfo * @param {!ProfileInfo} profileInfo
*/ */
setDefaultProfileInfo: function(profileInfo) { setDefaultProfileInfo(profileInfo) {
this.defaultProfileInfo_ = profileInfo; this.defaultProfileInfo_ = profileInfo;
}, }
/** /**
* @param {!Array<SupervisedUser>} supervisedUsers * @param {!Array<SupervisedUser>} supervisedUsers
*/ */
setExistingSupervisedUsers: function(supervisedUsers) { setExistingSupervisedUsers(supervisedUsers) {
this.existingSupervisedUsers_ = supervisedUsers; this.existingSupervisedUsers_ = supervisedUsers;
}, }
/** /**
* @param {boolean} allProfilesLocked * @param {boolean} allProfilesLocked
*/ */
setAllProfilesLocked: function(allProfilesLocked) { setAllProfilesLocked(allProfilesLocked) {
this.allProfilesLocked_ = allProfilesLocked; this.allProfilesLocked_ = allProfilesLocked;
}, }
/** @override */ /** @override */
getAvailableIcons: function() { getAvailableIcons() {
this.methodCalled('getAvailableIcons'); this.methodCalled('getAvailableIcons');
cr.webUIListenerCallback('profile-icons-received', this.icons_); cr.webUIListenerCallback('profile-icons-received', this.icons_);
cr.webUIListenerCallback('profile-defaults-received', cr.webUIListenerCallback('profile-defaults-received',
this.defaultProfileInfo_); this.defaultProfileInfo_);
}, }
/** @override */ /** @override */
getSignedInUsers: function() { getSignedInUsers() {
this.methodCalled('getSignedInUsers'); this.methodCalled('getSignedInUsers');
cr.webUIListenerCallback('signedin-users-received', this.signedInUsers_); cr.webUIListenerCallback('signedin-users-received', this.signedInUsers_);
}, }
/** @override */ /** @override */
cancelCreateProfile: function() { cancelCreateProfile() {
/** /**
* Flag used to test whether this method was not called. * Flag used to test whether this method was not called.
* @type {boolean} * @type {boolean}
*/ */
this.cancelCreateProfileCalled = true; this.cancelCreateProfileCalled = true;
this.methodCalled('cancelCreateProfile'); this.methodCalled('cancelCreateProfile');
}, }
/** @override */ /** @override */
createProfile: function(profileName, profileIconUrl, createShortcut, createProfile(
isSupervised, supervisedUserId, custodianProfilePath) { profileName,
profileIconUrl,
createShortcut,
isSupervised,
supervisedUserId,
custodianProfilePath
) {
this.methodCalled('createProfile', this.methodCalled('createProfile',
{profileName: profileName, {profileName: profileName,
profileIconUrl: profileIconUrl, profileIconUrl: profileIconUrl,
...@@ -110,22 +111,22 @@ TestProfileBrowserProxy.prototype = { ...@@ -110,22 +111,22 @@ TestProfileBrowserProxy.prototype = {
isSupervised: isSupervised, isSupervised: isSupervised,
supervisedUserId: supervisedUserId, supervisedUserId: supervisedUserId,
custodianProfilePath: custodianProfilePath}); custodianProfilePath: custodianProfilePath});
}, }
/** @override */ /** @override */
launchGuestUser: function() { launchGuestUser() {
this.methodCalled('launchGuestUser'); this.methodCalled('launchGuestUser');
}, }
/** @override */ /** @override */
getExistingSupervisedUsers: function() { getExistingSupervisedUsers() {
this.methodCalled('getExistingSupervisedUsers'); this.methodCalled('getExistingSupervisedUsers');
return Promise.resolve(this.existingSupervisedUsers_); return Promise.resolve(this.existingSupervisedUsers_);
}, }
/** @override */ /** @override */
areAllProfilesLocked: function() { areAllProfilesLocked() {
this.methodCalled('areAllProfilesLocked'); this.methodCalled('areAllProfilesLocked');
return Promise.resolve(this.allProfilesLocked_); return Promise.resolve(this.allProfilesLocked_);
}, }
}; }
...@@ -10,15 +10,14 @@ ...@@ -10,15 +10,14 @@
* called, which will trigger callers of |whenCalled| to get notified. * called, which will trigger callers of |whenCalled| to get notified.
* For example: * For example:
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
* var MyTestBrowserProxy = function() { * class MyTestBrowserProxy extends TestBrowserProxy {
* TestBrowserProxy.call(this, ['myMethod']); * constructor() {
* }; * super(['myMethod']);
* MyTestBrowserProxy.prototype = function() { * }
* __proto__: TestBrowserProxy.prototype,
* *
* myMethod: function(someId) { * myMethod(someId) {
* this.methodCalled('myMethod', someId); * this.methodCalled('myMethod', someId);
* }, * }
* }; * };
* *
* // Test code sample * // Test code sample
...@@ -30,18 +29,18 @@ ...@@ -30,18 +29,18 @@
* assertEquals(EXPECTED_ID, id); * assertEquals(EXPECTED_ID, id);
* }); * });
* -------------------------------------------------------------------------- * --------------------------------------------------------------------------
* */
* @constructor class TestBrowserProxy {
/**
* @param {!Array<string>} methodNames Names of all methods whose calls * @param {!Array<string>} methodNames Names of all methods whose calls
* need to be tracked. * need to be tracked.
*/ */
var TestBrowserProxy = function(methodNames) { constructor(methodNames) {
/** @private {!Map<string, !PromiseResolver>} */ /** @private {!Map<string, !PromiseResolver>} */
this.resolverMap_ = new Map(); this.resolverMap_ = new Map();
methodNames.forEach(this.resetResolver, this); methodNames.forEach(this.resetResolver, this);
}; }
TestBrowserProxy.prototype = {
/** /**
* Called by subclasses when a tracked method is called from the code that * Called by subclasses when a tracked method is called from the code that
* is being tested. * is being tested.
...@@ -51,33 +50,33 @@ TestBrowserProxy.prototype = { ...@@ -51,33 +50,33 @@ TestBrowserProxy.prototype = {
* the expected arguments. * the expected arguments.
* @protected * @protected
*/ */
methodCalled: function(methodName, opt_arg) { methodCalled(methodName, opt_arg) {
this.resolverMap_.get(methodName).resolve(opt_arg); this.resolverMap_.get(methodName).resolve(opt_arg);
}, }
/** /**
* @param {string} methodName * @param {string} methodName
* @return {!Promise} A promise that is resolved when the given method * @return {!Promise} A promise that is resolved when the given method
* is called. * is called.
*/ */
whenCalled: function(methodName) { whenCalled(methodName) {
return this.resolverMap_.get(methodName).promise; return this.resolverMap_.get(methodName).promise;
}, }
/** /**
* Resets the PromiseResolver associated with the given method. * Resets the PromiseResolver associated with the given method.
* @param {string} methodName * @param {string} methodName
*/ */
resetResolver: function(methodName) { resetResolver(methodName) {
this.resolverMap_.set(methodName, new PromiseResolver()); this.resolverMap_.set(methodName, new PromiseResolver());
}, }
/** /**
* Resets all PromiseResolvers. * Resets all PromiseResolvers.
*/ */
reset: function() { reset() {
this.resolverMap_.forEach(function(value, methodName) { this.resolverMap_.forEach(function(value, methodName) {
this.resolverMap_.set(methodName, new PromiseResolver()); this.resolverMap_.set(methodName, new PromiseResolver());
}.bind(this)); }.bind(this));
}, }
}; }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment