| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {ifEnvSupports} from '../test-util'; | 
					
						
							|  |  |  | declare const global: any; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('MutationObserver', ifEnvSupports('MutationObserver', function() { | 
					
						
							|  |  |  |            let elt: HTMLDivElement; | 
					
						
							|  |  |  |            const testZone = Zone.current.fork({name: 'test'}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |            beforeEach(function() { | 
					
						
							|  |  |  |              elt = document.createElement('div'); | 
					
						
							|  |  |  |            }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |            it('should run observers within the zone', function(done) { | 
					
						
							|  |  |  |              let ob; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              testZone.run(function() { | 
					
						
							|  |  |  |                ob = new MutationObserver(function() { | 
					
						
							|  |  |  |                  expect(Zone.current).toBe(testZone); | 
					
						
							|  |  |  |                  done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                ob.observe(elt, {childList: true}); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              elt.innerHTML = '<p>hey</p>'; | 
					
						
							|  |  |  |            }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            it('should only dequeue upon disconnect if something is observed', function() { | 
					
						
							|  |  |  |              let ob: MutationObserver; | 
					
						
							|  |  |  |              let flag = false; | 
					
						
							|  |  |  |              const elt = document.createElement('div'); | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |              const childZone = Zone.current.fork({ | 
					
						
							|  |  |  |                name: 'test', | 
					
						
							|  |  |  |                onInvokeTask: function() { | 
					
						
							|  |  |  |                  flag = true; | 
					
						
							|  |  |  |                } | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |              childZone.run(function() { | 
					
						
							|  |  |  |                ob = new MutationObserver(function() {}); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |              ob!.disconnect(); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |              expect(flag).toBe(false); | 
					
						
							|  |  |  |            }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('WebKitMutationObserver', ifEnvSupports('WebKitMutationObserver', function() { | 
					
						
							|  |  |  |            const testZone = Zone.current.fork({name: 'test'}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            it('should run observers within the zone', function(done) { | 
					
						
							|  |  |  |              let elt: HTMLDivElement; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              testZone.run(function() { | 
					
						
							|  |  |  |                elt = document.createElement('div'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                const ob = new global['WebKitMutationObserver'](function() { | 
					
						
							|  |  |  |                  expect(Zone.current).toBe(testZone); | 
					
						
							|  |  |  |                  done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                ob.observe(elt, {childList: true}); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |              elt!.innerHTML = '<p>hey</p>'; | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |            }); | 
					
						
							|  |  |  |          })); |