| <!doctype html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <title>Testing new callback</title> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| </head> |
| <body> |
| <script> |
| function waitFor(duration) |
| { |
| return new Promise((resolve) => setTimeout(resolve, duration)); |
| } |
| |
| function withFrame(url) |
| { |
| return new Promise((resolve) => { |
| let frame = document.createElement('iframe'); |
| frame.src = url; |
| frame.onload = function() { resolve(frame); }; |
| document.body.appendChild(frame); |
| }); |
| } |
| |
| async function verifyUserScriptInjectedCount(expected) |
| { |
| let counter = 0; |
| while (++counter < 100) { |
| if (testRunner.userScriptInjectedCount === expected) |
| return; |
| await waitFor(10); |
| } |
| return Promise.reject("Did not get expected value " + expected + " but " + testRunner.userScriptInjectedCount); |
| } |
| |
| promise_test(async () => { |
| if (!window.testRunner) { |
| reject("Test requires internals API"); |
| return; |
| } |
| assert_equals(testRunner.userScriptInjectedCount, 0); |
| testRunner.injectUserScript("function a() { }"); |
| |
| await withFrame("."); |
| await verifyUserScriptInjectedCount(1); |
| |
| await withFrame("."); |
| await verifyUserScriptInjectedCount(2); |
| }, 'Test willInjectUserScript callback being called'); |
| </script> |
| </body> |
| </html> |