From cf974acdbcc506b2b461551e61b727e5fbdf9f14 Mon Sep 17 00:00:00 2001 From: Magnus Melin Date: Sat, 5 Nov 2022 14:23:53 +1100 Subject: [PATCH] Bug 1798238 - move dump_view_state and friends to FolderDisplayHelpers.jsm. r=aleca Differential Revision: https://phabricator.services.mozilla.com/D161115 --HG-- extra : rebase_source : 43be1296227fd9ca9bd7e9911a46d56f036400ab --- .../unit/resources/viewWrapperTestUtils.js | 84 ++----------------- .../shared-modules/FolderDisplayHelpers.jsm | 82 +++++++++++++++++- mailnews/base/test/unit/test_nsMsgDBView.js | 28 +------ .../test/unit/test_viewSortByAddresses.js | 34 +------- 4 files changed, 93 insertions(+), 135 deletions(-) diff --git a/mail/base/test/unit/resources/viewWrapperTestUtils.js b/mail/base/test/unit/resources/viewWrapperTestUtils.js index 090089bbf3..155630fe90 100644 --- a/mail/base/test/unit/resources/viewWrapperTestUtils.js +++ b/mail/base/test/unit/resources/viewWrapperTestUtils.js @@ -18,6 +18,10 @@ var { MessageInjection } = ChromeUtils.import( "resource://testing-common/mailnews/MessageInjection.jsm" ); +var { dump_view_state } = ChromeUtils.import( + "resource://testing-common/mozmill/FolderDisplayHelpers.jsm" +); + var gMessageGenerator; var gMessageScenarioFactory; var messageInjection; @@ -304,85 +308,6 @@ function dump_message_header(aMsgHdr) { ); } -var WHITESPACE = " "; -var MSG_VIEW_FLAG_DUMMY = 0x20000000; -function dump_view_contents(aViewWrapper) { - let dbView = aViewWrapper.dbView; - let treeView = aViewWrapper.dbView.QueryInterface(Ci.nsITreeView); - let rowCount = treeView.rowCount; - - dump("********* Current View Contents\n"); - for (let iViewIndex = 0; iViewIndex < rowCount; iViewIndex++) { - let level = treeView.getLevel(iViewIndex); - let flags = dbView.getFlagsAt(iViewIndex); - let msgHdr = dbView.getMsgHdrAt(iViewIndex); - - let s = WHITESPACE.substr(0, level * 2); - if (treeView.isContainer(iViewIndex)) { - s += treeView.isContainerOpen(iViewIndex) ? "- " : "+ "; - } else { - s += ". "; - } - // s += treeView.getCellText(iViewIndex, ) - if (flags & MSG_VIEW_FLAG_DUMMY) { - s += "dummy: "; - } - s += dbView.cellTextForColumn(iViewIndex, "subject"); - s += " [" + msgHdr.folder.prettyName + "," + msgHdr.messageKey + "]"; - - dump(s + "\n"); - } - dump("********* end view contents\n"); -} - -function _lookupValueNameInInterface(aValue, aInterface) { - for (let key in aInterface) { - let value = aInterface[key]; - if (value == aValue) { - return key; - } - } - return "unknown: " + aValue; -} - -function dump_view_state(aViewWrapper, aDoNotDumpContents) { - if (aViewWrapper.dbView == null) { - dump("no nsIMsgDBView instance!\n"); - return; - } - if (!aDoNotDumpContents) { - dump_view_contents(aViewWrapper); - } - dump("View: " + aViewWrapper.dbView + "\n"); - dump( - " View Type: " + - _lookupValueNameInInterface( - aViewWrapper.dbView.viewType, - Ci.nsMsgViewType - ) + - " " + - "View Flags: " + - aViewWrapper.dbView.viewFlags + - "\n" - ); - dump( - " Sort Type: " + - _lookupValueNameInInterface( - aViewWrapper.dbView.sortType, - Ci.nsMsgViewSortType - ) + - " " + - "Sort Order: " + - _lookupValueNameInInterface( - aViewWrapper.dbView.sortOrder, - Ci.nsMsgViewSortOrder - ) + - "\n" - ); - - dump(aViewWrapper.search.prettyString()); -} - /** * Verify that the messages in the provided SyntheticMessageSets are the only * visible messages in the provided DBViewWrapper. If dummy headers are present @@ -528,6 +453,7 @@ function verify_view_row_at_index_is_container(aViewWrapper, ...aArgs) { * @param ... View indices to check. */ function verify_view_row_at_index_is_dummy(aViewWrapper, ...aArgs) { + const MSG_VIEW_FLAG_DUMMY = 0x20000000; for (let viewIndex of aArgs) { let flags = aViewWrapper.dbView.getFlagsAt(viewIndex); if (!(flags & MSG_VIEW_FLAG_DUMMY)) { diff --git a/mail/test/browser/shared-modules/FolderDisplayHelpers.jsm b/mail/test/browser/shared-modules/FolderDisplayHelpers.jsm index 32364c8925..70c76edd17 100644 --- a/mail/test/browser/shared-modules/FolderDisplayHelpers.jsm +++ b/mail/test/browser/shared-modules/FolderDisplayHelpers.jsm @@ -72,6 +72,8 @@ const EXPORTED_SYMBOLS = [ "delete_messages", "delete_via_popup", "display_message_in_folder_tab", + "dump_view_contents", + "dump_view_state", "empty_folder", "enter_folder", "expand_all_threads", @@ -3317,7 +3319,7 @@ function throw_and_dump_view_state(aMessage, aController) { } dump("******** " + aMessage + "\n"); - testHelperModule.dump_view_state(aController.folderDisplay.view); + dump_view_state(aController.folderDisplay.view); throw new Error(aMessage); } @@ -3428,3 +3430,81 @@ function load_via_src_path(aPath, aScope) { let uri = Services.io.newFileURI(file).spec; Services.scriptloader.loadSubScript(uri, aScope); } + +function dump_view_state(aViewWrapper, aDoNotDumpContents) { + if (aViewWrapper.dbView == null) { + dump("no nsIMsgDBView instance!\n"); + return; + } + if (!aDoNotDumpContents) { + dump_view_contents(aViewWrapper); + } + dump("View: " + aViewWrapper.dbView + "\n"); + dump( + " View Type: " + + _lookupValueNameInInterface( + aViewWrapper.dbView.viewType, + Ci.nsMsgViewType + ) + + " " + + "View Flags: " + + aViewWrapper.dbView.viewFlags + + "\n" + ); + dump( + " Sort Type: " + + _lookupValueNameInInterface( + aViewWrapper.dbView.sortType, + Ci.nsMsgViewSortType + ) + + " " + + "Sort Order: " + + _lookupValueNameInInterface( + aViewWrapper.dbView.sortOrder, + Ci.nsMsgViewSortOrder + ) + + "\n" + ); + dump(aViewWrapper.search.prettyString()); +} + +var WHITESPACE = " "; +var MSG_VIEW_FLAG_DUMMY = 0x20000000; +function dump_view_contents(aViewWrapper) { + let dbView = aViewWrapper.dbView; + let treeView = aViewWrapper.dbView.QueryInterface(Ci.nsITreeView); + let rowCount = treeView.rowCount; + + dump("********* Current View Contents\n"); + for (let iViewIndex = 0; iViewIndex < rowCount; iViewIndex++) { + let level = treeView.getLevel(iViewIndex); + let flags = dbView.getFlagsAt(iViewIndex); + let msgHdr = dbView.getMsgHdrAt(iViewIndex); + + let s = WHITESPACE.substr(0, level * 2); + if (treeView.isContainer(iViewIndex)) { + s += treeView.isContainerOpen(iViewIndex) ? "- " : "+ "; + } else { + s += ". "; + } + // s += treeView.getCellText(iViewIndex, ) + if (flags & MSG_VIEW_FLAG_DUMMY) { + s += "dummy: "; + } + s += dbView.cellTextForColumn(iViewIndex, "subject"); + s += " [" + msgHdr.folder.prettyName + "," + msgHdr.messageKey + "]"; + + dump(s + "\n"); + } + dump("********* end view contents\n"); +} + +function _lookupValueNameInInterface(aValue, aInterface) { + for (let key in aInterface) { + let value = aInterface[key]; + if (value == aValue) { + return key; + } + } + return "unknown: " + aValue; +} diff --git a/mailnews/base/test/unit/test_nsMsgDBView.js b/mailnews/base/test/unit/test_nsMsgDBView.js index 27c12c82ad..47efbff99d 100644 --- a/mailnews/base/test/unit/test_nsMsgDBView.js +++ b/mailnews/base/test/unit/test_nsMsgDBView.js @@ -29,6 +29,9 @@ var { MessageInjection } = ChromeUtils.import( var { PromiseUtils } = ChromeUtils.importESModule( "resource://gre/modules/PromiseUtils.sys.mjs" ); +var { dump_view_contents } = ChromeUtils.import( + "resource://testing-common/mozmill/FolderDisplayHelpers.jsm" +); // Items used to add messages to the folder var gMessageGenerator = new MessageGenerator(); @@ -103,31 +106,6 @@ async function make_and_add_message(aMessageArgs) { return [synMsg, msgSet]; } -var WHITESPACE = " "; -/** - * Print out the current db view as best we can. - */ -function dump_view_contents() { - dump("********* Current View State\n"); - for (let iViewIndex = 0; iViewIndex < gTreeView.rowCount; iViewIndex++) { - let level = gTreeView.getLevel(iViewIndex); - let flags = gDBView.getFlagsAt(iViewIndex); - - let s = WHITESPACE.substr(0, level * 2); - if (gTreeView.isContainer(iViewIndex)) { - s += gTreeView.isContainerOpen(iViewIndex) ? "- " : "+ "; - } else { - s += ". "; - } - if (flags & MSG_VIEW_FLAG_DUMMY) { - s += "dummy: "; - } - s += gDBView.cellTextForColumn(iViewIndex, "subject"); - dump(s + "\n"); - } - dump("********* end view state\n"); -} - function view_throw(why) { dump_view_contents(); do_throw(why); diff --git a/mailnews/base/test/unit/test_viewSortByAddresses.js b/mailnews/base/test/unit/test_viewSortByAddresses.js index 0a874a5a06..3cddfd2cba 100644 --- a/mailnews/base/test/unit/test_viewSortByAddresses.js +++ b/mailnews/base/test/unit/test_viewSortByAddresses.js @@ -19,6 +19,10 @@ var { MessageGenerator, SyntheticMessageSet } = ChromeUtils.import( var { MessageInjection } = ChromeUtils.import( "resource://testing-common/mailnews/MessageInjection.jsm" ); +var { dump_view_contents } = ChromeUtils.import( + "resource://testing-common/mozmill/FolderDisplayHelpers.jsm" +); + var gMessageGenerator = new MessageGenerator(); var messageInjection = new MessageInjection({ mode: "local" }); @@ -105,36 +109,6 @@ add_task(function test_view_sort_by_addresses() { } }); -var WHITESPACE = " "; -/** - * Print out the current db view as best we can. - */ -function dump_view_contents() { - dump("********* Current View State\n"); - for (let iViewIndex = 0; iViewIndex < gTreeView.rowCount; iViewIndex++) { - let level = gTreeView.getLevel(iViewIndex); - let flags = gDBView.getFlagsAt(iViewIndex); - - let s = WHITESPACE.substr(0, level * 2); - if (gTreeView.isContainer(iViewIndex)) { - s += gTreeView.isContainerOpen(iViewIndex) ? "- " : "+ "; - } else { - s += ". "; - } - let MSG_VIEW_FLAG_DUMMY = 0x20000000; - if (flags & MSG_VIEW_FLAG_DUMMY) { - s += "dummy: "; - } - s += - gDBView.cellTextForColumn(iViewIndex, "subjectCol") + - " " + - gDBView.cellTextForColumn(iViewIndex, "senderCol"); - - dump(s + "\n"); - } - dump("********* end view state\n"); -} - function view_throw(why) { dump_view_contents(); do_throw(why);