summaryrefslogtreecommitdiffstats
path: root/docshell/test/navigation/test_triggeringprincipal_iframe_iframe_window_open.html
blob: 115c5f4462c35b1e5409da50507a7642a552d42a (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
<!DOCTYPE html>
<html>
<head>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>        
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <script type="text/javascript" src="NavigationUtils.js"></script>        
</head>
<body>

<iframe name="framea" id="framea" src="file_triggeringprincipal_iframe_iframe_window_open_frame_a.html"></iframe>
<iframe name="frameb" id="frameb"></iframe>

<script type="text/javascript">

/* We load an iframe (Frame A) which then gets navigated by another iframe (Frame B)
 * by calling window.open("http://", "Frame A") later in the test. We then verify the
 * TriggeringPrincipal and LoadingPrincipal of the navigated iframe (Frame A).
 *
 * +---------------------------------------+
 * |   Parent                              |
 * |                                       |
 * |  +----------------------------+       |
 * |  | Frame A                    |       |
 * |  |                            |       |
 * |  |                            |       |
 * |  +----------------------------+       |
 * |                                       |
 * |  +----------------------------+       |
 * |  | Frame B                    |       |
 * |  |                            |       |
 * |  | win.open("http://", "A")   |       |
 * |  +----------------------------+       |
 * |                                       |
 * +---------------------------------------+
 *
 * Sequence of the test:
 *   [1] load Frame A
 *   [2] load Frame B which navigates A
 *   [3] load navigated Frame A and check triggeringPrincipal and loadingPrincipal
 */

const TRIGGERING_PRINCIPAL_URI =
  "http://mochi.test:8888/tests/docshell/test/navigation/file_triggeringprincipal_iframe_iframe_window_open_frame_b.html";

const LOADING_PRINCIPAL_URI =
  "http://mochi.test:8888/tests/docshell/test/navigation/test_triggeringprincipal_iframe_iframe_window_open.html";

var frameA = document.getElementById("framea");

function checkResults() {
  frameA.removeEventListener("load", checkResults);

  var channel = SpecialPowers.wrap(frameA.contentWindow).docShell.currentDocumentChannel;
  var triggeringPrincipal = channel.loadInfo.triggeringPrincipal.asciiSpec;
  var loadingPrincipal = channel.loadInfo.loadingPrincipal.asciiSpec;

  is(triggeringPrincipal, TRIGGERING_PRINCIPAL_URI,
    "TriggeringPrincipal for targeted window.open() should be the iframe triggering the load");

  is(frameA.contentDocument.referrer, TRIGGERING_PRINCIPAL_URI,
    "Referrer for targeted window.open() should be the principal of the iframe triggering the load");

  is(loadingPrincipal.split("?")[0], LOADING_PRINCIPAL_URI,
    "LoadingPrincipal for targeted window.open() should be the containing document");

  SimpleTest.finish();
}

function performNavigation() {
  frameA.removeEventListener("load", performNavigation);
  frameA.addEventListener("load", checkResults);

  // load Frame B which then navigates Frame A
  var frameB = document.getElementById("frameb");
  frameB.src = "file_triggeringprincipal_iframe_iframe_window_open_frame_b.html";
}

// start the test
SimpleTest.waitForExplicitFinish();

frameA.addEventListener("load", performNavigation);

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