summaryrefslogtreecommitdiffstats
path: root/toolkit/components/certviewer/tests/browser/browser_checkStandAlonePage.js
blob: 02d8fdc2503c300b50768a524cab460526c5d43c (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TYPE_CA = 1;
const TYPE_USER = 2;
const TYPE_EMAIL = 4;
const TYPE_SERVER = 8;

add_task(async function test_dbItemDisplayed() {
  await BrowserTestUtils.openNewForegroundTab(gBrowser, () => {
    gBrowser.selectedTab = BrowserTestUtils.addTab(
      gBrowser,
      "about:certificate"
    );
  });

  let categories = [
    {
      type: TYPE_CA,
      tabName: "Authorities",
      id: "ca",
    },
    {
      type: TYPE_USER,
      tabName: "Your Certificates",
      id: "mine",
    },
    {
      type: TYPE_EMAIL,
      tabName: "People",
      id: "people",
    },
    {
      type: TYPE_SERVER,
      tabName: "Servers",
      id: "servers",
    },
  ];

  let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
    Ci.nsIX509CertDB
  );
  Assert.ok(certdb, "certdb not null");
  let certcache = certdb.getCerts();
  Assert.ok(certcache, "certcache not null");

  for (let cert of certcache) {
    let category = categories.find(({ type }) => type & cert.certType);

    await SpecialPowers.spawn(
      gBrowser.selectedBrowser,
      [cert.displayName, category],
      async function (displayName, category) {
        let aboutCertificateSection = await ContentTaskUtils.waitForCondition(
          () => {
            return content.document.querySelector("about-certificate-section");
          },
          "Found aboutCertificateSection."
        );

        let tab = aboutCertificateSection.shadowRoot.querySelector(
          `.certificate-tabs #certificate-viewer-tab-${category.id}`
        );
        Assert.ok(tab, `${category.tabName} tab should exist.`);
        tab.click();

        let certificateItems = aboutCertificateSection.shadowRoot.querySelector(
          `.info-groups #certificate-viewer-tab-${category.id}`
        );

        let listItems =
          certificateItems.shadowRoot.querySelectorAll("list-item");

        let item = Array.from(listItems).find(
          i =>
            i.shadowRoot.querySelector(".item-name").textContent == displayName
        );
        Assert.ok(item, `${displayName} should be listed`);
      }
    );
  }

  gBrowser.removeCurrentTab(); // closes about:certificate
});