summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/srcdoc-attribute-reset.html
blob: 452a984afbbd025d75d526ead388bc6b5a8f3489 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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>