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,24 +55,20 @@ BluetoothInternalsTest.prototype = {
/**
* A test adapter factory proxy for the chrome://bluetooth-internals
* page.
*
* @constructor
* @extends {TestBrowserProxy}
*/
var TestAdapterFactoryProxy = function() {
TestBrowserProxy.call(this, [
'getAdapter',
]);
this.binding = new bindings.Binding(adapter.AdapterFactory, this);
this.adapter = new TestAdapterProxy();
this.adapterBinding_ = new bindings.Binding(adapter.Adapter,
this.adapter);
};
TestAdapterFactoryProxy.prototype = {
__proto__: TestBrowserProxy.prototype,
getAdapter: function() {
class TestAdapterFactoryProxy extends TestBrowserProxy {
constructor() {
super([
'getAdapter',
]);
this.binding = new bindings.Binding(adapter.AdapterFactory, this);
this.adapter = new TestAdapterProxy();
this.adapterBinding_ = new bindings.Binding(adapter.Adapter,
this.adapter);
}
getAdapter() {
this.methodCalled('getAdapter');
// Create message pipe bound to TestAdapter.
......@@ -80,30 +76,26 @@ BluetoothInternalsTest.prototype = {
adapter: this.adapterBinding_.createInterfacePtrAndBind(),
});
}
};
}
/**
* A test adapter proxy for the chrome://bluetooth-internals page.
* @constructor
* @extends {TestBrowserProxy}
*/
var TestAdapterProxy = function() {
TestBrowserProxy.call(this, [
'getInfo',
'getDevices',
'setClient',
]);
this.deviceProxyMap = new Map();
this.adapterInfo_ = null;
this.devices_ = [];
this.connectResult_ = adapter.AdapterInfo.SUCCESS;
};
TestAdapterProxy.prototype = {
__proto__: TestBrowserProxy.prototype,
connectToDevice: function(address) {
class TestAdapterProxy extends TestBrowserProxy {
constructor() {
super([
'getInfo',
'getDevices',
'setClient',
]);
this.deviceProxyMap = new Map();
this.adapterInfo_ = null;
this.devices_ = [];
this.connectResult_ = adapter.AdapterInfo.SUCCESS;
}
connectToDevice(address) {
assert(this.deviceProxyMap.has(address), 'Device does not exist');
return Promise.resolve({
......@@ -111,78 +103,74 @@ BluetoothInternalsTest.prototype = {
device: this.deviceProxyMap.get(
address).binding.createInterfacePtrAndBind(),
});
},
}
getInfo: function() {
getInfo() {
this.methodCalled('getInfo');
return Promise.resolve({info: this.adapterInfo_});
},
}
getDevices: function() {
getDevices() {
this.methodCalled('getDevices');
return Promise.resolve({devices: this.devices_});
},
}
setClient: function(client) {
setClient(client) {
this.methodCalled('setClient', client);
},
}
setTestAdapter: function(adapterInfo) {
setTestAdapter(adapterInfo) {
this.adapterInfo_ = adapterInfo;
},
}
setTestConnectResult: function(connectResult) {
setTestConnectResult(connectResult) {
this.connectResult_ = connectResult;
},
}
setTestDevices: function(devices) {
setTestDevices(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 {TestBrowserProxy}
* @param {!device.DeviceInfo} info
*/
var TestDeviceProxy = function(info) {
TestBrowserProxy.call(this, [
'getInfo',
'getServices',
]);
this.binding = new bindings.Binding(device.Device, this);
this.info_ = info;
this.services_ = [];
}
TestDeviceProxy.prototype = {
__proto__: TestBrowserProxy.prototype,
class TestDeviceProxy extends TestBrowserProxy {
constructor(info) {
super([
'getInfo',
'getServices',
]);
this.binding = new bindings.Binding(device.Device, this);
this.info_ = info;
this.services_ = [];
}
disconnect: function() {
disconnect() {
this.binding.close();
},
}
getInfo: function() {
getInfo() {
this.methodCalled('getInfo');
return Promise.resolve({info: this.info_});
},
}
getServices: function() {
getServices() {
this.methodCalled('getServices');
return Promise.resolve({services: this.services_});
},
}
setTestServices: function(services) {
setTestServices(services) {
this.services_ = services;
},
}
}
frameInterfaces.addInterfaceOverrideForTesting(
......@@ -207,7 +195,6 @@ BluetoothInternalsTest.prototype = {
this.setupResolver.resolve();
}.bind(this));
}.bind(this));
}.bind(this);
},
......
......@@ -4,105 +4,106 @@
/**
* The mock signin.ProfileBrowserProxy.
*
* @constructor
* @implements {signin.ProfileBrowserProxy}
* @extends {TestBrowserProxy}
*/
var TestProfileBrowserProxy = function() {
TestBrowserProxy.call(this, [
'getAvailableIcons',
'getSignedInUsers',
'launchGuestUser',
'createProfile',
'cancelCreateProfile',
'initializeUserManager',
'launchUser',
'getExistingSupervisedUsers',
'areAllProfilesLocked',
]);
/** @private {!Array<!AvatarIcon>} */
this.icons_ = [];
/** @private {!Array<SignedInUser>} */
this.signedInUsers_ = [];
/** @private {!ProfileInfo} */
this.defaultProfileInfo_ = {};
/** @private {!Array<SupervisedUser>} */
this.existingSupervisedUsers_ = [];
/** @private {boolean} */
this.allProfilesLocked_ = false;
};
TestProfileBrowserProxy.prototype = {
__proto__: TestBrowserProxy.prototype,
class TestProfileBrowserProxy extends TestBrowserProxy {
constructor() {
super([
'getAvailableIcons',
'getSignedInUsers',
'launchGuestUser',
'createProfile',
'cancelCreateProfile',
'initializeUserManager',
'launchUser',
'getExistingSupervisedUsers',
'areAllProfilesLocked',
]);
/** @private {!Array<!AvatarIcon>} */
this.icons_ = [];
/** @private {!Array<SignedInUser>} */
this.signedInUsers_ = [];
/** @private {!ProfileInfo} */
this.defaultProfileInfo_ = {};
/** @private {!Array<SupervisedUser>} */
this.existingSupervisedUsers_ = [];
/** @private {boolean} */
this.allProfilesLocked_ = false;
}
/**
* @param {!Array<!AvatarIcon>} icons
*/
setIcons: function(icons) {
setIcons(icons) {
this.icons_ = icons;
},
}
/**
* @param {!Array<SignedInUser>} signedInUsers
*/
setSignedInUsers: function(signedInUsers) {
setSignedInUsers(signedInUsers) {
this.signedInUsers_ = signedInUsers;
},
}
/**
* @param {!ProfileInfo} profileInfo
*/
setDefaultProfileInfo: function(profileInfo) {
setDefaultProfileInfo(profileInfo) {
this.defaultProfileInfo_ = profileInfo;
},
}
/**
* @param {!Array<SupervisedUser>} supervisedUsers
*/
setExistingSupervisedUsers: function(supervisedUsers) {
setExistingSupervisedUsers(supervisedUsers) {
this.existingSupervisedUsers_ = supervisedUsers;
},
}
/**
* @param {boolean} allProfilesLocked
*/
setAllProfilesLocked: function(allProfilesLocked) {
setAllProfilesLocked(allProfilesLocked) {
this.allProfilesLocked_ = allProfilesLocked;
},
}
/** @override */
getAvailableIcons: function() {
getAvailableIcons() {
this.methodCalled('getAvailableIcons');
cr.webUIListenerCallback('profile-icons-received', this.icons_);
cr.webUIListenerCallback('profile-defaults-received',
this.defaultProfileInfo_);
},
}
/** @override */
getSignedInUsers: function() {
getSignedInUsers() {
this.methodCalled('getSignedInUsers');
cr.webUIListenerCallback('signedin-users-received', this.signedInUsers_);
},
}
/** @override */
cancelCreateProfile: function() {
cancelCreateProfile() {
/**
* Flag used to test whether this method was not called.
* @type {boolean}
*/
this.cancelCreateProfileCalled = true;
this.methodCalled('cancelCreateProfile');
},
}
/** @override */
createProfile: function(profileName, profileIconUrl, createShortcut,
isSupervised, supervisedUserId, custodianProfilePath) {
createProfile(
profileName,
profileIconUrl,
createShortcut,
isSupervised,
supervisedUserId,
custodianProfilePath
) {
this.methodCalled('createProfile',
{profileName: profileName,
profileIconUrl: profileIconUrl,
......@@ -110,22 +111,22 @@ TestProfileBrowserProxy.prototype = {
isSupervised: isSupervised,
supervisedUserId: supervisedUserId,
custodianProfilePath: custodianProfilePath});
},
}
/** @override */
launchGuestUser: function() {
launchGuestUser() {
this.methodCalled('launchGuestUser');
},
}
/** @override */
getExistingSupervisedUsers: function() {
getExistingSupervisedUsers() {
this.methodCalled('getExistingSupervisedUsers');
return Promise.resolve(this.existingSupervisedUsers_);
},
}
/** @override */
areAllProfilesLocked: function() {
areAllProfilesLocked() {
this.methodCalled('areAllProfilesLocked');
return Promise.resolve(this.allProfilesLocked_);
},
};
}
}
......@@ -10,15 +10,14 @@
* called, which will trigger callers of |whenCalled| to get notified.
* For example:
* --------------------------------------------------------------------------
* var MyTestBrowserProxy = function() {
* TestBrowserProxy.call(this, ['myMethod']);
* };
* MyTestBrowserProxy.prototype = function() {
* __proto__: TestBrowserProxy.prototype,
* class MyTestBrowserProxy extends TestBrowserProxy {
* constructor() {
* super(['myMethod']);
* }
*
* myMethod: function(someId) {
* myMethod(someId) {
* this.methodCalled('myMethod', someId);
* },
* }
* };
*
* // Test code sample
......@@ -30,18 +29,18 @@
* assertEquals(EXPECTED_ID, id);
* });
* --------------------------------------------------------------------------
*
* @constructor
* @param {!Array<string>} methodNames Names of all methods whose calls
* need to be tracked.
*/
var TestBrowserProxy = function(methodNames) {
/** @private {!Map<string, !PromiseResolver>} */
this.resolverMap_ = new Map();
methodNames.forEach(this.resetResolver, this);
};
class TestBrowserProxy {
/**
* @param {!Array<string>} methodNames Names of all methods whose calls
* need to be tracked.
*/
constructor(methodNames) {
/** @private {!Map<string, !PromiseResolver>} */
this.resolverMap_ = new Map();
methodNames.forEach(this.resetResolver, this);
}
TestBrowserProxy.prototype = {
/**
* Called by subclasses when a tracked method is called from the code that
* is being tested.
......@@ -51,33 +50,33 @@ TestBrowserProxy.prototype = {
* the expected arguments.
* @protected
*/
methodCalled: function(methodName, opt_arg) {
methodCalled(methodName, opt_arg) {
this.resolverMap_.get(methodName).resolve(opt_arg);
},
}
/**
* @param {string} methodName
* @return {!Promise} A promise that is resolved when the given method
* is called.
*/
whenCalled: function(methodName) {
whenCalled(methodName) {
return this.resolverMap_.get(methodName).promise;
},
}
/**
* Resets the PromiseResolver associated with the given method.
* @param {string} methodName
*/
resetResolver: function(methodName) {
resetResolver(methodName) {
this.resolverMap_.set(methodName, new PromiseResolver());
},
}
/**
* Resets all PromiseResolvers.
*/
reset: function() {
reset() {
this.resolverMap_.forEach(function(value, methodName) {
this.resolverMap_.set(methodName, new PromiseResolver());
}.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