summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/bugs/test_bug593174.html
blob: 370d40b79cc633f4ecc601305d43b501d6abc5b8 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=593174
-->
<head>
  <title>Test for Bug 593174</title>
  <script type="text/javascript" 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=593174">Mozilla Bug 593174</a>

<script>

SimpleTest.waitForExplicitFinish();

var loadCount = 0;
var popup = null;

const kOriginalLocation = location.href;

function iframeLoaded(identifier) {
  loadCount++;
  dump("iframeLoaded. loadCount=" + loadCount +
                    " identifier='" + identifier + "'\n");

  var iframe = document.getElementById('iframe');
  var iframeCw = iframe.contentWindow;

  if (loadCount == 1) {
    // Test 1: Navigate iframe1.  This page should be the referer.
    // We'll get a callback from the inner page when its iframe finishes
    // loading, so get rid of the onload listener on our iframe.

    // Change this page's URI using replaceState; the referrer should be this
    // new value, not our original location.
    history.replaceState('', '', Math.random());

    iframe.onload = null;
    iframeCw.location = 'file_bug593174_2.html';
  }
  else if (loadCount == 2) {
    // Test 1: Check that this page is the referer.
    is(iframeCw.document.referrer, String(document.location), 'outer iframe referrer');

    // Test 2: file_bug593174_2.html itself contains an iframe, whose src is a
    // data: uri.  Call into that inner iframe and have it set its
    // document.location.  The new document's referrer should be
    // file_bug593174_2.html.

    // We'll get a call to iframeLoaded when this finishes.
    iframeCw.navigateInnerIframe();
  }
  else if (loadCount == 3) {
    is(iframeCw.getInnerIframeReferrer(), String(iframeCw.location), 'inner iframe referrer');

    // Now do the test again, this time with a popup.
    popup = window.open('file_bug593174_1.html');
    popup.onload = iframeLoaded('popup/outer');
  }
  else if (loadCount == 4) {
    history.replaceState('', '', Math.random());

    popup.onload = null;
    popup.location = 'file_bug593174_2.html';
  }
  else if (loadCount == 5) {
    is(popup.document.referrer, String(document.location), 'popup referrer after replaceState');
    popup.navigateInnerIframe();
  }
  else if (loadCount == 6) {
    is(popup.getInnerIframeReferrer(), String(popup.location), 'popup/inner iframe referrer');
    popup.close();
    history.replaceState('', '', kOriginalLocation);
    SimpleTest.finish();
  }
}

</script>

<iframe onload='iframeLoaded("outer")' id='iframe' src='file_bug593174_1.html'></iframe>

</body>
</html>