2015-06-15 18:41:09 -04:00
|
|
|
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
|
2015-06-22 15:14:19 -04:00
|
|
|
import {List} from 'angular2/src/facade/collection';
|
|
|
|
import {LocationStrategy} from 'angular2/src/router/location_strategy';
|
2015-06-15 18:41:09 -04:00
|
|
|
|
2015-06-22 15:14:19 -04:00
|
|
|
|
|
|
|
export class MockLocationStrategy extends LocationStrategy {
|
2015-06-15 18:41:09 -04:00
|
|
|
internalBaseHref: string = '/';
|
|
|
|
internalPath: string = '/';
|
|
|
|
internalTitle: string = '';
|
2015-06-17 14:17:21 -04:00
|
|
|
urlChanges: List<string> = [];
|
2015-06-15 18:41:09 -04:00
|
|
|
_subject: EventEmitter = new EventEmitter();
|
|
|
|
constructor() { super(); }
|
|
|
|
|
2015-07-07 23:03:00 -04:00
|
|
|
simulatePopState(url: string): void {
|
2015-06-15 18:41:09 -04:00
|
|
|
this.internalPath = url;
|
|
|
|
ObservableWrapper.callNext(this._subject, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
path(): string { return this.internalPath; }
|
|
|
|
|
|
|
|
simulateUrlPop(pathname: string): void {
|
|
|
|
ObservableWrapper.callNext(this._subject, {'url': pathname});
|
|
|
|
}
|
|
|
|
|
|
|
|
pushState(ctx: any, title: string, url: string): void {
|
|
|
|
this.internalTitle = title;
|
|
|
|
this.internalPath = url;
|
2015-06-17 14:17:21 -04:00
|
|
|
this.urlChanges.push(url);
|
2015-06-15 18:41:09 -04:00
|
|
|
}
|
|
|
|
|
2015-07-07 23:03:00 -04:00
|
|
|
onPopState(fn: (value: any) => void): void { ObservableWrapper.subscribe(this._subject, fn); }
|
2015-06-15 18:41:09 -04:00
|
|
|
|
|
|
|
getBaseHref(): string { return this.internalBaseHref; }
|
|
|
|
}
|