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

Side by Side Diff: chrome/browser/webdata/web_database_unittest.cc

Issue 279001: Move autofill related WebView{Delegate} methods into the WebKit API.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/webdata/web_database.cc ('k') | chrome/common/render_messages_internal.h » ('j') | 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) 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
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.AddAutofillFormElement( 394 EXPECT_TRUE(db.AddAutofillFormElement(
395 AutofillForm::Element(L"Name", L"Superman"))); 395 AutofillForm::Element(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"))));
396 std::vector<std::wstring> 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.AddAutofillFormElement( 398 EXPECT_TRUE(db.AddAutofillFormElement(
399 AutofillForm::Element(L"Name", L"Clark Kent"))); 399 AutofillForm::Element(ASCIIToUTF16("Name"),
400 ASCIIToUTF16("Clark Kent"))));
400 } 401 }
401 for (int i = 0; i < 3; i++) { 402 for (int i = 0; i < 3; i++) {
402 EXPECT_TRUE(db.AddAutofillFormElement( 403 EXPECT_TRUE(db.AddAutofillFormElement(
403 AutofillForm::Element(L"Name", L"Clark Sutter"))); 404 AutofillForm::Element(ASCIIToUTF16("Name"),
405 ASCIIToUTF16("Clark Sutter"))));
404 } 406 }
405 for (int i = 0; i < 2; i++) { 407 for (int i = 0; i < 2; i++) {
406 EXPECT_TRUE(db.AddAutofillFormElement( 408 EXPECT_TRUE(db.AddAutofillFormElement(
407 AutofillForm::Element(L"Favorite Color", L"Green"))); 409 AutofillForm::Element(ASCIIToUTF16("Favorite Color"),
410 ASCIIToUTF16("Green"))));
408 } 411 }
409 412
410 int count = 0; 413 int count = 0;
411 int64 pair_id = 0; 414 int64 pair_id = 0;
412 415
413 // We have added the name Clark Kent 5 times, so count should be 5 and pair_id 416 // We have added the name Clark Kent 5 times, so count should be 5 and pair_id
414 // should be somthing non-zero. 417 // should be somthing non-zero.
415 EXPECT_TRUE(db.GetIDAndCountOfFormElement( 418 EXPECT_TRUE(db.GetIDAndCountOfFormElement(
416 AutofillForm::Element(L"Name", L"Clark Kent"), &pair_id, &count)); 419 AutofillForm::Element(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")),
420 &pair_id, &count));
417 EXPECT_EQ(5, count); 421 EXPECT_EQ(5, count);
418 EXPECT_NE(0, pair_id); 422 EXPECT_NE(0, pair_id);
419 423
420 // Storing in the data base should be case sensitive, so there should be no 424 // Storing in the data base should be case sensitive, so there should be no
421 // database entry for clark kent lowercase. 425 // database entry for clark kent lowercase.
422 EXPECT_TRUE(db.GetIDAndCountOfFormElement( 426 EXPECT_TRUE(db.GetIDAndCountOfFormElement(
423 AutofillForm::Element(L"Name", L"clark kent"), &pair_id, &count)); 427 AutofillForm::Element(ASCIIToUTF16("Name"), ASCIIToUTF16("clark kent")),
428 &pair_id, &count));
424 EXPECT_EQ(0, count); 429 EXPECT_EQ(0, count);
425 430
426 EXPECT_TRUE(db.GetIDAndCountOfFormElement( 431 EXPECT_TRUE(db.GetIDAndCountOfFormElement(
427 AutofillForm::Element(L"Favorite Color", L"Green"), &pair_id, &count)); 432 AutofillForm::Element(ASCIIToUTF16("Favorite Color"),
433 ASCIIToUTF16("Green")),
434 &pair_id, &count));
428 EXPECT_EQ(2, count); 435 EXPECT_EQ(2, count);
429 436
430 // This is meant to get a list of suggestions for Name. The empty prefix 437 // This is meant to get a list of suggestions for Name. The empty prefix
431 // in the second argument means it should return all suggestions for a name 438 // in the second argument means it should return all suggestions for a name
432 // no matter what they start with. The order that the names occur in the list 439 // no matter what they start with. The order that the names occur in the list
433 // should be decreasing order by count. 440 // should be decreasing order by count.
434 EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", std::wstring(), &v, 6)); 441 EXPECT_TRUE(db.GetFormValuesForElementName(
442 ASCIIToUTF16("Name"), string16(), &v, 6));
435 EXPECT_EQ(3U, v.size()); 443 EXPECT_EQ(3U, v.size());
436 if (v.size() == 3) { 444 if (v.size() == 3) {
437 EXPECT_EQ(L"Clark Kent", v[0]); 445 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]);
438 EXPECT_EQ(L"Clark Sutter", v[1]); 446 EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]);
439 EXPECT_EQ(L"Superman", v[2]); 447 EXPECT_EQ(ASCIIToUTF16("Superman"), v[2]);
440 } 448 }
441 449
442 // If we query again limiting the list size to 1, we should only get the most 450 // If we query again limiting the list size to 1, we should only get the most
443 // frequent entry. 451 // frequent entry.
444 EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", L"", &v, 1)); 452 EXPECT_TRUE(db.GetFormValuesForElementName(
453 ASCIIToUTF16("Name"), string16(), &v, 1));
445 EXPECT_EQ(1U, v.size()); 454 EXPECT_EQ(1U, v.size());
446 if (v.size() == 1) { 455 if (v.size() == 1) {
447 EXPECT_EQ(L"Clark Kent", v[0]); 456 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]);
448 } 457 }
449 458
450 // Querying for suggestions given a prefix is case-insensitive, so the prefix 459 // Querying for suggestions given a prefix is case-insensitive, so the prefix
451 // "cLa" shoud get suggestions for both Clarks. 460 // "cLa" shoud get suggestions for both Clarks.
452 EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", L"cLa", &v, 6)); 461 EXPECT_TRUE(db.GetFormValuesForElementName(
462 ASCIIToUTF16("Name"), ASCIIToUTF16("cLa"), &v, 6));
453 EXPECT_EQ(2U, v.size()); 463 EXPECT_EQ(2U, v.size());
454 if (v.size() == 2) { 464 if (v.size() == 2) {
455 EXPECT_EQ(L"Clark Kent", v[0]); 465 EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]);
456 EXPECT_EQ(L"Clark Sutter", v[1]); 466 EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]);
457 } 467 }
458 468
459 // Removing all elements since the beginning of this function should remove 469 // Removing all elements since the beginning of this function should remove
460 // everything from the database. 470 // everything from the database.
461 EXPECT_TRUE(db.RemoveFormElementsAddedBetween(t1, Time())); 471 EXPECT_TRUE(db.RemoveFormElementsAddedBetween(t1, Time()));
462 472
463 EXPECT_TRUE(db.GetIDAndCountOfFormElement( 473 EXPECT_TRUE(db.GetIDAndCountOfFormElement(
464 AutofillForm::Element(L"Name", L"Clark Kent"), &pair_id, &count)); 474 AutofillForm::Element(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")),
475 &pair_id, &count));
465 EXPECT_EQ(0, count); 476 EXPECT_EQ(0, count);
466 477
467 EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", L"", &v, 6)); 478 EXPECT_TRUE(
479 db.GetFormValuesForElementName(ASCIIToUTF16("Name"), string16(), &v, 6));
468 EXPECT_EQ(0U, v.size()); 480 EXPECT_EQ(0U, v.size());
469 481
470 // Now add some values with empty strings. 482 // Now add some values with empty strings.
471 const std::wstring kValue = L" toto "; 483 const string16 kValue = ASCIIToUTF16(" toto ");
472 EXPECT_TRUE(db.AddAutofillFormElement(AutofillForm::Element(L"blank", L""))); 484 EXPECT_TRUE(db.AddAutofillFormElement(
473 EXPECT_TRUE(db.AddAutofillFormElement(AutofillForm::Element(L"blank", 485 AutofillForm::Element(ASCIIToUTF16("blank"), string16())));
474 L" "))); 486 EXPECT_TRUE(db.AddAutofillFormElement(
475 EXPECT_TRUE(db.AddAutofillFormElement(AutofillForm::Element(L"blank", 487 AutofillForm::Element(ASCIIToUTF16("blank"), ASCIIToUTF16(" "))));
476 L" "))); 488 EXPECT_TRUE(db.AddAutofillFormElement(
477 EXPECT_TRUE(db.AddAutofillFormElement(AutofillForm::Element(L"blank", 489 AutofillForm::Element(ASCIIToUTF16("blank"), ASCIIToUTF16(" "))));
478 kValue))); 490 EXPECT_TRUE(db.AddAutofillFormElement(
491 AutofillForm::Element(ASCIIToUTF16("blank"), kValue)));
479 492
480 // They should be stored normally as the DB layer does not check for empty 493 // They should be stored normally as the DB layer does not check for empty
481 // values. 494 // values.
482 v.clear(); 495 v.clear();
483 EXPECT_TRUE(db.GetFormValuesForElementName(L"blank", L"", &v, 10)); 496 EXPECT_TRUE(db.GetFormValuesForElementName(
497 ASCIIToUTF16("blank"), string16(), &v, 10));
484 EXPECT_EQ(4U, v.size()); 498 EXPECT_EQ(4U, v.size());
485 499
486 // Now we'll check that ClearAutofillEmptyValueElements() works as expected. 500 // Now we'll check that ClearAutofillEmptyValueElements() works as expected.
487 db.ClearAutofillEmptyValueElements(); 501 db.ClearAutofillEmptyValueElements();
488 502
489 v.clear(); 503 v.clear();
490 EXPECT_TRUE(db.GetFormValuesForElementName(L"blank", L"", &v, 10)); 504 EXPECT_TRUE(db.GetFormValuesForElementName(ASCIIToUTF16("blank"), string16(), &v, 10));
491 ASSERT_EQ(1U, v.size()); 505 ASSERT_EQ(1U, v.size());
492 506
493 EXPECT_EQ(kValue, v[0]); 507 EXPECT_EQ(kValue, v[0]);
494 } 508 }
495 509
496 static bool AddTimestampedLogin(WebDatabase* db, std::string url, 510 static bool AddTimestampedLogin(WebDatabase* db, std::string url,
497 std::wstring unique_string, const Time& time) { 511 std::wstring unique_string, const Time& time) {
498 // Example password form. 512 // Example password form.
499 PasswordForm form; 513 PasswordForm form;
500 form.origin = GURL(url + std::string("/LoginAuth")); 514 form.origin = GURL(url + std::string("/LoginAuth"));
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 ASSERT_EQ(16, images[0].height()); 693 ASSERT_EQ(16, images[0].height());
680 ASSERT_EQ(32, images[1].width()); 694 ASSERT_EQ(32, images[1].width());
681 ASSERT_EQ(32, images[1].height()); 695 ASSERT_EQ(32, images[1].height());
682 } else { 696 } else {
683 ASSERT_EQ(32, images[0].width()); 697 ASSERT_EQ(32, images[0].width());
684 ASSERT_EQ(32, images[0].height()); 698 ASSERT_EQ(32, images[0].height());
685 ASSERT_EQ(16, images[1].width()); 699 ASSERT_EQ(16, images[1].width());
686 ASSERT_EQ(16, images[1].height()); 700 ASSERT_EQ(16, images[1].height());
687 } 701 }
688 } 702 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_database.cc ('k') | chrome/common/render_messages_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698