summaryrefslogtreecommitdiffstats
path: root/browser/components/aboutlogins/tests/browser/browser_sessionRestore.js
blob: 5ab03f98670d19fc474ae543e013060240fdfe78 (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/ */

"use strict";

async function checkLoginDisplayed(browser, testGuid) {
  await SpecialPowers.spawn(browser, [testGuid], async function (guid) {
    let loginList = Cu.waiveXrays(content.document.querySelector("login-list"));
    let loginFound = await ContentTaskUtils.waitForCondition(() => {
      return (
        loginList._loginGuidsSortedOrder.length == 1 &&
        loginList._loginGuidsSortedOrder[0] == guid
      );
    }, "Waiting for login to be displayed in page");
    Assert.ok(loginFound, "Confirming that login is displayed in page");
  });
}

add_task(async function () {
  TEST_LOGIN1 = await addLogin(TEST_LOGIN1);
  registerCleanupFunction(() => {
    Services.logins.removeAllUserFacingLogins();
  });

  const testGuid = TEST_LOGIN1.guid;
  const tab = BrowserTestUtils.addTab(gBrowser, "about:logins");
  const browser = gBrowser.getBrowserForTab(tab);
  await BrowserTestUtils.browserLoaded(browser);

  await checkLoginDisplayed(browser, testGuid);

  BrowserTestUtils.removeTab(tab);
  info("Adding a lazy about:logins tab...");
  let lazyTab = BrowserTestUtils.addTab(gBrowser, "about:logins", {
    createLazyBrowser: true,
  });

  Assert.equal(lazyTab.linkedPanel, "", "Tab is lazy");
  let tabLoaded = new Promise(resolve => {
    gBrowser.addTabsProgressListener({
      async onLocationChange(aBrowser) {
        if (lazyTab.linkedBrowser == aBrowser) {
          gBrowser.removeTabsProgressListener(this);
          await Promise.resolve();
          resolve();
        }
      },
    });
  });

  info("Switching tab to cause it to get restored");
  const browserLoaded = BrowserTestUtils.browserLoaded(lazyTab.linkedBrowser);
  await BrowserTestUtils.switchTab(gBrowser, lazyTab);

  await tabLoaded;
  await browserLoaded;

  let lazyBrowser = lazyTab.linkedBrowser;
  await checkLoginDisplayed(lazyBrowser, testGuid);

  BrowserTestUtils.removeTab(lazyTab);
});