Skip to content

Commit

Permalink
Fix srcdoc attribute reset.
Browse files Browse the repository at this point in the history
Currently, resetting the srcdoc attribute on an iframe in chromium fails
to clear the current content. The existing test fails since it doesn't
synchronize with the page's onload event to confirm the srcdoc content
was there before clearing the attribute and checking that the content is
cleared too.

This CL fixes both the behavior and the test, and converts the test to
be a WPT test.

Bug: 1233143
Change-Id: I006ee39e4525c7cd015f1c2483c429a93cdd0ca6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3400984
Reviewed-by: Mason Freed <masonf@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: James Maclean <wjmaclean@chromium.org>
Cr-Commit-Position: refs/heads/main@{#961469}
  • Loading branch information
W. James MacLean authored and chromium-wpt-export-bot committed Jan 20, 2022
1 parent 215b7c5 commit 1b4f0a1
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<title>Verify that clearing srcdoc resets the iframe's content.</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/iframe-embed-object.html#process-the-iframe-attributes">
<link rel="author" title="James MacLean" href="mailto:wjmaclean@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<iframe id=myframe srcdoc='srcdoc_text'></iframe>
<script>
'use strict';

async_test(function(t) {
window.onload = () => {
// Verify that the srcdoc content is loaded before we start.
t.step(() => {
assert_true(typeof myframe.contentDocument !== 'undefined',
'iframe has contentDocument');
assert_equals(myframe.contentDocument.body.innerText, 'srcdoc_text',
'iframe contains srcdoc content');
});

myframe.onload = t.step_func_done(function() {
assert_true(typeof myframe.contentDocument !== 'undefined',
'iframe has contentDocument');
assert_equals(myframe.contentDocument.body.innerText, '',
'iframe content is empty');
});

// Don't remove srcdoc until the initial load has completed, and the
// frame's onload handler is in place.
myframe.removeAttribute('srcdoc');
};
}, 'Verify that the frame reloads with empty body after we remove srcdoc.');
</script>

0 comments on commit 1b4f0a1

Please sign in to comment.