summaryrefslogtreecommitdiffstats
path: root/docshell/test/browser/browser_bug673467.js
blob: 507410254c4ce372da20dc8489f9814f617b119a (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Test for bug 673467.  In a new tab, load a page which inserts a new iframe
// before the load and then sets its location during the load.  This should
// create just one SHEntry.

var doc =
  "data:text/html,<html><body onload='load()'>" +
  "<script>" +
  "  var iframe = document.createElement('iframe');" +
  "  iframe.id = 'iframe';" +
  "  document.documentElement.appendChild(iframe);" +
  "  function load() {" +
  "    iframe.src = 'data:text/html,Hello!';" +
  "  }" +
  "</script>" +
  "</body></html>";

function test() {
  waitForExplicitFinish();

  let taskFinished;

  let tab = BrowserTestUtils.addTab(gBrowser, doc, {}, tab => {
    taskFinished = ContentTask.spawn(tab.linkedBrowser, null, () => {
      return new Promise(resolve => {
        addEventListener(
          "load",
          function () {
            // The main page has loaded.  Now wait for the iframe to load.
            let iframe = content.document.getElementById("iframe");
            iframe.addEventListener(
              "load",
              function listener(aEvent) {
                // Wait for the iframe to load the new document, not about:blank.
                if (!iframe.src) {
                  return;
                }

                iframe.removeEventListener("load", listener, true);
                let shistory = content.docShell.QueryInterface(
                  Ci.nsIWebNavigation
                ).sessionHistory;

                Assert.equal(shistory.count, 1, "shistory count should be 1.");
                resolve();
              },
              true
            );
          },
          true
        );
      });
    });
  });

  taskFinished.then(() => {
    gBrowser.removeTab(tab);
    finish();
  });
}