summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/general/browser_restore_isAppTab.js
blob: ab26342692e1f070525bbb262f5c433e73b7d179 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

const { TabStateFlusher } = ChromeUtils.importESModule(
  "resource:///modules/sessionstore/TabStateFlusher.sys.mjs"
);

const DUMMY =
  "https://example.com/browser/browser/base/content/test/general/dummy_page.html";

function isBrowserAppTab(browser) {
  return browser.browsingContext.isAppTab;
}

// Restarts the child process by crashing it then reloading the tab
var restart = async function (browser) {
  // If the tab isn't remote this would crash the main process so skip it
  if (!browser.isRemoteBrowser) {
    return;
  }

  // Make sure the main process has all of the current tab state before crashing
  await TabStateFlusher.flush(browser);

  await BrowserTestUtils.crashFrame(browser);

  let tab = gBrowser.getTabForBrowser(browser);
  SessionStore.reviveCrashedTab(tab);

  await promiseTabLoaded(tab);
};

add_task(async function navigate() {
  let tab = BrowserTestUtils.addTab(gBrowser, "about:robots");
  let browser = tab.linkedBrowser;
  gBrowser.selectedTab = tab;
  await BrowserTestUtils.browserStopped(gBrowser);
  let isAppTab = isBrowserAppTab(browser);
  ok(!isAppTab, "Docshell shouldn't think it is an app tab");

  gBrowser.pinTab(tab);
  isAppTab = isBrowserAppTab(browser);
  ok(isAppTab, "Docshell should think it is an app tab");

  BrowserTestUtils.loadURIString(gBrowser, DUMMY);
  await BrowserTestUtils.browserStopped(gBrowser);
  isAppTab = isBrowserAppTab(browser);
  ok(isAppTab, "Docshell should think it is an app tab");

  gBrowser.unpinTab(tab);
  isAppTab = isBrowserAppTab(browser);
  ok(!isAppTab, "Docshell shouldn't think it is an app tab");

  gBrowser.pinTab(tab);
  isAppTab = isBrowserAppTab(browser);
  ok(isAppTab, "Docshell should think it is an app tab");

  BrowserTestUtils.loadURIString(gBrowser, "about:robots");
  await BrowserTestUtils.browserStopped(gBrowser);
  isAppTab = isBrowserAppTab(browser);
  ok(isAppTab, "Docshell should think it is an app tab");

  gBrowser.removeCurrentTab();
});

add_task(async function crash() {
  if (!gMultiProcessBrowser || !AppConstants.MOZ_CRASHREPORTER) {
    return;
  }

  let tab = BrowserTestUtils.addTab(gBrowser, DUMMY);
  let browser = tab.linkedBrowser;
  gBrowser.selectedTab = tab;
  await BrowserTestUtils.browserStopped(gBrowser);
  let isAppTab = isBrowserAppTab(browser);
  ok(!isAppTab, "Docshell shouldn't think it is an app tab");

  gBrowser.pinTab(tab);
  isAppTab = isBrowserAppTab(browser);
  ok(isAppTab, "Docshell should think it is an app tab");

  await restart(browser);
  isAppTab = isBrowserAppTab(browser);
  ok(isAppTab, "Docshell should think it is an app tab");

  gBrowser.removeCurrentTab();
});