@@ -73,6 +73,7 @@ export class CoreAppProvider {
7373 protected backActions = [ ] ;
7474 protected mainMenuId = 0 ;
7575 protected mainMenuOpen : number ;
76+ protected forceOffline = false ;
7677
7778 constructor ( dbProvider : CoreDbProvider , private platform : Platform , private keyboard : Keyboard , private appCtrl : App ,
7879 private network : Network , logger : CoreLoggerProvider , private events : CoreEventsProvider , zone : NgZone ,
@@ -102,6 +103,9 @@ export class CoreAppProvider {
102103 this . platform . registerBackButtonAction ( ( ) => {
103104 this . backButtonAction ( ) ;
104105 } , 100 ) ;
106+
107+ // Export the app provider so Behat tests can change the forceOffline flag.
108+ ( < any > window ) . appProvider = this ;
105109 }
106110
107111 /**
@@ -257,6 +261,10 @@ export class CoreAppProvider {
257261 * @return {boolean } Whether the app is online.
258262 */
259263 isOnline ( ) : boolean {
264+ if ( this . forceOffline ) {
265+ return false ;
266+ }
267+
260268 let online = this . network . type !== null && this . network . type != Connection . NONE && this . network . type != Connection . UNKNOWN ;
261269 // Double check we are not online because we cannot rely 100% in Cordova APIs. Also, check it in browser.
262270 if ( ! online && navigator . onLine ) {
@@ -567,4 +575,13 @@ export class CoreAppProvider {
567575 this . statusBar . styleLightContent ( ) : this . statusBar . styleDefault ( ) ;
568576 }
569577 }
578+
579+ /**
580+ * Set value of forceOffline flag. If true, the app will think the device is offline.
581+ *
582+ * @param {boolean } value Value to set.
583+ */
584+ setForceOffline ( value : boolean ) : void {
585+ this . forceOffline = ! ! value ;
586+ }
570587}
0 commit comments