Bug 1474091 - fix test-message-header.js by waiting for accessible element for message header to appear. r=jorgk
authoraceman <acelists@atlas.sk>
Tue, 11 Sep 2018 14:06:00 +0200
changeset 33132 a4f58095ed048c01694c7f66c1ad9f4f2431da57
parent 33131 37bdf33fc10c12f87f9229a9c6f7d56f3b3b9f01
child 33133 9dc7f65220a4a9b888d916d40d08cedbf673b416
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1474091
Bug 1474091 - fix test-message-header.js by waiting for accessible element for message header to appear. r=jorgk
mail/test/mozmill/message-header/test-message-header.js
--- a/mail/test/mozmill/message-header/test-message-header.js
+++ b/mail/test/mozmill/message-header/test-message-header.js
@@ -19,24 +19,19 @@ var elib = {};
 ChromeUtils.import("chrome://mozmill/content/modules/elementslib.js", elib);
 ChromeUtils.import("resource:///modules/MailServices.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var folder, folderMore;
 var gInterestingMessage;
 
 function setupModule(module) {
-  let fdh = collector.getModule('folder-display-helpers');
-  fdh.installInto(module);
-  let wh = collector.getModule('window-helpers');
-  wh.installInto(module);
-  let abh = collector.getModule('address-book-helpers');
-  abh.installInto(module);
-  let dh = collector.getModule('dom-helpers');
-  dh.installInto(module);
+  for (let lib of MODULE_REQUIRES) {
+    collector.getModule(lib).installInto(module);
+  }
 
   folder = create_folder("MessageWindowA");
   folderMore = create_folder("MesageHeaderMoreButton");
 
   // create a message that has the interesting headers that commonly
   // show up in the message header pane for testing
   gInterestingMessage = create_message({cc: msgGen.makeNamesAndAddresses(20), // YYY
     subject: "This is a really, really, really, really, really, really, really, really, long subject.",
@@ -159,87 +154,105 @@ function test_add_tag_with_really_long_l
  *        with the data.
  * @param expectedName code to be eval()ed returning the expected value of
  *                     nsIAccessible.name for the DOM element in question
  * @param expectedRole the expected value for nsIAccessible.role
  */
 let headersToTest = [
 {
   headerName: "Subject",
-  headerValueElement: "mc.a('expandedsubjectBox', {class: 'headerValue'})",
-  expectedName: "mc.e('expandedsubjectLabel').value + ': ' + " +
-                "headerValueElement.textContent",
+  headerValueElement: function(mc) {
+                      return mc.a("expandedsubjectBox", {class: "headerValue"}); },
+  expectedName: function(mc, headerValueElement) {
+                return mc.e("expandedsubjectLabel").value + ": " +
+                headerValueElement.textContent; },
   expectedRole: Ci.nsIAccessibleRole.ROLE_ENTRY
 },
 {
   headerName: "Content-Base",
-  headerValueElement: "mc.a('expandedcontent-baseBox', {class: 'headerValue text-link headerValueUrl'})",
-  expectedName: "mc.e('expandedcontent-baseLabel').value + ': ' + " +
-                "headerValueElement.textContent",
+  headerValueElement: function(mc) {
+                      return mc.a("expandedcontent-baseBox", {class: "headerValue text-link headerValueUrl"}); },
+  expectedName: function(mc, headerValueElement) {
+                return mc.e("expandedcontent-baseLabel").value + ": " +
+                headerValueElement.textContent; },
   expectedRole: Ci.nsIAccessibleRole.ROLE_ENTRY
 },
 {
   headerName: "From",
-  headerValueElement: "mc.window.document.getAnonymousElementByAttribute(" +
-                      "mc.a('expandedfromBox', {tagName: 'mail-emailaddress'})," +
-                      "'class', 'emailDisplayButton')",
-  expectedName: "mc.e('expandedfromLabel').value + ': ' + " +
-                "headerValueElement.parentNode.getAttribute('fullAddress')",
+  headerValueElement: function(mc) {
+                      return mc.window.document.getAnonymousElementByAttribute(
+                      mc.a("expandedfromBox", {tagName: "mail-emailaddress"}),
+                      "class", "emailDisplayButton"); },
+  expectedName: function(mc, headerValueElement) {
+                return mc.e("expandedfromLabel").value + ": " +
+                headerValueElement.parentNode.getAttribute("fullAddress"); },
   expectedRole: Ci.nsIAccessibleRole.ROLE_ENTRY
 },
 {
   headerName: "To",
-  headerValueElement: "mc.window.document.getAnonymousElementByAttribute(" +
-                      "mc.a('expandedtoBox', {tagName: 'mail-emailaddress'})," +
-                      "'class', 'emailDisplayButton')",
-  expectedName: "mc.e('expandedtoLabel').value + ': ' + " +
-                "headerValueElement.parentNode.getAttribute('fullAddress')",
+  headerValueElement: function(mc) {
+                      return mc.window.document.getAnonymousElementByAttribute(
+                      mc.a("expandedtoBox", {tagName: "mail-emailaddress"}),
+                      "class", "emailDisplayButton"); },
+  expectedName: function(mc, headerValueElement) {
+                return mc.e("expandedtoLabel").value + ": " +
+                headerValueElement.parentNode.getAttribute("fullAddress"); },
   expectedRole: Ci.nsIAccessibleRole.ROLE_ENTRY
 },
 {
   headerName: "Cc",
-  headerValueElement: "mc.window.document.getAnonymousElementByAttribute(" +
-                      "mc.a('expandedccBox', {tagName: 'mail-emailaddress'})," +
-                      "'class', 'emailDisplayButton')",
-  expectedName: "mc.e('expandedccLabel').value + ': ' + " +
-                "headerValueElement.parentNode.getAttribute('fullAddress')",
+  headerValueElement: function(mc) {
+                      return mc.window.document.getAnonymousElementByAttribute(
+                      mc.a("expandedccBox", {tagName: "mail-emailaddress"}),
+                      "class", "emailDisplayButton"); },
+  expectedName: function(mc, headerValueElement) {
+                return mc.e("expandedccLabel").value + ": " +
+                headerValueElement.parentNode.getAttribute("fullAddress"); },
   expectedRole: Ci.nsIAccessibleRole.ROLE_ENTRY
 },
 {
   headerName: "Bcc",
-  headerValueElement: "mc.window.document.getAnonymousElementByAttribute(" +
-                      "mc.a('expandedbccBox', {tagName: 'mail-emailaddress'})," +
-                      "'class', 'emailDisplayButton')",
-  expectedName: "mc.e('expandedbccLabel').value + ': ' + " +
-                "headerValueElement.parentNode.getAttribute('fullAddress')",
+  headerValueElement: function(mc) {
+                      return mc.window.document.getAnonymousElementByAttribute(
+                      mc.a("expandedbccBox", {tagName: "mail-emailaddress"}),
+                      "class", "emailDisplayButton"); },
+  expectedName: function(mc, headerValueElement) {
+                return mc.e("expandedbccLabel").value + ": " +
+                headerValueElement.parentNode.getAttribute("fullAddress"); },
   expectedRole: Ci.nsIAccessibleRole.ROLE_ENTRY
 },
 {
   headerName: "Reply-To",
-  headerValueElement: "mc.window.document.getAnonymousElementByAttribute(" +
-                      "mc.a('expandedreply-toBox', {tagName: 'mail-emailaddress'})," +
-                      "'class', 'emailDisplayButton')",
-  expectedName: "mc.e('expandedreply-toLabel').value + ': ' + " +
-                "headerValueElement.parentNode.getAttribute('fullAddress')",
+  headerValueElement: function(mc) {
+                      return mc.window.document.getAnonymousElementByAttribute(
+                      mc.a("expandedreply-toBox", {tagName: "mail-emailaddress"}),
+                      "class", "emailDisplayButton"); },
+  expectedName: function(mc, headerValueElement) {
+                return mc.e("expandedreply-toLabel").value + ": " +
+                headerValueElement.parentNode.getAttribute("fullAddress"); },
   expectedRole: Ci.nsIAccessibleRole.ROLE_ENTRY
 },
 {
   headerName: "Newsgroups",
-  headerValueElement: "mc.window.document.getAnonymousElementByAttribute(" +
-                      "mc.a('expandednewsgroupsBox', {tagName: 'mail-newsgroup'})," +
-                      "'class', 'newsgrouplabel')",
-  expectedName: "mc.e('expandednewsgroupsLabel').value + ': ' + " +
-                "headerValueElement.parentNode.parentNode.getAttribute('newsgroup')",
+  headerValueElement: function(mc) {
+                      return mc.window.document.getAnonymousElementByAttribute(
+                      mc.a("expandednewsgroupsBox", {tagName: "mail-newsgroup"}),
+                      "class", "newsgrouplabel"); },
+  expectedName: function(mc, headerValueElement) {
+                return mc.e("expandednewsgroupsLabel").value + ": " +
+                headerValueElement.parentNode.parentNode.getAttribute("newsgroup"); },
   expectedRole: Ci.nsIAccessibleRole.ROLE_ENTRY
 },
 {
   headerName: "Tags",
-  headerValueElement: "mc.a('expandedtagsBox', {class: 'tagvalue blc-FF0000'})",
-  expectedName: "mc.e('expandedtagsLabel').value + ': ' + " +
-                "headerValueElement.getAttribute('value')",
+  headerValueElement: function(mc) {
+                      return mc.a("expandedtagsBox", {class: "tagvalue blc-FF0000"}); },
+  expectedName: function(mc, headerValueElement) {
+                return mc.e("expandedtagsLabel").value + ": " +
+                headerValueElement.getAttribute("value"); },
   expectedRole: Ci.nsIAccessibleRole.ROLE_LABEL
 }
 ];
 
 // used to get the accessible object for a DOM node
 let gAccService = Cc["@mozilla.org/accessibilityService;1"].
                   getService(Ci.nsIAccessibilityService);
 
@@ -247,33 +260,32 @@ let gAccService = Cc["@mozilla.org/acces
  * Use the information from aHeaderInfo to verify that screenreaders will
  * do the right thing with the given message header.
  *
  * @param {Object} aHeaderInfo  Information about how to do the verification;
  *                              See the comments above the headersToTest array
  *                              for details.
  */
 function verify_header_a11y(aHeaderInfo) {
-  // XXX Don't use eval here.
-  let headerValueElement = eval(aHeaderInfo.headerValueElement);
+  let headerValueElement = aHeaderInfo.headerValueElement(mc);
+  assert_not_equals(headerValueElement, null,
+                    `element not found for header '${aHeaderInfo.headerName}'`);
+
+  let headerAccessible;
+  mc.waitFor(() => (headerAccessible = gAccService.getAccessibleFor(headerValueElement)) != null,
+    `didn't find accessible element for header '${aHeaderInfo.headerName}'`);
 
-  let headerAccessible = gAccService.getAccessibleFor(headerValueElement);
-  if (headerAccessible.role != aHeaderInfo.expectedRole) {
-    throw new Error("role for " + aHeaderInfo.headerName + " was " +
-                    headerAccessible.role + "; should have been " +
-                    aHeaderInfo.expectedRole);
-  }
+  assert_equals(headerAccessible.role, aHeaderInfo.expectedRole,
+    `role for ${aHeaderInfo.headerName} was ${headerAccessible.role}; ` +
+    `should have been ${aHeaderInfo.expectedRole}`);
 
-  // XXX Don't use eval here.
-  let expectedName = eval(aHeaderInfo.expectedName);
-  if (headerAccessible.name != expectedName) {
-    throw new Error("headerAccessible.name for " + aHeaderInfo.headerName +
-                    " was '" + headerAccessible.name + "'; expected '" +
-                    expectedName + "'");
-  }
+  let expectedName = aHeaderInfo.expectedName(mc, headerValueElement);
+  assert_equals(headerAccessible.name, expectedName,
+    `headerAccessible.name for ${aHeaderInfo.headerName} ` +
+    `was '${headerAccessible.name}'; expected '${expectedName}'`);
 }
 
 /**
  * Test the accessibility attributes of the various message headers.
  *
  * XXX This test used to be after test_more_button_with_many_recipients,
  * however, there were some accessibility changes that it didn't seem to play
  * nicely with, and the toggling of the "more" button on the cc field was