summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/base/test/unit/test_bug471682.js
blob: 73e431d84f79f568245909882dcea4c4e1159b6c (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* 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/. */

/*
 * Test of message database validity on local copy from bug 471682. What
 * we want to do here is to copy a couple of message to a new folder, and
 * then compare the date and filesize of the folder file with the
 * stored result in dbfolderinfo. If they don't match, that's bad.
 */
var { MailServices } = ChromeUtils.import(
  "resource:///modules/MailServices.jsm"
);

var bugmail1 = do_get_file("../../../data/bugmail1");
var gHdr; // header of test message in local folder

localAccountUtils.loadLocalMailAccount();
// create a subfolder as a target for copies
var gSubfolder =
  localAccountUtils.inboxFolder.createLocalSubfolder("subfolder");

function run_test() {
  // make sure we're using berkeley mailbox format here since this test
  // assumes berkeley mailbox format.
  if (
    Services.prefs.getCharPref("mail.serverDefaultStoreContractID") !=
    "@mozilla.org/msgstore/berkeleystore;1"
  ) {
    return;
  }

  do_test_pending();
  // step 1: copy a message into the local inbox
  MailServices.copy.copyFileMessage(
    bugmail1,
    localAccountUtils.inboxFolder,
    null,
    false,
    0,
    "",
    step2,
    null
  );
}

// step 2: copy one message into a subfolder to establish an
//         mbox file time and size
// nsIMsgCopyServiceListener implementation
var step2 = {
  OnStartCopy() {},
  OnProgress(aProgress, aProgressMax) {},
  SetMessageKey(aKey) {
    dump("in set message key\n");
    gHdr = localAccountUtils.inboxFolder.GetMessageHeader(aKey);
  },
  SetMessageId(aMessageId) {},
  OnStopCopy(aStatus) {
    Assert.notEqual(gHdr, null);
    // copy the message into the subfolder
    MailServices.copy.copyMessages(
      localAccountUtils.inboxFolder,
      [gHdr],
      gSubfolder,
      false,
      step3,
      null,
      false
    );
  },
};

// step 3: after the copy, delay to allow copy to complete and allow possible
//         file error time
// nsIMsgCopyServiceListener implementation
var step3 = {
  OnStartCopy() {},
  OnProgress(aProgress, aProgressMax) {},
  SetMessageKey(aKey) {},
  SetMessageId(aMessageId) {},
  OnStopCopy(aStatus) {
    do_timeout(2000, step4);
  },
};

// step 4: start a second copy
function step4() {
  MailServices.copy.copyMessages(
    localAccountUtils.inboxFolder,
    [gHdr],
    gSubfolder,
    false,
    step5,
    null,
    false
  );
}

// step 5:  actual tests of file size and date
// nsIMsgCopyServiceListener implementation
var step5 = {
  OnStartCopy() {},
  OnProgress(aProgress, aProgressMax) {},
  SetMessageKey(aKey) {},
  SetMessageId(aMessageId) {},
  OnStopCopy(aStatus) {
    var dbSize = gSubfolder.msgDatabase.dBFolderInfo.folderSize;
    var dbDate = gSubfolder.msgDatabase.dBFolderInfo.folderDate;
    var filePath = gSubfolder.filePath;
    var date = parseInt(filePath.lastModifiedTime / 1000);
    var size = filePath.fileSize;
    Assert.equal(size, dbSize);
    Assert.equal(date, dbDate);
    // End of test, so release our header reference
    gHdr = null;
    do_test_finished();
  },
};