Skip to content

Commit

Permalink
HTML: navigate cancels iframe lazy-load
Browse files Browse the repository at this point in the history
  • Loading branch information
zcorpan committed Apr 10, 2024
1 parent 650b316 commit cd96ee6
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>History state change for iframe loading='lazy' before it is loaded: history.pushState</title>
<iframe data-src="support/blank.htm?foo" src="support/blank.htm?src" loading="lazy"></iframe>
<script>
const iframe = document.querySelector('iframe');
// Should have no effect on lazy-loading
iframe.contentWindow.history.pushState(null, "", iframe.dataset.src);
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?src", location.href).href);
done();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>History state change for iframe loading='lazy' before it is loaded: history.replaceState</title>
<iframe data-src="support/blank.htm?foo" src="support/blank.htm?src" loading="lazy"></iframe>
<script>
const iframe = document.querySelector('iframe');
// Should have no effect on lazy-loading
iframe.contentWindow.history.replaceState(null, "", iframe.dataset.src);
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?src", location.href).href);
done();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>Navigating iframe loading='lazy' before it is loaded: form submit</title>
<iframe name="iframe" src="support/blank.htm?src" loading="lazy"></iframe>
<form action="support/blank.htm" target="iframe"></form>
<script>
const iframe = document.querySelector('iframe');
const form = document.querySelector('form');
form.submit();
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?", location.href).href);
done();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>Navigating iframe loading='lazy' before it is loaded: link click (fragment)</title>
<iframe name="iframe" src="support/blank.htm?src" loading="lazy"></iframe>
<a href="about:blank#fragment" target="iframe"></a>
<script>
const iframe = document.querySelector('iframe');
const a = document.querySelector('a');
a.click();
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_equals(iframe.contentWindow.location.href, "about:blank#fragment");
done();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>Navigating iframe loading='lazy' before it is loaded: link click</title>
<iframe name="iframe" src="support/blank.htm?src" loading="lazy"></iframe>
<a href="support/blank.htm?nav" target="iframe"></a>
<script>
const iframe = document.querySelector('iframe');
const a = document.querySelector('a');
a.click();
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?nav", location.href).href);
done();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<title>Navigating iframe loading='lazy' before it is loaded: location.assign</title>
<iframe data-src="support/blank.htm?nav" src="support/blank.htm?src" loading="lazy"></iframe>
<script>
const iframe = document.querySelector('iframe');
iframe.contentWindow.location.assign(iframe.dataset.src);
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?nav", location.href).href);
done();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<title>Navigating iframe loading='lazy' before it is loaded: location.replace</title>
<iframe data-src="support/blank.htm?nav" src="support/blank.htm?src" loading="lazy"></iframe>
<script>
const iframe = document.querySelector('iframe');
iframe.contentWindow.location.replace(iframe.dataset.src);
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?nav", location.href).href);
done();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<title>Navigating iframe loading='lazy' before it is loaded: meta refresh</title>
<!-- This test is optional because the spec allows delaying or doing nothing for meta refresh. -->
<iframe src="support/blank.htm?src" loading="lazy"></iframe>
<script>
const iframe = document.querySelector('iframe');
const meta = iframe.contentDocument.createElement('meta');
meta.httpEquiv = 'Refresh';
meta.content = '0; url=support/blank.htm?nav';
iframe.contentDocument.head.append(meta);
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?nav", location.href).href);
done();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>Navigating iframe loading='lazy' before it is loaded: navigation.navigate</title>
<iframe data-src="support/blank.htm?nav" src="support/blank.htm?src" loading="lazy"></iframe>
<script>
const iframe = document.querySelector('iframe');
iframe.contentWindow.navigation.navigate(iframe.dataset.src);
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_true("navigation" in window, "Navigation API is supported");
assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?nav", location.href).href);
done();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<title>Navigating iframe loading='lazy' before it is loaded: location.replace</title>
<iframe name="iframe" data-src="support/blank.htm?nav" src="support/blank.htm?src" loading="lazy"></iframe>
<script>
const iframe = document.querySelector('iframe');
window.open(iframe.dataset.src, 'iframe');
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?nav", location.href).href);
done();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>Reloading iframe loading='lazy' before it is loaded: location.reload</title>
<iframe src="support/blank.htm?src" loading="lazy"></iframe>
<script>
const iframe = document.querySelector('iframe');
// Should have no effect on lazy-loading
iframe.contentWindow.location.reload();
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?src", location.href).href);
done();
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>Reloading iframe loading='lazy' before it is loaded: location.reload</title>
<iframe src="support/blank.htm?src" loading="lazy"></iframe>
<script>
const iframe = document.querySelector('iframe');
// Should have no effect on lazy-loading
iframe.contentWindow.navigation.reload();
</script>
<!-- Loading testharness.js here is intentional. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({single_test: true});
onload = () => {
assert_true("navigation" in window, "Navigation API is supported");
assert_equals(iframe.contentWindow.location.href, new URL("support/blank.htm?src", location.href).href);
done();
}
</script>

0 comments on commit cd96ee6

Please sign in to comment.