summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_739531.js
blob: 507d10a5f1b487eeeed5450a9a18378791c5c02e (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// This test ensures that attempts made to save/restore ("duplicate") pages
// using designmode AND make changes to document structure (remove body)
// don't result in uncaught errors and a broken browser state.

function test() {
  waitForExplicitFinish();

  let testURL =
    "http://mochi.test:8888/browser/" +
    "browser/components/sessionstore/test/browser_739531_sample.html";

  let loadCount = 0;
  let tab = BrowserTestUtils.addTab(gBrowser, testURL);

  let removeFunc;
  removeFunc = BrowserTestUtils.addContentEventListener(
    tab.linkedBrowser,
    "load",
    function onLoad(aEvent) {
      // make sure both the page and the frame are loaded
      if (++loadCount < 2) {
        return;
      }
      removeFunc();

      // executeSoon to allow the JS to execute on the page
      executeSoon(function () {
        let tab2;
        let caughtError = false;
        try {
          tab2 = ss.duplicateTab(window, tab);
        } catch (e) {
          caughtError = true;
          info(e);
        }

        is(gBrowser.tabs.length, 3, "there should be 3 tabs");

        ok(!caughtError, "duplicateTab didn't throw");

        // if the test fails, we don't want to try to close a tab that doesn't exist
        if (tab2) {
          gBrowser.removeTab(tab2);
        }
        gBrowser.removeTab(tab);

        finish();
      });
    },
    true
  );
}