summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_newtab_userTypedValue.js
blob: 66dc93380398184d03e87ad6257ef1e8c29e9247 (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
"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(function* () {
  let win = yield BrowserTestUtils.openNewBrowserWindow();
  yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:logo");
  let tabOpenedAndSwitchedTo = BrowserTestUtils.switchTab(win.gBrowser, () => {});

  // This opens about:newtab:
  win.BrowserOpenTab();
  let tab = yield 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;

  yield BrowserTestUtils.closeWindow(win);

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

  win = SessionStore.undoCloseWindow(0);
  yield 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.
  yield 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");

  yield 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());
    yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, url);
    yield BrowserTestUtils.closeWindow(win);

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

    win = SessionStore.undoCloseWindow(0);
    yield TestUtils.topicObserved("sessionstore-single-window-restored",
                                  subject => subject == win);
    yield BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser);
    yield 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());
    yield BrowserTestUtils.removeTab(tab);
    info("Finished removing tab - " + new Date());
  }
  info("Removing window - " + new Date());
  yield BrowserTestUtils.closeWindow(win);
  info("Finished removing window - " + new Date());
});