From 410ac149470391f1da303199e20a87e5e2eed620 Mon Sep 17 00:00:00 2001 From: Sebastian Hengst Date: Thu, 16 Mar 2017 00:24:47 +0100 Subject: [PATCH] Backed out changeset a84419a2e52d (bug 1347329) --HG-- rename : browser/base/content/test/forms/browser_selectpopup.js => browser/base/content/test/general/browser_selectpopup.js --- browser/base/content/test/forms/browser.ini | 7 - .../test/forms/browser_selectpopup_colors.js | 227 ---------------- browser/base/content/test/forms/head.js | 19 -- browser/base/content/test/general/browser.ini | 2 + .../{forms => general}/browser_selectpopup.js | 253 ++++++++++++++++++ browser/base/moz.build | 1 - 6 files changed, 255 insertions(+), 254 deletions(-) delete mode 100644 browser/base/content/test/forms/browser.ini delete mode 100644 browser/base/content/test/forms/browser_selectpopup_colors.js delete mode 100644 browser/base/content/test/forms/head.js rename browser/base/content/test/{forms => general}/browser_selectpopup.js (73%) diff --git a/browser/base/content/test/forms/browser.ini b/browser/base/content/test/forms/browser.ini deleted file mode 100644 index ce983f59e484..000000000000 --- a/browser/base/content/test/forms/browser.ini +++ /dev/null @@ -1,7 +0,0 @@ -[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/forms/browser_selectpopup_colors.js b/browser/base/content/test/forms/browser_selectpopup_colors.js deleted file mode 100644 index 3e6c69eac7b1..000000000000 --- a/browser/base/content/test/forms/browser_selectpopup_colors.js +++ /dev/null @@ -1,227 +0,0 @@ -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 deleted file mode 100644 index 47bff77fb138..000000000000 --- a/browser/base/content/test/forms/head.js +++ /dev/null @@ -1,19 +0,0 @@ -/* 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 85610dc696b5..1e0932f34a82 100644 --- a/browser/base/content/test/general/browser.ini +++ b/browser/base/content/test/general/browser.ini @@ -324,6 +324,8 @@ 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/content/test/forms/browser_selectpopup.js b/browser/base/content/test/general/browser_selectpopup.js similarity index 73% rename from browser/base/content/test/forms/browser_selectpopup.js rename to browser/base/content/test/general/browser_selectpopup.js index da136b7783f8..df218d3c25c4 100644 --- a/browser/base/content/test/forms/browser_selectpopup.js +++ b/browser/base/content/test/general/browser_selectpopup.js @@ -79,6 +79,92 @@ 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"); @@ -97,6 +183,24 @@ 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; @@ -115,6 +219,85 @@ 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); @@ -728,6 +911,30 @@ 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/moz.build b/browser/base/moz.build index 2801dd464910..da97ad140de1 100644 --- a/browser/base/moz.build +++ b/browser/base/moz.build @@ -17,7 +17,6 @@ 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',