mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
feat: add support for long-animation-frame script attribution (#49706)
* feat: add support for `long-animation-frame` script attribution * docs: document `AlwaysLogLOAFURL` * chore: add test * docs: adjust docs as per PR comment * fix: test failures * chore: simplify test * fix: tests on Windows and Linux
This commit is contained in:
@@ -3280,6 +3280,29 @@ describe('chromium features', () => {
|
||||
expect(rgb).to.equal('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('long-animation-frame', () => {
|
||||
it('should include script attribution on custom protocols if AlwaysLogLOAFURL is enabled', async () => {
|
||||
const rc = await startRemoteControlApp(['--enable-features=AlwaysLogLOAFURL']);
|
||||
const hasAttribution = await rc.remotely(async (fixture: string) => {
|
||||
const { BrowserWindow, protocol, net } = require('electron/main');
|
||||
const { pathToFileURL } = require('node:url');
|
||||
|
||||
protocol.handle('custom', () => net.fetch(pathToFileURL(fixture).toString()));
|
||||
|
||||
// `show: true` is necessary on Windows and Linux due to https://github.com/electron/electron/issues/32001
|
||||
const w = new BrowserWindow({ show: true });
|
||||
await w.loadURL('custom://my-url');
|
||||
|
||||
const hasAttribution = await w.webContents.executeJavaScript('hasAttributionPromise');
|
||||
|
||||
global.setTimeout(() => require('electron').app.quit());
|
||||
|
||||
return hasAttribution;
|
||||
}, path.join(fixturesPath, 'chromium', 'long-animation-frame.html'));
|
||||
expect(hasAttribution).to.be.true();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('font fallback', () => {
|
||||
|
||||
29
spec/fixtures/chromium/long-animation-frame.html
vendored
Normal file
29
spec/fixtures/chromium/long-animation-frame.html
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<body>
|
||||
<div id="update"></div>
|
||||
<script>
|
||||
var hasAttributionPromise = new Promise((resolve) => {
|
||||
new PerformanceObserver((list) => {
|
||||
const entries = list.getEntries();
|
||||
const has_attribution =
|
||||
entries.length > 0 &&
|
||||
entries.every(
|
||||
({ scripts }) =>
|
||||
scripts.length > 0 &&
|
||||
scripts.every(({ sourceURL }) => sourceURL === location.href),
|
||||
);
|
||||
resolve(has_attribution);
|
||||
}).observe({ entryTypes: ["long-animation-frame"] });
|
||||
|
||||
// Produce a long animation frame
|
||||
requestAnimationFrame(() => {
|
||||
const before = performance.now();
|
||||
document.querySelector("#update").innerHTML = "Update";
|
||||
while (performance.now() < before + 60) {}
|
||||
requestAnimationFrame(() => {});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user