Skip to content

Commit

Permalink
fix(idle): check expiry on timeout doCountdown
Browse files Browse the repository at this point in the history
[On behalf of Lexmark International, Inc] Check expiry in docountdown to see if it has changed and if so interrupt. For multi-tab support.
  • Loading branch information
markmaynard authored and grbsk committed Mar 7, 2017
1 parent 753afad commit e23233d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions modules/core/src/idle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,27 @@ describe('core/Idle', () => {
instance.stop();
}));

it('emits an onInterrupt event when the countdown ticks and expiry last has been updated', fakeAsync(() => {
spyOn(instance.onInterrupt, 'emit').and.callThrough();

instance.setTimeout(3);
expiry.mockNow = new Date();
instance.watch();

expiry.mockNow = new Date(expiry.now().getTime() + instance.getIdle() * 1000);
tick(3000);
expect(instance.isIdling()).toBe(true);

tick(1000); // going once
tick(1000); // going twice
expiry.last(new Date(expiry.now().getTime() + 6000));
tick(1000); // going thrice

expect(instance.onInterrupt.emit).toHaveBeenCalledTimes(1);

instance.stop();
}));

it('does not emit an onTimeoutWarning when timeout is disabled', fakeAsync(() => {
spyOn(instance.onTimeoutWarning, 'emit').and.callThrough();

Expand Down
9 changes: 9 additions & 0 deletions modules/core/src/idle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ export class Idle implements OnDestroy {
}

private doCountdown(): void {
let timeout = !this.timeoutVal ? 0 : this.timeoutVal;
let now: Date = this.expiry.now();
let diff: Number = this.expiry.last().getTime() - now.getTime() - (timeout * 1000);
if (diff > 0) {
this.safeClearInterval('timeoutHandle');
this.interrupt(true);
return;
}

if (!this.idling) {
return;
}
Expand Down

0 comments on commit e23233d

Please sign in to comment.