Diff
Modified: trunk/Source/WebDriver/CMakeLists.txt (289466 => 289467)
--- trunk/Source/WebDriver/CMakeLists.txt 2022-02-09 12:42:22 UTC (rev 289466)
+++ trunk/Source/WebDriver/CMakeLists.txt 2022-02-09 13:49:12 UTC (rev 289467)
@@ -26,15 +26,33 @@
set(WebDriver_SCRIPTS
- ${WEBKIT_DIR}/UIProcess/Automation/atoms/ElementAttribute.js
- ${WEBKIT_DIR}/UIProcess/Automation/atoms/ElementDisplayed.js
- ${WEBKIT_DIR}/UIProcess/Automation/atoms/ElementEnabled.js
- ${WEBKIT_DIR}/UIProcess/Automation/atoms/EnterFullscreen.js
- ${WEBKIT_DIR}/UIProcess/Automation/atoms/FindNodes.js
- ${WEBKIT_DIR}/UIProcess/Automation/atoms/FormElementClear.js
- ${WEBKIT_DIR}/UIProcess/Automation/atoms/FormSubmit.js
+ ${WebDriver_DERIVED_SOURCES_DIR}/ElementAttribute.js
+ ${WebDriver_DERIVED_SOURCES_DIR}/ElementDisplayed.js
+ ${WebDriver_DERIVED_SOURCES_DIR}/ElementEnabled.js
+ ${WebDriver_DERIVED_SOURCES_DIR}/ElementText.js
+ ${WebDriver_DERIVED_SOURCES_DIR}/EnterFullscreen.js
+ ${WebDriver_DERIVED_SOURCES_DIR}/FindNodes.js
+ ${WebDriver_DERIVED_SOURCES_DIR}/FormElementClear.js
+ ${WebDriver_DERIVED_SOURCES_DIR}/FormSubmit.js
)
+macro(GENERATE_ATOMS _inputs)
+ foreach (_file IN ITEMS ${_inputs})
+ get_filename_component(_name ${_file} NAME)
+ add_custom_command(
+ OUTPUT ${_file}
+ MAIN_DEPENDENCY ${WEBKIT_DIR}/Scripts/generate-automation-atom.py
+ DEPENDS
+ ${WEBKIT_DIR}/UIProcess/Automation/atoms/${_name}
+ ${WEBKIT_DIR}/UIProcess/Automation/atoms/utils.js
+ COMMAND ${PYTHON_EXECUTABLE} ${WEBKIT_DIR}/Scripts/generate-automation-atom.py ${WEBKIT_DIR}/UIProcess/Automation/atoms/${_name} ${_file}
+ VERBATIM
+ )
+ endforeach ()
+endmacro()
+
+GENERATE_ATOMS("${WebDriver_SCRIPTS}")
+
MAKE_JS_FILE_ARRAYS(
${WebDriver_DERIVED_SOURCES_DIR}/WebDriverAtoms.cpp
${WebDriver_DERIVED_SOURCES_DIR}/WebDriverAtoms.h
Modified: trunk/Source/WebDriver/ChangeLog (289466 => 289467)
--- trunk/Source/WebDriver/ChangeLog 2022-02-09 12:42:22 UTC (rev 289466)
+++ trunk/Source/WebDriver/ChangeLog 2022-02-09 13:49:12 UTC (rev 289467)
@@ -1,3 +1,17 @@
+2022-02-09 Carlos Garcia Campos <[email protected]>
+
+ WebDriver: add a _javascript_ atom to get the visible text
+ https://bugs.webkit.org/show_bug.cgi?id=174617
+ <rdar://problem/32307461>
+
+ Reviewed by Adrian Perez de Castro.
+
+ Generate the _javascript_ atoms using the new command and use the new atom to get element text.
+
+ * CMakeLists.txt:
+ * Session.cpp:
+ (WebDriver::Session::getElementText):
+
2022-02-07 Carlos Garcia Campos <[email protected]>
[WebDriver] Add support for shadow roots
Modified: trunk/Source/WebDriver/Session.cpp (289466 => 289467)
--- trunk/Source/WebDriver/Session.cpp 2022-02-09 12:42:22 UTC (rev 289466)
+++ trunk/Source/WebDriver/Session.cpp 2022-02-09 13:49:12 UTC (rev 289467)
@@ -1358,7 +1358,7 @@
if (m_currentBrowsingContext)
parameters->setString("frameHandle"_s, m_currentBrowsingContext.value());
// FIXME: Add an atom to properly implement this instead of just using innerText.
- parameters->setString("function"_s, "function(element) { return element.innerText.replace(/^[^\\S\\xa0]+|[^\\S\\xa0]+$/g, '') }"_s);
+ parameters->setString("function"_s, StringImpl::createWithoutCopying(ElementTextJavaScript, sizeof(ElementTextJavaScript)));
parameters->setArray("arguments"_s, WTFMove(arguments));
m_host->sendCommandToBackend("evaluateJavaScriptFunction"_s, WTFMove(parameters), [protectedThis, completionHandler = WTFMove(completionHandler)](SessionHost::CommandResponse&& response) {
if (response.isError || !response.responseObject) {
Modified: trunk/Source/WebKit/ChangeLog (289466 => 289467)
--- trunk/Source/WebKit/ChangeLog 2022-02-09 12:42:22 UTC (rev 289466)
+++ trunk/Source/WebKit/ChangeLog 2022-02-09 13:49:12 UTC (rev 289467)
@@ -1,3 +1,44 @@
+2022-02-09 Carlos Garcia Campos <[email protected]>
+
+ WebDriver: add a _javascript_ atom to get the visible text
+ https://bugs.webkit.org/show_bug.cgi?id=174617
+ <rdar://problem/32307461>
+
+ Reviewed by Adrian Perez de Castro.
+
+ Add a new _javascript_ atom to get the visible text according to the spec. The new atom uses code from other atoms
+ like ElementDisplayed and it's also used now by FindNodes one. The atoms are now autogenerated using a script to
+ include the duplicated code from a common source utils.js.
+
+ * Scripts/generate-automation-atom.py: Added.
+ (collect_utils):
+ (parse_utils):
+ (append_functions):
+ (main):
+ * UIProcess/Automation/atoms/ElementDisplayed.js:
+ (isShown.nodeIsElement): Deleted.
+ (isShown.parentElementForElement): Deleted.
+ (isShown.enclosingNodeOrSelfMatchingPredicate): Deleted.
+ (isShown.enclosingElementOrSelfMatchingPredicate): Deleted.
+ (isShown.cascadedStylePropertyForElement): Deleted.
+ (isShown.elementSubtreeHasNonZeroDimensions): Deleted.
+ (isShown): Deleted.
+ (isShown.isElementSubtreeHiddenByOverflow): Deleted.
+ * UIProcess/Automation/atoms/ElementText.js: Added.
+ * UIProcess/Automation/atoms/FindNodes.js:
+ (tryToFindNode):
+ * UIProcess/Automation/atoms/utils.js: Added.
+ (utils.nodeIsElement):
+ (utils.enclosingNodeOrSelfMatchingPredicate):
+ (utils.parentElementForElement):
+ (utils.cascadedStylePropertyForElement):
+ (elementSubtreeHasNonZeroDimensions):
+ (isElementSubtreeHiddenByOverflow):
+ (utils.isShown):
+ (appendLines.currentLine):
+ (appendLines):
+ (utils.getText):
+
2022-02-09 Tim Horton <[email protected]>
WKHoverPlatter should scale up the platter content to make it easier to see
Added: trunk/Source/WebKit/Scripts/generate-automation-atom.py (0 => 289467)
--- trunk/Source/WebKit/Scripts/generate-automation-atom.py (rev 0)
+++ trunk/Source/WebKit/Scripts/generate-automation-atom.py 2022-02-09 13:49:12 UTC (rev 289467)
@@ -0,0 +1,95 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2022 Igalia S.L.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import os
+import re
+import sys
+
+
+def collect_utils(data):
+ match = re.findall(r'(?P<destination>utils\.[A-Za-z_0-9]+)', data)
+ return set(match)
+
+
+def parse_utils(utils):
+ functions = {}
+ current_function = None
+ with open(utils, "r") as fd:
+ for line in fd.readlines():
+ if line.startswith("utils."):
+ current_function = line.split(" ", 1)[0]
+ functions.setdefault(current_function, "")
+ elif line.startswith("}"):
+ functions[current_function] += line
+ current_function = None
+
+ if current_function is not None:
+ functions[current_function] += line
+ return functions
+
+
+def append_functions(utils_data, util_functions, util_functions_impl, functions_written):
+ for function in util_functions:
+ if function in functions_written:
+ continue
+
+ function_impl = util_functions_impl[function]
+ dependencies = collect_utils(function_impl)
+ if function in dependencies:
+ dependencies.remove(function)
+ append_functions(utils_data, dependencies, util_functions_impl, functions_written)
+
+ for line in function_impl.split("\n"):
+ if not line.strip():
+ utils_data.append(line)
+ else:
+ utils_data.append(" " + line)
+ functions_written.append(function)
+
+
+def main(args):
+ input = args[0]
+ output = args[1]
+ utils = os.path.join(os.path.dirname(input), "utils.js")
+
+ with open(input, "r") as fd:
+ input_data = fd.read()
+
+ util_functions = collect_utils(input_data)
+
+ if util_functions:
+ utils_data = [" var utils = { };", ""]
+ util_functions_impl = parse_utils(utils)
+ functions_written = []
+ append_functions(utils_data, util_functions, util_functions_impl, functions_written)
+ input_data = input_data.replace('"use strict";\n', '"use strict";\n\n' + "\n".join(utils_data))
+
+ with open(output, "w") as fd:
+ fd.write(input_data)
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
Modified: trunk/Source/WebKit/UIProcess/Automation/atoms/ElementDisplayed.js (289466 => 289467)
--- trunk/Source/WebKit/UIProcess/Automation/atoms/ElementDisplayed.js 2022-02-09 12:42:22 UTC (rev 289466)
+++ trunk/Source/WebKit/UIProcess/Automation/atoms/ElementDisplayed.js 2022-02-09 13:49:12 UTC (rev 289467)
@@ -23,178 +23,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-function isShown(element) {
+function(element) {
"use strict";
- function nodeIsElement(node) {
- return !!node && node.nodeType === Node.ELEMENT_NODE;
-
- }
-
- function parentElementForElement(element) {
- if (!element)
- return null;
-
- return enclosingNodeOrSelfMatchingPredicate(element.parentNode, nodeIsElement);
- }
-
- function enclosingNodeOrSelfMatchingPredicate(targetNode, predicate) {
- for (let node = targetNode; node && node !== targetNode.getRootNode(); node = node.parentNode)
- if (predicate(node))
- return node;
-
- return null;
- }
-
- function enclosingElementOrSelfMatchingPredicate(targetElement, predicate) {
- for (let element = targetElement; element && element !== targetElement.getRootNode(); element = parentElementForElement(element))
- if (predicate(element))
- return element;
-
- return null;
- }
-
- function cascadedStylePropertyForElement(element, property) {
- if (!element || !property)
- return null;
-
- let computedStyle = window.getComputedStyle(element);
- let computedStyleProperty = computedStyle.getPropertyValue(property);
- if (computedStyleProperty && computedStyleProperty !== "inherit")
- return computedStyleProperty;
-
- // Ideally getPropertyValue would return the 'used' or 'actual' value, but
- // it doesn't for legacy reasons. So we need to do our own poor man's cascade.
- // Fall back to the first non-'inherit' value found in an ancestor.
- // In any case, getPropertyValue will not return 'initial'.
-
- // FIXME: will this incorrectly inherit non-inheritable CSS properties?
- // I think all important non-inheritable properties (width, height, etc.)
- // for our purposes here are specially resolved, so this may not be an issue.
- // Specification is here: https://drafts.csswg.org/cssom/#resolved-values
- let parentElement = parentElementForElement(element);
- return cascadedStylePropertyForElement(parentElement, property);
- }
-
- function elementSubtreeHasNonZeroDimensions(element) {
- let boundingBox = element.getBoundingClientRect();
- if (boundingBox.width > 0 && boundingBox.height > 0)
- return true;
-
- // Paths can have a zero width or height. Treat them as shown if the stroke width is positive.
- if (element.tagName.toUpperCase() === "PATH" && boundingBox.width + boundingBox.height > 0) {
- let strokeWidth = cascadedStylePropertyForElement(element, "stroke-width");
- return !!strokeWidth && (parseInt(strokeWidth, 10) > 0);
- }
-
- let cascadedOverflow = cascadedStylePropertyForElement(element, "overflow");
- if (cascadedOverflow === "hidden")
- return false;
-
- // If the container's overflow is not hidden and it has zero size, consider the
- // container to have non-zero dimensions if a child node has non-zero dimensions.
- return Array.from(element.childNodes).some((childNode) => {
- if (childNode.nodeType === Node.TEXT_NODE)
- return true;
-
- if (nodeIsElement(childNode))
- return elementSubtreeHasNonZeroDimensions(childNode);
-
- return false;
- });
- }
-
- function elementOverflowsContainer(element) {
- let cascadedOverflow = cascadedStylePropertyForElement(element, "overflow");
- if (cascadedOverflow !== "hidden")
- return false;
-
- // FIXME: this needs to take into account the scroll position of the element,
- // the display modes of it and its ancestors, and the container it overflows.
- // See Selenium's bot.dom.getOverflowState atom for an exhaustive list of edge cases.
- return true;
- }
-
- function isElementSubtreeHiddenByOverflow(element) {
- if (!element)
- return false;
-
- if (!elementOverflowsContainer(element))
- return false;
-
- if (!element.childNodes.length)
- return false;
-
- // This element's subtree is hidden by overflow if all child subtrees are as well.
- return Array.from(element.childNodes).every((childNode) => {
- // Returns true if the child node is overflowed or otherwise hidden.
- // Base case: not an element, has zero size, scrolled out, or doesn't overflow container.
- if (!nodeIsElement(childNode))
- return true;
-
- if (!elementSubtreeHasNonZeroDimensions(childNode))
- return true;
-
- // Recurse.
- return isElementSubtreeHiddenByOverflow(childNode);
- });
- }
-
- // This is a partial reimplementation of Selenium's "element is displayed" algorithm.
- // When the W3C specification's algorithm stabilizes, we should implement that.
-
- if (!(element instanceof Element))
- throw new Error("Cannot check the displayedness of a non-Element argument.");
-
- // If this command is misdirected to the wrong document, treat it as not shown.
- if (!document.contains(element))
- return false;
-
- // Special cases for specific tag names.
- switch (element.tagName.toUpperCase()) {
- case "BODY":
- return true;
-
- case "SCRIPT":
- case "NOSCRIPT":
- return false;
-
- case "OPTGROUP":
- case "OPTION":
- // Option/optgroup are considered shown if the containing <select> is shown.
- let enclosingSelectElement = enclosingNodeOrSelfMatchingPredicate(element, (e) => e.tagName.toUpperCase() === "SELECT");
- return isShown(enclosingSelectElement);
-
- case "INPUT":
- // <input type="hidden"> is considered not shown.
- if (element.type === "hidden")
- return false;
- break;
-
- case "MAP":
- // FIXME: Selenium has special handling for <map> elements. We don't do anything now.
-
- default:
- break;
- }
-
- if (cascadedStylePropertyForElement(element, "visibility") !== "visible")
- return false;
-
- let hasAncestorWithZeroOpacity = !!enclosingElementOrSelfMatchingPredicate(element, (e) => {
- return Number(cascadedStylePropertyForElement(e, "opacity")) === 0;
- });
- let hasAncestorWithDisplayNone = !!enclosingElementOrSelfMatchingPredicate(element, (e) => {
- return cascadedStylePropertyForElement(e, "display") === "none";
- });
- if (hasAncestorWithZeroOpacity || hasAncestorWithDisplayNone)
- return false;
-
- if (!elementSubtreeHasNonZeroDimensions(element))
- return false;
-
- if (isElementSubtreeHiddenByOverflow(element))
- return false;
-
- return true;
+ return utils.isShown(element);
}
Added: trunk/Source/WebKit/UIProcess/Automation/atoms/ElementText.js (0 => 289467)
--- trunk/Source/WebKit/UIProcess/Automation/atoms/ElementText.js (rev 0)
+++ trunk/Source/WebKit/UIProcess/Automation/atoms/ElementText.js 2022-02-09 13:49:12 UTC (rev 289467)
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2022 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function(element) {
+ "use strict";
+
+ return utils.getText(element);
+}
Modified: trunk/Source/WebKit/UIProcess/Automation/atoms/FindNodes.js (289466 => 289467)
--- trunk/Source/WebKit/UIProcess/Automation/atoms/FindNodes.js 2022-02-09 12:42:22 UTC (rev 289466)
+++ trunk/Source/WebKit/UIProcess/Automation/atoms/FindNodes.js 2022-02-09 13:49:12 UTC (rev 289467)
@@ -24,6 +24,8 @@
*/
function(strategy, ancestorElement, query, firstResultOnly, timeoutDuration, callback) {
+ "use strict";
+
ancestorElement = ancestorElement || document;
switch (strategy) {
@@ -67,7 +69,7 @@
case "link text":
let linkTextResult = [];
for (let link of ancestorElement.querySelectorAll("a")) {
- if (link.text.trim() == query) {
+ if (utils.getText(link).trim() == query) {
linkTextResult.push(link);
if (firstResultOnly)
break;
@@ -80,7 +82,7 @@
case "partial link text":
let partialLinkResult = [];
for (let link of ancestorElement.querySelectorAll("a")) {
- if (link.text.includes(query)) {
+ if (utils.getText(link).includes(query)) {
partialLinkResult.push(link);
if (firstResultOnly)
break;
Added: trunk/Source/WebKit/UIProcess/Automation/atoms/utils.js (0 => 289467)
--- trunk/Source/WebKit/UIProcess/Automation/atoms/utils.js (rev 0)
+++ trunk/Source/WebKit/UIProcess/Automation/atoms/utils.js 2022-02-09 13:49:12 UTC (rev 289467)
@@ -0,0 +1,335 @@
+/*
+ * Copyright (C) 2022 Igalia S.L.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+var utils = { };
+
+utils.nodeIsElement = function(node) {
+ return !!node && node.nodeType === Node.ELEMENT_NODE;
+}
+
+utils.enclosingNodeOrSelfMatchingPredicate = function(targetNode, predicate) {
+ for (let node = targetNode; node && node !== targetNode.getRootNode(); node = node.parentNode)
+ if (predicate(node))
+ return node;
+
+ return null;
+}
+
+utils.parentElementForElement = function(element) {
+ if (!element)
+ return null;
+
+ return utils.enclosingNodeOrSelfMatchingPredicate(element.parentNode, utils.nodeIsElement);
+}
+
+utils.cascadedStylePropertyForElement = function(element, property) {
+ if (!element || !property)
+ return null;
+
+ let computedStyle = window.getComputedStyle(element);
+ let computedStyleProperty = computedStyle.getPropertyValue(property);
+ if (computedStyleProperty && computedStyleProperty !== "inherit")
+ return computedStyleProperty;
+
+ // Ideally getPropertyValue would return the 'used' or 'actual' value, but
+ // it doesn't for legacy reasons. So we need to do our own poor man's cascade.
+ // Fall back to the first non-'inherit' value found in an ancestor.
+ // In any case, getPropertyValue will not return 'initial'.
+
+ // FIXME: will this incorrectly inherit non-inheritable CSS properties?
+ // I think all important non-inheritable properties (width, height, etc.)
+ // for our purposes here are specially resolved, so this may not be an issue.
+ // Specification is here: https://drafts.csswg.org/cssom/#resolved-values
+ let parentElement = utils.parentElementForElement(element);
+ return utils.cascadedStylePropertyForElement(parentElement, property);
+}
+
+utils.isShown = function(element) {
+ function enclosingElementOrSelfMatchingPredicate(targetElement, predicate) {
+ for (let element = targetElement; element && element !== targetElement.getRootNode(); element = utils.parentElementForElement(element))
+ if (predicate(element))
+ return element;
+
+ return null;
+ }
+
+ function elementSubtreeHasNonZeroDimensions(element) {
+ let boundingBox = element.getBoundingClientRect();
+ if (boundingBox.width > 0 && boundingBox.height > 0)
+ return true;
+
+ // Paths can have a zero width or height. Treat them as shown if the stroke width is positive.
+ if (element.tagName.toUpperCase() === "PATH" && boundingBox.width + boundingBox.height > 0) {
+ let strokeWidth = utils.cascadedStylePropertyForElement(element, "stroke-width");
+ return !!strokeWidth && (parseInt(strokeWidth, 10) > 0);
+ }
+
+ let cascadedOverflow = utils.cascadedStylePropertyForElement(element, "overflow");
+ if (cascadedOverflow === "hidden")
+ return false;
+
+ // If the container's overflow is not hidden and it has zero size, consider the
+ // container to have non-zero dimensions if a child node has non-zero dimensions.
+ return Array.from(element.childNodes).some((childNode) => {
+ if (childNode.nodeType === Node.TEXT_NODE)
+ return true;
+
+ if (utils.nodeIsElement(childNode))
+ return elementSubtreeHasNonZeroDimensions(childNode);
+
+ return false;
+ });
+ }
+
+ function elementOverflowsContainer(element) {
+ let cascadedOverflow = utils.cascadedStylePropertyForElement(element, "overflow");
+ if (cascadedOverflow !== "hidden")
+ return false;
+
+ // FIXME: this needs to take into account the scroll position of the element,
+ // the display modes of it and its ancestors, and the container it overflows.
+ // See Selenium's bot.dom.getOverflowState atom for an exhaustive list of edge cases.
+ return true;
+ }
+
+ function isElementSubtreeHiddenByOverflow(element) {
+ if (!element)
+ return false;
+
+ if (!elementOverflowsContainer(element))
+ return false;
+
+ if (!element.childNodes.length)
+ return false;
+
+ // This element's subtree is hidden by overflow if all child subtrees are as well.
+ return Array.from(element.childNodes).every((childNode) => {
+ // Returns true if the child node is overflowed or otherwise hidden.
+ // Base case: not an element, has zero size, scrolled out, or doesn't overflow container.
+ if (!utils.nodeIsElement(childNode))
+ return true;
+
+ if (!elementSubtreeHasNonZeroDimensions(childNode))
+ return true;
+
+ // Recurse.
+ return isElementSubtreeHiddenByOverflow(childNode);
+ });
+ }
+
+ // This is a partial reimplementation of Selenium's "element is displayed" algorithm.
+ // When the W3C specification's algorithm stabilizes, we should implement that.
+
+ if (!(element instanceof Element))
+ throw new Error("Cannot check the displayedness of a non-Element argument.");
+
+ // Special cases for specific tag names.
+ switch (element.tagName.toUpperCase()) {
+ case "BODY":
+ return true;
+
+ case "SCRIPT":
+ case "NOSCRIPT":
+ return false;
+
+ case "OPTGROUP":
+ case "OPTION":
+ // Option/optgroup are considered shown if the containing <select> is shown.
+ let enclosingSelectElement = utils.enclosingNodeOrSelfMatchingPredicate(element, (e) => e.tagName.toUpperCase() === "SELECT");
+ return utils.isShown(enclosingSelectElement);
+
+ case "INPUT":
+ // <input type="hidden"> is considered not shown.
+ if (element.type === "hidden")
+ return false;
+ break;
+
+ case "MAP":
+ // FIXME: Selenium has special handling for <map> elements. We don't do anything now.
+
+ default:
+ break;
+ }
+
+ if (utils.cascadedStylePropertyForElement(element, "visibility") !== "visible")
+ return false;
+
+ let hasAncestorWithZeroOpacity = !!enclosingElementOrSelfMatchingPredicate(element, (e) => {
+ return Number(utils.cascadedStylePropertyForElement(e, "opacity")) === 0;
+ });
+ let hasAncestorWithDisplayNone = !!enclosingElementOrSelfMatchingPredicate(element, (e) => {
+ return utils.cascadedStylePropertyForElement(e, "display") === "none";
+ });
+ if (hasAncestorWithZeroOpacity || hasAncestorWithDisplayNone)
+ return false;
+
+ if (!elementSubtreeHasNonZeroDimensions(element))
+ return false;
+
+ if (isElementSubtreeHiddenByOverflow(element))
+ return false;
+
+ return true;
+}
+
+utils.getText = function(element) {
+ var lines = [];
+
+ function appendLinesFromTextNode(textNode, whitespace, textTransform) {
+ // Remove zero-width characters.
+ let text = textNode.nodeValue.replace(/[\u200b\u200e\u200f]/g, '');
+
+ // Canonicalize the new lines.
+ text = text.replace(/(\r\n|\r|\n)/g, '\n');
+
+ let collapseAll = true;
+ switch (whitespace) {
+ case "normal":
+ case "nowrap":
+ // Collapse new lines.
+ text = text.replace(/\n/g, ' ');
+ break;
+ case "pre":
+ case "pre-wrap":
+ // Convert all breaking spaces to be non-breaking.
+ text = text.replace(/[ \f\t\v\u2028\u2029]/g, '\xa0');
+ collapseAll = false;
+ break;
+ }
+
+ if (collapseAll) {
+ // Collapse all breaking spaces.
+ text = text.replace(/[\ \f\t\v\u2028\u2029]+/g, ' ');
+ }
+
+ switch (textTransform) {
+ case "capitalize":
+ text = text.replace(/(^|[^\d\p{L}\p{S}])([\p{Ll}|\p{S}])/gu, function() {
+ return arguments[1] + arguments[2].toUpperCase();
+ });
+ break;
+ case "uppercase":
+ text = text.toUpperCase();
+ break;
+ case "lowercase":
+ text = text.toLowerCase();
+ break;
+ }
+
+ let currentLine = lines.pop() || '';
+ if (currentLine.endsWith(' ') && text.startsWith(' '))
+ text = text.substr(1);
+ lines.push(currentLine + text);
+ }
+
+ function appendLinesFromNode(node, shown, whitespace, textTransform) {
+ switch (node.nodeType) {
+ case Node.TEXT_NODE:
+ if (shown)
+ appendLinesFromTextNode(node, whitespace, textTransform);
+ break;
+ case Node.ELEMENT_NODE:
+ if (node.tagName.toUpperCase() == "SLOT") {
+ let parentNode = node;
+ while (parentNode.parentNode)
+ parentNode = parentNode.parentNode;
+ if (parentNode instanceof ShadowRoot) {
+ Array.from(node.assignedNodes()).forEach((childNode) => {
+ appendLinesFromNode(childNode, shown, whitespace, textTransform);
+ });
+ return;
+ }
+ }
+ appendLinesFromElement(node);
+ break;
+ }
+ }
+
+ function appendLines(element) {
+ function currentLine() {
+ return lines[lines.length - 1] || '';
+ }
+
+ let isTableCell = false, display = null, isBlock = false;
+ if (element.tagName.toUpperCase() === "BR")
+ lines.push('');
+ else {
+ isTableCell = element.tagName.toUpperCase() === "TD";
+ display = utils.cascadedStylePropertyForElement(element, "display");
+ isBlock = !isTableCell
+ && !(display === "inline"
+ || display === "inline-block"
+ || display === "inline-table"
+ || display === "none"
+ || display === "table-cell"
+ || display === "table-column"
+ || display === "table-column-group");
+ let previousElementSibling = element.previousElementSibling;
+ let previousDisplay = previousElementSibling ? utils.cascadedStylePropertyForElement(previousElementSibling, "display") : '';
+ let elementFloat = utils.cascadedStylePropertyForElement(element, "float") || utils.cascadedStylePropertyForElement(element, "cssFloat");
+ let runIntoThis = previousDisplay == "run-in" && elementFloat == "none";
+ if (isBlock && !runIntoThis && /^[\s\xa0]*$/.test(currentLine()))
+ lines.push('');
+ }
+
+ let shown = utils.isShown(element);
+ let whitespace = null, textTransform = null;
+ if (shown) {
+ whitespace = utils.cascadedStylePropertyForElement(element, "white-space");
+ textTransform = utils.cascadedStylePropertyForElement(element, "text-transform");
+ }
+
+ Array.from(element.childNodes).forEach((childNode) => {
+ if (!childNode.assignedSlot)
+ appendLinesFromNode(childNode, shown, whitespace, textTransform);
+ });
+
+ let line = currentLine();
+ if ((isTableCell || display == "table-cell") && line && line.endsWith(' '))
+ lines[lines.length - 1] += ' ';
+
+ if (isBlock && display != "run-in" && /^[\s\xa0]*$/.test(line))
+ lines.push('');
+ }
+
+ function appendLinesFromElement(element) {
+ if (element.shadowRoot) {
+ Array.from(element.shadowRoot.childNodes).forEach((childNode) => {
+ appendLinesFromNode(childNode, true, null, null);
+ });
+ }
+
+ appendLines(element);
+ }
+
+ appendLinesFromElement(element);
+
+ lines = lines.map((str) => str.replace(/^[^\S\xa0]+|[^\S\xa0]+$/g, ''));
+ let trimmed = lines.join('\n').replace(/^[^\S\xa0]+|[^\S\xa0]+$/g, '');
+
+ // Replace non-breakable spaces with regular ones.
+ return trimmed.replace(/\xa0/g, ' ');
+}
Modified: trunk/WebDriverTests/ChangeLog (289466 => 289467)
--- trunk/WebDriverTests/ChangeLog 2022-02-09 12:42:22 UTC (rev 289466)
+++ trunk/WebDriverTests/ChangeLog 2022-02-09 13:49:12 UTC (rev 289467)
@@ -1,3 +1,15 @@
+2022-02-09 Carlos Garcia Campos <[email protected]>
+
+ WebDriver: add a _javascript_ atom to get the visible text
+ https://bugs.webkit.org/show_bug.cgi?id=174617
+ <rdar://problem/32307461>
+
+ Reviewed by Adrian Perez de Castro.
+
+ Remove expectations of tests that are now passing.
+
+ * TestExpectations.json:
+
2022-02-07 Carlos Garcia Campos <[email protected]>
[WebDriver] Add support for shadow roots
Modified: trunk/WebDriverTests/TestExpectations.json (289466 => 289467)
--- trunk/WebDriverTests/TestExpectations.json 2022-02-09 12:42:22 UTC (rev 289466)
+++ trunk/WebDriverTests/TestExpectations.json 2022-02-09 13:49:12 UTC (rev 289467)
@@ -133,9 +133,6 @@
},
"imported/selenium/py/test/selenium/webdriver/common/select_class_tests.py": {
"subtests": {
- "testSelectByVisibleTextShouldNormalizeSpaces": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/174617"}}
- },
"testSelectByIndexMultiple": {
"expected": {"all": {"slow": true}}
},
@@ -149,20 +146,11 @@
},
"imported/selenium/py/test/selenium/webdriver/common/text_handling_tests.py": {
"subtests": {
- "testShouldConvertANonBreakingSpaceIntoANormalSpaceCharacter": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/174617"}}
- },
- "testShouldTreatANonBreakingSpaceAsAnyOtherWhitespaceCharacterWhenCollapsingWhitespace": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/174617"}}
- },
"testShouldBeAbleToSetMoreThanOneLineOfTextInATextArea": {
"expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/174617"}}
},
"testShouldHandleSiblingBlockLevelElements": {
"expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/174617"}}
- },
- "testShouldOnlyIncludeVisibleText": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/174617"}}
}
}
},
@@ -839,18 +827,6 @@
},
"imported/w3c/webdriver/tests/find_element/find.py": {
"subtests": {
- "test_find_element_link_text[<a href="" {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_element_link_text[<a href=# style='text-transform: uppercase'>link text</a>-LINK TEXT]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_element_partial_link_text[<a href="" link<br>text</a>-k\\nt]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_element_partial_link_text[<a href=# style='text-transform: uppercase'>partial link text</a>-LINK]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
"test_no_top_browsing_context": {
"expected": {"wpe": {"status": ["FAIL"], "bug": "webkit.org/b/212950"}}
},
@@ -861,18 +837,6 @@
},
"imported/w3c/webdriver/tests/find_elements/find.py": {
"subtests": {
- "test_find_elements_link_text[<a href="" {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_elements_link_text[<a href=# style='text-transform: uppercase'>link text</a>-LINK TEXT]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_elements_partial_link_text[<a href="" link<br>text</a>-k\\nt]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_elements_partial_link_text[<a href=# style='text-transform: uppercase'>partial link text</a>-LINK]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
"test_no_top_browsing_context": {
"expected": {"wpe": {"status": ["FAIL"], "bug": "webkit.org/b/212950"}}
},
@@ -883,18 +847,6 @@
},
"imported/w3c/webdriver/tests/find_elements_from_element/find.py": {
"subtests": {
- "test_find_elements_link_text[<a href="" {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_elements_link_text[<a href=# style='text-transform: uppercase'>link text</a>-LINK TEXT]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_elements_partial_link_text[<a href="" link<br>text</a>-k\\nt]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_elements_partial_link_text[<a href=# style='text-transform: uppercase'>partial link text</a>-LINK]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
"test_parent_of_document_node_errors": {
"expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
},
@@ -908,18 +860,6 @@
},
"imported/w3c/webdriver/tests/find_element_from_element/find.py": {
"subtests": {
- "test_find_element_link_text[<a href="" {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_element_link_text[<a href=# style='text-transform: uppercase'>link text</a>-LINK TEXT]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_element_partial_link_text[<a href="" link<br>text</a>-k\\nt]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_element_partial_link_text[<a href=# style='text-transform: uppercase'>partial link text</a>-LINK]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
"test_parent_of_document_node_errors": {
"expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
},
@@ -1575,18 +1515,6 @@
},
"test_find_element[xpath-//a]": {
"expected": { "all": { "status": ["SKIP"]}}
- },
- "test_find_element_link_text[<a href="" {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_element_link_text[<a href=# style='text-transform: uppercase'>link text</a>-LINK TEXT]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_element_partial_link_text[<a href="" link<br>text</a>-k\\nt]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_element_partial_link_text[<a href=# style='text-transform: uppercase'>partial link text</a>-LINK]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
}
}
},
@@ -1597,18 +1525,6 @@
},
"test_find_elements[xpath-//a]": {
"expected": { "all": { "status": ["SKIP"]}}
- },
- "test_find_elements_link_text[<a href="" {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_elements_link_text[<a href=# style='text-transform: uppercase'>link text</a>-LINK TEXT]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_elements_partial_link_text[<a href="" link<br>text</a>-k\\nt]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
- },
- "test_find_elements_partial_link_text[<a href=# style='text-transform: uppercase'>partial link text</a>-LINK]": {
- "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/184964"}}
}
}
},