From 925e02b6ecb2b23582da4a391aea3c28d95cbf81 Mon Sep 17 00:00:00 2001 From: Jared Wein Date: Tue, 14 Mar 2017 19:27:33 -0400 Subject: [PATCH] Bug 1347329 - Move the select tests to a forms subdirectory and split apart the color tests to their own file since the test was getting very long. r=mossop MozReview-Commit-ID: IGjS2aiL4a2 --HG-- rename : browser/base/content/test/general/browser_selectpopup.js => browser/base/content/test/forms/browser_selectpopup.js extra : rebase_source : cf2a9bee2cbc46808c0f559baddd50cbdae90aab --- browser/base/content/test/forms/browser.ini | 7 + .../{general => forms}/browser_selectpopup.js | 253 ------------------ .../test/forms/browser_selectpopup_colors.js | 227 ++++++++++++++++ browser/base/content/test/forms/head.js | 19 ++ browser/base/content/test/general/browser.ini | 2 - browser/base/moz.build | 1 + 6 files changed, 254 insertions(+), 255 deletions(-) create mode 100644 browser/base/content/test/forms/browser.ini rename browser/base/content/test/{general => forms}/browser_selectpopup.js (73%) create mode 100644 browser/base/content/test/forms/browser_selectpopup_colors.js create mode 100644 browser/base/content/test/forms/head.js diff --git a/browser/base/content/test/forms/browser.ini b/browser/base/content/test/forms/browser.ini new file mode 100644 index 000000000000..ce983f59e484 --- /dev/null +++ b/browser/base/content/test/forms/browser.ini @@ -0,0 +1,7 @@ +[DEFAULT] +support-files = + head.js + +[browser_selectpopup.js] +skip-if = os == "linux" # Bug 1329991 - test fails intermittently on Linux builds +[browser_selectpopup_colors.js] diff --git a/browser/base/content/test/general/browser_selectpopup.js b/browser/base/content/test/forms/browser_selectpopup.js similarity index 73% rename from browser/base/content/test/general/browser_selectpopup.js rename to browser/base/content/test/forms/browser_selectpopup.js index df218d3c25c4..da136b7783f8 100644 --- a/browser/base/content/test/general/browser_selectpopup.js +++ b/browser/base/content/test/forms/browser_selectpopup.js @@ -79,92 +79,6 @@ const PAGECONTENT_TRANSLATED = "" + ""; -const PAGECONTENT_COLORS = - "" + - ""; - -const PAGECONTENT_COLORS_ON_SELECT = - "" + - ""; - -const TRANSPARENT_SELECT = - "" + - ""; - -const OPTION_COLOR_EQUAL_TO_UABACKGROUND_COLOR_SELECT = - "" + - ""; - -const GENERIC_OPTION_STYLED_AS_IMPORTANT = - "" + - ""; - -const TRANSLUCENT_SELECT_BECOMES_OPAQUE = - "" + - ""; - -const DISABLED_OPTGROUP_AND_OPTIONS = - "" + - ""; - function openSelectPopup(selectPopup, mode = "key", selector = "select", win = window) { let popupShownPromise = BrowserTestUtils.waitForEvent(selectPopup, "popupshown"); @@ -183,24 +97,6 @@ function openSelectPopup(selectPopup, mode = "key", selector = "select", win = w return popupShownPromise; } -function hideSelectPopup(selectPopup, mode = "enter", win = window) { - let browser = win.gBrowser.selectedBrowser; - let selectClosedPromise = ContentTask.spawn(browser, null, function*() { - Cu.import("resource://gre/modules/SelectContentHelper.jsm"); - return ContentTaskUtils.waitForCondition(() => !SelectContentHelper.open); - }); - - if (mode == "escape") { - EventUtils.synthesizeKey("KEY_Escape", { code: "Escape" }, win); - } else if (mode == "enter") { - EventUtils.synthesizeKey("KEY_Enter", { code: "Enter" }, win); - } else if (mode == "click") { - EventUtils.synthesizeMouseAtCenter(selectPopup.lastChild, { }, win); - } - - return selectClosedPromise; -} - function getInputEvents() { return ContentTask.spawn(gBrowser.selectedBrowser, {}, function() { return content.wrappedJSObject.gInputEvents; @@ -219,85 +115,6 @@ function getClickEvents() { }); } -function getSystemColor(color) { - // Need to convert system color to RGB color. - let textarea = document.createElementNS("http://www.w3.org/1999/xhtml", "textarea"); - textarea.style.color = color; - return getComputedStyle(textarea).color; -} - -function testOptionColors(index, item, menulist) { - // The label contains a JSON string of the expected colors for - // `color` and `background-color`. - let expected; - try { - expected = JSON.parse(item.label); - } catch (ex) { - info(`Failed parsing: ${item.label}`); - info(`Failed parsing element with outerHTML: ${item.outerHTML}`); - ok(false, ex.message); - return; - } - - for (let color of Object.keys(expected)) { - if (color.toLowerCase().includes("color") && - !expected[color].startsWith("rgb")) { - expected[color] = getSystemColor(expected[color]); - } - } - - // Press Down to move the selected item to the next item in the - // list and check the colors of this item when it's not selected. - EventUtils.synthesizeKey("KEY_ArrowDown", { code: "ArrowDown" }); - - if (expected.end) { - return; - } - - if (expected.unstyled) { - ok(!item.hasAttribute("customoptionstyling"), - `Item ${index} should not have any custom option styling`); - } 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); @@ -911,30 +728,6 @@ add_task(function* test_somehidden() { yield BrowserTestUtils.removeTab(tab); }); -// This test checks when a element has styles applied to itself. -add_task(function* test_colors_applied_to_popup() { - 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 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() { - // The popup has a black background and white text, but the - // options inside of it have flipped the colors. - 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 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() { - // The popup is requested to show a translucent background - // but we force the alpha channel to 1 on the popup. - let options = { - selectColor: "rgb(0, 0, 0)", - selectBgColor: "rgb(255, 255, 255)" - }; - yield testSelectColors(TRANSLUCENT_SELECT_BECOMES_OPAQUE, 2, options); -}); - -add_task(function* test_disabled_optgroup_and_options() { - // The colors used by this test are platform-specific. - if (AppConstants.platform != "win") { - return; - } - - yield testSelectColors(DISABLED_OPTGROUP_AND_OPTIONS, 17, - {skipSelectColorTest: true}); -}); diff --git a/browser/base/content/test/forms/browser_selectpopup_colors.js b/browser/base/content/test/forms/browser_selectpopup_colors.js new file mode 100644 index 000000000000..3e6c69eac7b1 --- /dev/null +++ b/browser/base/content/test/forms/browser_selectpopup_colors.js @@ -0,0 +1,227 @@ +const PAGECONTENT_COLORS = + "" + + ""; + +const PAGECONTENT_COLORS_ON_SELECT = + "" + + ""; + +const TRANSPARENT_SELECT = + "" + + ""; + +const OPTION_COLOR_EQUAL_TO_UABACKGROUND_COLOR_SELECT = + "" + + ""; + +const GENERIC_OPTION_STYLED_AS_IMPORTANT = + "" + + ""; + +const TRANSLUCENT_SELECT_BECOMES_OPAQUE = + "" + + ""; + +const DISABLED_OPTGROUP_AND_OPTIONS = + "" + + ""; + +function getSystemColor(color) { + // Need to convert system color to RGB color. + let textarea = document.createElementNS("http://www.w3.org/1999/xhtml", "textarea"); + textarea.style.color = color; + return getComputedStyle(textarea).color; +} + +function testOptionColors(index, item, menulist) { + // The label contains a JSON string of the expected colors for + // `color` and `background-color`. + let expected = JSON.parse(item.label); + + for (let color of Object.keys(expected)) { + if (color.toLowerCase().includes("color") && + !expected[color].startsWith("rgb")) { + expected[color] = getSystemColor(expected[color]); + } + } + + // Press Down to move the selected item to the next item in the + // list and check the colors of this item when it's not selected. + EventUtils.synthesizeKey("KEY_ArrowDown", { code: "ArrowDown" }); + + if (expected.end) { + return; + } + + if (expected.unstyled) { + ok(!item.hasAttribute("customoptionstyling"), + `Item ${index} should not have any custom option styling`); + } 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); +} + +// This test checks when a element has styles applied to itself. +add_task(function* test_colors_applied_to_popup() { + 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 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() { + // The popup has a black background and white text, but the + // options inside of it have flipped the colors. + 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 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() { + // The popup is requested to show a translucent background + // but we force the alpha channel to 1 on the popup. + let options = { + selectColor: "rgb(0, 0, 0)", + selectBgColor: "rgb(255, 255, 255)" + }; + yield testSelectColors(TRANSLUCENT_SELECT_BECOMES_OPAQUE, 2, options); +}); + +add_task(function* test_disabled_optgroup_and_options() { + // The colors used by this test are platform-specific. + if (AppConstants.platform != "win") { + return; + } + + yield testSelectColors(DISABLED_OPTGROUP_AND_OPTIONS, 17, + {skipSelectColorTest: true}); +}); diff --git a/browser/base/content/test/forms/head.js b/browser/base/content/test/forms/head.js new file mode 100644 index 000000000000..47bff77fb138 --- /dev/null +++ b/browser/base/content/test/forms/head.js @@ -0,0 +1,19 @@ +/* eslint-env mozilla/frame-script */ + +function hideSelectPopup(selectPopup, mode = "enter", win = window) { + let browser = win.gBrowser.selectedBrowser; + let selectClosedPromise = ContentTask.spawn(browser, null, function*() { + Cu.import("resource://gre/modules/SelectContentHelper.jsm"); + return ContentTaskUtils.waitForCondition(() => !SelectContentHelper.open); + }); + + if (mode == "escape") { + EventUtils.synthesizeKey("KEY_Escape", { code: "Escape" }, win); + } else if (mode == "enter") { + EventUtils.synthesizeKey("KEY_Enter", { code: "Enter" }, win); + } else if (mode == "click") { + EventUtils.synthesizeMouseAtCenter(selectPopup.lastChild, { }, win); + } + + return selectClosedPromise; +} diff --git a/browser/base/content/test/general/browser.ini b/browser/base/content/test/general/browser.ini index 1e0932f34a82..85610dc696b5 100644 --- a/browser/base/content/test/general/browser.ini +++ b/browser/base/content/test/general/browser.ini @@ -324,8 +324,6 @@ skip-if = e10s && debug && os == "win" # Bug 1280505 support-files = contentSearchUI.html contentSearchUI.js -[browser_selectpopup.js] -skip-if = os == "linux" # Bug 1329991 - test fails intermittently on Linux builds [browser_selectTabAtIndex.js] [browser_ssl_error_reports.js] [browser_star_hsts.js] diff --git a/browser/base/moz.build b/browser/base/moz.build index da97ad140de1..2801dd464910 100644 --- a/browser/base/moz.build +++ b/browser/base/moz.build @@ -17,6 +17,7 @@ MOCHITEST_CHROME_MANIFESTS += [ BROWSER_CHROME_MANIFESTS += [ 'content/test/alerts/browser.ini', 'content/test/captivePortal/browser.ini', + 'content/test/forms/browser.ini', 'content/test/general/browser.ini', 'content/test/newtab/browser.ini', 'content/test/pageinfo/browser.ini',