summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/folder-pane/browser_folderPane.js
blob: 5b4ca546ff9e698d5b5bbc9706d8e6ce6b95b319 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* 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/. */

/*
 * Tests for the folder pane, in particular the tree view. This is kept separate
 * from the main folder-display suite so that the folders created by other tests
 * there don't influence the results here.
 */

"use strict";

var {
  FAKE_SERVER_HOSTNAME,
  assert_folder_mode,
  assert_folder_tree_view_row_count,
  be_in_folder,
  collapse_folder,
  create_folder,
  enter_folder,
  expand_folder,
  get_about_3pane,
  mc,
} = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);

var { MailUtils } = ChromeUtils.import("resource:///modules/MailUtils.jsm");
var { MailServices } = ChromeUtils.import(
  "resource:///modules/MailServices.jsm"
);

/**
 * Assert the Folder Pane is in All Folder mode by default.  Check that the
 * correct number of rows for accounts and folders are always shown as new
 * folders are created, expanded, and collapsed.
 */
add_task(async function test_all_folders_toggle_folder_open_state() {
  // Test that we are in All Folders mode by default
  assert_folder_mode("all");

  let pop3Server = MailServices.accounts.findServer(
    "tinderbox",
    FAKE_SERVER_HOSTNAME,
    "pop3"
  );
  collapse_folder(pop3Server.rootFolder);
  collapse_folder(MailServices.accounts.localFoldersServer.rootFolder);

  // All folders mode should give us only 2 rows to start
  // (tinderbox account and local folders)
  let accounts = 2;
  assert_folder_tree_view_row_count(accounts);

  let inbox = 1;
  let trash = 1;
  let outbox = 1;
  let archives = 1;
  let folderPaneA = 1;
  // Create archives folder - this is ugly, but essentially the same as
  // what mailWindowOverlay.js does. We can't use the built-in helper
  // method to create the folder because we need the archive flag to get
  // set before the folder added notification is sent out, which means
  // creating the folder object via RDF, setting the flag, and then
  // creating the storage, which sends the notification.
  let folder = MailUtils.getOrCreateFolder(
    pop3Server.rootFolder.URI + "/Archives"
  );
  folder.setFlag(Ci.nsMsgFolderFlags.Archive);
  folder.createStorageIfMissing(null);
  // After creating Archives, account should have expanded
  // so that we should have 5 rows visible
  assert_folder_tree_view_row_count(accounts + inbox + trash + archives);
  // close the tinderbox server.
  collapse_folder(pop3Server.rootFolder);
  let folderA = await create_folder("FolderPaneA");
  await be_in_folder(folderA);

  // After creating our first folder we should have 6 rows visible
  assert_folder_tree_view_row_count(
    accounts + inbox + trash + outbox + folderPaneA
  );

  let about3Pane = get_about_3pane();
  let oneFolderCount = about3Pane.folderTree.rowCount;

  // This makes sure the folder can be toggled
  folderA.createSubfolder("FolderPaneB", null);
  let folderB = folderA.getChildNamed("FolderPaneB");
  // Enter folderB, then enter folderA. This makes sure that folderA is not
  // collapsed.
  await enter_folder(folderB);
  await enter_folder(folderA);

  // At this point folderA should be open, so the view should have one more
  // item than before (FolderPaneB).
  assert_folder_tree_view_row_count(oneFolderCount + 1);

  // Toggle the open state of folderA
  collapse_folder(folderA);

  // folderA should be collapsed so we are back to the original count
  assert_folder_tree_view_row_count(oneFolderCount);

  // Toggle it back to open
  expand_folder(folderA);

  // folderB should be visible again
  assert_folder_tree_view_row_count(oneFolderCount + 1);

  // Close folderA and delete folderB.
  collapse_folder(folderA);
  MailServices.accounts.localFoldersServer.rootFolder.propagateDelete(
    folderB,
    true
  );
  // Open folderA again and check folderB is deleted.
  expand_folder(folderA);
  assert_folder_tree_view_row_count(oneFolderCount);

  // Clean up
  expand_folder(pop3Server.rootFolder);
  folder.clearFlag(Ci.nsMsgFolderFlags.Archive);
  pop3Server.rootFolder.propagateDelete(folder, true, null);
  MailServices.accounts.localFoldersServer.rootFolder.propagateDelete(
    folderA,
    true
  );

  Assert.report(
    false,
    undefined,
    undefined,
    "Test ran to completion successfully"
  );
});