Skip to content

Commit

Permalink
Merge pull request #129 from cwmrowe/feature/Always_allow_interrupt_f…
Browse files Browse the repository at this point in the history
…rom_another_tab

Always allow interrupt when initiated by a change in session expiry date from another tab
  • Loading branch information
moribvndvs committed Dec 8, 2015
2 parents f8fab28 + 61aee73 commit f11caba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/idle/idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])

stopKeepalive();
},
interrupt: function(noExpiryUpdate) {
interrupt: function(anotherTab) {
if (!state.running) return;

if (options.timeout && this.isExpired()) {
Expand All @@ -198,7 +198,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
}

// note: you can no longer auto resume once we exceed the expiry; you will reset state by calling watch() manually
if (options.autoResume === 'idle' || (options.autoResume === 'notIdle' && !state.idling)) this.watch(noExpiryUpdate);
if (anotherTab || options.autoResume === 'idle' || (options.autoResume === 'notIdle' && !state.idling)) this.watch(anotherTab);
}
};

Expand Down
17 changes: 17 additions & 0 deletions src/idle/idle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,23 @@ describe('ngIdle', function() {
Idle.interrupt();
expect(Idle.watch).not.toHaveBeenCalled();
});

it ('interrupt(true) should call watch() if idle and autoResume is notIdle', function() {
IdleProvider.autoResume('notIdle');
Idle = create();

spyOn(Idle, 'watch').andCallThrough();

// arrange
Idle.watch(); // start watching
Idle.watch.reset(); // reset watch spy to ignore the prior setup call

$interval.flush(DEFAULTIDLEDURATION);

Idle.interrupt(true);
expect(Idle.watch).toHaveBeenCalled();
});

});

describe('Idle with timeout disabled', function() {
Expand Down

0 comments on commit f11caba

Please sign in to comment.