File: test_triggeringprincipal_iframe_iframe_window_open.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (87 lines) | stat: -rw-r--r-- 3,285 bytes parent folder | download | duplicates (21)
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>