summaryrefslogtreecommitdiffstats
path: root/docshell/test/navigation/test_recursive_frames.html
blob: 3ccc09dd14c4eadea90576f07cacba40462dd34a (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Recursive Loads</title>
  <meta charset="utf-8">
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1597427">Mozilla Bug 1597427</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
  <script type="application/javascript">
  const TEST_CASES = [
    { // too many recursive iframes
      frameId: "recursiveFrame",
      expectedLocations: [
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.com/tests/docshell/test/navigation/frame_recursive.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.com/tests/docshell/test/navigation/frame_recursive.html",
        "about:blank",
      ],
    },
    { // too many recursive iframes
      frameId: "twoRecursiveIframes",
      expectedLocations: [
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.com/tests/docshell/test/navigation/frame_load_as_example_com.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.org/tests/docshell/test/navigation/frame_load_as_example_org.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.com/tests/docshell/test/navigation/frame_load_as_example_com.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.org/tests/docshell/test/navigation/frame_load_as_example_org.html",
        "about:blank",
      ],
    },
    { // too many recursive iframes
      frameId: "threeRecursiveIframes",
      expectedLocations: [
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://sub1.test1.mochi.test:8888/tests/docshell/test/navigation/frame_load_as_host1.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.com/tests/docshell/test/navigation/frame_load_as_host2.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://test1.mochi.test:8888/tests/docshell/test/navigation/frame_load_as_host3.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://sub1.test1.mochi.test:8888/tests/docshell/test/navigation/frame_load_as_host1.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.com/tests/docshell/test/navigation/frame_load_as_host2.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://test1.mochi.test:8888/tests/docshell/test/navigation/frame_load_as_host3.html",
        "about:blank",
      ],
    },
    { // too many nested iframes
      frameId: "sixRecursiveIframes",
      expectedLocations: [
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.com/tests/docshell/test/navigation/frame_1_out_of_6.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://test1.mochi.test:8888/tests/docshell/test/navigation/frame_2_out_of_6.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://sub1.test1.mochi.test:8888/tests/docshell/test/navigation/frame_3_out_of_6.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://sub2.xn--lt-uia.mochi.test:8888/tests/docshell/test/navigation/frame_4_out_of_6.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://test2.mochi.test:8888/tests/docshell/test/navigation/frame_5_out_of_6.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.org/tests/docshell/test/navigation/frame_6_out_of_6.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.com/tests/docshell/test/navigation/frame_1_out_of_6.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://test1.mochi.test:8888/tests/docshell/test/navigation/frame_2_out_of_6.html",
      ],
    },
    { // too many recursive objects
      frameId: "recursiveObject",
      expectedLocations: [
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://sub2.xn--lt-uia.mochi.test:8888/tests/docshell/test/navigation/object_recursive_load.html",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://sub2.xn--lt-uia.mochi.test:8888/tests/docshell/test/navigation/object_recursive_load.html",
      ],
    },
    { // 3 nested srcdocs, should show all of them
      frameId: "nestedSrcdoc",
      expectedLocations: [
        "about:srcdoc",
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.com/tests/docshell/test/navigation/file_nested_srcdoc.html",
        "about:srcdoc",
        "about:srcdoc",
      ],
    },
  ];

  async function checkRecursiveLoad(level) {
    let el = content.document.getElementById("static");
    let documentURI = await SpecialPowers.spawn(
      el,
      [],
      () => this.content.document.documentURI
    );
    if (documentURI == "about:blank") {
      // If we had too many recursive frames, the most inner iframe's uri will be about:blank
      return [documentURI];
    }
    if (documentURI == "about:srcdoc" && level == 3) {
      // Check that we have the correct most inner srcdoc iframe
      let innerText = await SpecialPowers.spawn(
        el,
        [],
        () => this.content.document.body.innerText
      );
      is(innerText, "Third nested srcdoc", "correct most inner srcdoc iframe");
    }
    let nestedIfrOrObjectURI = [];
    try {
      // Throws an error when we have too many nested frames/objects, because we
      // claim to have no content window for the inner most frame/object.
      nestedIfrOrObjectURI = await SpecialPowers.spawn(
        el,
        [level + 1],
        checkRecursiveLoad
      );
    } catch (err) {
      info(
        `Tried to spawn another task in the iframe/object, but got err: ${err}, must have had too many nested iframes/objects\n`
      );
    }
    return [documentURI, ...nestedIfrOrObjectURI];
  }

  add_task(async () => {
    for (const testCase of TEST_CASES) {
      let el = document.getElementById(testCase.frameId);
      let loc = await SpecialPowers.spawn(
        el,
        [],
        () => this.content.location.href
      );
      let locations = await SpecialPowers.spawn(el, [1], checkRecursiveLoad);
      isDeeply(
        [loc, ...locations],
        testCase.expectedLocations,
        "iframes/object loaded in correct order"
      );
    }
  });

  </script>
</pre>
<div>
  <iframe style="height: 100vh; width:25%;" id="recursiveFrame" src="http://example.com/tests/docshell/test/navigation/frame_recursive.html"></iframe>
  <iframe style="height: 100vh; width:25%;" id="twoRecursiveIframes" src="http://example.com/tests/docshell/test/navigation/frame_load_as_example_com.html"></iframe>
  <iframe style="height: 100vh; width:25%;" id="threeRecursiveIframes" src="http://sub1.test1.mochi.test:8888/tests/docshell/test/navigation/frame_load_as_host1.html"></iframe>
  <iframe style="height: 100vh; width:25%;" id="sixRecursiveIframes" src="http://example.com/tests/docshell/test/navigation/frame_1_out_of_6.html"></iframe>
  <object width="400" height="300" id="recursiveObject" data="http://sub2.xn--lt-uia.mochi.test:8888/tests/docshell/test/navigation/object_recursive_load.html"></object> 
  <iframe id="nestedSrcdoc" srcdoc="Srcdoc that will embed an iframe &lt;iframe id=&quot;static&quot; src=&quot;http://example.com/tests/docshell/test/navigation/file_nested_srcdoc.html&quot;&gt;&lt;/iframe&gt;"></iframe>
</div>
</body>
</html>