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

Side by Side Diff: components/autofill/core/browser/webdata/autofill_table_unittest.cc

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <utility> 5 #include <utility>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h"
8 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
10 #include "base/guid.h" 11 #include "base/guid.h"
11 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
12 #include "base/stl_util.h" 13 #include "base/stl_util.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 #include "components/autofill/core/browser/autofill_profile.h" 18 #include "components/autofill/core/browser/autofill_profile.h"
18 #include "components/autofill/core/browser/autofill_test_utils.h" 19 #include "components/autofill/core/browser/autofill_test_utils.h"
19 #include "components/autofill/core/browser/autofill_type.h" 20 #include "components/autofill/core/browser/autofill_type.h"
20 #include "components/autofill/core/browser/credit_card.h" 21 #include "components/autofill/core/browser/credit_card.h"
21 #include "components/autofill/core/browser/webdata/autofill_change.h" 22 #include "components/autofill/core/browser/webdata/autofill_change.h"
22 #include "components/autofill/core/browser/webdata/autofill_entry.h" 23 #include "components/autofill/core/browser/webdata/autofill_entry.h"
23 #include "components/autofill/core/browser/webdata/autofill_table.h" 24 #include "components/autofill/core/browser/webdata/autofill_table.h"
25 #include "components/autofill/core/common/autofill_switches.h"
26 #include "components/autofill/core/common/autofill_util.h"
24 #include "components/autofill/core/common/form_field_data.h" 27 #include "components/autofill/core/common/form_field_data.h"
25 #include "components/os_crypt/os_crypt.h" 28 #include "components/os_crypt/os_crypt.h"
26 #include "components/webdata/common/web_database.h" 29 #include "components/webdata/common/web_database.h"
27 #include "sql/statement.h" 30 #include "sql/statement.h"
28 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
29 32
30 using base::ASCIIToUTF16; 33 using base::ASCIIToUTF16;
31 using base::Time; 34 using base::Time;
32 using base::TimeDelta; 35 using base::TimeDelta;
33 36
(...skipping 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 base::Time(), base::Time::Max(), &profile_guids, &credit_card_guids)); 1852 base::Time(), base::Time::Max(), &profile_guids, &credit_card_guids));
1850 1853
1851 // Should be masked again. 1854 // Should be masked again.
1852 ASSERT_TRUE(table_->GetServerCreditCards(&outputs.get())); 1855 ASSERT_TRUE(table_->GetServerCreditCards(&outputs.get()));
1853 ASSERT_EQ(1u, outputs.size()); 1856 ASSERT_EQ(1u, outputs.size());
1854 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, outputs[0]->record_type()); 1857 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, outputs[0]->record_type());
1855 EXPECT_EQ(masked_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER)); 1858 EXPECT_EQ(masked_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER));
1856 outputs.clear(); 1859 outputs.clear();
1857 } 1860 }
1858 1861
1862 TEST_F(AutofillTableTest, GetFormValuesForElementName) {
please use gerrit instead 2015/07/06 20:15:18 Please use a test name that mentions the substring
Pritam Nikam 2015/07/07 16:18:31 Done.
1863 // Token matching is currently behind a flag.
1864 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1865 autofill::switches::kEnableSuggestionsWithSubstringMatch);
1866
1867 const size_t kMaxCount = 2;
1868 const struct {
1869 const char* const field_suggestion[kMaxCount];
1870 const char* const field_contents;
1871 size_t expected_suggestion_count;
1872 const char* const expected_suggestion[kMaxCount];
1873 } kTestCases[] = {
1874 {{"user.test", "test_user"}, "TEST", 2, {"test_user", "user.test"}},
1875 {{"user test", "test-user"}, "user", 2, {"user test", "test-user"}},
1876 {{"user test", "test-rest"}, "user", 1, {"user test", nullptr}},
1877 {{"user@test", "test_user"}, "user@t", 1, {"user@test", nullptr}},
1878 {{"user.test", "test_user"}, "er.tes", 0, {nullptr, nullptr}},
1879 {{"user test", "test_user"}, "_ser", 0, {nullptr, nullptr}},
1880 {{"user.test", "test_user"}, "%ser", 0, {nullptr, nullptr}},
1881 {{"user.test", "test_user"},
1882 "; DROP TABLE autofill;",
1883 0,
1884 {nullptr, nullptr}},
1885 };
1886
1887 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
1888 SCOPED_TRACE(testing::Message()
1889 << "suggestion = " << kTestCases[i].field_suggestion[0]
1890 << ", contents = " << kTestCases[i].field_contents);
1891
1892 Time t1 = Time::Now();
1893
1894 // Simulate the submission of a handful of entries in a field called "Name".
1895 AutofillChangeList changes;
1896 FormFieldData field;
1897 for (size_t k = 0; k < kMaxCount; ++k) {
1898 field.name = ASCIIToUTF16("Name");
1899 field.value = ASCIIToUTF16(kTestCases[i].field_suggestion[k]);
1900 table_->AddFormFieldValue(field, &changes);
1901 }
1902
1903 std::vector<base::string16> v;
1904 table_->GetFormValuesForElementName(
1905 ASCIIToUTF16("Name"), ASCIIToUTF16(kTestCases[i].field_contents), &v,
1906 6);
1907
1908 EXPECT_EQ(kTestCases[i].expected_suggestion_count, v.size());
1909 for (size_t j = 0; j < kTestCases[i].expected_suggestion_count; ++j) {
1910 EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_suggestion[j]), v[j]);
1911 }
1912
1913 changes.clear();
1914 table_->RemoveFormElementsAddedBetween(t1, Time(), &changes);
1915 }
1916 }
1917
1859 } // namespace autofill 1918 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698