OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 TEST_F(WebDatabaseTest, Autofill) { | 385 TEST_F(WebDatabaseTest, Autofill) { |
386 WebDatabase db; | 386 WebDatabase db; |
387 | 387 |
388 EXPECT_TRUE(db.Init(file_)); | 388 EXPECT_TRUE(db.Init(file_)); |
389 | 389 |
390 Time t1 = Time::Now(); | 390 Time t1 = Time::Now(); |
391 | 391 |
392 // Simulate the submission of a handful of entries in a field called "Name", | 392 // Simulate the submission of a handful of entries in a field called "Name", |
393 // some more often than others. | 393 // some more often than others. |
394 EXPECT_TRUE(db.AddFormFieldValue( | 394 EXPECT_TRUE(db.AddFormFieldValue( |
395 FormField(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman")))); | 395 FormField(ASCIIToUTF16("Name"), string16(), ASCIIToUTF16("Superman")))); |
396 std::vector<string16> v; | 396 std::vector<string16> v; |
397 for (int i = 0; i < 5; i++) { | 397 for (int i = 0; i < 5; i++) { |
398 EXPECT_TRUE(db.AddFormFieldValue( | 398 EXPECT_TRUE(db.AddFormFieldValue( |
399 FormField(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")))); | 399 FormField(ASCIIToUTF16("Name"), |
| 400 string16(), |
| 401 ASCIIToUTF16("Clark Kent")))); |
400 } | 402 } |
401 for (int i = 0; i < 3; i++) { | 403 for (int i = 0; i < 3; i++) { |
402 EXPECT_TRUE(db.AddFormFieldValue( | 404 EXPECT_TRUE(db.AddFormFieldValue( |
403 FormField(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Sutter")))); | 405 FormField(ASCIIToUTF16("Name"), |
| 406 string16(), |
| 407 ASCIIToUTF16("Clark Sutter")))); |
404 } | 408 } |
405 for (int i = 0; i < 2; i++) { | 409 for (int i = 0; i < 2; i++) { |
406 EXPECT_TRUE(db.AddFormFieldValue( | 410 EXPECT_TRUE(db.AddFormFieldValue( |
407 FormField(ASCIIToUTF16("Favorite Color"), ASCIIToUTF16("Green")))); | 411 FormField(ASCIIToUTF16("Favorite Color"), |
| 412 string16(), |
| 413 ASCIIToUTF16("Green")))); |
408 } | 414 } |
409 | 415 |
410 int count = 0; | 416 int count = 0; |
411 int64 pair_id = 0; | 417 int64 pair_id = 0; |
412 | 418 |
413 // We have added the name Clark Kent 5 times, so count should be 5 and pair_id | 419 // We have added the name Clark Kent 5 times, so count should be 5 and pair_id |
414 // should be somthing non-zero. | 420 // should be somthing non-zero. |
415 EXPECT_TRUE(db.GetIDAndCountOfFormElement( | 421 EXPECT_TRUE(db.GetIDAndCountOfFormElement( |
416 FormField(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")), | 422 FormField(ASCIIToUTF16("Name"), string16(), ASCIIToUTF16("Clark Kent")), |
417 &pair_id, &count)); | 423 &pair_id, &count)); |
418 EXPECT_EQ(5, count); | 424 EXPECT_EQ(5, count); |
419 EXPECT_NE(0, pair_id); | 425 EXPECT_NE(0, pair_id); |
420 | 426 |
421 // Storing in the data base should be case sensitive, so there should be no | 427 // Storing in the data base should be case sensitive, so there should be no |
422 // database entry for clark kent lowercase. | 428 // database entry for clark kent lowercase. |
423 EXPECT_TRUE(db.GetIDAndCountOfFormElement( | 429 EXPECT_TRUE(db.GetIDAndCountOfFormElement( |
424 FormField(ASCIIToUTF16("Name"), ASCIIToUTF16("clark kent")), | 430 FormField(ASCIIToUTF16("Name"), string16(), ASCIIToUTF16("clark kent")), |
425 &pair_id, &count)); | 431 &pair_id, &count)); |
426 EXPECT_EQ(0, count); | 432 EXPECT_EQ(0, count); |
427 | 433 |
428 EXPECT_TRUE(db.GetIDAndCountOfFormElement( | 434 EXPECT_TRUE(db.GetIDAndCountOfFormElement( |
429 FormField(ASCIIToUTF16("Favorite Color"), ASCIIToUTF16("Green")), | 435 FormField(ASCIIToUTF16("Favorite Color"), |
| 436 string16(), |
| 437 ASCIIToUTF16("Green")), |
430 &pair_id, &count)); | 438 &pair_id, &count)); |
431 EXPECT_EQ(2, count); | 439 EXPECT_EQ(2, count); |
432 | 440 |
433 // This is meant to get a list of suggestions for Name. The empty prefix | 441 // This is meant to get a list of suggestions for Name. The empty prefix |
434 // in the second argument means it should return all suggestions for a name | 442 // in the second argument means it should return all suggestions for a name |
435 // no matter what they start with. The order that the names occur in the list | 443 // no matter what they start with. The order that the names occur in the list |
436 // should be decreasing order by count. | 444 // should be decreasing order by count. |
437 EXPECT_TRUE(db.GetFormValuesForElementName( | 445 EXPECT_TRUE(db.GetFormValuesForElementName( |
438 ASCIIToUTF16("Name"), string16(), &v, 6)); | 446 ASCIIToUTF16("Name"), string16(), &v, 6)); |
439 EXPECT_EQ(3U, v.size()); | 447 EXPECT_EQ(3U, v.size()); |
(...skipping 20 matching lines...) Expand all Loading... |
460 if (v.size() == 2) { | 468 if (v.size() == 2) { |
461 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]); | 469 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]); |
462 EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]); | 470 EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]); |
463 } | 471 } |
464 | 472 |
465 // Removing all elements since the beginning of this function should remove | 473 // Removing all elements since the beginning of this function should remove |
466 // everything from the database. | 474 // everything from the database. |
467 EXPECT_TRUE(db.RemoveFormElementsAddedBetween(t1, Time())); | 475 EXPECT_TRUE(db.RemoveFormElementsAddedBetween(t1, Time())); |
468 | 476 |
469 EXPECT_TRUE(db.GetIDAndCountOfFormElement( | 477 EXPECT_TRUE(db.GetIDAndCountOfFormElement( |
470 FormField(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")), | 478 FormField(ASCIIToUTF16("Name"), string16(), ASCIIToUTF16("Clark Kent")), |
471 &pair_id, &count)); | 479 &pair_id, &count)); |
472 EXPECT_EQ(0, count); | 480 EXPECT_EQ(0, count); |
473 | 481 |
474 EXPECT_TRUE( | 482 EXPECT_TRUE( |
475 db.GetFormValuesForElementName(ASCIIToUTF16("Name"), string16(), &v, 6)); | 483 db.GetFormValuesForElementName(ASCIIToUTF16("Name"), string16(), &v, 6)); |
476 EXPECT_EQ(0U, v.size()); | 484 EXPECT_EQ(0U, v.size()); |
477 | 485 |
478 // Now add some values with empty strings. | 486 // Now add some values with empty strings. |
479 const string16 kValue = ASCIIToUTF16(" toto "); | 487 const string16 kValue = ASCIIToUTF16(" toto "); |
480 EXPECT_TRUE(db.AddFormFieldValue(FormField(ASCIIToUTF16("blank"), | 488 EXPECT_TRUE(db.AddFormFieldValue(FormField(ASCIIToUTF16("blank"), |
| 489 string16(), |
481 string16()))); | 490 string16()))); |
482 EXPECT_TRUE(db.AddFormFieldValue(FormField(ASCIIToUTF16("blank"), | 491 EXPECT_TRUE(db.AddFormFieldValue(FormField(ASCIIToUTF16("blank"), |
| 492 string16(), |
483 ASCIIToUTF16(" ")))); | 493 ASCIIToUTF16(" ")))); |
484 EXPECT_TRUE(db.AddFormFieldValue(FormField(ASCIIToUTF16("blank"), | 494 EXPECT_TRUE(db.AddFormFieldValue(FormField(ASCIIToUTF16("blank"), |
| 495 string16(), |
485 ASCIIToUTF16(" ")))); | 496 ASCIIToUTF16(" ")))); |
486 EXPECT_TRUE(db.AddFormFieldValue(FormField(ASCIIToUTF16("blank"), | 497 EXPECT_TRUE(db.AddFormFieldValue(FormField(ASCIIToUTF16("blank"), |
| 498 string16(), |
487 kValue))); | 499 kValue))); |
488 | 500 |
489 // They should be stored normally as the DB layer does not check for empty | 501 // They should be stored normally as the DB layer does not check for empty |
490 // values. | 502 // values. |
491 v.clear(); | 503 v.clear(); |
492 EXPECT_TRUE(db.GetFormValuesForElementName( | 504 EXPECT_TRUE(db.GetFormValuesForElementName( |
493 ASCIIToUTF16("blank"), string16(), &v, 10)); | 505 ASCIIToUTF16("blank"), string16(), &v, 10)); |
494 EXPECT_EQ(4U, v.size()); | 506 EXPECT_EQ(4U, v.size()); |
495 | 507 |
496 // Now we'll check that ClearAutofillEmptyValueElements() works as expected. | 508 // Now we'll check that ClearAutofillEmptyValueElements() works as expected. |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 ASSERT_EQ(16, images[0].height()); | 703 ASSERT_EQ(16, images[0].height()); |
692 ASSERT_EQ(32, images[1].width()); | 704 ASSERT_EQ(32, images[1].width()); |
693 ASSERT_EQ(32, images[1].height()); | 705 ASSERT_EQ(32, images[1].height()); |
694 } else { | 706 } else { |
695 ASSERT_EQ(32, images[0].width()); | 707 ASSERT_EQ(32, images[0].width()); |
696 ASSERT_EQ(32, images[0].height()); | 708 ASSERT_EQ(32, images[0].height()); |
697 ASSERT_EQ(16, images[1].width()); | 709 ASSERT_EQ(16, images[1].width()); |
698 ASSERT_EQ(16, images[1].height()); | 710 ASSERT_EQ(16, images[1].height()); |
699 } | 711 } |
700 } | 712 } |
OLD | NEW |