2016-05-10 22:48:02 +02:00
/ * *
* LightDMMock "class"
*
* @ author Roel Walraven < mail @ cytodev . io >
*
* A LightDM Mock that is tightly based on the source C code of
* Antergos ' lightdm - webkit2 - greeter . Please note that the deprecation errors
* are intrusive for a reason .
*
* Usage :
* Include the file in your theme that needs mocking
* < script type = "text/javascript" src = "mock/LightDMMock.js" > < / s c r i p t >
* Create a new instance of LightDMMock
2016-07-12 23:05:10 +02:00
* if ( ! ( "lightdm" in window ) ) {
* var LightDMMock = LightDMMock || { } ;
* window . lightdm = new LightDMMock ( autofill , timeout , autoGuest ) ;
* }
2016-05-10 22:48:02 +02:00
*
* @ param { boolean } autofill [ wether or not the arrays for users , languages ,
* layouts , and sessions need to be filled with mock
* data . I advise to test both to make your theme
* less prone to crashing . ]
* @ param { number } timeout [ Value to use for simulated autologin ( this value
* is in seconds ) . ]
* @ param { boolean } autoGuest [ Wether or not to simulate automatic guest login .
* This will also enable a guest account
* in lightdm . has _guest _account ]
* /
"use strict" ;
function LightDMMock ( autofill , timeout , autoGuest ) {
this . hostname = null ;
this . users = null ;
2016-07-12 23:51:10 +02:00
this . default _language = null ;
2016-05-10 22:48:02 +02:00
this . language = null ;
this . languages = null ;
2016-07-12 23:51:10 +02:00
this . default _layout = null ;
2016-05-10 22:48:02 +02:00
this . layouts = null ;
this . layout = null ;
this . sessions = null ;
this . num _users = 0 ;
this . default _session = null ;
2016-07-12 23:51:10 +02:00
this . timed _login _user = null ;
this . timed _login _delay = null ;
2016-05-10 22:48:02 +02:00
this . authentication _user = null ;
this . in _authentication = false ;
this . is _authenticated = false ;
this . can _suspend = false ;
this . can _hibernate = false ;
this . can _restart = false ;
this . can _shutdown = false ;
this . lock _hint = false ;
this . has _guest _account = false ;
this . hide _users = false ;
this . select _user = null ;
this . select _guest = false ;
this . autologin _user = null ;
this . autologin _guest = false ;
this . autologin _timeout = 0 ;
2016-07-12 23:51:10 +02:00
if ( typeof autofill === "boolean" && autofill ) {
2016-07-13 00:03:41 +02:00
this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ml0X0lUIiwicmVhbF9uYW1lIjoiQ3Jpc3RvZm9ybyBDb2xvbWJvIiwibGF5b3V0IjpudWxsLCJpbWFnZSI6Im1vY2svY3Jpc3RvY29sb21iby8uZmFjZSIsImhvbWVfZGlyZWN0b3J5IjoibW9jay9jcmlzdG9jb2xvbWJvIiwibmFtZSI6ImNyaXN0b2NvbG9tYm8iLCJsb2dnZWRfaW4iOmZhbHNlLCJzZXNzaW9uIjpudWxsfSx7ImRpc3BsYXlfbmFtZSI6IldpbGxlbSB2YW4gT3JhbmplIiwibGFuZ3VhZ2UiOiJubF9OTCIsInJlYWxfbmFtZSI6IldpbGxlbSB2YW4gT3JhbmplIiwibGF5b3V0IjpudWxsLCJpbWFnZSI6Im1vY2svc2lsZW50d2lsbC8uZmFjZSIsImhvbWVfZGlyZWN0b3J5IjoibW9jay9zaWxlbnR3aWxsIiwibmFtZSI6InNpbGVudHdpbGwiLCJsb2dnZWRfaW4iOmZhbHNlLCJzZXNzaW9uIjpudWxsfSx7ImRpc3BsYXlfbmFtZSI6IkdlbmdoaXMgS2hhbiIsImxhbmd1YWdlIjoibW5fTU4iLCJyZWFsX25hbWUiOiJHZW5naGlzIEtoYW4iLCJsYXlvdXQiOm51bGwsImltYWdlIjoibW9jay9raGFnYW50ZW11amluLy5mYWNlIiwiaG9tZV9kaXJlY3RvcnkiOiJtb2NrL2toYWdhbnRlbXVqaW4iLCJuYW1lIjoia2hhZ2FudGVtdWppbiIsImxvZ2dlZF9pbiI6ZmFsc2UsInNlc3Npb24iOm51bGx9LHsiZGlzcGxheV9uYW1
2016-05-10 22:48:02 +02:00
this . languages = JSON . parse ( atob ( "W3sibmFtZSI6IkVuZ2xpc2giLCJjb2RlIjoiZW4iLCJ0ZXJyaXRvcnkiOm51bGx9XQ==" ) ) ;
this . layouts = JSON . parse ( atob ( " W3sibmFtZSI6InVzIiwic2hvcnRfZGVzY3JpcHRpb24iOiJlbiIsImRlc2NyaXB0aW9uIjoiRW5nbGlzaCAoVVMp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7Im5hbWUiOiJUV00iLCJrZXkiOiJ0d20iLCJjb21tZW50IjoiVGhlIFRhYiBXaW5kb3cgTWFuYWdlciJ9LHsibmFtZSI6IlRpbnl3bSIsImtleSI6InRpbnl3bSIsImNvbW1lbnQiOiJSaWRpY3Vsb3VzbHkgdGlueSB3aW5kb3cgbWFuYWdlciJ9XQ" ) ) ;
this . language = this . languages [ 0 ] . name ;
this . layout = this . layouts [ 0 ] . name ;
this . default _session = this . sessions [ 0 ] . name ;
this . layout = this . layouts [ 0 ] . name ;
this . num _users = this . users . length ;
if ( typeof timeout === "number" && timeout > 0 ) {
2016-07-12 23:51:10 +02:00
if ( typeof autoGuest === "boolean" && autoGuest ) {
this . autologin _user = null ;
this . autologin _guest = autoGuest ;
}
this . autologin _user = this . users [ 0 ] . name ;
2016-05-10 22:48:02 +02:00
this . autologin _timeout = timeout * 1000 ;
setTimeout ( function ( ) {
2016-07-12 23:51:10 +02:00
if ( ( typeof autoGuest === "boolean" && autoGuest ) || this . autologin _user !== null )
2016-05-10 22:48:02 +02:00
window . autologin _timer _expired ( ) ;
} . bind ( this ) , this . timed _login _delay ) ;
}
for ( var i = 0 ; i <= this . users ; i ++ ) {
this . users [ i ] . logged _in = Boolean ( Math . floor ( Math . random ( ) * 2 ) ) ;
this . users [ i ] . session = this . sessions [ Math . floor ( ( Math . random ( ) * this . sessions . length ) ) ] . name ;
}
}
}
/ * *
* Deprecated method .
* /
2016-07-12 23:51:10 +02:00
LightDMMock . prototype . cancel _timed _login = function ( ) {
window . deprecationNotifier ( "method" , "lightdm.cancel_timed_login()" , "lightdm.cancel_autologin()" ) ;
} ;
2016-05-10 22:48:02 +02:00
/ * *
* Cancels the authentication of the autologin user . The older function
* lightdm . cancel _timed _login ( ) has been deprecated .
* /
LightDMMock . prototype . cancel _autologin = function ( ) {
window . checkArguments ( arguments , 0 , [ ] ) ;
this . autologin _user = null ;
this . autologin _guest = false ;
this . autologin _timeout = 0 ;
} ;
/ * *
* Deprecated method .
* /
2016-07-12 23:51:10 +02:00
LightDMMock . prototype . start _authentication = function ( ) {
window . deprecationNotifier ( "method" , "lightdm.start_authentication()" , "lightdm.authenticate(username)" ) ;
} ;
2016-05-10 22:48:02 +02:00
/ * *
* Specifies the username of the user we ' d like to start authenticating as .
* Note that if you call lightdm . authenticate with no argument , LightDM
* ( via PAM ) will issue a show _prompt ( ) call to ask for the username . The
* older function lightdm . start _authentication ( ) has been deprecated .
*
* @ param { String } username [ username to authenticate ]
* /
LightDMMock . prototype . authenticate = function ( username ) {
window . checkArguments ( arguments , 1 , [ "string" ] ) ;
if ( this . in _authentication ) {
window . show _message ( "Already authenticating " + this . authentication _user , "error" ) ;
return ;
}
var exists = false ;
for ( var i = 0 ; i <= this . users . length ; i ++ ) {
if ( this . users . name === username )
exists = true ;
}
if ( ! exists ) {
window . show _message ( "Invalid username" , "error" ) ;
return ;
}
this . authentication _user = username ;
this . in _authentication = true ;
window . show _prompt ( "Password:" , "password" ) ;
} ;
/ * *
* Authenticates as the guest user .
* /
LightDMMock . prototype . authenticate _as _guest = function ( ) {
window . checkArguments ( arguments , 0 , [ ] ) ;
if ( ! this . has _guest _account )
throw new IlligalUsageException ( "Guest accounts are turned off. Make sure you check the value of 'lightdm.has_guest_account' before calling this function." ) ;
if ( this . in _authentication ) {
window . show _message ( "Already authenticating" + this . authentication _user , "error" ) ;
return ;
}
this . authentication _user = "guest" ;
this . in _authentication = true ;
} ;
/ * *
* When LightDM has prompted for input , provide the response to LightDM . The
* deprecated function was "provide_secret" . This is still available for
* backwards compatibility , but authors of greeters should move
* to using lightdm . respond ( ) .
*
* @ param { String } text [ the response to the challange , usually a password ]
* /
LightDMMock . prototype . respond = function ( text ) {
window . checkArguments ( arguments , 1 , [ "string" ] ) ;
if ( ! this . in _authentication )
throw new IlligalUsageException ( "LightDM is currently not in the authentication phase. Make sure to call 'lightdm.authenticate(username)' before calling this function." ) ;
if ( text === "password" ) {
this . is _authenticated = true ;
window . authentication _complete ( ) ;
} else {
window . show _message ( "Invalid password" , "error" ) ;
}
} ;
/ * *
* Deprecated method .
* /
2016-07-12 23:51:10 +02:00
LightDMMock . prototype . provide _secret = function ( ) {
window . deprecationNotifier ( "method" , "lightdm.provide_secret(text)" , "lightdm.respond(text)" ) ;
} ;
2016-05-10 22:48:02 +02:00
/ * *
* Cancels the authentication of any user currently in the
* process of authenticating .
* /
LightDMMock . prototype . cancel _authentication = function ( ) {
window . checkArguments ( arguments , 0 , [ ] ) ;
this . authentication _user = null ;
this . in _authentication = false ;
} ;
/ * *
* Suspends the system , if the greeter has the authority to do so .
* /
LightDMMock . prototype . suspend = function ( ) {
window . checkArguments ( arguments , 0 , [ ] ) ;
if ( ! this . can _suspend )
throw new IlligalUsageException ( "LightDM cannot suspend the system. Make sure you check the value of 'lightdm.can_suspend' before calling this function." ) ;
window . alert ( "System suspended." ) ;
document . location . reload ( true ) ;
} ;
/ * *
* Hibernates the system , if the greeter has the authority to do so .
* /
LightDMMock . prototype . hibernate = function ( ) {
window . checkArguments ( arguments , 0 , [ ] ) ;
if ( ! this . can _hibernate )
throw new IlligalUsageException ( "LightDM cannot hibernate the system. Make sure you check the value of 'lightdm.can_hibernate' before calling this function." ) ;
window . alert ( "System hibernated." ) ;
document . location . reload ( true ) ;
} ;
/ * *
* Shuts down the system , if the greeter has the authority to do so .
* /
LightDMMock . prototype . shutdown = function ( ) {
window . checkArguments ( arguments , 0 , [ ] ) ;
if ( ! this . can _shutdown )
throw new IlligalUsageException ( "LightDM cannot shut down the system. Make sure you check the value of 'lightdm.can_shutdown' before calling this function." ) ;
window . alert ( "System shut down." ) ;
document . location . reload ( true ) ;
} ;
/ * *
* Restarts the system , if the greeter has the authority to do so .
* /
LightDMMock . prototype . restart = function ( ) {
window . checkArguments ( arguments , 0 , [ ] ) ;
if ( ! this . can _restart )
throw new IlligalUsageException ( "LightDM cannot restart the system. Make sure you check the value of 'lightdm.can_restart' before calling this function." ) ;
window . alert ( "System restarted." ) ;
document . location . reload ( true ) ;
} ;
/ * *
* Will set the language for the current LightDM session .
*
* @ param { String } lang [ the language to change to ]
* /
LightDMMock . prototype . set _language = function ( lang ) {
window . checkArguments ( arguments , 1 , [ "string" ] ) ;
this . language = lang ;
} ;
/ * *
* Deprecated method .
* /
2016-07-12 23:51:10 +02:00
LightDMMock . prototype . login = function ( ) {
window . deprecationNotifier ( "method" , "lightdm.login()" , "lightdm.start_session_sync(session)" ) ;
} ;
2016-05-10 22:48:02 +02:00
/ * *
* Once LightDM has successfully authenticated the user , start the user ' s
* session by calling this function . "session" is the authenticated user ' s
* session . If no session is passed , start the authenticated user with the
* system default session . The older function lightdm . login ( user , session )
* has been deprecated .
*
* @ param { String } session [ the session name to start ]
* /
LightDMMock . prototype . start _session _sync = function ( session ) {
window . checkArguments ( arguments , 1 , [ "string" ] ) ;
if ( ! this . in _authentication )
throw new IlligalUsageException ( "LightDM is currently not in the authentication phase. Make sure to call 'lightdm.authenticate(username)' before calling this function." ) ;
if ( ! this . is _authenticated )
throw new IlligalUsageException ( "LightDM has no authenticated users to log in. Make sure to call 'lightdm.respond()' before calling this function." ) ;
window . alert ( "LightDM has started a " + session + " session for " + this . authentication _user ) ;
} ;
/ * *
* Returns the value of a named hint provided by LightDM .
*
* @ param { String } hint _name [ name of the hint to show ]
* /
LightDMMock . prototype . get _hint = function ( hint _name ) {
window . checkArguments ( arguments , 1 , [ "string" ] ) ;
// @fixme: I have no clue how to simulate this...
} ;
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Throwables *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/ * *
* Throwable IlligalUsageException
*
* @ param { string } message [ description of illigal usage ]
* /
function IlligalUsageException ( message ) {
this . name = "IlligalUsageException" ;
this . message = message ;
this . toString = function ( ) {
return "[" + this . name + "] " + this . message ;
} ;
}
/ * *
* Throwable DeprecationException
*
* @ param { String } type [ method || property ]
2016-07-12 23:51:10 +02:00
* @ param { String } depricated [ deprecated method or property name ]
2016-05-10 22:48:02 +02:00
* @ param { String } alternative [ alternative method or property to use ]
* /
2016-07-12 23:51:10 +02:00
function DeprecationException ( type , deprecated , alternative ) {
2016-05-10 22:48:02 +02:00
this . name = "DeprecationException" ;
2016-07-12 23:51:10 +02:00
this . message = "The " + type + " '" + deprecated + "' is deprecated. Consider using '" + alternative + "' instead." ;
2016-05-10 22:48:02 +02:00
this . toString = function ( ) {
return "[" + this . name + "] " + this . message ;
} ;
}
/ * *
* Throwable IncompatibleArgumentCountException
*
* @ param { Number } expected [ expected length of arguments ]
* @ param { Number } received [ found length of arguments ]
* /
function IncompatibleArgumentCountException ( expected , received ) {
this . name = "IncompatibleArgumentCountException" ;
this . message = "Incorrect number of arguments in function call. Expected " + expected + ", found " + received ;
this . toString = function ( ) {
return "[" + this . name + "] " + this . message ;
} ;
}
/ * *
* Throwable IncompatibleArgumentTypesException
*
* @ param { Number } type [ argument number ( non - zero ) ]
* @ param { String } expected [ expected type ]
* @ param { String } received [ found type ]
* /
function IncompatibleArgumentTypesException ( number , expected , received ) {
this . name = "IncompatibleArgumentTypesException" ;
this . message = "Argument " + number + " is of a wrong type. Expected '" + expected + "', found '" + received + "'" ;
this . toString = function ( ) {
return "[" + this . name + "] " + this . message ;
} ;
}
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Helpers *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/ * *
* global helper deprecationNotifier
* throws ~ balls ~ errors at users who use deprecated methods and properties .
*
* @ param { String } type [ method || property ]
2016-07-12 23:51:10 +02:00
* @ param { String } depricated [ deprecated method or property name ]
2016-05-10 22:48:02 +02:00
* @ param { String } alternative [ alternative method or property to use ]
*
* @ throws { DeprecationException }
* /
2016-07-12 23:51:10 +02:00
window . deprecationNotifier = function ( type , deprecated , alternative ) {
throw new DeprecationException ( type , deprecated , alternative ) ;
2016-05-10 22:48:02 +02:00
} ;
/ * *
* global helper checkArguments
* throws ~ tables ~ errors at users who call methods
* with erroneous arguments .
*
* @ param { Array } args [ the arguments passed to the original method ]
* @ param { Number } length [ the expected amount of arguments ]
* @ param { Arrray } types [ the expected types of the arguments ]
*
* @ throws { IncompatibleArgumentTypesException }
* /
window . checkArguments = function ( args , length , types ) {
2016-07-13 00:09:51 +02:00
if ( args . length !== length )
throw new IncompatibleArgumentCountException ( length , args . length ) ;
2016-05-10 22:48:02 +02:00
for ( var i = 1 ; i <= types . length ; i ++ ) {
if ( typeof args [ i ] !== types [ i - 1 ] )
throw new IncompatibleArgumentTypesException ( i , types [ i - 1 ] , typeof args [ i ] ) ;
}
} ;
2016-07-12 23:51:10 +02:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Object . watch shim *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2016-08-04 15:20:23 +02:00
/ *
* object . watch polyfill
*
* 2012 - 04 - 03
*
* By Eli Grey , http : //eligrey.com
* Public Domain .
* NO WARRANTY EXPRESSED OR IMPLIED . USE AT YOUR OWN RISK .
* /
// object.watch
if ( ! Object . prototype . watch ) {
Object . defineProperty ( Object . prototype , "watch" , {
enumerable : false ,
configurable : true ,
writable : false ,
value : function ( prop , handler ) {
var oldval = this [ prop ] ,
newval = oldval ,
getter = function ( ) {
return newval ;
} ,
setter = function ( val ) {
oldval = newval ;
newval = handler . call ( this , prop , oldval , val ) ;
return newval ;
} ;
if ( delete this [ prop ] ) { // can't watch constants
Object . defineProperty ( this , prop , {
get : getter ,
set : setter ,
enumerable : true ,
configurable : true
} ) ;
}
2016-07-12 23:51:10 +02:00
}
2016-08-04 15:20:23 +02:00
} ) ;
2016-07-12 23:51:10 +02:00
}
2016-08-04 15:20:23 +02:00
// object.unwatch
2016-07-12 23:51:10 +02:00
if ( ! Object . prototype . unwatch ) {
2016-08-04 15:20:23 +02:00
Object . defineProperty ( Object . prototype , "unwatch" , {
enumerable : false ,
configurable : true ,
writable : false ,
value : function ( prop ) {
var val = this [ prop ] ;
delete this [ prop ] ; // remove accessors
this [ prop ] = val ;
}
} ) ;
2016-07-12 23:51:10 +02:00
}
LightDMMock . watch ( 'default_language' , function ( ) {
window . deprecationNotifier ( "property" , "default_language" , "lightdm.language" ) ;
} ) ;
LightDMMock . watch ( 'default_layout' , function ( ) {
window . deprecationNotifier ( "property" , "default_layout" , "lightdm.layout" ) ;
} ) ;
LightDMMock . watch ( 'timed_login_user' , function ( ) {
window . deprecationNotifier ( "property" , "timed_login_user" , "lightdm.autologin_user" ) ;
} ) ;
LightDMMock . watch ( 'timed_login_delay' , function ( ) {
window . deprecationNotifier ( "property" , "timed_login_delay" , "lightdm.autologin_timeout" ) ;
} ) ;