summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_embed_xorigin_document.html
blob: 4566d485340f07260669b3d681a5da9633f504a0 (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
<!DOCTYPE HTML>
<html>
<head>
<title>test for embedding a cross-origin document</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script>
// Get the path of the current test, without hostname or filename.
const testPath = window.location.href.replace("http://mochi.test:8888", "");
const testDir = testPath.substring(0, testPath.lastIndexOf('/') + 1);

add_task(async function() {
  info("Loading image in embed");
  let embed = document.createElement("embed");
  document.body.appendChild(embed);

  info("x-site image load from element");
  embed.setAttribute("src", "http://example.com" + testDir + "green.png");
  await new Promise(resolve => embed.addEventListener("load", resolve, { once: true }));
  is(
    SpecialPowers.wrap(embed).displayedType,
    SpecialPowers.Ci.nsIObjectLoadingContent.TYPE_DOCUMENT,
    `image load should have document type`
  );

  ok(SpecialPowers.wrap(embed).frameLoader, "should have frameloader");
  ok(SpecialPowers.wrap(embed).browsingContext, "should have bc");

  info("x-site document load from element");
  embed.setAttribute("src", "http://example.com" + testDir + "file_empty.html");
  await new Promise(resolve => embed.addEventListener("load", resolve, { once: true }));
  is(
    SpecialPowers.wrap(embed).displayedType,
    SpecialPowers.Ci.nsIObjectLoadingContent.TYPE_DOCUMENT,
    "document load should have document type"
  );
  ok(SpecialPowers.wrap(embed).frameLoader, "should have frameloader");
  ok(SpecialPowers.wrap(embed).browsingContext, "should have bc");

  info("load x-site document in iframe & compare processes");
  let iframe = document.createElement("iframe");
  iframe.setAttribute("src", "http://example.com" + testDir + "file_empty.html");
  document.body.appendChild(iframe);
  await new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));

  let embedRemoteType = await SpecialPowers.spawn(embed, [], () => Services.appinfo.remoteType);
  let iframeRemoteType = await SpecialPowers.spawn(iframe, [], () => Services.appinfo.remoteType);
  is(iframeRemoteType, embedRemoteType, "remote types should match");

  info("x-site image load from docshell");
  SpecialPowers.spawn(embed, ["http://example.com" + testDir + "green.png"], uri => {
    content.location.href = uri;
  })
  await new Promise(resolve => embed.addEventListener("load", resolve, { once: true }));
  is(
    SpecialPowers.wrap(embed).displayedType,
    SpecialPowers.Ci.nsIObjectLoadingContent.TYPE_DOCUMENT,
    "image load via location should have document type"
  );
  ok(SpecialPowers.wrap(embed).frameLoader, "should have frameloader");
  ok(SpecialPowers.wrap(embed).browsingContext, "should have bc");

  info("x-site image load from element");
  embed.setAttribute("src", "http://example.com" + testDir + "green.png");
  await new Promise(resolve => embed.addEventListener("load", resolve, { once: true }));
  is(
    SpecialPowers.wrap(embed).displayedType,
    SpecialPowers.Ci.nsIObjectLoadingContent.TYPE_DOCUMENT,
    `image load should have document type`
  );

  ok(SpecialPowers.wrap(embed).frameLoader, "should have frameloader");
  ok(SpecialPowers.wrap(embed).browsingContext, "should have bc");
});
</script>
</body>
</html>