summaryrefslogtreecommitdiffstats
path: root/dom/html/test/test_srcdoc.html
blob: f7e48fde94325f96be80544152ebbb042a49de77 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!doctype html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=802895
-->
    <head>
<title>Tests for srcdoc iframes introduced in bug 802895</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=802895">Mozilla Bug 802895</a>

<iframe id="pframe" src="file_srcdoc.html"></iframe>

<pre id="test">
<script>

  SimpleTest.waitForExplicitFinish();
  SimpleTest.requestFlakyTimeout("untriaged");
  var pframe = $("pframe");

  var loadState = 0;
  pframe.contentWindow.addEventListener("load", function () {

    var pframeDoc = pframe.contentDocument;

    var iframe = pframeDoc.getElementById("iframe");
    var innerDoc = iframe.contentDocument;
    var iframe1 = pframeDoc.getElementById("iframe1");
    var innerDoc1 = iframe1.contentDocument;

    var finish = false;
    var finish1 = false;
    var finish3 = false;



    is(iframe.srcdoc, "Hello World", "Bad srcdoc attribute contents")

    is(innerDoc.domain, document.domain, "Wrong domain");
    is(innerDoc.referrer, pframeDoc.referrer, "Wrong referrer");
    is(innerDoc.body.innerHTML, "Hello World", "Wrong body");
    is(innerDoc.compatMode, "CSS1Compat", "Not standards compliant");

    is(innerDoc1.domain, document.domain, "Wrong domain with src attribute");
    is(innerDoc1.referrer, pframeDoc.referrer, "Wrong referrer with src attribute");
    is(innerDoc1.body.innerHTML, "Goodbye World", "Wrong body with src attribute")
    is(innerDoc1.compatMode, "CSS1Compat", "Not standards compliant with src attribute");

    var iframe2 = pframeDoc.getElementById("iframe2");
    var innerDoc2 = iframe2.contentDocument;
    try {
      innerDoc2.domain;
      foundError = false;
    }
    catch (error) {
      foundError = true;
    }
    ok(foundError, "srcdoc iframe not sandboxed");

    //Test changed srcdoc attribute
    iframe.onload = function () {

      iframe = pframeDoc.getElementById("iframe");
      innerDoc = iframe.contentDocument;

      is(iframe.srcdoc, "Hello again", "Bad srcdoc attribute contents with srcdoc attribute changed");
      is(innerDoc.domain, document.domain, "Wrong domain with srcdoc attribute changed");
      is(innerDoc.referrer, pframeDoc.referrer, "Wrong referrer with srcdoc attribute changed");
      is(innerDoc.body.innerHTML, "Hello again", "Wrong body with srcdoc attribute changed");
      is(innerDoc.compatMode, "CSS1Compat", "Not standards compliant with srcdoc attribute changed");

      finish = true;
      if (finish && finish1 && finish3) {
        SimpleTest.finish();
      }
    };

    iframe.srcdoc = "Hello again";

    var iframe3 = pframeDoc.getElementById("iframe3");

    // Test srcdoc attribute removal
    iframe3.onload = function () {
      var innerDoc3 = iframe3.contentDocument;
      is(innerDoc3.body.innerHTML, "Gone", "Bad srcdoc attribute removal");
      finish3 = true;
      if (finish && finish1 && finish3) {
        SimpleTest.finish();
      }
    }

    iframe3.removeAttribute("srcdoc");


    var iframe1load = false;
    iframe1.onload = function () {
      iframe1load = true;
    }

    iframe1.src = "data:text/plain;charset=US-ASCII,Goodbyeeee";

    // Need to test that changing the src doesn't change the iframe.
    setTimeout(function () {
      ok(!iframe1load, "Changing src attribute shouldn't cause a load when srcdoc is set");
      finish1 = true;
      if (finish && finish1 && finish3) {
        SimpleTest.finish();
      }
    }, 2000);

  }, false);

</script>
</pre>
</body>
</html>