| 
									
										
										
										
											2017-03-22 17:13:24 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2017-03-22 17:13:24 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class MockScriptElement { | 
					
						
							|  |  |  |   constructor() {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   listeners: { | 
					
						
							|  |  |  |     load?: (event: Event) => void, | 
					
						
							|  |  |  |     error?: (err: Error) => void, | 
					
						
							|  |  |  |   } = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   addEventListener(event: 'load'|'error', handler: Function): void { | 
					
						
							|  |  |  |     this.listeners[event] = handler as any; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   removeEventListener(event: 'load'|'error'): void { | 
					
						
							|  |  |  |     delete this.listeners[event]; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-03-22 17:13:24 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class MockDocument { | 
					
						
							| 
									
										
										
										
											2018-06-18 16:38:33 -07:00
										 |  |  |   // TODO(issue/24571): remove '!'.
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   mock!: MockScriptElement|null; | 
					
						
							| 
									
										
										
										
											2017-09-15 16:12:02 -07:00
										 |  |  |   readonly body: any = this; | 
					
						
							| 
									
										
										
										
											2017-03-22 17:13:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   createElement(tag: 'script'): HTMLScriptElement { | 
					
						
							|  |  |  |     return new MockScriptElement() as any as HTMLScriptElement; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   appendChild(node: any): void { | 
					
						
							|  |  |  |     this.mock = node; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-03-22 17:13:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   removeNode(node: any): void { | 
					
						
							|  |  |  |     if (this.mock === node) { | 
					
						
							|  |  |  |       this.mock = null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   mockLoad(): void { | 
					
						
							|  |  |  |     this.mock!.listeners.load!(null as any); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-03-22 17:13:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   mockError(err: Error) { | 
					
						
							|  |  |  |     this.mock!.listeners.error!(err); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-09-15 16:12:02 -07:00
										 |  |  | } |