Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML: test <iframe src=javascript:...> #50193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<title>javascript: URL in iframe src</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#process-the-iframe-attributes">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
const tests = [
// desc, url, expected body.textContent
['string', 'javascript:"foo"', 'foo'],
['empty string', 'javascript:""', ''],
['String object', 'javascript:new String("foo")', ''],
['undefined', 'javascript:void(0)', ''],
['number', 'javascript:1', ''],
['boolean', 'javascript:true', ''],
['null', 'javascript:null', ''],
['global', 'javascript:window', ''],
['host object', 'javascript:document', ''],
['function', 'javascript:(() => { return function() {}; })()', ''],
['regexp', 'javascript:/foo/', ''],
['array', 'javascript:["foo"]', ''],
['object', 'javascript:{"foo": "bar"}', ''],
['ArrayBuffer', 'javascript:new ArrayBuffer(8)', ''],
['TypeError', 'javascript:new TypeError("foo")', ''],
];
for (const [desc, url, expected_textContent] of tests) {
async_test(t => {
const iframe = document.createElement('iframe');
iframe.src = url;
iframe.hidden = true;
let load_events = 0;
iframe.onload = t.step_func(() => {
load_events++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an assert before this that load_events is 0? And maybe make it a boolean? That way we can exit early and not wait 100ms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that but I figured out would be nice to know how many load events you got if there are more than 1. All browsers currently pass at least 1 subtest (which take 100ms), so the test as a whole doesn't complete faster if some subtests get too many load events. The subtests also run in parallel.

assert_equals(iframe.contentDocument.URL, 'about:blank');
assert_equals(iframe.contentDocument.body.textContent, expected_textContent);
if (load_events === 1) {
t.step_timeout(() => {
assert_equals(load_events, 1);
t.done();
}, 100);
}
});
document.body.append(iframe);
}, `${desc}: ${url}`);
}
</script>
Loading