Skip to content

Commit

Permalink
Infer a speculation rule's source from the other keys.
Browse files Browse the repository at this point in the history
This is behind a RuntimeEnabledFeature, so we can enable it
once we're convinced it's reasonable, and disable it remotely
if anything surprising happens.

Bug: 1517696
Change-Id: Ie41529a13ab48671fc19c30003471e61fcc00781
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5186903
Reviewed-by: Kevin McNee <mcnee@chromium.org>
Auto-Submit: Jeremy Roman <jbroman@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1246177}
  • Loading branch information
jeremyroman authored and chromium-wpt-export-bot committed Jan 12, 2024
1 parent 40b49b7 commit 9344126
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions speculation-rules/prefetch/implicit-source.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="resources/utils.sub.js"></script>
<body>
<script>
setup(() => assertSpeculationRulesIsSupported());

promise_test(async t => {
let urls = getPrefetchUrlList(2);

let a = document.createElement('a');
a.className = 'prefetch-me';
a.href = urls[1];
a.textContent = 'prefetch me!';
document.body.appendChild(a);
t.add_cleanup(() => a.remove());

insertSpeculationRules({prefetch: [
{urls: [urls[0]]},
{where: {selector_matches: '.prefetch-me'}, eagerness: 'immediate'},
]});

await new Promise(resolve => t.step_timeout(resolve, 2000));

let wasPrefetched = urls.map(isUrlPrefetched);
assert_true(!!(await wasPrefetched[0]), 'implicit list rule should have worked');
assert_true(!!(await wasPrefetched[1]), 'implicit document rule should have worked');
}, 'rules should be accepted without an explicit source');
</script>
</body>

0 comments on commit 9344126

Please sign in to comment.