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