Bug 1474219 - Tidy up test-general-content-policy.js. r=jorgk
authoraceman <acelists@atlas.sk>
Sun, 09 Sep 2018 11:46:53 +0200
changeset 33114 2dfed3b880129ede14e468363acce324d36c8c11
parent 33113 3c055eb08eb5b451158c54dfee74203c8dc5434f
child 33115 9e4a6da09ad841d6dc7f6d4265b6e905d87e718b
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1474219
Bug 1474219 - Tidy up test-general-content-policy.js. r=jorgk
mail/test/mozmill/content-policy/test-general-content-policy.js
--- a/mail/test/mozmill/content-policy/test-general-content-policy.js
+++ b/mail/test/mozmill/content-policy/test-general-content-policy.js
@@ -145,24 +145,21 @@ function addMsgToFolderAndCheckContent(f
 
   if (msgDbHdr != msgHdr)
     throw new Error("Selected Message Header is not the same as generated header");
 
   assert_selected_and_displayed(gMsgNo);
 
   // Now check that the content hasn't been loaded
   if (test.checkDenied) {
-    if (test.checkForAllowed(mozmill.getMail3PaneController()
-            .window.content.document.getElementById("testelement")))
+    if (test.checkForAllowed(mc.window.content.document.getElementById("testelement"))) {
       throw new Error(test.type + " has not been blocked in message content as expected.");
-  }
-  else {
-    if (!test.checkForAllowed(mozmill.getMail3PaneController()
-             .window.content.document.getElementById("testelement")))
-      throw new Error(test.type + " has been unexpectedly blocked in message content.");
+    }
+  } else if (!test.checkForAllowed(mc.window.content.document.getElementById("testelement"))) {
+    throw new Error(test.type + " has been unexpectedly blocked in message content.");
   }
 
   ++gMsgNo;
 }
 
 /**
  * Check remote content in a compose window.
  *
@@ -183,17 +180,17 @@ function checkComposeWindow(test, replyT
                     " in reply window as expected.");
 
   close_compose_window(replyWindow);
 }
 
 /**
  * Check remote content in stand-alone message window, and reload
  */
