Bug 1347089 - Consolidate some of the testing functions to remove duplication. r=mossop a=gchang
authorJared Wein <jwein@mozilla.com>
Tue, 14 Mar 2017 14:56:23 -0400
changeset 395279 4fb9f172ec9d1a1f625634a145726a73f4deb641
parent 395278 cfa5921c738463d6a7181c08d6cffee495ea30e8
child 395280 abcd69fb8b220962b2d1bbc7be7fc6d96fd38c80
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop, gchang
bugs1347089
milestone54.0a2
Bug 1347089 - Consolidate some of the testing functions to remove duplication. r=mossop a=gchang MozReview-Commit-ID: IsBwyICdS6d
browser/base/content/test/general/browser_selectpopup.js
--- a/browser/base/content/test/general/browser_selectpopup.js
+++ b/browser/base/content/test/general/browser_selectpopup.js
@@ -228,16 +228,49 @@ function testOptionColors(index, item, m
   } else {
     is(getComputedStyle(item).color, expected.color,
        "Item " + (index) + " has correct foreground color");
     is(getComputedStyle(item).backgroundColor, expected.backgroundColor,
        "Item " + (index) + " has correct background color");
   }
 }
 
+function* testSelectColors(select, itemCount, options) {
+  const pageUrl = "data:text/html," + escape(select);
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
+
+  let menulist = document.getElementById("ContentSelectDropdown");
+  let selectPopup = menulist.menupopup;
+
+  let popupShownPromise = BrowserTestUtils.waitForEvent(selectPopup, "popupshown");
+  yield BrowserTestUtils.synthesizeMouseAtCenter("#one", { type: "mousedown" }, gBrowser.selectedBrowser);
+  yield popupShownPromise;
+
+  is(selectPopup.parentNode.itemCount, itemCount, "Correct number of items");
+  let child = selectPopup.firstChild;
+  let idx = 1;
+
+  if (!options.skipSelectColorTest) {
+    is(getComputedStyle(selectPopup).color, options.selectColor,
+      "popup has expected foreground color");
+    is(getComputedStyle(selectPopup).backgroundColor, options.selectBgColor,
+      "popup has expected background color");
+  }
+
+  ok(!child.selected, "The first child should not be selected");
+  while (child) {
+    testOptionColors(idx, child, menulist);
+    idx++;
+    child = child.nextSibling;
+  }
+
+  yield hideSelectPopup(selectPopup, "escape");
+
+  yield BrowserTestUtils.removeTab(tab);
+}
 function* doSelectTests(contentType, dtd) {
   const pageUrl = "data:" + contentType + "," + escape(dtd + "\n" + PAGECONTENT);
   let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
 
   let menulist = document.getElementById("ContentSelectDropdown");
   let selectPopup = menulist.menupopup;
 
   yield openSelectPopup(selectPopup);
@@ -826,107 +859,36 @@ add_task(function* test_somehidden() {
   }
 
   yield hideSelectPopup(selectPopup, "escape");
   yield BrowserTestUtils.removeTab(tab);
 });
 
 // This test checks when a <select> element has styles applied to <option>s within it.
 add_task(function* test_colors_applied_to_popup_items() {
-  const pageUrl = "data:text/html," + escape(PAGECONTENT_COLORS);
-  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
-
-  let menulist = document.getElementById("ContentSelectDropdown");
-  let selectPopup = menulist.menupopup;
-
-  let popupShownPromise = BrowserTestUtils.waitForEvent(selectPopup, "popupshown");
-  yield BrowserTestUtils.synthesizeMouseAtCenter("#one", { type: "mousedown" }, gBrowser.selectedBrowser);
-  yield popupShownPromise;
-
-  // The label contains a JSON string of the expected colors for
-  // `color` and `background-color`.
-  is(selectPopup.parentNode.itemCount, 7, "Correct number of items");
-  let child = selectPopup.firstChild;
-  let idx = 1;
-
-  ok(!child.selected, "The first child should not be selected");
-  while (child) {
-    testOptionColors(idx, child, menulist);
-    idx++;
-    child = child.nextSibling;
-  }
-
-  yield hideSelectPopup(selectPopup, "escape");
-  yield BrowserTestUtils.removeTab(tab);
+  yield testSelectColors(PAGECONTENT_COLORS, 7,
+                         {skipSelectColorTest: true});
 });
 
 // This test checks when a <select> element has styles applied to itself.
 add_task(function* test_colors_applied_to_popup() {
-  const pageUrl = "data:text/html," + escape(PAGECONTENT_COLORS_ON_SELECT);
-  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
-
-  let menulist = document.getElementById("ContentSelectDropdown");
-  let selectPopup = menulist.menupopup;
-
-  let popupShownPromise = BrowserTestUtils.waitForEvent(selectPopup, "popupshown");
-  yield BrowserTestUtils.synthesizeMouseAtCenter("#one", { type: "mousedown" }, gBrowser.selectedBrowser);
-  yield popupShownPromise;
-
-  is(selectPopup.parentNode.itemCount, 4, "Correct number of items");
-  let child = selectPopup.firstChild;
-  let idx = 1;
-
-  is(getComputedStyle(selectPopup).color, "rgb(255, 255, 255)",
-    "popup has expected foreground color");
-  is(getComputedStyle(selectPopup).backgroundColor, "rgb(126, 58, 58)",
-    "popup has expected background color");
-
-  ok(!child.selected, "The first child should not be selected");
-  while (child) {
-    testOptionColors(idx, child, menulist);
-    idx++;
-    child = child.nextSibling;
-  }
-
-  yield hideSelectPopup(selectPopup, "escape");
-
-  yield BrowserTestUtils.removeTab(tab);
+  let options = {
+    selectColor: "rgb(255, 255, 255)",
+    selectBgColor: "rgb(126, 58, 58)"
+  };
+  yield testSelectColors(PAGECONTENT_COLORS_ON_SELECT, 4, options);
 });
 
 // This test checks when a <select> element has a transparent background applied to itself.
 add_task(function* test_transparent_applied_to_popup() {
-  const pageUrl = "data:text/html," + escape(TRANSPARENT_SELECT);
-  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
-
-  let menulist = document.getElementById("ContentSelectDropdown");
-  let selectPopup = menulist.menupopup;
-
-  let popupShownPromise = BrowserTestUtils.waitForEvent(selectPopup, "popupshown");
-  yield BrowserTestUtils.synthesizeMouseAtCenter("#one", { type: "mousedown" }, gBrowser.selectedBrowser);
-  yield popupShownPromise;
-
-  is(selectPopup.parentNode.itemCount, 2, "Correct number of items");
-  let child = selectPopup.firstChild;
-  let idx = 1;
-
-  is(getComputedStyle(selectPopup).color, getSystemColor("-moz-ComboboxText"),
-    "popup has expected foreground color");
-  is(getComputedStyle(selectPopup).backgroundColor, getSystemColor("-moz-Combobox"),
-    "popup has expected background color");
-
-  ok(!child.selected, "The first child should not be selected");
-  while (child) {
-    testOptionColors(idx, child, menulist);
-    idx++;
-    child = child.nextSibling;
-  }
-
-  yield hideSelectPopup(selectPopup, "escape");
-
-  yield BrowserTestUtils.removeTab(tab);
+  let options = {
+    selectColor: getSystemColor("-moz-ComboboxText"),
+    selectBgColor: getSystemColor("-moz-Combobox")
+  };
+  yield testSelectColors(TRANSPARENT_SELECT, 2, options);
 });
 
 // This test checks that the popup is closed when the select element is blurred.
 add_task(function* test_blur_hides_popup() {
   const pageUrl = "data:text/html," + escape(PAGECONTENT_SMALL);
   let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
 
   yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
@@ -956,108 +918,38 @@ add_task(function* test_blur_hides_popup
   yield BrowserTestUtils.removeTab(tab);
 });
 
 // This test checks when a <select> element has a background set, and the
 // options have their own background set which is equal to the default
 // user-agent background color, but should be used because the select
 // background color has been changed.
 add_task(function* test_options_inverted_from_select_background() {
-  const pageUrl = "data:text/html," + escape(OPTION_COLOR_EQUAL_TO_UABACKGROUND_COLOR_SELECT);
-  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
-
-  let menulist = document.getElementById("ContentSelectDropdown");
-  let selectPopup = menulist.menupopup;
-
-  let popupShownPromise = BrowserTestUtils.waitForEvent(selectPopup, "popupshown");
-  yield BrowserTestUtils.synthesizeMouseAtCenter("#one", { type: "mousedown" }, gBrowser.selectedBrowser);
-  yield popupShownPromise;
-
-  is(selectPopup.parentNode.itemCount, 2, "Correct number of items");
-  let child = selectPopup.firstChild;
-  let idx = 1;
-
   // The popup has a black background and white text, but the
   // options inside of it have flipped the colors.
-  is(getComputedStyle(selectPopup).color, "rgb(255, 255, 255)",
-    "popup has expected foreground color");
-  is(getComputedStyle(selectPopup).backgroundColor, "rgb(0, 0, 0)",
-    "popup has expected background color");
-
-  ok(!child.selected, "The first child should not be selected");
-  while (child) {
-    testOptionColors(idx, child, menulist);
-    idx++;
-    child = child.nextSibling;
-  }
-
-  yield hideSelectPopup(selectPopup, "escape");
-
-  yield BrowserTestUtils.removeTab(tab);
+  let options = {
+    selectColor: "rgb(255, 255, 255)",
+    selectBgColor: "rgb(0, 0, 0)"
+  };
+  yield testSelectColors(OPTION_COLOR_EQUAL_TO_UABACKGROUND_COLOR_SELECT,
+                         2, options);
 });
 
 // This test checks when a <select> element has a background set using !important,
 // which was affecting how we calculated the user-agent styling.
 add_task(function* test_select_background_using_important() {
-  const pageUrl = "data:text/html," + escape(GENERIC_OPTION_STYLED_AS_IMPORTANT);
-  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
-
-  let menulist = document.getElementById("ContentSelectDropdown");
-  let selectPopup = menulist.menupopup;
-
-  let popupShownPromise = BrowserTestUtils.waitForEvent(selectPopup, "popupshown");
-  yield BrowserTestUtils.synthesizeMouseAtCenter("#one", { type: "mousedown" }, gBrowser.selectedBrowser);
-  yield popupShownPromise;
-
-  is(selectPopup.parentNode.itemCount, 2, "Correct number of items");
-  let child = selectPopup.firstChild;
-  let idx = 1;
-  ok(!child.selected, "The first child should not be selected");
-
-  while (child) {
-    testOptionColors(idx, child, menulist);
-    idx++;
-    child = child.nextSibling;
-  }
-
-  yield hideSelectPopup(selectPopup, "escape");
-
-  yield BrowserTestUtils.removeTab(tab);
+  yield testSelectColors(GENERIC_OPTION_STYLED_AS_IMPORTANT, 2,
+                         {skipSelectColorTest: true});
 });
 
-
 // This test checks when a <select> element has a background set, and the
 // options have their own background set which is equal to the default
 // user-agent background color, but should be used because the select
 // background color has been changed.
 add_task(function* test_translucent_select_becomes_opaque() {
-  const pageUrl = "data:text/html," + escape(TRANSLUCENT_SELECT_BECOMES_OPAQUE);
-  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
-
-  let menulist = document.getElementById("ContentSelectDropdown");
-  let selectPopup = menulist.menupopup;
-
-  let popupShownPromise = BrowserTestUtils.waitForEvent(selectPopup, "popupshown");
-  yield BrowserTestUtils.synthesizeMouseAtCenter("#one", { type: "mousedown" }, gBrowser.selectedBrowser);
-  yield popupShownPromise;
-
-  is(selectPopup.parentNode.itemCount, 2, "Correct number of items");
-  let child = selectPopup.firstChild;
-  let idx = 1;
-
   // The popup is requested to show a translucent background
   // but we force the alpha channel to 1 on the popup.
-  is(getComputedStyle(selectPopup).color, "rgb(0, 0, 0)",
-    "popup has expected foreground color");
-  is(getComputedStyle(selectPopup).backgroundColor, "rgb(255, 255, 255)",
-    "popup has expected background color");
-
-  ok(!child.selected, "The first child should not be selected");
-  while (child) {
-    testOptionColors(idx, child, menulist);
-    idx++;
-    child = child.nextSibling;
-  }
-
-  yield hideSelectPopup(selectPopup, "escape");
-
-  yield BrowserTestUtils.removeTab(tab);
+  let options = {
+    selectColor: "rgb(0, 0, 0)",
+    selectBgColor: "rgb(255, 255, 255)"
+  };
+  yield testSelectColors(TRANSLUCENT_SELECT_BECOMES_OPAQUE, 2, options);
 });