3
0
mirror of https://github.com/cytodev/LightDMMock.git synced 2024-11-28 17:09:47 +01:00

Adds logCall function

Helps to debug a lightdm js script.
This commit is contained in:
Roel Walraven 2016-08-04 16:50:31 +02:00
parent f8ccaab454
commit 249777f9f7

View File

@ -95,6 +95,7 @@ function LightDMMock(autofill, timeout, autoGuest) {
* Deprecated method. * Deprecated method.
*/ */
LightDMMock.prototype.cancel_timed_login = function() { LightDMMock.prototype.cancel_timed_login = function() {
window.logCall("cancel_timed_login", arguments);
window.deprecationNotifier("method", "lightdm.cancel_timed_login()", "lightdm.cancel_autologin()"); window.deprecationNotifier("method", "lightdm.cancel_timed_login()", "lightdm.cancel_autologin()");
}; };
@ -103,6 +104,7 @@ LightDMMock.prototype.cancel_timed_login = function() {
* lightdm.cancel_timed_login() has been deprecated. * lightdm.cancel_timed_login() has been deprecated.
*/ */
LightDMMock.prototype.cancel_autologin = function() { LightDMMock.prototype.cancel_autologin = function() {
window.logCall("cancel_autologin", arguments);
window.checkArguments(arguments, 0, []); window.checkArguments(arguments, 0, []);
this.autologin_user = null; this.autologin_user = null;
@ -114,6 +116,7 @@ LightDMMock.prototype.cancel_autologin = function() {
* Deprecated method. * Deprecated method.
*/ */
LightDMMock.prototype.start_authentication = function() { LightDMMock.prototype.start_authentication = function() {
window.logCall("start_authentication", arguments);
window.deprecationNotifier("method", "lightdm.start_authentication()", "lightdm.authenticate(username)"); window.deprecationNotifier("method", "lightdm.start_authentication()", "lightdm.authenticate(username)");
}; };
@ -126,6 +129,7 @@ LightDMMock.prototype.start_authentication = function() {
* @param {String} username [username to authenticate] * @param {String} username [username to authenticate]
*/ */
LightDMMock.prototype.authenticate = function(username) { LightDMMock.prototype.authenticate = function(username) {
window.logCall("authenticate", arguments);
window.checkArguments(arguments, 1, ["string"]); window.checkArguments(arguments, 1, ["string"]);
if(this.in_authentication) { if(this.in_authentication) {
@ -155,6 +159,7 @@ LightDMMock.prototype.authenticate = function(username) {
* Authenticates as the guest user. * Authenticates as the guest user.
*/ */
LightDMMock.prototype.authenticate_as_guest = function() { LightDMMock.prototype.authenticate_as_guest = function() {
window.logCall("authenticate_as_guest", arguments);
window.checkArguments(arguments, 0, []); window.checkArguments(arguments, 0, []);
if(!this.has_guest_account) if(!this.has_guest_account)
@ -178,6 +183,7 @@ LightDMMock.prototype.authenticate_as_guest = function() {
* @param {String} text [the response to the challange, usually a password] * @param {String} text [the response to the challange, usually a password]
*/ */
LightDMMock.prototype.respond = function(text) { LightDMMock.prototype.respond = function(text) {
window.logCall("respond", arguments);
window.checkArguments(arguments, 1, ["string"]); window.checkArguments(arguments, 1, ["string"]);
if(!this.in_authentication) if(!this.in_authentication)
@ -195,6 +201,7 @@ LightDMMock.prototype.respond = function(text) {
* Deprecated method. * Deprecated method.
*/ */
LightDMMock.prototype.provide_secret = function() { LightDMMock.prototype.provide_secret = function() {
window.logCall("provide_secret", arguments);
window.deprecationNotifier("method", "lightdm.provide_secret(text)", "lightdm.respond(text)"); window.deprecationNotifier("method", "lightdm.provide_secret(text)", "lightdm.respond(text)");
}; };
@ -203,6 +210,7 @@ LightDMMock.prototype.provide_secret = function() {
* process of authenticating. * process of authenticating.
*/ */
LightDMMock.prototype.cancel_authentication = function() { LightDMMock.prototype.cancel_authentication = function() {
window.logCall("cancel_authentication", arguments);
window.checkArguments(arguments, 0, []); window.checkArguments(arguments, 0, []);
this.authentication_user = null; this.authentication_user = null;
@ -213,6 +221,7 @@ LightDMMock.prototype.cancel_authentication = function() {
* Suspends the system, if the greeter has the authority to do so. * Suspends the system, if the greeter has the authority to do so.
*/ */
LightDMMock.prototype.suspend = function() { LightDMMock.prototype.suspend = function() {
window.logCall("suspend", arguments);
window.checkArguments(arguments, 0, []); window.checkArguments(arguments, 0, []);
if(!this.can_suspend) if(!this.can_suspend)
@ -226,6 +235,7 @@ LightDMMock.prototype.suspend = function() {
* Hibernates the system, if the greeter has the authority to do so. * Hibernates the system, if the greeter has the authority to do so.
*/ */
LightDMMock.prototype.hibernate = function() { LightDMMock.prototype.hibernate = function() {
window.logCall("hibernate", arguments);
window.checkArguments(arguments, 0, []); window.checkArguments(arguments, 0, []);
if(!this.can_hibernate) if(!this.can_hibernate)
@ -239,6 +249,7 @@ LightDMMock.prototype.hibernate = function() {
* Shuts down the system, if the greeter has the authority to do so. * Shuts down the system, if the greeter has the authority to do so.
*/ */
LightDMMock.prototype.shutdown = function() { LightDMMock.prototype.shutdown = function() {
window.logCall("shutdown", arguments);
window.checkArguments(arguments, 0, []); window.checkArguments(arguments, 0, []);
if(!this.can_shutdown) if(!this.can_shutdown)
@ -252,6 +263,7 @@ LightDMMock.prototype.shutdown = function() {
* Restarts the system, if the greeter has the authority to do so. * Restarts the system, if the greeter has the authority to do so.
*/ */
LightDMMock.prototype.restart = function() { LightDMMock.prototype.restart = function() {
window.logCall("restart", arguments);
window.checkArguments(arguments, 0, []); window.checkArguments(arguments, 0, []);
if(!this.can_restart) if(!this.can_restart)
@ -267,6 +279,7 @@ LightDMMock.prototype.restart = function() {
* @param {String} lang [the language to change to] * @param {String} lang [the language to change to]
*/ */
LightDMMock.prototype.set_language = function(lang) { LightDMMock.prototype.set_language = function(lang) {
window.logCall("set_language", arguments);
window.checkArguments(arguments, 1, ["string"]); window.checkArguments(arguments, 1, ["string"]);
this.language = lang; this.language = lang;
@ -276,6 +289,7 @@ LightDMMock.prototype.set_language = function(lang) {
* Deprecated method. * Deprecated method.
*/ */
LightDMMock.prototype.login = function() { LightDMMock.prototype.login = function() {
window.logCall("login", arguments);
window.deprecationNotifier("method", "lightdm.login()", "lightdm.start_session_sync(session)"); window.deprecationNotifier("method", "lightdm.login()", "lightdm.start_session_sync(session)");
}; };
@ -289,6 +303,7 @@ LightDMMock.prototype.login = function() {
* @param {String} session [the session name to start] * @param {String} session [the session name to start]
*/ */
LightDMMock.prototype.start_session_sync = function(session) { LightDMMock.prototype.start_session_sync = function(session) {
window.logCall("start_session_sync", arguments);
window.checkArguments(arguments, 1, ["string"]); window.checkArguments(arguments, 1, ["string"]);
if(!this.in_authentication) if(!this.in_authentication)
@ -306,6 +321,7 @@ LightDMMock.prototype.start_session_sync = function(session) {
* @param {String} hint_name [name of the hint to show] * @param {String} hint_name [name of the hint to show]
*/ */
LightDMMock.prototype.get_hint = function(hint_name) { LightDMMock.prototype.get_hint = function(hint_name) {
window.logCall("get_hint", arguments);
window.checkArguments(arguments, 1, ["string"]); window.checkArguments(arguments, 1, ["string"]);
// @fixme: I have no clue how to simulate this... // @fixme: I have no clue how to simulate this...
@ -413,6 +429,32 @@ window.checkArguments = function(args, length, types) {
} }
}; };
/**
* global helper logCall
* logs a function call with the arguments provided to help with debugging a
* lightdm js script.
*
* @param {String} name [called function name]
* @param {Array} args [called function arguments]
*
* @return {window.console.info}
*/
window.logCall = function(name, args) {
var argv = [];
if(args !== undefined && args.length !== 0) {
for(var i = 0; i <= args.length; i++) {
if(args[i] !== undefined)
argv.push({type: typeof args[i], value: args[i]});
}
}
if(argv.length > 0)
return window.console.info("[lightdm." + name + "] called with " + argv.length + " argument(s)", argv);
return window.console.info("[lightdm." + name + "] called with 0 arguments");
};
/****************************************************************************** /******************************************************************************
* Object.watch shim * * Object.watch shim *