In |InferLabelFromPrevious|, <b> tagged element is not considered as inferred...

In |InferLabelFromPrevious|, <b> tagged element is not considered as inferred label. So <b> tag is added for checking. Also implemented to look for text node prior to <b
    
BUG=76296
TEST=1. Run grabber-bestbuy.com.html. 2. Make sure "6. ZIP 7. UNKNOWN"


Review URL: http://codereview.chromium.org/6993053

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88479 0039d316-1c4b-4281-b951-d872f2087c98
parent c9952f7e
......@@ -153,29 +153,32 @@ string16 InferLabelFromPrevious(const WebFormControlElement& element) {
// If we didn't find text, check for previous paragraph.
// Eg. <p>Some Text</p><input ...>
// Note the lack of whitespace between <p> and <input> elements.
// Eg. <b>Some Text</b><input ...>
// Note the lack of whitespace between (<p> or <b>) and <input> elements.
if (inferred_label.empty() && previous.isElementNode()) {
WebElement element = previous.to<WebElement>();
if (element.hasTagName("p")) {
if (element.hasTagName("p") || element.hasTagName("b")) {
inferred_label = FindChildText(element);
}
}
// If we didn't find paragraph, check for previous paragraph to this.
// Eg. <p>Some Text</p> <input ...>
// Note the whitespace between <p> and <input> elements.
// Eg. <b>Some Text</b> <input ...>
// Note the whitespace between (<p> or <b>) and <input> elements.
if (inferred_label.empty()) {
WebNode sibling = previous.previousSibling();
if (!sibling.isNull() && sibling.isElementNode()) {
WebElement element = sibling.to<WebElement>();
if (element.hasTagName("p")) {
if (element.hasTagName("p") || element.hasTagName("b")) {
inferred_label = FindChildText(element);
}
}
}
// Look for text node prior to <img> tag.
// Look for text node prior to <img> or <br> tag.
// Eg. Some Text<img/><input ...>
// Eg. Some Text<br/><input ...>
if (inferred_label.empty()) {
while (inferred_label.empty() && !previous.isNull()) {
if (previous.isTextNode()) {
......@@ -183,7 +186,7 @@ string16 InferLabelFromPrevious(const WebFormControlElement& element) {
TrimWhitespace(inferred_label, TRIM_ALL, &inferred_label);
} else if (previous.isElementNode()) {
WebElement element = previous.to<WebElement>();
if (!element.hasTagName("img"))
if (!element.hasTagName("img") && !element.hasTagName("br"))
break;
} else {
break;
......
......@@ -1119,6 +1119,32 @@ TEST_F(FormManagerTest, LabelsInferredFromParagraph) {
"</FORM>");
}
TEST_F(FormManagerTest, LabelsInferredFromBold) {
ExpectJohnSmithLabels(
"<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
" <B>First name:</B><INPUT type=\"text\" "
" id=\"firstname\" value=\"John\"/>"
" <B>Last name:</B>"
" <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
" <B>Email:</B>"
" <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
" <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
"</FORM>");
}
TEST_F(FormManagerTest, LabelsInferredPriorToImgOrBr) {
ExpectJohnSmithLabels(
"<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
" First name:<IMG/><INPUT type=\"text\" "
" id=\"firstname\" value=\"John\"/>"
" Last name:<IMG/>"
" <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
" Email:<BR/>"
" <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
" <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
"</FORM>");
}
TEST_F(FormManagerTest, LabelsInferredFromTableCell) {
ExpectJohnSmithLabels(
"<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
......
......@@ -3,5 +3,5 @@ NAME_MIDDLE_INITIAL
NAME_LAST
EMAIL_ADDRESS
EMAIL_ADDRESS
EMAIL_ADDRESS
EMAIL_ADDRESS
ADDRESS_HOME_ZIP
UNKNOWN_TYPE
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