Bug 1310022 - cleanup test-charset-upgrade.js. r=jorgk
authoraceman <acelists@atlas.sk>
Sat, 15 Oct 2016 02:08:59 +0200
changeset 20552 118a8202a7457b3d9ffecbbe97feff4e8287bf70
parent 20551 d1c77b5622b86dbf6d7ab90e940f8b1494f90fc0
child 20553 ac4e9e57cfbbb374b2ba9bbd6817384dfdc45f73
push id12409
push useracelists@atlas.sk
push dateSat, 15 Oct 2016 00:09:24 +0000
treeherdercomm-central@118a8202a745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1310022
Bug 1310022 - cleanup test-charset-upgrade.js. r=jorgk
mail/test/mozmill/composition/test-charset-upgrade.js
--- a/mail/test/mozmill/composition/test-charset-upgrade.js
+++ b/mail/test/mozmill/composition/test-charset-upgrade.js
@@ -9,22 +9,18 @@
 
 // make SOLO_TEST=composition/test-charset-upgrade.js mozmill-one
 
 var MODULE_NAME = "test-charset-upgrade";
 
 var RELATIVE_ROOT = "../shared-modules";
 var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers", "compose-helpers"];
 
-var os = {};
-Cu.import("resource://mozmill/stdlib/os.js", os);
 Cu.import('resource://gre/modules/Services.jsm');
 Cu.import("resource:///modules/mailServices.js");
