| <!DOCTYPE html><!-- webkit-test-runner [ ResizeObserverEnabled=true ] --> |
| <html> |
| <head> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="../resources/gc.js"></script> |
| </head> |
| <body> |
| <div id="container"></div> |
| <script> |
| function accessToObserverInCallback() { |
| let test = async_test("test: Resize observer inside callback should be garbage collected if no one refers to it"); |
| let initialObserverCount = internals.numberOfResizeObservers(document); |
| const iterationCount = 50; |
| let callbackCount = 0; |
| for (let j = 0; j < iterationCount; ++j) { |
| const div = document.createElement('div'); |
| container.appendChild(div); |
| let observer = new ResizeObserver(() => { |
| callbackCount++; |
| observer.disconnect(); |
| container.removeChild(div); |
| if (callbackCount == iterationCount) { |
| window.requestAnimationFrame(() => { |
| gc(); |
| test.step(() => { |
| let observerCount = internals.numberOfResizeObservers(document) - initialObserverCount; |
| assert_true(observerCount < iterationCount, 'Resize observers should be collected.'); |
| test.done(); |
| }); |
| }); |
| } |
| }); |
| observer.observe(div); |
| } |
| } |
| |
| test(_ => { |
| assert_own_property(window, "ResizeObserver"); |
| }, "ResizeObserver implemented"); |
| |
| window.onload = accessToObserverInCallback(); |
| </script> |
| |
| </body> |
| |
| </html> |