Commit e2eed2c1 authored by Vadym Doroshenko's avatar Vadym Doroshenko Committed by Commit Bot

Moving getElementByNameWithParent to common and simplifying.

1.getElementByNameWithParent is a generic function that's not used
 password_controller.js anymore, so common is the better place for it
(it would also allow to test it).
2.isPassword argument is not needed anymore, so function is simpified.
3.Added a test for it.

Bug: 782224
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ida9a6719f1533d36c4dd468100860046a0db809f
Reviewed-on: https://chromium-review.googlesource.com/758402
Commit-Queue: Vadym Doroshenko <dvadym@chromium.org>
Reviewed-by: default avatarVaclav Brozek <vabr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#518597}
parent 37e0f535
...@@ -24,6 +24,26 @@ __gCrWeb.suggestion = {}; ...@@ -24,6 +24,26 @@ __gCrWeb.suggestion = {};
// minification. // minification.
__gCrWeb['suggestion'] = __gCrWeb.suggestion; __gCrWeb['suggestion'] = __gCrWeb.suggestion;
/**
* Returns the element with the specified name that is a child of the
* specified parent element.
* @param {Element} parent The parent of the desired element.
* @param {string} name The name of the desired element.
* @return {Element} The element if found, otherwise null;
*/
var getElementByNameWithParent_ = function(parent, name) {
if (parent.name === name)
return parent;
var el;
for (var i = 0; i < parent.children.length; i++) {
el = getElementByNameWithParent_(parent.children[i], name);
if (el)
return el;
}
return null;
};
/** /**
* Returns the first element in |elements| that is later than |elementToCompare| * Returns the first element in |elements| that is later than |elementToCompare|
* in tab order. * in tab order.
...@@ -271,7 +291,7 @@ __gCrWeb.suggestion.getFormElement = function(formName, fieldName) { ...@@ -271,7 +291,7 @@ __gCrWeb.suggestion.getFormElement = function(formName, fieldName) {
var form = __gCrWeb.common.getFormElementFromIdentifier(formName); var form = __gCrWeb.common.getFormElementFromIdentifier(formName);
if (!form) if (!form)
return null; return null;
return __gCrWeb.getElementByNameWithParent(form, fieldName); return getElementByNameWithParent_(form, fieldName);
}; };
/** /**
......
...@@ -186,33 +186,6 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) { ...@@ -186,33 +186,6 @@ if (__gCrWeb && !__gCrWeb['fillPasswordForm']) {
formData, username, password, window, opt_normalizedOrigin); formData, username, password, window, opt_normalizedOrigin);
}; };
/**
* Returns the element with the specified name that is a child of the
* specified parent element.
* @param {Element} parent The parent of the desired element.
* @param {string} name The name of the desired element.
* @param {boolen} isPassword Whether the field should be a password field;
* if not supplied, |false| is assumed.
* @return {Element} The element if found, otherwise null;
*/
__gCrWeb['getElementByNameWithParent'] = function(
parent, name, isPassword) {
isPassword = isPassword || false;
var parentType = parent.type || "";
var isParentPassword = parentType === "password";
if (parent.name === name && (isPassword === isParentPassword)) {
return parent;
}
for (var i = 0; i < parent.children.length; i++) {
var el = __gCrWeb.getElementByNameWithParent(
parent.children[i], name, isPassword);
if (el) {
return el;
}
}
return null;
};
/** /**
* Given a description of a form (origin, action and input fields), * Given a description of a form (origin, action and input fields),
* finds that form on the page and fills in the specified username * finds that form on the page and fills in the specified username
......
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