summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_newtab_userTypedValue.js
blob: 755a1f28594ba5e1cc3f32230342268d51275727 (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
88
89
90
91
92
"use strict";

requestLongerTimeout(4);

/**
 * Test that when restoring an 'initial page' with session restore, it
 * produces an empty URL bar, rather than leaving its URL explicitly
 * there as a 'user typed value'.
 */
add_task(async function () {
  let win = await BrowserTestUtils.openNewBrowserWindow();
  await BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:logo");
  let tabOpenedAndSwitchedTo = BrowserTestUtils.switchTab(
    win.gBrowser,
    () => {}
  );

  // This opens about:newtab:
  win.BrowserOpenTab();
  let tab = await tabOpenedAndSwitchedTo;
  is(win.gURLBar.value, "", "URL bar should be empty");
  is(tab.linkedBrowser.userTypedValue, null, "userTypedValue should be null");
  let state = JSON.parse(SessionStore.getTabState(tab));
  ok(
    !state.userTypedValue,
    "userTypedValue should be undefined on the tab's state"
  );
  tab = null;

  await BrowserTestUtils.closeWindow(win);

  ok(SessionStore.getClosedWindowCount(), "Should have a closed window");

  await forceSaveState();

  win = SessionStore.undoCloseWindow(0);
  await TestUtils.topicObserved(
    "sessionstore-single-window-restored",
    subject => subject == win
  );
  // Don't wait for load here because it's about:newtab and we may have swapped in
  // a preloaded browser.
  await TabStateFlusher.flush(win.gBrowser.selectedBrowser);

  is(win.gURLBar.value, "", "URL bar should be empty");
  tab = win.gBrowser.selectedTab;
  is(tab.linkedBrowser.userTypedValue, null, "userTypedValue should be null");
  state = JSON.parse(SessionStore.getTabState(tab));
  ok(
    !state.userTypedValue,
    "userTypedValue should be undefined on the tab's state"
  );

  BrowserTestUtils.removeTab(tab);

  for (let url of gInitialPages) {
    if (url == BROWSER_NEW_TAB_URL) {
      continue; // We tested about:newtab using BrowserOpenTab() above.
    }
    info("Testing " + url + " - " + new Date());
    await BrowserTestUtils.openNewForegroundTab(win.gBrowser, url);
    await BrowserTestUtils.closeWindow(win);

    ok(SessionStore.getClosedWindowCount(), "Should have a closed window");

    await forceSaveState();

    win = SessionStore.undoCloseWindow(0);
    await TestUtils.topicObserved(
      "sessionstore-single-window-restored",
      subject => subject == win
    );
    await BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
    await TabStateFlusher.flush(win.gBrowser.selectedBrowser);

    is(win.gURLBar.value, "", "URL bar should be empty");
    tab = win.gBrowser.selectedTab;
    is(tab.linkedBrowser.userTypedValue, null, "userTypedValue should be null");
    state = JSON.parse(SessionStore.getTabState(tab));
    ok(
      !state.userTypedValue,
      "userTypedValue should be undefined on the tab's state"
    );

    info("Removing tab - " + new Date());
    BrowserTestUtils.removeTab(tab);
    info("Finished removing tab - " + new Date());
  }
  info("Removing window - " + new Date());
  await BrowserTestUtils.closeWindow(win);
  info("Finished removing window - " + new Date());
});