summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/local/test/unit/test_folderLoaded.js
blob: 398aa6bff45d7928de0204f429485ce1927fcbb2 (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
/* 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/. */

/**
 * The intent of this file is to show a folder loaded event after a load
 * with a null database.
 */

var { MessageGenerator, SyntheticMessageSet } = ChromeUtils.import(
  "resource://testing-common/mailnews/MessageGenerator.jsm"
);
var { MessageInjection } = ChromeUtils.import(
  "resource://testing-common/mailnews/MessageInjection.jsm"
);
var { PromiseTestUtils } = ChromeUtils.import(
  "resource://testing-common/mailnews/PromiseTestUtils.jsm"
);

var testSubjects = [
  "[Bug 397009] A filter will let me tag, but not untag",
  "Hello, did you receive my bugmail?",
];
var gMsgFile1 = do_get_file("../../../data/bugmail1");
var gMsgFile2 = do_get_file("../../../data/draft1");

var gTargetFolder = null;

add_setup(async function () {
  if (typeof localAccountUtils.inboxFolder == "undefined") {
    localAccountUtils.loadLocalMailAccount();
  }
  localAccountUtils.rootFolder.createSubfolder("target", null);
  gTargetFolder = localAccountUtils.rootFolder.getChildNamed("target");

  let copyListenerFile1 = new PromiseTestUtils.PromiseCopyListener();
  MailServices.copy.copyFileMessage(
    gMsgFile1,
    gTargetFolder,
    null,
    false,
    0,
    "",
    copyListenerFile1,
    null
  );
  await copyListenerFile1.promise;

  let copyListenerFile2 = new PromiseTestUtils.PromiseCopyListener();
  MailServices.copy.copyFileMessage(
    gMsgFile2,
    gTargetFolder,
    null,
    false,
    0,
    "",
    copyListenerFile2,
    null
  );
  await copyListenerFile2.promise;
});

add_task(async function firstUpdate() {
  // Get message headers for the target folder.
  var msgCount = 0;
  for (let hdr of gTargetFolder.msgDatabase.enumerateMessages()) {
    msgCount++;
    Assert.equal(hdr.subject, testSubjects[msgCount - 1]);
  }
  Assert.equal(msgCount, 2);

  let folderAddedListener = PromiseTestUtils.promiseFolderEvent(
    gTargetFolder,
    "FolderLoaded"
  );
  gTargetFolder.updateFolder(null);
  await folderAddedListener;
});

add_task(async function secondUpdate() {
  // If the following executes, the test hangs in bug 787557.
  gTargetFolder.msgDatabase = null;
  let folderAddedListener = PromiseTestUtils.promiseFolderEvent(
    gTargetFolder,
    "FolderLoaded"
  );
  gTargetFolder.updateFolder(null);
  await folderAddedListener;
});