- function checkStandaloneMessageWindow(test, loadAllowed) {
+function checkStandaloneMessageWindow(test, loadAllowed) {
   plan_for_new_window("mail:messageWindow");
   // Open it
   set_open_message_behavior("NEW_WINDOW");
   open_selected_message();
   let msgc = wait_for_new_window("mail:messageWindow");
   wait_for_message_display_completion(msgc, true);
   if (test.checkForAllowed(
           msgc.window.content.document.getElementById("testelement")) != loadAllowed)
@@ -286,19 +283,19 @@ function checkAllowFeedMsg(test) {
 
   // select the newly created message
   let msgHdr = select_click_row(gMsgNo);
 
   assert_equals(msgDbHdr, msgHdr);
   assert_selected_and_displayed(gMsgNo);
 
   // Now check that the content hasn't been blocked
-  if (!test.checkForAllowed(mozmill.getMail3PaneController()
-           .window.content.document.getElementById("testelement")))
+  if (!test.checkForAllowed(mc.window.content.document.getElementById("testelement"))) {
     throw new Error(test.type + " has been unexpectedly blocked in feed message content.");
+  }
 
   ++gMsgNo;
 }
 
 /**
  * Check remote content is not blocked for a sender with permissions.
  */
 function checkAllowForSenderWithPerms(test) {
@@ -316,20 +313,19 @@ function checkAllowForSenderWithPerms(te
 
   // select the newly created message
   let msgHdr = select_click_row(gMsgNo);
 
   assert_equals(msgDbHdr, msgHdr);
   assert_selected_and_displayed(gMsgNo);
 
   // Now check that the content hasn't been blocked
-  if (!test.checkForAllowed(mozmill.getMail3PaneController()
-           .window.content.document.getElementById("testelement")))
-    throw new Error(test.type + " has been unexpectedly blocked for sender=" +
-                    authorEmailAddress);
+  if (!test.checkForAllowed(mc.window.content.document.getElementById("testelement"))) {
+    throw new Error(`${test.type} has been unexpectedly blocked for sender=${authorEmailAddress}`);
+  }
 
   // Clean up after ourselves, and make sure that worked as expected.
   Services.perms.remove(uri, "image");
   assert_true(Services.perms.testPermission(uri, "image") ==
               Services.perms.UNKNOWN_ACTION);
 
   ++gMsgNo;
 }
@@ -341,18 +337,17 @@ function checkAllowForHostsWithPerms(tes
   let msgDbHdr = addToFolder(test.type + " priv host test message " + gMsgNo,
                              msgBodyStart + test.body + msgBodyEnd, folder);
 
   // Select the newly created message.
   let msgHdr = select_click_row(gMsgNo);
   assert_equals(msgDbHdr, msgHdr);
   assert_selected_and_displayed(gMsgNo);
 
-  let src = mozmill.getMail3PaneController().window.content.document
-                   .getElementById("testelement").src;
+  let src = mc.window.content.document.getElementById("testelement").src;
 
   if (!src.startsWith("http"))
     return; // just test http in this test
 
   let uri = Services.io.newURI(src);
   Services.perms.add(uri, "image", Services.perms.ALLOW_ACTION);
   assert_true(Services.perms.testPermission(uri, "image") ==
               Services.perms.ALLOW_ACTION);
@@ -395,34 +390,33 @@ function test_generalContentPolicy() {
       // Check denied in forward window
       checkComposeWindow(TESTS[i], false, false);
 
       if (i == 0) {
         // Now check that image is visible after site is whitelisted.
         // We do the first test which is the one with the image.
 
         // Add the site to the whitelist.
-        let src = mozmill.getMail3PaneController().window.content.document
-                         .getElementById("testelement").src;
+        let src = mc.window.content.document.getElementById("testelement").src;
 
         let uri = Services.io.newURI(src);
         Services.perms.add(uri, "image", Services.perms.ALLOW_ACTION);
-        assert_true(Services.perms.testPermission(uri, "image") ==
-                    Services.perms.ALLOW_ACTION);
+        assert_equals(Services.perms.testPermission(uri, "image"),
+                      Services.perms.ALLOW_ACTION);
 
         // Check allowed in reply window
         checkComposeWindow(TESTS[i], true, true);
 
         // Check allowed in forward window
         checkComposeWindow(TESTS[i], false, true);
 
         // Clean up after ourselves, and make sure that worked as expected.
         Services.perms.remove(uri, "image");
-        assert_true(Services.perms.testPermission(uri, "image") ==
-                    Services.perms.UNKNOWN_ACTION);
+        assert_equals(Services.perms.testPermission(uri, "image"),
+                      Services.perms.UNKNOWN_ACTION);
       }
 
       // Check denied in standalone message window
       checkStandaloneMessageWindow(TESTS[i], false);
 
       // Now allow the remote content and check result
       allowRemoteContentAndCheck(TESTS[i]);
     }
@@ -461,23 +455,21 @@ function test_generalContentPolicy() {
 function putHTMLOnClipboard(html) {
   let trans = Cc["@mozilla.org/widget/transferable;1"]
                 .createInstance(Ci.nsITransferable);
 
   // Register supported data flavors
   trans.init(null);
   trans.addDataFlavor("text/html");
 
-  let wapper = Cc["@mozilla.org/supports-string;1"]
-   .createInstance(Ci.nsISupportsString);
+  let wapper = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
   wapper.data = html;
   trans.setTransferData("text/html", wapper, wapper.data.length * 2);
 
-  Services.clipboard.setData(trans, null,
-    Ci.nsIClipboard.kGlobalClipboard);
+  Services.clipboard.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard);
 }
 
 function subtest_insertImageIntoReplyForward(aReplyType) {
   let msgDbHdr = addToFolder("Test insert image into reply or forward",
                              "Stand by for image insertion ;-)",
                              folder);
   gMsgNo++;