-var elib = {};
-Cu.import("resource://mozmill/modules/elementslib.js", elib);
 
 var draftsFolder;
 var outboxFolder;
 
 function setupModule(module) {
   for (let req of MODULE_REQUIRES) {
     collector.getModule(req).installInto(module);
   }
@@ -32,30 +28,24 @@ function setupModule(module) {
                    .localFoldersServer
                    .rootFolder
                    .containsChildNamed("Drafts")) {
      create_folder("Drafts", [Ci.nsMsgFolderFlags.Drafts]);
   }
   draftsFolder = MailServices.accounts
                              .localFoldersServer
                              .rootFolder
-                             .getChildNamed("Drafts");
+                             .getFolderWithFlags(Ci.nsMsgFolderFlags.Drafts);
   if (!draftsFolder)
     throw new Error("draftsFolder not found");
 
-  if (!MailServices.accounts
-                   .localFoldersServer
-                   .rootFolder
-                   .containsChildNamed("Outbox")) {
-     create_folder("Outbox", [Ci.nsMsgFolderFlags.Outbox]);
-  }
   outboxFolder = MailServices.accounts
                              .localFoldersServer
                              .rootFolder
-                             .getChildNamed("Outbox");
+                             .getFolderWithFlags(Ci.nsMsgFolderFlags.Queue);
   if (!outboxFolder)
     throw new Error("outboxFolder not found");
 
   // Ensure reply charset isn't UTF-8, otherwise there's no need to upgrade,
   //  which is what this test tests.
   let str = Components.classes["@mozilla.org/pref-localizedstring;1"]
                       .createInstance(Components.interfaces.nsIPrefLocalizedString);
   str.data = "windows-1252";
@@ -64,55 +54,51 @@ function setupModule(module) {
 
   // Don't create paragraphs in the test.
   // When creating a paragraph, the test fails to retrieve the
   // original character set windows-1252. Until we understand why,
   // we run without paragraphs.
   Services.prefs.setBoolPref("mail.compose.default_to_paragraph", false);
 }
 
-function teardownModule(module) {
-  Services.prefs.clearUserPref("mail.compose.default_to_paragraph");
-}
-
 /**
  * Test that if all characters don't fit the current charset selection,
  * we upgrade properly to UTF-8. In HTML composition.
  */
 function test_encoding_upgrade_html_compose() {
+  Services.prefs.setBoolPref("mail.identity.default.compose_html", true);
   let compWin = open_compose_new_mail();
 
-  compWin.type(null, "someone@example.com");
-  compWin.type(compWin.eid("msgSubject"), "encoding upgrade test - html mode")
-  compWin.type(compWin.eid("content-frame"), "so far, this is latin1\n");
+  setup_msg_contents(compWin,
+                     "someone@example.com",
+                     "encoding upgrade test - html mode",
+                     "so far, this is latin1\n");
 
   // Ctrl+S = save as draft.
   compWin.keypress(null, "s", {shiftKey: false, accelKey: true});
 
   be_in_folder(draftsFolder);
   let draftMsg = select_click_row(0);
 
   // Charset should still be the default.
   assert_equals(draftMsg.Charset, "windows-1252");
 
   let draftMsgContent = get_msg_source(draftMsg, true);
   if (!draftMsgContent.includes('content="text/html; charset=windows-1252"'))
     throw new Error("Expected content type not in msg; draftMsgContent=" +
                     draftMsgContent);
 
   const CHINESE = "漢皇重色思傾國漢皇重色思傾國";
-  compWin.type(compWin.eid("content-frame"),
-    "but now, we enter some chinese: " + CHINESE +"\n");
+  type_in_composer(compWin, ["but now, we enter some chinese: " + CHINESE + "\n"]);
 
   // Ctrl+U = Underline (so we can check multipart/alternative gets right,
   // without it html->plaintext conversion will it as send plain text only)
   compWin.keypress(null, "U", {shiftKey: false, accelKey: true});
 
-  compWin.type(compWin.eid("content-frame"),
-    "content need to be upgraded to utf-8 now.");
+  type_in_composer(compWin, ["content need to be upgraded to utf-8 now."]);
 
   // Ctrl+S = save as draft.
   compWin.keypress(null, "s", {shiftKey: false, accelKey: true});
 
   be_in_folder(draftsFolder);
   let draftMsg2 = select_click_row(0);
   // Charset should have be upgraded to UTF-8.
   assert_equals(draftMsg2.Charset, "UTF-8");
@@ -121,20 +107,19 @@ function test_encoding_upgrade_html_comp
   if (!draftMsg2Content.includes('content="text/html; charset=UTF-8"'))
     throw new Error("Expected content type not in msg; draftMsg2Content=" +
                     draftMsg2Content);
 
   if (!draftMsg2Content.includes(CHINESE))
     throw new Error("Chinese text not in msg; CHINESE=" + CHINESE +
                     ", draftMsg2Content=" + draftMsg2Content);
 
-  compWin.window.setTimeout(function() {
-    // Ctrl+Shift+Return = Send Later
-    compWin.keypress(null, "VK_RETURN", {shiftKey: true, accelKey: true});
-  }, 0);
+  plan_for_window_close(compWin);
+  compWin.window.goDoCommand("cmd_sendLater");
+  wait_for_window_close();
 
   be_in_folder(outboxFolder);
   let outMsg = select_click_row(0);
   let outMsgContent = get_msg_source(outMsg, true);
 
   // This message should be multipart/alternative.
   if (!outMsgContent.includes("Content-Type: multipart/alternative"))
     throw new Error("Expected multipart/alternative; content=" + outMsgContent);
@@ -159,35 +144,33 @@ function test_encoding_upgrade_html_comp
  * Test that if all characters don't fit the current charset selection,
  * we upgrade properly to UTF-8. In plaintext composition.
  */
 function test_encoding_upgrade_plaintext_compose() {
   Services.prefs.setBoolPref("mail.identity.default.compose_html", false);
   let compWin = open_compose_new_mail();
   Services.prefs.setBoolPref("mail.identity.default.compose_html", true);
 
-  compWin.type(null, "someone-else@example.com");
-  compWin.type(compWin.eid("msgSubject"), "encoding upgrade test - plaintext");
-  compWin.type(compWin.eid("content-frame"), "this is plaintext latin1\n");
+  setup_msg_contents(compWin,
+                     "someone-else@example.com",
+                     "encoding upgrade test - plaintext",
+                     "this is plaintext latin1\n");
 
   // Ctrl+S = Save as Draft.
   compWin.keypress(null, "s", {shiftKey: false, accelKey: true});
 
   be_in_folder(draftsFolder);
   let draftMsg = select_click_row(0);
 
   // Charset should still be the default.
   assert_equals(draftMsg.Charset, "windows-1252");
 
   const CHINESE = "漢皇重色思傾國漢皇重色思傾國";
-  compWin.type(compWin.eid("content-frame"),
-    "enter some plain text chinese: " + CHINESE +"\n");
-
-  compWin.type(compWin.eid("content-frame"),
-    "content need to be upgraded to utf-8 now.");
+  type_in_composer(compWin, ["enter some plain text chinese: " + CHINESE,
+                             "content need to be upgraded to utf-8 now."]);
 
   // Ctrl+S = Save as Draft.
   compWin.keypress(null, "s", {shiftKey: false, accelKey: true});
 
   be_in_folder(draftsFolder);
   let draftMsg2 = select_click_row(0);
   // Charset should have be upgraded to UTF-8.
   assert_equals(draftMsg2.Charset, "UTF-8");
@@ -196,20 +179,19 @@ function test_encoding_upgrade_plaintext
   if (draftMsg2Content.includes("<html>"))
     throw new Error("Plaintext draft contained <html>; "+
                     "draftMsg2Content=" + draftMsg2Content);
 
   if (!draftMsg2Content.includes(CHINESE))
     throw new Error("Chinese text not in msg; CHINESE=" + CHINESE +
                     ", draftMsg2Content=" + draftMsg2Content);
 
-  compWin.window.setTimeout(function() {
-    // Ctrl+Shift+Return = Send Later.
-    compWin.keypress(null, "VK_RETURN", {shiftKey: true, accelKey: true});
-  }, 0);
+  plan_for_window_close(compWin);
+  compWin.window.goDoCommand("cmd_sendLater");
+  wait_for_window_close();
 
   be_in_folder(outboxFolder);
   let outMsg = select_click_row(0);
   let outMsgContent = get_msg_source(outMsg, true);
 
   // This message should be text/plain;
   if (!outMsgContent.includes("Content-Type: text/plain"))
     throw new Error("Expected text/plain; content=" + outMsgContent);
@@ -218,9 +200,11 @@ function test_encoding_upgrade_plaintext
     throw new Error("Chinese text not in msg; CHINESE=" + CHINESE +
                     ", outMsgContent=" + outMsgContent);
 
   press_delete(); // Delete the msg from Outbox.
 }
 
 function teardownModule(module) {
   Services.prefs.clearUserPref("mailnews.send_default_charset");
+  Services.prefs.clearUserPref("mail.compose.default_to_paragraph");
+  Services.prefs.clearUserPref("mail.identity.default.compose_html");
 }