| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  | import {Injectable} from '../di'; | 
					
						
							| 
									
										
										
										
											2017-03-01 15:18:10 -08:00
										 |  |  | import {scheduleMicroTask} from '../util'; | 
					
						
							| 
									
										
										
										
											2015-10-08 13:33:22 -07:00
										 |  |  | import {NgZone} from '../zone/ng_zone'; | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-29 13:08:28 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Testability API. | 
					
						
							|  |  |  |  * `declare` keyword causes tsickle to generate externs, so these methods are | 
					
						
							|  |  |  |  * not renamed by Closure Compiler. | 
					
						
							|  |  |  |  * @experimental | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export declare interface PublicTestability { | 
					
						
							|  |  |  |   isStable(): boolean; | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |   whenStable(callback: Function, timeout?: number, updateCallback?: Function): void; | 
					
						
							| 
									
										
										
										
											2016-08-29 13:08:28 -07:00
										 |  |  |   findProviders(using: any, provider: string, exactMatch: boolean): any[]; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  | // Angular internal, not intended for public API.
 | 
					
						
							|  |  |  | export interface PendingMacrotask { | 
					
						
							|  |  |  |   source: string; | 
					
						
							|  |  |  |   isPeriodic: boolean; | 
					
						
							|  |  |  |   delay?: number; | 
					
						
							|  |  |  |   creationLocation: Error; | 
					
						
							|  |  |  |   xhr?: XMLHttpRequest; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Angular internal, not intended for public API.
 | 
					
						
							|  |  |  | export type DoneCallback = (didWork: boolean, tasks?: PendingMacrotask[]) => void; | 
					
						
							|  |  |  | export type UpdateCallback = (tasks: PendingMacrotask[]) => boolean; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | interface WaitCallback { | 
					
						
							|  |  |  |   // Needs to be 'any' - setTimeout returns a number according to ES6, but
 | 
					
						
							|  |  |  |   // on NodeJS it returns a Timer.
 | 
					
						
							|  |  |  |   timeoutId: any; | 
					
						
							|  |  |  |   doneCb: DoneCallback; | 
					
						
							|  |  |  |   updateCb?: UpdateCallback; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * The Testability service provides testing hooks that can be accessed from | 
					
						
							|  |  |  |  * the browser and by services such as Protractor. Each bootstrapped Angular | 
					
						
							|  |  |  |  * application on the page will have an instance of Testability. | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @experimental | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-03-31 12:36:43 -07:00
										 |  |  | @Injectable() | 
					
						
							| 
									
										
										
										
											2016-08-29 13:08:28 -07:00
										 |  |  | export class Testability implements PublicTestability { | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |   private _pendingCount: number = 0; | 
					
						
							|  |  |  |   private _isZoneStable: boolean = true; | 
					
						
							| 
									
										
										
										
											2016-01-05 12:56:24 -08:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Whether any work was done since the last 'whenStable' callback. This is | 
					
						
							|  |  |  |    * useful to detect if this could have potentially destabilized another | 
					
						
							|  |  |  |    * component while it is stabilizing. | 
					
						
							|  |  |  |    * @internal | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |   private _didWork: boolean = false; | 
					
						
							|  |  |  |   private _callbacks: WaitCallback[] = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private taskTrackingZone: any; | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |   constructor(private _ngZone: NgZone) { | 
					
						
							|  |  |  |     this._watchAngularEvents(); | 
					
						
							|  |  |  |     _ngZone.run(() => { this.taskTrackingZone = Zone.current.get('TaskTrackingZone'); }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private _watchAngularEvents(): void { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |     this._ngZone.onUnstable.subscribe({ | 
					
						
							|  |  |  |       next: () => { | 
					
						
							|  |  |  |         this._didWork = true; | 
					
						
							|  |  |  |         this._isZoneStable = false; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-01-05 12:56:24 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-11-03 18:45:55 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 14:24:17 -08:00
										 |  |  |     this._ngZone.runOutsideAngular(() => { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |       this._ngZone.onStable.subscribe({ | 
					
						
							|  |  |  |         next: () => { | 
					
						
							|  |  |  |           NgZone.assertNotInAngularZone(); | 
					
						
							|  |  |  |           scheduleMicroTask(() => { | 
					
						
							|  |  |  |             this._isZoneStable = true; | 
					
						
							|  |  |  |             this._runCallbacksIfReady(); | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-11-03 18:45:55 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Increases the number of pending request | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |    * @deprecated pending requests are now tracked with zones. | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2015-07-24 12:46:12 -07:00
										 |  |  |   increasePendingRequestCount(): number { | 
					
						
							|  |  |  |     this._pendingCount += 1; | 
					
						
							| 
									
										
										
										
											2016-01-05 12:56:24 -08:00
										 |  |  |     this._didWork = true; | 
					
						
							| 
									
										
										
										
											2015-07-24 12:46:12 -07:00
										 |  |  |     return this._pendingCount; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Decreases the number of pending request | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |    * @deprecated pending requests are now tracked with zones | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2015-07-24 12:46:12 -07:00
										 |  |  |   decreasePendingRequestCount(): number { | 
					
						
							|  |  |  |     this._pendingCount -= 1; | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  |     if (this._pendingCount < 0) { | 
					
						
							| 
									
										
										
										
											2016-08-25 00:50:16 -07:00
										 |  |  |       throw new Error('pending async requests below zero'); | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-24 12:46:12 -07:00
										 |  |  |     this._runCallbacksIfReady(); | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  |     return this._pendingCount; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Whether an associated application is stable | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-02-25 14:24:17 -08:00
										 |  |  |   isStable(): boolean { | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |     return this._isZoneStable && this._pendingCount === 0 && !this._ngZone.hasPendingMacrotasks; | 
					
						
							| 
									
										
										
										
											2016-02-25 14:24:17 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-08-27 17:44:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |   private _runCallbacksIfReady(): void { | 
					
						
							| 
									
										
										
										
											2016-02-25 14:24:17 -08:00
										 |  |  |     if (this.isStable()) { | 
					
						
							| 
									
										
										
										
											2018-01-17 15:28:21 -08:00
										 |  |  |       // Schedules the call backs in a new frame so that it is always async.
 | 
					
						
							|  |  |  |       scheduleMicroTask(() => { | 
					
						
							|  |  |  |         while (this._callbacks.length !== 0) { | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |           let cb = this._callbacks.pop() !; | 
					
						
							|  |  |  |           clearTimeout(cb.timeoutId); | 
					
						
							|  |  |  |           cb.doneCb(this._didWork); | 
					
						
							| 
									
										
										
										
											2018-01-17 15:28:21 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-02-25 14:24:17 -08:00
										 |  |  |         this._didWork = false; | 
					
						
							| 
									
										
										
										
											2018-01-17 15:28:21 -08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-02-25 14:24:17 -08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |       // Still not stable, send updates.
 | 
					
						
							|  |  |  |       let pending = this.getPendingTasks(); | 
					
						
							|  |  |  |       this._callbacks = this._callbacks.filter((cb) => { | 
					
						
							|  |  |  |         if (cb.updateCb && cb.updateCb(pending)) { | 
					
						
							|  |  |  |           clearTimeout(cb.timeoutId); | 
					
						
							|  |  |  |           return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-05 12:56:24 -08:00
										 |  |  |       this._didWork = true; | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |   private getPendingTasks(): PendingMacrotask[] { | 
					
						
							|  |  |  |     if (!this.taskTrackingZone) { | 
					
						
							|  |  |  |       return []; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return this.taskTrackingZone.macroTasks.map((t: Task) => { | 
					
						
							|  |  |  |       return { | 
					
						
							|  |  |  |         source: t.source, | 
					
						
							|  |  |  |         isPeriodic: t.data.isPeriodic, | 
					
						
							|  |  |  |         delay: t.data.delay, | 
					
						
							|  |  |  |         // From TaskTrackingZone:
 | 
					
						
							|  |  |  |         // https://github.com/angular/zone.js/blob/master/lib/zone-spec/task-tracking.ts#L40
 | 
					
						
							|  |  |  |         creationLocation: (t as any).creationLocation as Error, | 
					
						
							|  |  |  |         // Added by Zones for XHRs
 | 
					
						
							|  |  |  |         // https://github.com/angular/zone.js/blob/master/lib/browser/browser.ts#L133
 | 
					
						
							|  |  |  |         xhr: (t.data as any).target | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private addCallback(cb: DoneCallback, timeout?: number, updateCb?: UpdateCallback) { | 
					
						
							|  |  |  |     let timeoutId: any = -1; | 
					
						
							|  |  |  |     if (timeout && timeout > 0) { | 
					
						
							|  |  |  |       timeoutId = setTimeout(() => { | 
					
						
							|  |  |  |         this._callbacks = this._callbacks.filter((cb) => cb.timeoutId !== timeoutId); | 
					
						
							|  |  |  |         cb(this._didWork, this.getPendingTasks()); | 
					
						
							|  |  |  |       }, timeout); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     this._callbacks.push(<WaitCallback>{doneCb: cb, timeoutId: timeoutId, updateCb: updateCb}); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |   /** | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |    * Wait for the application to be stable with a timeout. If the timeout is reached before that | 
					
						
							|  |  |  |    * happens, the callback receives a list of the macro tasks that were pending, otherwise null. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * @param doneCb The callback to invoke when Angular is stable or the timeout expires | 
					
						
							|  |  |  |    *    whichever comes first. | 
					
						
							|  |  |  |    * @param timeout Optional. The maximum time to wait for Angular to become stable. If not | 
					
						
							|  |  |  |    *    specified, whenStable() will wait forever. | 
					
						
							|  |  |  |    * @param updateCb Optional. If specified, this callback will be invoked whenever the set of | 
					
						
							|  |  |  |    *    pending macrotasks changes. If this callback returns true doneCb will not be invoked | 
					
						
							|  |  |  |    *    and no further updates will be issued. | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |   whenStable(doneCb: Function, timeout?: number, updateCb?: Function): void { | 
					
						
							|  |  |  |     if (updateCb && !this.taskTrackingZone) { | 
					
						
							|  |  |  |       throw new Error( | 
					
						
							|  |  |  |           'Task tracking zone is required when passing an update callback to ' + | 
					
						
							|  |  |  |           'whenStable(). Is "zone.js/dist/task-tracking.js" loaded?'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // These arguments are 'Function' above to keep the public API simple.
 | 
					
						
							|  |  |  |     this.addCallback(doneCb as DoneCallback, timeout, updateCb as UpdateCallback); | 
					
						
							| 
									
										
										
										
											2015-07-24 12:46:12 -07:00
										 |  |  |     this._runCallbacksIfReady(); | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Get the number of pending requests | 
					
						
							| 
									
										
										
										
											2017-04-27 11:44:14 -07:00
										 |  |  |    * @deprecated pending requests are now tracked with zones | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2015-07-24 12:46:12 -07:00
										 |  |  |   getPendingRequestCount(): number { return this._pendingCount; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Find providers by name | 
					
						
							|  |  |  |    * @param using The root element to search from | 
					
						
							|  |  |  |    * @param provider The name of binding variable | 
					
						
							|  |  |  |    * @param exactMatch Whether using exactMatch | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2015-10-10 22:11:13 -07:00
										 |  |  |   findProviders(using: any, provider: string, exactMatch: boolean): any[] { | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  |     // TODO(juliemr): implement.
 | 
					
						
							|  |  |  |     return []; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-03 15:49:09 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * A global registry of {@link Testability} instances for specific elements. | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @experimental | 
					
						
							| 
									
										
										
										
											2015-12-03 15:49:09 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-03-31 12:36:43 -07:00
										 |  |  | @Injectable() | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  | export class TestabilityRegistry { | 
					
						
							| 
									
										
										
										
											2015-10-09 17:21:25 -07:00
										 |  |  |   /** @internal */ | 
					
						
							| 
									
										
										
										
											2015-09-29 11:11:06 -07:00
										 |  |  |   _applications = new Map<any, Testability>(); | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 15:24:36 -08:00
										 |  |  |   constructor() { _testabilityGetter.addToWindow(this); } | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Registers an application with a testability hook so that it can be tracked | 
					
						
							|  |  |  |    * @param token token of application, root element | 
					
						
							|  |  |  |    * @param testability Testability hook | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2015-07-07 20:03:00 -07:00
										 |  |  |   registerApplication(token: any, testability: Testability) { | 
					
						
							| 
									
										
										
										
											2015-06-17 16:21:40 -07:00
										 |  |  |     this._applications.set(token, testability); | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Unregisters an application. | 
					
						
							|  |  |  |    * @param token token of application, root element | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   unregisterApplication(token: any) { this._applications.delete(token); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Unregisters all applications | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   unregisterAllApplications() { this._applications.clear(); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Get a testability hook associated with the application | 
					
						
							|  |  |  |    * @param elem root element | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 |  |  |   getTestability(elem: any): Testability|null { return this._applications.get(elem) || null; } | 
					
						
							| 
									
										
										
										
											2015-11-17 15:24:36 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Get all registered testabilities | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-11-03 16:58:27 -07:00
										 |  |  |   getAllTestabilities(): Testability[] { return Array.from(this._applications.values()); } | 
					
						
							| 
									
										
										
										
											2015-07-30 15:51:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Get all registered applications(root elements) | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-11-03 16:58:27 -07:00
										 |  |  |   getAllRootElements(): any[] { return Array.from(this._applications.keys()); } | 
					
						
							| 
									
										
										
										
											2016-02-18 13:51:20 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 11:50:13 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Find testability of a node in the Tree | 
					
						
							|  |  |  |    * @param elem node | 
					
						
							|  |  |  |    * @param findInAncestors whether finding testability in ancestors if testability was not found in | 
					
						
							|  |  |  |    * current node | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 |  |  |   findTestabilityInTree(elem: Node, findInAncestors: boolean = true): Testability|null { | 
					
						
							| 
									
										
										
										
											2015-11-17 15:24:36 -08:00
										 |  |  |     return _testabilityGetter.findTestabilityInTree(this, elem, findInAncestors); | 
					
						
							| 
									
										
										
										
											2015-03-23 16:46:18 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-03 15:49:09 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Adapter interface for retrieving the `Testability` service associated for a | 
					
						
							|  |  |  |  * particular context. | 
					
						
							| 
									
										
										
										
											2016-06-27 12:27:23 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @experimental Testability apis are primarily intended to be used by e2e test tool vendors like | 
					
						
							|  |  |  |  * the Protractor team. | 
					
						
							| 
									
										
										
										
											2015-12-03 15:49:09 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-11-17 15:24:36 -08:00
										 |  |  | export interface GetTestability { | 
					
						
							|  |  |  |   addToWindow(registry: TestabilityRegistry): void; | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |   findTestabilityInTree(registry: TestabilityRegistry, elem: any, findInAncestors: boolean): | 
					
						
							| 
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 |  |  |       Testability|null; | 
					
						
							| 
									
										
										
										
											2015-11-17 15:24:36 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 15:24:36 -08:00
										 |  |  | class _NoopGetTestability implements GetTestability { | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  |   addToWindow(registry: TestabilityRegistry): void {} | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |   findTestabilityInTree(registry: TestabilityRegistry, elem: any, findInAncestors: boolean): | 
					
						
							| 
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 |  |  |       Testability|null { | 
					
						
							| 
									
										
										
										
											2015-11-17 15:24:36 -08:00
										 |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-03 15:49:09 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Set the {@link GetTestability} implementation used by the Angular testing framework. | 
					
						
							| 
									
										
										
										
											2016-05-25 15:00:05 -07:00
										 |  |  |  * @experimental | 
					
						
							| 
									
										
										
										
											2015-12-03 15:49:09 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | export function setTestabilityGetter(getter: GetTestability): void { | 
					
						
							| 
									
										
										
										
											2015-11-17 15:24:36 -08:00
										 |  |  |   _testabilityGetter = getter; | 
					
						
							| 
									
										
										
										
											2015-09-02 15:19:26 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  | let _testabilityGetter: GetTestability = new _NoopGetTestability(); |