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

Side by Side Diff: chrome/browser/autofill/name_field_unittest.cc

Issue 3067029: AutoFill: Add more NameField tests and fix incorrect logic in ParseEmpty. (Closed)
Patch Set: Fix test. Created 10 years, 4 months 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
« no previous file with comments | « chrome/browser/autofill/form_field.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/scoped_ptr.h" 5 #include "base/scoped_ptr.h"
6 #include "base/scoped_vector.h" 6 #include "base/scoped_vector.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/autofill/autofill_field.h" 8 #include "chrome/browser/autofill/autofill_field.h"
9 #include "chrome/browser/autofill/name_field.h" 9 #include "chrome/browser/autofill/name_field.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end()); 189 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
190 EXPECT_EQ(NAME_FIRST, field_type_map_[ASCIIToUTF16("name1")]); 190 EXPECT_EQ(NAME_FIRST, field_type_map_[ASCIIToUTF16("name1")]);
191 ASSERT_TRUE( 191 ASSERT_TRUE(
192 field_type_map_.find(ASCIIToUTF16("name2")) != field_type_map_.end()); 192 field_type_map_.find(ASCIIToUTF16("name2")) != field_type_map_.end());
193 EXPECT_EQ(NAME_MIDDLE, field_type_map_[ASCIIToUTF16("name2")]); 193 EXPECT_EQ(NAME_MIDDLE, field_type_map_[ASCIIToUTF16("name2")]);
194 ASSERT_TRUE( 194 ASSERT_TRUE(
195 field_type_map_.find(ASCIIToUTF16("name3")) != field_type_map_.end()); 195 field_type_map_.find(ASCIIToUTF16("name3")) != field_type_map_.end());
196 EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name3")]); 196 EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name3")]);
197 } 197 }
198 198
199 TEST_F(NameFieldTest, FirstLastEmpty) {
200 list_.push_back(
201 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Name"),
202 ASCIIToUTF16("first_name"),
203 string16(),
204 ASCIIToUTF16("text"),
205 0),
206 ASCIIToUTF16("name1")));
207 list_.push_back(
208 new AutoFillField(webkit_glue::FormField(string16(),
209 ASCIIToUTF16("last_name"),
210 string16(),
211 ASCIIToUTF16("text"),
212 0),
213 ASCIIToUTF16("name2")));
214 list_.push_back(NULL);
215 iter_ = list_.begin();
216 field_.reset(NameField::Parse(&iter_, false));
217 ASSERT_NE(static_cast<NameField*>(NULL), field_.get());
218 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
219 ASSERT_TRUE(
220 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
221 EXPECT_EQ(NAME_FIRST, field_type_map_[ASCIIToUTF16("name1")]);
222 ASSERT_TRUE(
223 field_type_map_.find(ASCIIToUTF16("name2")) != field_type_map_.end());
224 EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name2")]);
225 }
226
227 TEST_F(NameFieldTest, FirstMiddleLastEmpty) {
228 list_.push_back(
229 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Name"),
230 ASCIIToUTF16("first_name"),
231 string16(),
232 ASCIIToUTF16("text"),
233 0),
234 ASCIIToUTF16("name1")));
235 list_.push_back(
236 new AutoFillField(webkit_glue::FormField(string16(),
237 ASCIIToUTF16("middle_name"),
238 string16(),
239 ASCIIToUTF16("text"),
240 0),
241 ASCIIToUTF16("name2")));
242 list_.push_back(
243 new AutoFillField(webkit_glue::FormField(string16(),
244 ASCIIToUTF16("last_name"),
245 string16(),
246 ASCIIToUTF16("text"),
247 0),
248 ASCIIToUTF16("name3")));
249 list_.push_back(NULL);
250 iter_ = list_.begin();
251 field_.reset(NameField::Parse(&iter_, false));
252 ASSERT_NE(static_cast<NameField*>(NULL), field_.get());
253 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
254 ASSERT_TRUE(
255 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
256 EXPECT_EQ(NAME_FIRST, field_type_map_[ASCIIToUTF16("name1")]);
257 ASSERT_TRUE(
258 field_type_map_.find(ASCIIToUTF16("name2")) != field_type_map_.end());
259 EXPECT_EQ(NAME_MIDDLE_INITIAL, field_type_map_[ASCIIToUTF16("name2")]);
260 ASSERT_TRUE(
261 field_type_map_.find(ASCIIToUTF16("name3")) != field_type_map_.end());
262 EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name3")]);
263 }
264
265 TEST_F(NameFieldTest, MiddleInitial) {
266 list_.push_back(
267 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("First Name"),
268 ASCIIToUTF16("first_name"),
269 string16(),
270 ASCIIToUTF16("text"),
271 0),
272 ASCIIToUTF16("name1")));
273 list_.push_back(
274 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("MI"),
275 ASCIIToUTF16("middle_name"),
276 string16(),
277 ASCIIToUTF16("text"),
278 0),
279 ASCIIToUTF16("name2")));
280 list_.push_back(
281 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Last Name"),
282 ASCIIToUTF16("last_name"),
283 string16(),
284 ASCIIToUTF16("text"),
285 0),
286 ASCIIToUTF16("name3")));
287 list_.push_back(NULL);
288 iter_ = list_.begin();
289 field_.reset(NameField::Parse(&iter_, false));
290 ASSERT_NE(static_cast<NameField*>(NULL), field_.get());
291 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
292 ASSERT_TRUE(
293 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
294 EXPECT_EQ(NAME_FIRST, field_type_map_[ASCIIToUTF16("name1")]);
295 ASSERT_TRUE(
296 field_type_map_.find(ASCIIToUTF16("name2")) != field_type_map_.end());
297 EXPECT_EQ(NAME_MIDDLE_INITIAL, field_type_map_[ASCIIToUTF16("name2")]);
298 ASSERT_TRUE(
299 field_type_map_.find(ASCIIToUTF16("name3")) != field_type_map_.end());
300 EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name3")]);
301 }
302
303 TEST_F(NameFieldTest, MiddleInitialNoLastName) {
304 list_.push_back(
305 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("First Name"),
306 ASCIIToUTF16("first_name"),
307 string16(),
308 ASCIIToUTF16("text"),
309 0),
310 ASCIIToUTF16("name1")));
311 list_.push_back(
312 new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("MI"),
313 ASCIIToUTF16("middle_name"),
314 string16(),
315 ASCIIToUTF16("text"),
316 0),
317 ASCIIToUTF16("name2")));
318 list_.push_back(NULL);
319 iter_ = list_.begin();
320 field_.reset(NameField::Parse(&iter_, false));
321 ASSERT_EQ(static_cast<NameField*>(NULL), field_.get());
322 }
323
324 TEST_F(NameFieldTest, ECMLNoName) {
325 list_.push_back(new AutoFillField(
326 webkit_glue::FormField(ASCIIToUTF16("Company"),
327 ASCIIToUTF16("ecom_shipto_postal_company"),
328 string16(),
329 ASCIIToUTF16("text"),
330 0),
331 ASCIIToUTF16("field1")));
332 list_.push_back(NULL);
333 iter_ = list_.begin();
334 field_.reset(NameField::Parse(&iter_, true));
335 ASSERT_EQ(static_cast<NameField*>(NULL), field_.get());
336 }
337
338 TEST_F(NameFieldTest, ECMLMiddleInitialNoLastName) {
339 list_.push_back(new AutoFillField(
340 webkit_glue::FormField(ASCIIToUTF16("First Name"),
341 ASCIIToUTF16("ecom_shipto_postal_name_first"),
342 string16(),
343 ASCIIToUTF16("text"),
344 0),
345 ASCIIToUTF16("name1")));
346 list_.push_back(new AutoFillField(
347 webkit_glue::FormField(ASCIIToUTF16("Middle"),
348 ASCIIToUTF16("ecom_shipto_postal_name_middle"),
349 string16(),
350 ASCIIToUTF16("text"),
351 0),
352 ASCIIToUTF16("name2")));
353 list_.push_back(NULL);
354 iter_ = list_.begin();
355 field_.reset(NameField::Parse(&iter_, true));
356 ASSERT_EQ(static_cast<NameField*>(NULL), field_.get());
357 }
358
359 TEST_F(NameFieldTest, ECMLFirstMiddleLast) {
360 list_.push_back(new AutoFillField(
361 webkit_glue::FormField(string16(),
362 ASCIIToUTF16("ecom_shipto_postal_name_first"),
363 string16(),
364 ASCIIToUTF16("text"),
365 0),
366 ASCIIToUTF16("name1")));
367 list_.push_back(new AutoFillField(
368 webkit_glue::FormField(string16(),
369 ASCIIToUTF16("ecom_shipto_postal_name_middle"),
370 string16(),
371 ASCIIToUTF16("text"),
372 0),
373 ASCIIToUTF16("name2")));
374 list_.push_back(new AutoFillField(
375 webkit_glue::FormField(string16(),
376 ASCIIToUTF16("ecom_shipto_postal_name_last"),
377 string16(),
378 ASCIIToUTF16("text"),
379 0),
380 ASCIIToUTF16("name3")));
381 list_.push_back(NULL);
382 iter_ = list_.begin();
383 field_.reset(NameField::Parse(&iter_, true));
384 ASSERT_NE(static_cast<NameField*>(NULL), field_.get());
385 ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
386 ASSERT_TRUE(
387 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
388 EXPECT_EQ(NAME_FIRST, field_type_map_[ASCIIToUTF16("name1")]);
389 ASSERT_TRUE(
390 field_type_map_.find(ASCIIToUTF16("name2")) != field_type_map_.end());
391 EXPECT_EQ(NAME_MIDDLE, field_type_map_[ASCIIToUTF16("name2")]);
392 ASSERT_TRUE(
393 field_type_map_.find(ASCIIToUTF16("name3")) != field_type_map_.end());
394 EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name3")]);
395 }
396
199 } // namespace 397 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/autofill/form_field.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698