Commit 6b753c2b authored by Tricia Crichton's avatar Tricia Crichton Committed by Commit Bot

[ChromeDriver] Update atoms from SeleniumHQ

Pull latest atoms changes from SeleniumHQ. Also updated instructions for
building atoms and the patch.diff.

Modified the javascript conversion to cc code to enable use of char[] and string. This change has a pending PR at selenium HQ.

Modified the isElementClickable source code prevent attribute renaming bazel conversion.

Bug: chromedriver:1049
Change-Id: I3df9ef0b69da849e054c938a697753b72c8187a7
Fixed: chromedriver:1049
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1888531
Commit-Queue: Tricia Crichton <triciac@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723025}
parent 23e80815
...@@ -18,20 +18,27 @@ Contents: ...@@ -18,20 +18,27 @@ Contents:
atoms.h, atoms.cc atoms.h, atoms.cc
These atoms are generated by the webdriver team and are to be checked in These atoms are generated by the webdriver team and are to be checked in
manually. The current version was generated from revision manually. The current version was generated from revision
6772bd50767d123a9febe00f2ac2190e06b7e12c. 0834ca83b274e1790cd812a8d56add5f2e982308.
To generate the atoms using the code found in selenium tree: To generate the atoms using the code found in selenium tree:
$ git clone https://github.com/SeleniumHQ/selenium.git $ git clone https://github.com/SeleniumHQ/selenium.git
$ cd selenium $ cd selenium
$ git apply <chromium_dir>/src/third_party/webdriver/patch.diff $ git apply <chromium_dir>/src/third_party/webdriver/patch.diff
$ ./go //javascript/chrome-driver:atoms $ ./bazel build javascript/chrome-driver/...
$ cp build/javascript/chrome-driver/atoms.h \ $ cp bazel-bin/javascript/chrome-driver/atoms.h \
<chromium_dir>/src/third_party/webdriver/atoms.h <chromium_dir>/src/third_party/webdriver/atoms.h
$ cp build/javascript/chrome-driver/atoms.cc \ $ cp bazel-bin/javascript/chrome-driver/atoms.cc \
<chromium_dir>/src/third_party/webdriver/atoms.cc <chromium_dir>/src/third_party/webdriver/atoms.cc
The atoms.h/cc files are only used directly in the chrome version of The atoms.h/cc files are only used directly in the chrome version of
webdriver found under the path src/chrome/test/chromedriver. webdriver found under the path src/chrome/test/chromedriver.
bazel-bin is a symlink. To find files within the selenium folder, add -L
$ find -L . -name atoms.h
If the patch.diff fails to apply, rerun with --reject. Review the output and
manually merge the failed changes. Regenerate the patch when finished:
$ git diff > <chromium_dir>/src/third_party/webdriver/patch.diff
Local Modifications: Local Modifications:
- Applied changes in patch.diff to the selenium tree prior to building the atoms. - Applied changes in patch.diff to the selenium tree prior to building the atoms.
This diff is collapsed.
...@@ -14,9 +14,10 @@ ...@@ -14,9 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
/* AUTO GENERATED - DO NOT EDIT BY HAND */ /* AUTO GENERATED - DO NOT EDIT BY HAND */
#ifndef WEBDRIVER_ATOMS_H_ #ifndef WEBDRIVER_ATOMS_H
#define WEBDRIVER_ATOMS_H_ #define WEBDRIVER_ATOMS_H
#include <string> // For std::(w)string. #include <string> // For std::(w)string.
...@@ -24,41 +25,41 @@ namespace webdriver { ...@@ -24,41 +25,41 @@ namespace webdriver {
namespace atoms { namespace atoms {
extern const char* const CLEAR[]; extern const char* const CLEAR[];
extern const char* const CLEAR_LOCAL_STORAGE[];
extern const char* const CLEAR_SESSION_STORAGE[];
extern const char* const CLICK[]; extern const char* const CLICK[];
extern const char* const EXECUTE_ASYNC_SCRIPT[]; extern const char* const EXECUTE_ASYNC_SCRIPT[];
extern const char* const EXECUTE_SCRIPT[]; extern const char* const EXECUTE_SCRIPT[];
extern const char* const EXECUTE_SQL[]; extern const char* const EXECUTE_SQL[];
extern const char* const FIND_ELEMENTS[];
extern const char* const GET_EFFECTIVE_STYLE[];
extern const char* const GET_LOCATION[];
extern const char* const GET_SIZE[];
extern const char* const IS_DISPLAYED[];
extern const char* const IS_ENABLED[];
extern const char* const SUBMIT[];
extern const char* const FIND_ELEMENT[]; extern const char* const FIND_ELEMENT[];
extern const char* const GET_FIRST_CLIENT_RECT[]; extern const char* const FIND_ELEMENTS[];
extern const char* const GET_LOCATION_IN_VIEW[];
extern const char* const GET_PAGE_ZOOM[];
extern const char* const IS_ELEMENT_CLICKABLE[];
extern const char* const IS_ELEMENT_DISPLAYED[];
extern const char* const CLEAR_LOCAL_STORAGE[];
extern const char* const CLEAR_SESSION_STORAGE[];
extern const char* const GET_APPCACHE_STATUS[]; extern const char* const GET_APPCACHE_STATUS[];
extern const char* const GET_ATTRIBUTE[]; extern const char* const GET_ATTRIBUTE[];
extern const char* const GET_EFFECTIVE_STYLE[];
extern const char* const GET_FIRST_CLIENT_RECT[];
extern const char* const GET_LOCAL_STORAGE_ITEM[]; extern const char* const GET_LOCAL_STORAGE_ITEM[];
extern const char* const GET_LOCAL_STORAGE_KEY[]; extern const char* const GET_LOCAL_STORAGE_KEY[];
extern const char* const GET_LOCAL_STORAGE_KEYS[]; extern const char* const GET_LOCAL_STORAGE_KEYS[];
extern const char* const GET_LOCAL_STORAGE_SIZE[]; extern const char* const GET_LOCAL_STORAGE_SIZE[];
extern const char* const GET_LOCATION[];
extern const char* const GET_LOCATION_IN_VIEW[];
extern const char* const GET_PAGE_ZOOM[];
extern const char* const GET_SESSION_STORAGE_ITEM[]; extern const char* const GET_SESSION_STORAGE_ITEM[];
extern const char* const GET_SESSION_STORAGE_KEY[]; extern const char* const GET_SESSION_STORAGE_KEY[];
extern const char* const GET_SESSION_STORAGE_KEYS[]; extern const char* const GET_SESSION_STORAGE_KEYS[];
extern const char* const GET_SESSION_STORAGE_SIZE[]; extern const char* const GET_SESSION_STORAGE_SIZE[];
extern const char* const GET_SIZE[];
extern const char* const GET_TEXT[]; extern const char* const GET_TEXT[];
extern const char* const IS_DISPLAYED[];
extern const char* const IS_ELEMENT_CLICKABLE[];
extern const char* const IS_ELEMENT_DISPLAYED[];
extern const char* const IS_ENABLED[];
extern const char* const IS_SELECTED[]; extern const char* const IS_SELECTED[];
extern const char* const REMOVE_LOCAL_STORAGE_ITEM[]; extern const char* const REMOVE_LOCAL_STORAGE_ITEM[];
extern const char* const REMOVE_SESSION_STORAGE_ITEM[]; extern const char* const REMOVE_SESSION_STORAGE_ITEM[];
extern const char* const SET_LOCAL_STORAGE_ITEM[]; extern const char* const SET_LOCAL_STORAGE_ITEM[];
extern const char* const SET_SESSION_STORAGE_ITEM[]; extern const char* const SET_SESSION_STORAGE_ITEM[];
extern const char* const SUBMIT[];
static inline std::string asString(const char* const atom[]) { static inline std::string asString(const char* const atom[]) {
std::string source; std::string source;
...@@ -71,4 +72,4 @@ static inline std::string asString(const char* const atom[]) { ...@@ -71,4 +72,4 @@ static inline std::string asString(const char* const atom[]) {
} // namespace atoms } // namespace atoms
} // namespace webdriver } // namespace webdriver
#endif // WEBDRIVER_ATOMS_H_ #endif // WEBDRIVER_ATOMS_H
diff --git a/javascript/atoms/action.js b/javascript/atoms/action.js
index 74a0fa1c1b..91c2caba62 100644
--- a/javascript/atoms/action.js
+++ b/javascript/atoms/action.js
@@ -98,7 +98,6 @@ bot.action.clear = function(element) {
element.value = '';
}
bot.events.fire(element, bot.events.EventType.CHANGE);
- bot.events.fire(element, bot.events.EventType.BLUR);
var body = bot.getDocument().body;
if (body) {
bot.action.LegacyDevice_.focusOnElement(body);
@@ -113,13 +112,18 @@ bot.action.clear = function(element) {
// current value or not
bot.action.LegacyDevice_.focusOnElement(element);
element.value = '';
- }
-
- if (bot.dom.isContentEditable(element)) {
+ } else if (bot.dom.isContentEditable(element)) {
// A single space is required, if you put empty string here you'll not be
// able to interact with this element anymore in Firefox.
bot.action.LegacyDevice_.focusOnElement(element);
- element.innerHTML = ' ';
+ element.innerHTML = goog.userAgent.GECKO ? ' ' : '';
+ var body = bot.getDocument().body;
+ if (body) {
+ bot.action.LegacyDevice_.focusOnElement(body);
+ } else {
+ throw new bot.Error(bot.ErrorCode.UNKNOWN_ERROR,
+ 'Cannot unfocus element after clearing.');
+ }
// contentEditable does not generate onchange event.
}
};
diff --git a/javascript/atoms/dom.js b/javascript/atoms/dom.js diff --git a/javascript/atoms/dom.js b/javascript/atoms/dom.js
index 196412d3cb..bb24c3058a 100644 index 7dd4e846e4..66b85cdc95 100644
--- a/javascript/atoms/dom.js --- a/javascript/atoms/dom.js
+++ b/javascript/atoms/dom.js +++ b/javascript/atoms/dom.js
@@ -595,14 +595,8 @@ bot.dom.isShown = function(elem, opt_ignoreOpacity) { @@ -587,14 +587,8 @@ bot.dom.isShown = function(elem, opt_ignoreOpacity) {
var parent = bot.dom.getParentNodeInComposedDom(e); var parent = bot.dom.getParentNodeInComposedDom(e);
if (bot.dom.IS_SHADOW_DOM_ENABLED && (parent instanceof ShadowRoot)) { if (bot.dom.IS_SHADOW_DOM_ENABLED && (parent instanceof ShadowRoot)) {
...@@ -54,8 +19,8 @@ index 196412d3cb..bb24c3058a 100644 ...@@ -54,8 +19,8 @@ index 196412d3cb..bb24c3058a 100644
} }
if (parent && (parent.nodeType == goog.dom.NodeType.DOCUMENT || if (parent && (parent.nodeType == goog.dom.NodeType.DOCUMENT ||
@@ -610,7 +604,7 @@ bot.dom.isShown = function(elem, opt_ignoreOpacity) { @@ -609,7 +603,7 @@ bot.dom.isShown = function(elem, opt_ignoreOpacity) {
return true; return false;
} }
- return parent && displayed(parent); - return parent && displayed(parent);
...@@ -63,7 +28,7 @@ index 196412d3cb..bb24c3058a 100644 ...@@ -63,7 +28,7 @@ index 196412d3cb..bb24c3058a 100644
} }
return bot.dom.isShown_(elem, !!opt_ignoreOpacity, displayed); return bot.dom.isShown_(elem, !!opt_ignoreOpacity, displayed);
@@ -1271,13 +1265,6 @@ bot.dom.getOpacityNonIE_ = function(elem) { @@ -1270,13 +1264,6 @@ bot.dom.getOpacityNonIE_ = function(elem) {
bot.dom.getParentNodeInComposedDom = function(node) { bot.dom.getParentNodeInComposedDom = function(node) {
var /**@type {Node}*/ parent = node.parentNode; var /**@type {Node}*/ parent = node.parentNode;
...@@ -77,7 +42,7 @@ index 196412d3cb..bb24c3058a 100644 ...@@ -77,7 +42,7 @@ index 196412d3cb..bb24c3058a 100644
// Shadow DOM V0 (deprecated) // Shadow DOM V0 (deprecated)
if (node.getDestinationInsertionPoints) { if (node.getDestinationInsertionPoints) {
var destinations = node.getDestinationInsertionPoints(); var destinations = node.getDestinationInsertionPoints();
@@ -1286,6 +1273,13 @@ bot.dom.getParentNodeInComposedDom = function(node) { @@ -1285,6 +1272,13 @@ bot.dom.getParentNodeInComposedDom = function(node) {
} }
} }
...@@ -115,34 +80,141 @@ index 737ed50f62..1bc9e858f5 100644 ...@@ -115,34 +80,141 @@ index 737ed50f62..1bc9e858f5 100644
} else { } else {
buttonValueMap[bot.events.EventType.CLICK] = [0, 1, 2, null]; buttonValueMap[bot.events.EventType.CLICK] = [0, 1, 2, null];
buttonValueMap[bot.events.EventType.CONTEXTMENU] = [null, null, 2, null]; buttonValueMap[bot.events.EventType.CONTEXTMENU] = [null, null, 2, null];
diff --git a/javascript/chrome-driver/BUILD.bazel b/javascript/chrome-driver/BUILD.bazel
index 9e33cc769e..c231b8e7fd 100644
--- a/javascript/chrome-driver/BUILD.bazel
+++ b/javascript/chrome-driver/BUILD.bazel
@@ -109,6 +109,7 @@ closure_lang_file(
name = "header",
out = "atoms.h",
lang = "hdecl",
+ utf8 = True,
deps = ATOMS,
)
@@ -116,6 +117,7 @@ closure_lang_file(
name = "source",
out = "atoms.cc",
lang = "cc",
+ utf8 = True,
deps = ATOMS,
)
diff --git a/javascript/chrome-driver/atoms.js b/javascript/chrome-driver/atoms.js diff --git a/javascript/chrome-driver/atoms.js b/javascript/chrome-driver/atoms.js
index 5cf4416460..7cd02f0507 100644 index 5185e010fb..3febbeba5c 100644
--- a/javascript/chrome-driver/atoms.js --- a/javascript/chrome-driver/atoms.js
+++ b/javascript/chrome-driver/atoms.js +++ b/javascript/chrome-driver/atoms.js
@@ -142,7 +142,12 @@ webdriver.chrome.scrollIntoView_ = function(elem, region, center) { @@ -211,7 +211,7 @@ webdriver.chrome.getFirstClientRect = function(elem) {
* at the given location. Useful for debugging test clicking issues.
offset = goog.style.getClientPosition(elem); *
var windowSize = goog.dom.getDomHelper(elem).getViewportSize(); * @param {!Element} elem The element to use.
- scrollHelper(doc.body, windowSize, offset, region, center); - * @param {!goog.math.Coordinate} coord The coordinate to use.
+ // Chrome uses either doc.documentElement or doc.body, depending on + * @param {!Object} coord The coordinate to use.
+ // compatibility settings. For reliability, call scrollHelper on both. * @return {{clickable:boolean, message: (string|undefined)}} Object containing
+ // Calling scrollHelper on the wrong object is harmless. * a boolean "clickable" property, as to whether it can be clicked, and an
+ scrollHelper(doc.documentElement, windowSize, offset, region, center); * optional "message" string property, which contains any warning/error
+ if (doc.body) diff --git a/javascript/private/gen_file.py b/javascript/private/gen_file.py
+ scrollHelper(doc.body, windowSize, offset, region, center); index 27c9fd3236..b37ccbfeff 100644
}; --- a/javascript/private/gen_file.py
+++ b/javascript/private/gen_file.py
@@ -33,6 +33,9 @@ def write_atom_literal(out, name, contents, lang):
contents = contents.replace('"', '\\"')
if "cc" == lang or "hh" == lang:
+ if utf8:
+ line_format = " \"{}\",\n"
+ else:
line_format = " L\"{}\",\n"
elif "java" == lang:
line_format = " .append\(\"{}\")\n"
@@ -42,7 +45,9 @@ def write_atom_literal(out, name, contents, lang):
name = get_atom_name(name)
if "cc" == lang or "hh" == lang:
- out.write("const wchar_t* const %s[] = {\n" % name)
+ string_type = "std::string" if utf8 else "std::wstring"
+ char_type = "char" if utf8 else "wchar_t"
+ out.write("const %s* const %s[] = {\n" % (char_type, name))
elif "java" == lang:
out.write(" %s(new StringBuilder()\n" % name)
else:
@@ -69,30 +74,31 @@ def write_atom_literal(out, name, contents, lang):
def generate_header(file_name, out, js_map, just_declare):
define_guard = "WEBDRIVER_%s" % os.path.basename(file_name.upper()).replace(".", "_")
+ include_stddef = "" if utf8 else "\n#include <stddef.h> // For wchar_t."
out.write("""%s
/* AUTO GENERATED - DO NOT EDIT BY HAND */
#ifndef %s
#define %s
-
-#include <stddef.h> // For wchar_t.
+%s
#include <string> // For std::(w)string.
namespace webdriver {
namespace atoms {
-""" % (_copyright, define_guard, define_guard))
+""" % (_copyright, define_guard, define_guard, include_stddef))
+
+ string_type = "std::string" if utf8 else "std::wstring"
+ char_type = "char" if utf8 else "wchar_t"
for (name, file) in js_map.items():
if just_declare:
- out.write("extern const wchat_t* const %s[];\n" % name.upper())
+ out.write("extern const %s* const %s[];\n" % (char_type, name.upper()))
else:
contents = open(file, "r").read()
write_atom_literal(out, name, contents, "hh")
- string_type = "std::wstring"
- char_type = "wchar_t"
out.write("""
static inline %s asString(const %s* const atom[]) {
%s source;
@@ -168,14 +174,17 @@ public enum %s {
}
""" % class_name)
+utf8 = False
def main(argv=[]):
lang = argv[1]
file_name = argv[2]
preamble = argv[3]
+ global utf8
+ utf8 = (argv[4] == "true")
diff --git a/rake-tasks/crazy_fun/mappings/javascript.rb b/rake-tasks/crazy_fun/mappings/javascript.rb js_map = {}
index 1ac2b2066a..dfa11fbbc2 100644 - for i in range(4, len(argv), 2):
--- a/rake-tasks/crazy_fun/mappings/javascript.rb + for i in range(5, len(argv), 2):
+++ b/rake-tasks/crazy_fun/mappings/javascript.rb js_map[argv[i]] = argv[i + 1]
@@ -857,6 +857,8 @@ module Javascript
flags.push("--jscomp_error=undefinedVars")
flags.push("--jscomp_error=uselessCode")
flags.push("--jscomp_error=visibility")
+ # Work around https://github.com/google/closure-compiler/issues/1044
+ flags.push("--use_types_for_optimization=false")
expanded_flags = flags.join(" ") << with open(file_name, "w") as out:
" --js='" << diff --git a/javascript/private/header.bzl b/javascript/private/header.bzl
index ced4059a3d..754879bb1f 100644
--- a/javascript/private/header.bzl
+++ b/javascript/private/header.bzl
@@ -22,6 +22,7 @@ def _closure_lang_file_impl(ctx):
args.add(ctx.attr.lang)
args.add(ctx.outputs.out)
args.add(ctx.attr.preamble)
+ args.add(ctx.attr.utf8)
for key in sorted(binaries.keys()):
args.add(key)
args.add(binaries[key])
@@ -59,5 +60,10 @@ closure_lang_file = rule(
executable = True,
cfg = "host",
),
+ "utf8": attr.bool(
+ doc = "Generate utf8 or not. True will generate string and char."
+ "False, will generate wchar_t and wstring. Defaults to False",
+ default = False,
+ ),
},
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment