Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: chrome/renderer/form_manager_browsertest.cc

Issue 4249002: AutoFill: Fix two heuristic issues with nrm.org. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/string_util.h" 5 #include "base/string_util.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/renderer/form_manager.h" 7 #include "chrome/renderer/form_manager.h"
8 #include "chrome/test/render_view_test.h" 8 #include "chrome/test/render_view_test.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" 10 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 20), 1242 20),
1243 fields[1]); 1243 fields[1]);
1244 EXPECT_EQ(FormField(string16(), 1244 EXPECT_EQ(FormField(string16(),
1245 ASCIIToUTF16("reply-send"), 1245 ASCIIToUTF16("reply-send"),
1246 ASCIIToUTF16("Send"), 1246 ASCIIToUTF16("Send"),
1247 ASCIIToUTF16("submit"), 1247 ASCIIToUTF16("submit"),
1248 0), 1248 0),
1249 fields[2]); 1249 fields[2]);
1250 } 1250 }
1251 1251
1252 TEST_F(FormManagerTest, LabelsInferredFromTableTDInterveningElements) {
1253 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1254 "<TABLE>"
1255 " <TR>"
1256 " <TD>"
1257 " First Name:"
1258 " <BR>"
1259 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
1260 " </TD>"
1261 " </TR>"
1262 " <TR>"
1263 " <TD>"
1264 " Last Name:"
1265 " <BR>"
1266 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
1267 " </TD>"
1268 " </TR>"
1269 "</TABLE>"
1270 "<INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
1271 "</FORM>");
1272
1273 WebFrame* web_frame = GetMainFrame();
1274 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
1275
1276 FormManager form_manager;
1277 form_manager.ExtractForms(web_frame);
1278
1279 std::vector<FormData> forms;
1280 form_manager.GetFormsInFrame(web_frame, FormManager::REQUIRE_NONE, &forms);
1281 ASSERT_EQ(1U, forms.size());
1282
1283 const FormData& form = forms[0];
1284 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
1285 EXPECT_EQ(GURL(web_frame->url()), form.origin);
1286 EXPECT_EQ(GURL("http://cnn.com"), form.action);
1287
1288 const std::vector<FormField>& fields = form.fields;
1289 ASSERT_EQ(3U, fields.size());
1290 EXPECT_EQ(FormField(ASCIIToUTF16("First Name:"),
1291 ASCIIToUTF16("firstname"),
1292 ASCIIToUTF16("John"),
1293 ASCIIToUTF16("text"),
1294 20),
1295 fields[0]);
1296 EXPECT_EQ(FormField(ASCIIToUTF16("Last Name:"),
1297 ASCIIToUTF16("lastname"),
1298 ASCIIToUTF16("Smith"),
1299 ASCIIToUTF16("text"),
1300 20),
1301 fields[1]);
1302 EXPECT_EQ(FormField(string16(),
1303 ASCIIToUTF16("reply-send"),
1304 ASCIIToUTF16("Send"),
1305 ASCIIToUTF16("submit"),
1306 0),
1307 fields[2]);
1308 }
1309
1252 TEST_F(FormManagerTest, LabelsInferredFromDefinitionList) { 1310 TEST_F(FormManagerTest, LabelsInferredFromDefinitionList) {
1253 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" 1311 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
1254 "<DL>" 1312 "<DL>"
1255 " <DT>" 1313 " <DT>"
1256 " <SPAN>" 1314 " <SPAN>"
1257 " *" 1315 " *"
1258 " </SPAN>" 1316 " </SPAN>"
1259 " <SPAN>" 1317 " <SPAN>"
1260 " First name:" 1318 " First name:"
1261 " </SPAN>" 1319 " </SPAN>"
(...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after
2814 2872
2815 WebElement e = web_frame->document().getElementById("firstname"); 2873 WebElement e = web_frame->document().getElementById("firstname");
2816 WebFormControlElement firstname = e.to<WebFormControlElement>(); 2874 WebFormControlElement firstname = e.to<WebFormControlElement>();
2817 2875
2818 // Hidden form control element should not have a label set. 2876 // Hidden form control element should not have a label set.
2819 FormManager form_manager; 2877 FormManager form_manager;
2820 EXPECT_EQ(string16(), form_manager.LabelForElement(firstname)); 2878 EXPECT_EQ(string16(), form_manager.LabelForElement(firstname));
2821 } 2879 }
2822 2880
2823 } // namespace 2881 } // namespace
OLDNEW
« chrome/browser/autofill/address_field.cc ('K') | « chrome/renderer/form_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698