@@ -841,11 +841,13 @@ var Protractor = function(webdriverInstance, opt_baseUrl, opt_rootElement) {
841
841
*/
842
842
this . params = { } ;
843
843
844
- this . moduleNames_ = [ ] ;
845
-
846
- this . moduleScripts_ = [ ] ;
847
-
848
- this . moduleArgs_ = [ ] ;
844
+ /**
845
+ * Information about mock modules that will be installed during every
846
+ * get().
847
+ *
848
+ * @type {Array<{name: string, script: function|string, args: Array.<string>}> }
849
+ */
850
+ this . mockModules_ = [ ] ;
849
851
} ;
850
852
851
853
/**
@@ -930,30 +932,32 @@ Protractor.prototype.isElementPresent = function(locatorOrElement) {
930
932
* the script and may be referenced using the `arguments` object.
931
933
*/
932
934
Protractor . prototype . addMockModule = function ( name , script ) {
933
- this . moduleNames_ . push ( name ) ;
934
- this . moduleScripts_ . push ( script ) ;
935
935
var moduleArgs = Array . prototype . slice . call ( arguments , 2 ) ;
936
- this . moduleArgs_ . push ( moduleArgs ) ;
936
+
937
+ this . mockModules_ . push ( {
938
+ name : name ,
939
+ script : script ,
940
+ args : moduleArgs
941
+ } ) ;
937
942
} ;
938
943
939
944
/**
940
945
* Clear the list of registered mock modules.
941
946
*/
942
947
Protractor . prototype . clearMockModules = function ( ) {
943
- this . moduleNames_ = [ ] ;
944
- this . moduleScripts_ = [ ] ;
945
- this . moduleArgs_ = [ ] ;
948
+ this . mockModules_ = [ ] ;
946
949
} ;
947
950
948
951
/**
949
952
* Remove a registered mock module.
950
953
* @param {!string } name The name of the module to remove.
951
954
*/
952
955
Protractor . prototype . removeMockModule = function ( name ) {
953
- var index = this . moduleNames_ . indexOf ( name ) ;
954
- this . moduleNames_ . splice ( index , 1 ) ;
955
- this . moduleScripts_ . splice ( index , 1 ) ;
956
- this . moduleArgs_ . splice ( index , 1 ) ;
956
+ for ( var i = 0 ; i < this . mockModules_ . length ; ++ i ) {
957
+ if ( this . mockModules_ [ i ] . name == name ) {
958
+ this . mockModules_ . splice ( i , 1 ) ;
959
+ }
960
+ }
957
961
} ;
958
962
959
963
/**
@@ -1020,20 +1024,22 @@ Protractor.prototype.get = function(destination, opt_timeout) {
1020
1024
1021
1025
// At this point, Angular will pause for us, until angular.resumeBootstrap
1022
1026
// is called.
1023
- for ( var i = 0 ; i < this . moduleScripts_ . length ; ++ i ) {
1024
- var name = this . moduleNames_ [ i ] ;
1025
- var executeScriptArgs = [ this . moduleScripts_ [ i ] ] .
1026
- concat ( this . moduleArgs_ [ i ] ) ;
1027
+ var moduleNames = [ ] ;
1028
+ for ( var i = 0 ; i < this . mockModules_ . length ; ++ i ) {
1029
+ var mockModule = this . mockModules_ [ i ] ;
1030
+ var name = mockModule . name ;
1031
+ moduleNames . push ( name ) ;
1032
+ var executeScriptArgs = [ mockModule . script ] . concat ( mockModule . args ) ;
1027
1033
this . driver . executeScript . apply ( this , executeScriptArgs ) .
1028
- then ( null , function ( err ) {
1029
- throw 'Error wile running module script ' + name +
1030
- ': ' + err . message ;
1031
- } ) ;
1034
+ then ( null , function ( err ) {
1035
+ throw 'Error wile running module script ' + name +
1036
+ ': ' + err . message ;
1037
+ } ) ;
1032
1038
}
1033
1039
1034
1040
return this . driver . executeScript (
1035
1041
'angular.resumeBootstrap(arguments[0]);' ,
1036
- this . moduleNames_ ) ;
1042
+ moduleNames ) ;
1037
1043
} ;
1038
1044
1039
1045
/**
0 commit comments