mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 14:42:44 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			55 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <!DOCTYPE html>
 | |
| <head>
 | |
|     <style>
 | |
|         #box {
 | |
|             width: 200px;
 | |
|             height: 200px;
 | |
|             background-color: lightblue;
 | |
|         }
 | |
|     </style>
 | |
| </head>
 | |
| <body>
 | |
|     <div id="box"></div>
 | |
| </body>
 | |
| <script src="../include.js"></script>
 | |
| <script>
 | |
|     asyncTest(async done => {
 | |
|         const box = document.getElementById("box");
 | |
| 
 | |
|         let resolve = null;
 | |
|         function createResizeObserverPromise() {
 | |
|             return new Promise(r => {
 | |
|                 resolve = r;
 | |
|             });
 | |
|         }
 | |
| 
 | |
|         function createTimeoutPromise(timeout) {
 | |
|             return new Promise(r => {
 | |
|                 setTimeout(r, timeout);
 | |
|             });
 | |
|         }
 | |
| 
 | |
|         const resizeObserver = new ResizeObserver(entries => {
 | |
|             for (let entry of entries) {
 | |
|                 const { width, height } = entry.contentRect;
 | |
|                 println(`Size changed: ${width}px x ${height}px`);
 | |
|             }
 | |
| 
 | |
|             if (resolve) resolve();
 | |
|         });
 | |
| 
 | |
|         let observerCallbackInvocation = createResizeObserverPromise();
 | |
|         resizeObserver.observe(box);
 | |
|         await observerCallbackInvocation;
 | |
| 
 | |
|         resizeObserver.unobserve(box);
 | |
| 
 | |
|         box.style.width = "400px";
 | |
|         box.style.height = "400px";
 | |
| 
 | |
|         // Let event loop run to ensure that observer callback is not invoked.
 | |
|         await createTimeoutPromise(0);
 | |
| 
 | |
|         done();
 | |
|     });
 | |
| </script>
 | 
