summaryrefslogtreecommitdiffstats
path: root/comm/mail/components/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mail/components/test/unit')
-rw-r--r--comm/mail/components/test/unit/head_mailcomponents.js20
-rw-r--r--comm/mail/components/test/unit/test_about_support.js219
-rw-r--r--comm/mail/components/test/unit/test_telemetry_buildconfig.js151
-rw-r--r--comm/mail/components/test/unit/xpcshell.ini6
4 files changed, 396 insertions, 0 deletions
diff --git a/comm/mail/components/test/unit/head_mailcomponents.js b/comm/mail/components/test/unit/head_mailcomponents.js
new file mode 100644
index 0000000000..0c275d8abb
--- /dev/null
+++ b/comm/mail/components/test/unit/head_mailcomponents.js
@@ -0,0 +1,20 @@
+var { MailServices } = ChromeUtils.import(
+ "resource:///modules/MailServices.jsm"
+);
+var { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+var { mailTestUtils } = ChromeUtils.import(
+ "resource://testing-common/mailnews/MailTestUtils.jsm"
+);
+
+var CC = Components.Constructor;
+
+// Ensure the profile directory is set up
+do_get_profile();
+
+var gDEPTH = "../../../../";
+
+registerCleanupFunction(function () {
+ load(gDEPTH + "mailnews/resources/mailShutdown.js");
+});
diff --git a/comm/mail/components/test/unit/test_about_support.js b/comm/mail/components/test/unit/test_about_support.js
new file mode 100644
index 0000000000..5626cbbe83
--- /dev/null
+++ b/comm/mail/components/test/unit/test_about_support.js
@@ -0,0 +1,219 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// mail/components/about-support/content/accounts.js
+/* globals AboutSupport, AboutSupportPlatform */
+
+var { localAccountUtils } = ChromeUtils.import(
+ "resource://testing-common/mailnews/LocalAccountUtils.jsm"
+);
+
+/*
+ * Test the about:support module.
+ */
+
+var gAccountList = [
+ {
+ type: "pop3",
+ port: 1234,
+ user: "pop3user",
+ password: "pop3password",
+ socketType: Ci.nsMsgSocketType.plain,
+ authMethod: Ci.nsMsgAuthMethod.old,
+ smtpServers: [],
+ },
+ {
+ type: "imap",
+ port: 2345,
+ user: "imapuser",
+ password: "imappassword",
+ socketType: Ci.nsMsgSocketType.trySTARTTLS,
+ authMethod: Ci.nsMsgAuthMethod.passwordCleartext,
+ smtpServers: [
+ {
+ port: 3456,
+ user: "imapout",
+ password: "imapoutpassword",
+ isDefault: true,
+ socketType: Ci.nsMsgSocketType.alwaysSTARTTLS,
+ authMethod: Ci.nsMsgAuthMethod.passwordEncrypted,
+ },
+ ],
+ },
+ {
+ type: "nntp",
+ port: 4567,
+ user: null,
+ password: null,
+ socketType: Ci.nsMsgSocketType.SSL,
+ authMethod: Ci.nsMsgAuthMethod.GSSAPI,
+ smtpServers: [
+ {
+ port: 5678,
+ user: "newsout1",
+ password: "newsoutpassword1",
+ isDefault: true,
+ socketType: Ci.nsMsgSocketType.SSL,
+ authMethod: Ci.nsMsgAuthMethod.NTLM,
+ },
+ {
+ port: 6789,
+ user: "newsout2",
+ password: "newsoutpassword2",
+ isDefault: false,
+ socketType: Ci.nsMsgSocketType.SSL,
+ authMethod: Ci.nsMsgAuthMethod.External,
+ },
+ ],
+ },
+];
+
+// A map of account keys to servers. Populated by setup_accounts.
+var gAccountMap = new Map();
+// A map of SMTP server names to SMTP servers. Populated by setup_accounts.
+var gSMTPMap = new Map();
+
+/**
+ * A list of sensitive data: it shouldn't be present in the account
+ * details. Populated by setup_accounts.
+ */
+var gSensitiveData = [];
+
+/**
+ * Set up accounts based on the given data.
+ */
+function setup_accounts() {
+ // First make sure the local folders account is set up.
+ localAccountUtils.loadLocalMailAccount();
+
+ // Now run through the details and set up accounts accordingly.
+ for (let details of gAccountList) {
+ let server = localAccountUtils.create_incoming_server(
+ details.type,
+ details.port,
+ details.user,
+ details.password
+ );
+ server.socketType = details.socketType;
+ server.authMethod = details.authMethod;
+ gSensitiveData.push(details.password);
+ let account = MailServices.accounts.FindAccountForServer(server);
+ for (let smtpDetails of details.smtpServers) {
+ let outgoing = localAccountUtils.create_outgoing_server(
+ smtpDetails.port,
+ smtpDetails.user,
+ smtpDetails.password
+ );
+ outgoing.socketType = smtpDetails.socketType;
+ outgoing.authMethod = smtpDetails.authMethod;
+ localAccountUtils.associate_servers(
+ account,
+ outgoing,
+ smtpDetails.isDefault
+ );
+ gSensitiveData.push(smtpDetails.password);
+
+ // Add the SMTP server to our server name -> server map
+ gSMTPMap.set("localhost:" + smtpDetails.port, smtpDetails);
+ }
+
+ // Add the server to our account -> server map
+ gAccountMap.set(account.key, details);
+ }
+}
+
+/**
+ * Verify that the given account's details match our details for the key.
+ */
+function verify_account_details(aDetails) {
+ let expectedDetails = gAccountMap.get(aDetails.key);
+ // All our servers are at localhost
+ let expectedHostDetails =
+ "(" + expectedDetails.type + ") localhost:" + expectedDetails.port;
+ Assert.equal(aDetails.hostDetails, expectedHostDetails);
+ Assert.equal(aDetails.socketType, expectedDetails.socketType);
+ Assert.equal(aDetails.authMethod, expectedDetails.authMethod);
+
+ let smtpToSee = expectedDetails.smtpServers.map(
+ smtpDetails => "localhost:" + smtpDetails.port
+ );
+
+ for (let smtpDetails of aDetails.smtpServers) {
+ // Check that we're expecting to see this server
+ let toSeeIndex = smtpToSee.indexOf(smtpDetails.name);
+ Assert.notEqual(toSeeIndex, -1);
+ smtpToSee.splice(toSeeIndex, 1);
+
+ let expectedSMTPDetails = gSMTPMap.get(smtpDetails.name);
+ Assert.equal(smtpDetails.socketType, expectedSMTPDetails.socketType);
+ Assert.equal(smtpDetails.authMethod, expectedSMTPDetails.authMethod);
+ Assert.equal(smtpDetails.isDefault, expectedSMTPDetails.isDefault);
+ }
+
+ // Check that we saw all the SMTP servers we wanted to see
+ Assert.equal(smtpToSee.length, 0);
+}
+
+/**
+ * Tests the getFileSystemType function. This is more a check to make sure the
+ * function returns something meaningful and doesn't throw an exception, since
+ * we don't have any information about what sort of file system we're running
+ * on.
+ */
+function test_get_file_system_type() {
+ let fsType = AboutSupportPlatform.getFileSystemType(do_get_cwd());
+ if ("nsILocalFileMac" in Ci) {
+ // Mac should return null
+ Assert.equal(fsType, null);
+ } else {
+ // Windows and Linux should return a string
+ Assert.ok(["local", "network", "unknown"].includes(fsType));
+ }
+}
+
+/**
+ * Test the getAccountDetails function.
+ */
+function test_get_account_details() {
+ let accountDetails = AboutSupport.getAccountDetails();
+ let accountDetailsText = uneval(accountDetails);
+ // The list of accounts we are looking for
+ let accountsToSee = [...gAccountMap.keys()];
+
+ // Our first check is to see that no sensitive data has crept in
+ for (let data of gSensitiveData) {
+ Assert.ok(!accountDetailsText.includes(data));
+ }
+
+ for (let details of accountDetails) {
+ // We're going to make one exception: for the local folders server. We don't
+ // care too much about its details.
+ if (details.key == localAccountUtils.msgAccount.key) {
+ continue;
+ }
+
+ // Check that we're expecting to see this server
+ let toSeeIndex = accountsToSee.indexOf(details.key);
+ Assert.notEqual(toSeeIndex, -1);
+ accountsToSee.splice(toSeeIndex, 1);
+
+ verify_account_details(details);
+ }
+ // Check that we got all the accounts we wanted to see
+ Assert.equal(accountsToSee.length, 0);
+}
+
+var tests = [test_get_file_system_type, test_get_account_details];
+
+function run_test() {
+ Services.scriptloader.loadSubScript(
+ "chrome://messenger/content/about-support/accounts.js"
+ );
+
+ setup_accounts();
+
+ for (let test of tests) {
+ test();
+ }
+}
diff --git a/comm/mail/components/test/unit/test_telemetry_buildconfig.js b/comm/mail/components/test/unit/test_telemetry_buildconfig.js
new file mode 100644
index 0000000000..aa8d20bbb8
--- /dev/null
+++ b/comm/mail/components/test/unit/test_telemetry_buildconfig.js
@@ -0,0 +1,151 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// This test is a copy of parts of the following tests:
+//
+// * toolkit/components/telemetry/tests/unit/test_TelemetryEvents.js
+// * toolkit/components/telemetry/tests/unit/test_TelemetryHistograms.js
+// * toolkit/components/telemetry/tests/unit/test_TelemetryScalars.js
+//
+// The probe names have been changed to probes that only exist in a Thunderbird build.
+// If this test begins to fail, check for recent changes in toolkit/components/telemetry.
+
+ChromeUtils.defineESModuleGetters(this, {
+ TelemetryTestUtils: "resource://testing-common/TelemetryTestUtils.sys.mjs",
+});
+
+const Telemetry = Services.telemetry;
+
+const UINT_SCALAR = "tb.test.unsigned_int_kind";
+const STRING_SCALAR = "tb.test.string_kind";
+const BOOLEAN_SCALAR = "tb.test.boolean_kind";
+
+/**
+ * Check that stored events correspond to expectations.
+ *
+ * @param {Array} summaries - Summary of the expected events.
+ * @param {boolean} clearScalars - Whether to clear out data after snapshotting.
+ */
+function checkEventSummary(summaries, clearScalars) {
+ let scalars = Telemetry.getSnapshotForKeyedScalars("main", clearScalars);
+
+ for (let [process, [category, eObject, method], count] of summaries) {
+ let uniqueEventName = `${category}#${eObject}#${method}`;
+ let summaryCount;
+ if (process === "dynamic") {
+ summaryCount =
+ scalars.dynamic["telemetry.dynamic_event_counts"][uniqueEventName];
+ } else {
+ summaryCount =
+ scalars[process]["telemetry.event_counts"][uniqueEventName];
+ }
+ Assert.equal(
+ summaryCount,
+ count,
+ `${uniqueEventName} had wrong summary count`
+ );
+ }
+}
+
+/**
+ * Test Thunderbird events are included in the build.
+ */
+add_task(async function test_recording_state() {
+ Telemetry.clearEvents();
+ Telemetry.clearScalars();
+
+ const events = [["tb.test", "test", "object1"]];
+
+ // Recording off by default.
+ events.forEach(e => Telemetry.recordEvent(...e));
+ TelemetryTestUtils.assertEvents([]);
+ // But still expect a non-zero summary count.
+ checkEventSummary(
+ events.map(e => ["parent", e, 1]),
+ true
+ );
+
+ // Once again, with recording on.
+ Telemetry.setEventRecordingEnabled("tb.test", true);
+ events.forEach(e => Telemetry.recordEvent(...e));
+ TelemetryTestUtils.assertEvents(events);
+ checkEventSummary(
+ events.map(e => ["parent", e, 1]),
+ true
+ );
+});
+
+/**
+ * Test Thunderbird histograms are included in the build.
+ */
+add_task(async function test_categorical_histogram() {
+ let h1 = Telemetry.getHistogramById("TELEMETRY_TEST_TB_CATEGORICAL");
+ for (let v of ["CommonLabel", "CommonLabel", "Label2", "Label3"]) {
+ h1.add(v);
+ }
+ for (let s of ["", "Label4", "1234"]) {
+ // The |add| method should not throw for unexpected values, but rather
+ // print an error message in the console.
+ h1.add(s);
+ }
+
+ let snapshot = h1.snapshot();
+ Assert.deepEqual(snapshot.values, { 0: 2, 1: 1, 2: 1, 3: 0 });
+ // sum is a little meaningless for categorical histograms, but hey.
+ // (CommonLabel is 0, Label2 is 1, Label3 is 2)
+ Assert.equal(snapshot.sum, 0 * 2 + 1 * 1 + 2 * 1);
+ Assert.deepEqual(snapshot.range, [1, 50]);
+});
+
+/**
+ * Test Thunderbird scalars are included in the build.
+ */
+add_task(async function test_serializationFormat() {
+ Telemetry.clearScalars();
+
+ // Set the scalars to a known value.
+ const expectedUint = 3785;
+ const expectedString = "some value";
+ Telemetry.scalarSet(UINT_SCALAR, expectedUint);
+ Telemetry.scalarSet(STRING_SCALAR, expectedString);
+ Telemetry.scalarSet(BOOLEAN_SCALAR, true);
+
+ // Get a snapshot of the scalars for the main process (internally called "default").
+ const scalars = TelemetryTestUtils.getProcessScalars("parent");
+
+ // Check that they are serialized to the correct format.
+ Assert.equal(
+ typeof scalars[UINT_SCALAR],
+ "number",
+ UINT_SCALAR + " must be serialized to the correct format."
+ );
+ Assert.ok(
+ Number.isInteger(scalars[UINT_SCALAR]),
+ UINT_SCALAR + " must be a finite integer."
+ );
+ Assert.equal(
+ scalars[UINT_SCALAR],
+ expectedUint,
+ UINT_SCALAR + " must have the correct value."
+ );
+ Assert.equal(
+ typeof scalars[STRING_SCALAR],
+ "string",
+ STRING_SCALAR + " must be serialized to the correct format."
+ );
+ Assert.equal(
+ scalars[STRING_SCALAR],
+ expectedString,
+ STRING_SCALAR + " must have the correct value."
+ );
+ Assert.equal(
+ typeof scalars[BOOLEAN_SCALAR],
+ "boolean",
+ BOOLEAN_SCALAR + " must be serialized to the correct format."
+ );
+ Assert.equal(
+ scalars[BOOLEAN_SCALAR],
+ true,
+ BOOLEAN_SCALAR + " must have the correct value."
+ );
+});
diff --git a/comm/mail/components/test/unit/xpcshell.ini b/comm/mail/components/test/unit/xpcshell.ini
new file mode 100644
index 0000000000..1b37e9a3d9
--- /dev/null
+++ b/comm/mail/components/test/unit/xpcshell.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+head = head_mailcomponents.js
+tail =
+
+[test_about_support.js]
+[test_telemetry_buildconfig.js]