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

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

Issue 7576001: Refactor webkit_glue::FormField to remove hacky methods (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copyright header Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <vector> 5 #include <vector>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 TEST_F(AutofillTableTest, Autofill) { 132 TEST_F(AutofillTableTest, Autofill) {
133 WebDatabase db; 133 WebDatabase db;
134 134
135 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 135 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
136 136
137 Time t1 = Time::Now(); 137 Time t1 = Time::Now();
138 138
139 // Simulate the submission of a handful of entries in a field called "Name", 139 // Simulate the submission of a handful of entries in a field called "Name",
140 // some more often than others. 140 // some more often than others.
141 AutofillChangeList changes; 141 AutofillChangeList changes;
142 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue( 142 FormField field;
143 FormField(string16(), 143 field.name = ASCIIToUTF16("Name");
144 ASCIIToUTF16("Name"), 144 field.value = ASCIIToUTF16("Superman");
145 ASCIIToUTF16("Superman"), 145 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
146 string16(),
147 0,
148 false),
149 &changes));
150 std::vector<string16> v; 146 std::vector<string16> v;
151 for (int i = 0; i < 5; i++) { 147 for (int i = 0; i < 5; i++) {
152 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue( 148 field.value = ASCIIToUTF16("Clark Kent");
153 FormField(string16(), 149 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
154 ASCIIToUTF16("Name"),
155 ASCIIToUTF16("Clark Kent"),
156 string16(),
157 0,
158 false),
159 &changes));
160 } 150 }
161 for (int i = 0; i < 3; i++) { 151 for (int i = 0; i < 3; i++) {
162 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue( 152 field.value = ASCIIToUTF16("Clark Sutter");
163 FormField(string16(), 153 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
164 ASCIIToUTF16("Name"),
165 ASCIIToUTF16("Clark Sutter"),
166 string16(),
167 0,
168 false),
169 &changes));
170 } 154 }
171 for (int i = 0; i < 2; i++) { 155 for (int i = 0; i < 2; i++) {
172 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue( 156 field.name = ASCIIToUTF16("Favorite Color");
173 FormField(string16(), 157 field.value = ASCIIToUTF16("Green");
174 ASCIIToUTF16("Favorite Color"), 158 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
175 ASCIIToUTF16("Green"),
176 string16(),
177 0,
178 false),
179 &changes));
180 } 159 }
181 160
182 int count = 0; 161 int count = 0;
183 int64 pair_id = 0; 162 int64 pair_id = 0;
184 163
185 // We have added the name Clark Kent 5 times, so count should be 5 and pair_id 164 // We have added the name Clark Kent 5 times, so count should be 5 and pair_id
186 // should be somthing non-zero. 165 // should be somthing non-zero.
187 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( 166 field.name = ASCIIToUTF16("Name");
188 FormField(string16(), 167 field.value = ASCIIToUTF16("Clark Kent");
189 ASCIIToUTF16("Name"), 168 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id,
190 ASCIIToUTF16("Clark Kent"), 169 &count));
191 string16(),
192 0,
193 false),
194 &pair_id, &count));
195 EXPECT_EQ(5, count); 170 EXPECT_EQ(5, count);
196 EXPECT_NE(0, pair_id); 171 EXPECT_NE(0, pair_id);
197 172
198 // Storing in the data base should be case sensitive, so there should be no 173 // Storing in the data base should be case sensitive, so there should be no
199 // database entry for clark kent lowercase. 174 // database entry for clark kent lowercase.
200 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( 175 field.value = ASCIIToUTF16("clark kent");
201 FormField(string16(), 176 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id,
202 ASCIIToUTF16("Name"), 177 &count));
203 ASCIIToUTF16("clark kent"),
204 string16(),
205 0,
206 false),
207 &pair_id, &count));
208 EXPECT_EQ(0, count); 178 EXPECT_EQ(0, count);
209 179
210 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( 180 field.name = ASCIIToUTF16("Favorite Color");
211 FormField(string16(), 181 field.value = ASCIIToUTF16("Green");
212 ASCIIToUTF16("Favorite Color"), 182 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id,
213 ASCIIToUTF16("Green"), 183 &count));
214 string16(),
215 0,
216 false),
217 &pair_id, &count));
218 EXPECT_EQ(2, count); 184 EXPECT_EQ(2, count);
219 185
220 // This is meant to get a list of suggestions for Name. The empty prefix 186 // This is meant to get a list of suggestions for Name. The empty prefix
221 // in the second argument means it should return all suggestions for a name 187 // in the second argument means it should return all suggestions for a name
222 // no matter what they start with. The order that the names occur in the list 188 // no matter what they start with. The order that the names occur in the list
223 // should be decreasing order by count. 189 // should be decreasing order by count.
224 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName( 190 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName(
225 ASCIIToUTF16("Name"), string16(), &v, 6)); 191 ASCIIToUTF16("Name"), string16(), &v, 6));
226 EXPECT_EQ(3U, v.size()); 192 EXPECT_EQ(3U, v.size());
227 if (v.size() == 3) { 193 if (v.size() == 3) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 ASCIIToUTF16("Clark Sutter"))), 233 ASCIIToUTF16("Clark Sutter"))),
268 AutofillChange(AutofillChange::REMOVE, 234 AutofillChange(AutofillChange::REMOVE,
269 AutofillKey(ASCIIToUTF16("Favorite Color"), 235 AutofillKey(ASCIIToUTF16("Favorite Color"),
270 ASCIIToUTF16("Green"))), 236 ASCIIToUTF16("Green"))),
271 }; 237 };
272 EXPECT_EQ(arraysize(expected_changes), changes.size()); 238 EXPECT_EQ(arraysize(expected_changes), changes.size());
273 for (size_t i = 0; i < arraysize(expected_changes); i++) { 239 for (size_t i = 0; i < arraysize(expected_changes); i++) {
274 EXPECT_EQ(expected_changes[i], changes[i]); 240 EXPECT_EQ(expected_changes[i], changes[i]);
275 } 241 }
276 242
277 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( 243 field.name = ASCIIToUTF16("Name");
278 FormField(string16(), 244 field.value = ASCIIToUTF16("Clark Kent");
279 ASCIIToUTF16("Name"), 245 EXPECT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(field, &pair_id,
280 ASCIIToUTF16("Clark Kent"), 246 &count));
281 string16(),
282 0,
283 false),
284 &pair_id, &count));
285 EXPECT_EQ(0, count); 247 EXPECT_EQ(0, count);
286 248
287 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName( 249 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName(
288 ASCIIToUTF16("Name"), string16(), &v, 6)); 250 ASCIIToUTF16("Name"), string16(), &v, 6));
289 EXPECT_EQ(0U, v.size()); 251 EXPECT_EQ(0U, v.size());
290 252
291 // Now add some values with empty strings. 253 // Now add some values with empty strings.
292 const string16 kValue = ASCIIToUTF16(" toto "); 254 const string16 kValue = ASCIIToUTF16(" toto ");
293 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue( 255 field.name = ASCIIToUTF16("blank");
294 FormField(string16(), 256 field.value = string16();
295 ASCIIToUTF16("blank"), 257 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
296 string16(), 258 field.name = ASCIIToUTF16("blank");
297 string16(), 259 field.value = ASCIIToUTF16(" ");
298 0, 260 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
299 false), 261 field.name = ASCIIToUTF16("blank");
300 &changes)); 262 field.value = ASCIIToUTF16(" ");
301 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue( 263 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
302 FormField(string16(), 264 field.name = ASCIIToUTF16("blank");
303 ASCIIToUTF16("blank"), 265 field.value = kValue;
304 ASCIIToUTF16(" "), 266 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
305 string16(),
306 0,
307 false),
308 &changes));
309 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(
310 FormField(string16(),
311 ASCIIToUTF16("blank"),
312 ASCIIToUTF16(" "),
313 string16(),
314 0,
315 false),
316 &changes));
317 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(
318 FormField(string16(),
319 ASCIIToUTF16("blank"),
320 kValue,
321 string16(),
322 0,
323 false),
324 &changes));
325 267
326 // They should be stored normally as the DB layer does not check for empty 268 // They should be stored normally as the DB layer does not check for empty
327 // values. 269 // values.
328 v.clear(); 270 v.clear();
329 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName( 271 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName(
330 ASCIIToUTF16("blank"), string16(), &v, 10)); 272 ASCIIToUTF16("blank"), string16(), &v, 10));
331 EXPECT_EQ(4U, v.size()); 273 EXPECT_EQ(4U, v.size());
332 274
333 // Now we'll check that ClearAutofillEmptyValueElements() works as expected. 275 // Now we'll check that ClearAutofillEmptyValueElements() works as expected.
334 db.GetAutofillTable()->ClearAutofillEmptyValueElements(); 276 db.GetAutofillTable()->ClearAutofillEmptyValueElements();
335 277
336 v.clear(); 278 v.clear();
337 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName( 279 EXPECT_TRUE(db.GetAutofillTable()->GetFormValuesForElementName(
338 ASCIIToUTF16("blank"), string16(), &v, 10)); 280 ASCIIToUTF16("blank"), string16(), &v, 10));
339 ASSERT_EQ(1U, v.size()); 281 ASSERT_EQ(1U, v.size());
340 282
341 EXPECT_EQ(kValue, v[0]); 283 EXPECT_EQ(kValue, v[0]);
342 } 284 }
343 285
344 TEST_F(AutofillTableTest, Autofill_RemoveBetweenChanges) { 286 TEST_F(AutofillTableTest, Autofill_RemoveBetweenChanges) {
345 WebDatabase db; 287 WebDatabase db;
346 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 288 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
347 289
348 TimeDelta one_day(TimeDelta::FromDays(1)); 290 TimeDelta one_day(TimeDelta::FromDays(1));
349 Time t1 = Time::Now(); 291 Time t1 = Time::Now();
350 Time t2 = t1 + one_day; 292 Time t2 = t1 + one_day;
351 293
352 AutofillChangeList changes; 294 AutofillChangeList changes;
353 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime( 295 FormField field;
354 FormField(string16(), 296 field.name = ASCIIToUTF16("Name");
355 ASCIIToUTF16("Name"), 297 field.value = ASCIIToUTF16("Superman");
356 ASCIIToUTF16("Superman"), 298 EXPECT_TRUE(
357 string16(), 299 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t1));
358 0, 300 EXPECT_TRUE(
359 false), 301 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t2));
360 &changes,
361 t1));
362 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime(
363 FormField(string16(),
364 ASCIIToUTF16("Name"),
365 ASCIIToUTF16("Superman"),
366 string16(),
367 0,
368 false),
369 &changes,
370 t2));
371 302
372 changes.clear(); 303 changes.clear();
373 EXPECT_TRUE(db.GetAutofillTable()->RemoveFormElementsAddedBetween( 304 EXPECT_TRUE(db.GetAutofillTable()->RemoveFormElementsAddedBetween(
374 t1, t2, &changes)); 305 t1, t2, &changes));
375 ASSERT_EQ(1U, changes.size()); 306 ASSERT_EQ(1U, changes.size());
376 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE, 307 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE,
377 AutofillKey(ASCIIToUTF16("Name"), 308 AutofillKey(ASCIIToUTF16("Name"),
378 ASCIIToUTF16("Superman"))), 309 ASCIIToUTF16("Superman"))),
379 changes[0]); 310 changes[0]);
380 changes.clear(); 311 changes.clear();
381 312
382 EXPECT_TRUE(db.GetAutofillTable()->RemoveFormElementsAddedBetween( 313 EXPECT_TRUE(db.GetAutofillTable()->RemoveFormElementsAddedBetween(
383 t2, t2 + one_day, &changes)); 314 t2, t2 + one_day, &changes));
384 ASSERT_EQ(1U, changes.size()); 315 ASSERT_EQ(1U, changes.size());
385 EXPECT_EQ(AutofillChange(AutofillChange::REMOVE, 316 EXPECT_EQ(AutofillChange(AutofillChange::REMOVE,
386 AutofillKey(ASCIIToUTF16("Name"), 317 AutofillKey(ASCIIToUTF16("Name"),
387 ASCIIToUTF16("Superman"))), 318 ASCIIToUTF16("Superman"))),
388 changes[0]); 319 changes[0]);
389 } 320 }
390 321
391 TEST_F(AutofillTableTest, Autofill_AddChanges) { 322 TEST_F(AutofillTableTest, Autofill_AddChanges) {
392 WebDatabase db; 323 WebDatabase db;
393 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 324 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
394 325
395 TimeDelta one_day(TimeDelta::FromDays(1)); 326 TimeDelta one_day(TimeDelta::FromDays(1));
396 Time t1 = Time::Now(); 327 Time t1 = Time::Now();
397 Time t2 = t1 + one_day; 328 Time t2 = t1 + one_day;
398 329
399 AutofillChangeList changes; 330 AutofillChangeList changes;
400 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime( 331 FormField field;
401 FormField(string16(), 332 field.name = ASCIIToUTF16("Name");
402 ASCIIToUTF16("Name"), 333 field.value = ASCIIToUTF16("Superman");
403 ASCIIToUTF16("Superman"), 334 EXPECT_TRUE(
404 string16(), 335 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t1));
405 0,
406 false),
407 &changes,
408 t1));
409 ASSERT_EQ(1U, changes.size()); 336 ASSERT_EQ(1U, changes.size());
410 EXPECT_EQ(AutofillChange(AutofillChange::ADD, 337 EXPECT_EQ(AutofillChange(AutofillChange::ADD,
411 AutofillKey(ASCIIToUTF16("Name"), 338 AutofillKey(ASCIIToUTF16("Name"),
412 ASCIIToUTF16("Superman"))), 339 ASCIIToUTF16("Superman"))),
413 changes[0]); 340 changes[0]);
414 341
415 changes.clear(); 342 changes.clear();
416 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime( 343 EXPECT_TRUE(
417 FormField(string16(), 344 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t2));
418 ASCIIToUTF16("Name"),
419 ASCIIToUTF16("Superman"),
420 string16(),
421 0,
422 false),
423 &changes,
424 t2));
425 ASSERT_EQ(1U, changes.size()); 345 ASSERT_EQ(1U, changes.size());
426 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE, 346 EXPECT_EQ(AutofillChange(AutofillChange::UPDATE,
427 AutofillKey(ASCIIToUTF16("Name"), 347 AutofillKey(ASCIIToUTF16("Name"),
428 ASCIIToUTF16("Superman"))), 348 ASCIIToUTF16("Superman"))),
429 changes[0]); 349 changes[0]);
430 } 350 }
431 351
432 TEST_F(AutofillTableTest, Autofill_UpdateOneWithOneTimestamp) { 352 TEST_F(AutofillTableTest, Autofill_UpdateOneWithOneTimestamp) {
433 WebDatabase db; 353 WebDatabase db;
434 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 354 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
435 355
436 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, -1)); 356 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, -1));
437 std::vector<AutofillEntry> entries; 357 std::vector<AutofillEntry> entries;
438 entries.push_back(entry); 358 entries.push_back(entry);
439 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries)); 359 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries));
440 360
441 FormField field(string16(), 361 FormField field;
442 ASCIIToUTF16("foo"), 362 field.name = ASCIIToUTF16("foo");
443 ASCIIToUTF16("bar"), 363 field.value = ASCIIToUTF16("bar");
444 string16(),
445 0,
446 false);
447 int64 pair_id; 364 int64 pair_id;
448 int count; 365 int count;
449 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( 366 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(
450 field, &pair_id, &count)); 367 field, &pair_id, &count));
451 EXPECT_LE(0, pair_id); 368 EXPECT_LE(0, pair_id);
452 EXPECT_EQ(1, count); 369 EXPECT_EQ(1, count);
453 370
454 std::vector<AutofillEntry> all_entries; 371 std::vector<AutofillEntry> all_entries;
455 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries)); 372 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries));
456 ASSERT_EQ(1U, all_entries.size()); 373 ASSERT_EQ(1U, all_entries.size());
457 EXPECT_TRUE(entry == all_entries[0]); 374 EXPECT_TRUE(entry == all_entries[0]);
458 } 375 }
459 376
460 TEST_F(AutofillTableTest, Autofill_UpdateOneWithTwoTimestamps) { 377 TEST_F(AutofillTableTest, Autofill_UpdateOneWithTwoTimestamps) {
461 WebDatabase db; 378 WebDatabase db;
462 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 379 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
463 380
464 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, 2)); 381 AutofillEntry entry(MakeAutofillEntry("foo", "bar", 1, 2));
465 std::vector<AutofillEntry> entries; 382 std::vector<AutofillEntry> entries;
466 entries.push_back(entry); 383 entries.push_back(entry);
467 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries)); 384 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries));
468 385
469 FormField field(string16(), 386 FormField field;
470 ASCIIToUTF16("foo"), 387 field.name = ASCIIToUTF16("foo");
471 ASCIIToUTF16("bar"), 388 field.value = ASCIIToUTF16("bar");
472 string16(),
473 0,
474 false);
475 int64 pair_id; 389 int64 pair_id;
476 int count; 390 int count;
477 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( 391 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(
478 field, &pair_id, &count)); 392 field, &pair_id, &count));
479 EXPECT_LE(0, pair_id); 393 EXPECT_LE(0, pair_id);
480 EXPECT_EQ(2, count); 394 EXPECT_EQ(2, count);
481 395
482 std::vector<AutofillEntry> all_entries; 396 std::vector<AutofillEntry> all_entries;
483 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries)); 397 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries));
484 ASSERT_EQ(1U, all_entries.size()); 398 ASSERT_EQ(1U, all_entries.size());
(...skipping 22 matching lines...) Expand all
507 WebDatabase db; 421 WebDatabase db;
508 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 422 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
509 423
510 AutofillEntry entry0(MakeAutofillEntry("foo", "bar0", 1, -1)); 424 AutofillEntry entry0(MakeAutofillEntry("foo", "bar0", 1, -1));
511 AutofillEntry entry1(MakeAutofillEntry("foo", "bar1", 2, 3)); 425 AutofillEntry entry1(MakeAutofillEntry("foo", "bar1", 2, 3));
512 std::vector<AutofillEntry> entries; 426 std::vector<AutofillEntry> entries;
513 entries.push_back(entry0); 427 entries.push_back(entry0);
514 entries.push_back(entry1); 428 entries.push_back(entry1);
515 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries)); 429 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries));
516 430
517 FormField field0(string16(), 431 FormField field0;
518 ASCIIToUTF16("foo"), 432 field0.name = ASCIIToUTF16("foo");
519 ASCIIToUTF16("bar0"), 433 field0.value = ASCIIToUTF16("bar0");
520 string16(),
521 0,
522 false);
523 int64 pair_id; 434 int64 pair_id;
524 int count; 435 int count;
525 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( 436 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(
526 field0, &pair_id, &count)); 437 field0, &pair_id, &count));
527 EXPECT_LE(0, pair_id); 438 EXPECT_LE(0, pair_id);
528 EXPECT_EQ(1, count); 439 EXPECT_EQ(1, count);
529 440
530 FormField field1(string16(), 441 FormField field1;
531 ASCIIToUTF16("foo"), 442 field1.name = ASCIIToUTF16("foo");
532 ASCIIToUTF16("bar1"), 443 field1.value = ASCIIToUTF16("bar1");
533 string16(),
534 0,
535 false);
536 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement( 444 ASSERT_TRUE(db.GetAutofillTable()->GetIDAndCountOfFormElement(
537 field1, &pair_id, &count)); 445 field1, &pair_id, &count));
538 EXPECT_LE(0, pair_id); 446 EXPECT_LE(0, pair_id);
539 EXPECT_EQ(2, count); 447 EXPECT_EQ(2, count);
540 } 448 }
541 449
542 TEST_F(AutofillTableTest, Autofill_UpdateReplace) { 450 TEST_F(AutofillTableTest, Autofill_UpdateReplace) {
543 WebDatabase db; 451 WebDatabase db;
544 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 452 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
545 453
546 AutofillChangeList changes; 454 AutofillChangeList changes;
547 // Add a form field. This will be replaced. 455 // Add a form field. This will be replaced.
548 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue( 456 FormField field;
549 FormField(string16(), 457 field.name = ASCIIToUTF16("Name");
550 ASCIIToUTF16("Name"), 458 field.value = ASCIIToUTF16("Superman");
551 ASCIIToUTF16("Superman"), 459 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValue(field, &changes));
552 string16(),
553 0,
554 false),
555 &changes));
556 460
557 AutofillEntry entry(MakeAutofillEntry("Name", "Superman", 1, 2)); 461 AutofillEntry entry(MakeAutofillEntry("Name", "Superman", 1, 2));
558 std::vector<AutofillEntry> entries; 462 std::vector<AutofillEntry> entries;
559 entries.push_back(entry); 463 entries.push_back(entry);
560 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries)); 464 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries));
561 465
562 std::vector<AutofillEntry> all_entries; 466 std::vector<AutofillEntry> all_entries;
563 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries)); 467 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries));
564 ASSERT_EQ(1U, all_entries.size()); 468 ASSERT_EQ(1U, all_entries.size());
565 EXPECT_TRUE(entry == all_entries[0]); 469 EXPECT_TRUE(entry == all_entries[0]);
566 } 470 }
567 471
568 TEST_F(AutofillTableTest, Autofill_UpdateDontReplace) { 472 TEST_F(AutofillTableTest, Autofill_UpdateDontReplace) {
569 WebDatabase db; 473 WebDatabase db;
570 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 474 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
571 475
572 Time t = Time::Now(); 476 Time t = Time::Now();
573 AutofillEntry existing( 477 AutofillEntry existing(
574 MakeAutofillEntry("Name", "Superman", t.ToTimeT(), -1)); 478 MakeAutofillEntry("Name", "Superman", t.ToTimeT(), -1));
575 479
576 AutofillChangeList changes; 480 AutofillChangeList changes;
577 // Add a form field. This will NOT be replaced. 481 // Add a form field. This will NOT be replaced.
578 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime( 482 FormField field;
579 FormField(string16(), 483 field.name = existing.key().name();
580 existing.key().name(), 484 field.value = existing.key().value();
581 existing.key().value(), 485 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime(field, &changes, t));
582 string16(),
583 0,
584 false),
585 &changes,
586 t));
587 AutofillEntry entry(MakeAutofillEntry("Name", "Clark Kent", 1, 2)); 486 AutofillEntry entry(MakeAutofillEntry("Name", "Clark Kent", 1, 2));
588 std::vector<AutofillEntry> entries; 487 std::vector<AutofillEntry> entries;
589 entries.push_back(entry); 488 entries.push_back(entry);
590 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries)); 489 ASSERT_TRUE(db.GetAutofillTable()->UpdateAutofillEntries(entries));
591 490
592 std::vector<AutofillEntry> all_entries; 491 std::vector<AutofillEntry> all_entries;
593 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries)); 492 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&all_entries));
594 ASSERT_EQ(2U, all_entries.size()); 493 ASSERT_EQ(2U, all_entries.size());
595 AutofillEntrySet expected_entries(all_entries.begin(), 494 AutofillEntrySet expected_entries(all_entries.begin(),
596 all_entries.end(), 495 all_entries.end(),
597 CompareAutofillEntries); 496 CompareAutofillEntries);
598 EXPECT_EQ(1U, expected_entries.count(existing)); 497 EXPECT_EQ(1U, expected_entries.count(existing));
599 EXPECT_EQ(1U, expected_entries.count(entry)); 498 EXPECT_EQ(1U, expected_entries.count(entry));
600 } 499 }
601 500
602 TEST_F(AutofillTableTest, Autofill_AddFormFieldValues) { 501 TEST_F(AutofillTableTest, Autofill_AddFormFieldValues) {
603 WebDatabase db; 502 WebDatabase db;
604 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 503 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
605 504
606 Time t = Time::Now(); 505 Time t = Time::Now();
607 506
608 // Add multiple values for "firstname" and "lastname" names. Test that only 507 // Add multiple values for "firstname" and "lastname" names. Test that only
609 // first value of each gets added. Related to security issue: 508 // first value of each gets added. Related to security issue:
610 // http://crbug.com/51727. 509 // http://crbug.com/51727.
611 std::vector<FormField> elements; 510 std::vector<FormField> elements;
612 elements.push_back(FormField(string16(), 511 FormField field;
613 ASCIIToUTF16("firstname"), 512 field.name = ASCIIToUTF16("firstname");
614 ASCIIToUTF16("Joe"), 513 field.value = ASCIIToUTF16("Joe");
615 string16(), 514 elements.push_back(field);
616 0, 515
617 false)); 516 field.name = ASCIIToUTF16("firstname");
618 elements.push_back(FormField(string16(), 517 field.value = ASCIIToUTF16("Jane");
619 ASCIIToUTF16("firstname"), 518 elements.push_back(field);
620 ASCIIToUTF16("Jane"), 519
621 string16(), 520 field.name = ASCIIToUTF16("lastname");
622 0, 521 field.value = ASCIIToUTF16("Smith");
623 false)); 522 elements.push_back(field);
624 elements.push_back(FormField(string16(), 523
625 ASCIIToUTF16("lastname"), 524 field.name = ASCIIToUTF16("lastname");
626 ASCIIToUTF16("Smith"), 525 field.value = ASCIIToUTF16("Jones");
627 string16(), 526 elements.push_back(field);
628 0,
629 false));
630 elements.push_back(FormField(string16(),
631 ASCIIToUTF16("lastname"),
632 ASCIIToUTF16("Jones"),
633 string16(),
634 0,
635 false));
636 527
637 std::vector<AutofillChange> changes; 528 std::vector<AutofillChange> changes;
638 db.GetAutofillTable()->AddFormFieldValuesTime(elements, &changes, t); 529 db.GetAutofillTable()->AddFormFieldValuesTime(elements, &changes, t);
639 530
640 ASSERT_EQ(2U, changes.size()); 531 ASSERT_EQ(2U, changes.size());
641 EXPECT_EQ(changes[0], AutofillChange(AutofillChange::ADD, 532 EXPECT_EQ(changes[0], AutofillChange(AutofillChange::ADD,
642 AutofillKey(ASCIIToUTF16("firstname"), 533 AutofillKey(ASCIIToUTF16("firstname"),
643 ASCIIToUTF16("Joe")))); 534 ASCIIToUTF16("Joe"))));
644 EXPECT_EQ(changes[1], AutofillChange(AutofillChange::ADD, 535 EXPECT_EQ(changes[1], AutofillChange(AutofillChange::ADD,
645 AutofillKey(ASCIIToUTF16("lastname"), 536 AutofillKey(ASCIIToUTF16("lastname"),
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_OneResult) { 1346 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_OneResult) {
1456 WebDatabase db; 1347 WebDatabase db;
1457 1348
1458 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 1349 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
1459 1350
1460 AutofillChangeList changes; 1351 AutofillChangeList changes;
1461 std::map<std::string, std::vector<Time> > name_value_times_map; 1352 std::map<std::string, std::vector<Time> > name_value_times_map;
1462 1353
1463 time_t start = 0; 1354 time_t start = 0;
1464 std::vector<Time> timestamps1; 1355 std::vector<Time> timestamps1;
1465 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime( 1356 FormField field;
1466 FormField(string16(), 1357 field.name = ASCIIToUTF16("Name");
1467 ASCIIToUTF16("Name"), 1358 field.value = ASCIIToUTF16("Superman");
1468 ASCIIToUTF16("Superman"), 1359 EXPECT_TRUE(
1469 string16(), 1360 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes,
1470 0, 1361 Time::FromTimeT(start)));
1471 false),
1472 &changes,
1473 Time::FromTimeT(start)));
1474 timestamps1.push_back(Time::FromTimeT(start)); 1362 timestamps1.push_back(Time::FromTimeT(start));
1475 std::string key1("NameSuperman"); 1363 std::string key1("NameSuperman");
1476 name_value_times_map.insert(std::pair<std::string, 1364 name_value_times_map.insert(std::pair<std::string,
1477 std::vector<Time> > (key1, timestamps1)); 1365 std::vector<Time> > (key1, timestamps1));
1478 1366
1479 AutofillEntrySet expected_entries(CompareAutofillEntries); 1367 AutofillEntrySet expected_entries(CompareAutofillEntries);
1480 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman")); 1368 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"));
1481 AutofillEntry ae1(ak1, timestamps1); 1369 AutofillEntry ae1(ak1, timestamps1);
1482 1370
1483 expected_entries.insert(ae1); 1371 expected_entries.insert(ae1);
(...skipping 16 matching lines...) Expand all
1500 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoDistinct) { 1388 TEST_F(AutofillTableTest, Autofill_GetAllAutofillEntries_TwoDistinct) {
1501 WebDatabase db; 1389 WebDatabase db;
1502 1390
1503 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 1391 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
1504 1392
1505 AutofillChangeList changes; 1393 AutofillChangeList changes;
1506 std::map<std::string, std::vector<Time> > name_value_times_map; 1394 std::map<std::string, std::vector<Time> > name_value_times_map;
1507 time_t start = 0; 1395 time_t start = 0;
1508 1396
1509 std::vector<Time> timestamps1; 1397 std::vector<Time> timestamps1;
1510 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime( 1398 FormField field;
1511 FormField(string16(), 1399 field.name = ASCIIToUTF16("Name");
1512 ASCIIToUTF16("Name"), 1400 field.value = ASCIIToUTF16("Superman");
1513 ASCIIToUTF16("Superman"), 1401 EXPECT_TRUE(
1514 string16(), 1402 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes,
1515 0, 1403 Time::FromTimeT(start)));
1516 false),
1517 &changes,
1518 Time::FromTimeT(start)));
1519 timestamps1.push_back(Time::FromTimeT(start)); 1404 timestamps1.push_back(Time::FromTimeT(start));
1520 std::string key1("NameSuperman"); 1405 std::string key1("NameSuperman");
1521 name_value_times_map.insert(std::pair<std::string, 1406 name_value_times_map.insert(std::pair<std::string,
1522 std::vector<Time> > (key1, timestamps1)); 1407 std::vector<Time> > (key1, timestamps1));
1523 1408
1524 start++; 1409 start++;
1525 std::vector<Time> timestamps2; 1410 std::vector<Time> timestamps2;
1526 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime( 1411 field.name = ASCIIToUTF16("Name");
1527 FormField(string16(), 1412 field.value = ASCIIToUTF16("Clark Kent");
1528 ASCIIToUTF16("Name"), 1413 EXPECT_TRUE(
1529 ASCIIToUTF16("Clark Kent"), 1414 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes,
1530 string16(), 1415 Time::FromTimeT(start)));
1531 0,
1532 false),
1533 &changes,
1534 Time::FromTimeT(start)));
1535 timestamps2.push_back(Time::FromTimeT(start)); 1416 timestamps2.push_back(Time::FromTimeT(start));
1536 std::string key2("NameClark Kent"); 1417 std::string key2("NameClark Kent");
1537 name_value_times_map.insert(std::pair<std::string, 1418 name_value_times_map.insert(std::pair<std::string,
1538 std::vector<Time> > (key2, timestamps2)); 1419 std::vector<Time> > (key2, timestamps2));
1539 1420
1540 AutofillEntrySet expected_entries(CompareAutofillEntries); 1421 AutofillEntrySet expected_entries(CompareAutofillEntries);
1541 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman")); 1422 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"));
1542 AutofillKey ak2(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")); 1423 AutofillKey ak2(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent"));
1543 AutofillEntry ae1(ak1, timestamps1); 1424 AutofillEntry ae1(ak1, timestamps1);
1544 AutofillEntry ae2(ak2, timestamps2); 1425 AutofillEntry ae2(ak2, timestamps2);
(...skipping 20 matching lines...) Expand all
1565 WebDatabase db; 1446 WebDatabase db;
1566 1447
1567 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); 1448 ASSERT_EQ(sql::INIT_OK, db.Init(file_));
1568 1449
1569 AutofillChangeList changes; 1450 AutofillChangeList changes;
1570 std::map<std::string, std::vector<Time> > name_value_times_map; 1451 std::map<std::string, std::vector<Time> > name_value_times_map;
1571 1452
1572 time_t start = 0; 1453 time_t start = 0;
1573 std::vector<Time> timestamps; 1454 std::vector<Time> timestamps;
1574 for (int i = 0; i < 2; i++) { 1455 for (int i = 0; i < 2; i++) {
1575 EXPECT_TRUE(db.GetAutofillTable()->AddFormFieldValueTime( 1456 FormField field;
1576 FormField(string16(), 1457 field.name = ASCIIToUTF16("Name");
1577 ASCIIToUTF16("Name"), 1458 field.value = ASCIIToUTF16("Superman");
1578 ASCIIToUTF16("Superman"), 1459 EXPECT_TRUE(
1579 string16(), 1460 db.GetAutofillTable()->AddFormFieldValueTime(field, &changes,
1580 0, 1461 Time::FromTimeT(start)));
1581 false),
1582 &changes,
1583 Time::FromTimeT(start)));
1584 timestamps.push_back(Time::FromTimeT(start)); 1462 timestamps.push_back(Time::FromTimeT(start));
1585 start++; 1463 start++;
1586 } 1464 }
1587 1465
1588 std::string key("NameSuperman"); 1466 std::string key("NameSuperman");
1589 name_value_times_map.insert(std::pair<std::string, 1467 name_value_times_map.insert(std::pair<std::string,
1590 std::vector<Time> > (key, timestamps)); 1468 std::vector<Time> > (key, timestamps));
1591 1469
1592 AutofillEntrySet expected_entries(CompareAutofillEntries); 1470 AutofillEntrySet expected_entries(CompareAutofillEntries);
1593 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman")); 1471 AutofillKey ak1(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"));
1594 AutofillEntry ae1(ak1, timestamps); 1472 AutofillEntry ae1(ak1, timestamps);
1595 1473
1596 expected_entries.insert(ae1); 1474 expected_entries.insert(ae1);
1597 1475
1598 std::vector<AutofillEntry> entries; 1476 std::vector<AutofillEntry> entries;
1599 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&entries)); 1477 ASSERT_TRUE(db.GetAutofillTable()->GetAllAutofillEntries(&entries));
1600 AutofillEntrySet entry_set(entries.begin(), entries.end(), 1478 AutofillEntrySet entry_set(entries.begin(), entries.end(),
1601 CompareAutofillEntries); 1479 CompareAutofillEntries);
1602 1480
1603 // make sure the lists of entries match 1481 // make sure the lists of entries match
1604 ASSERT_EQ(expected_entries.size(), entry_set.size()); 1482 ASSERT_EQ(expected_entries.size(), entry_set.size());
1605 AutofillEntrySetIterator it; 1483 AutofillEntrySetIterator it;
1606 for (it = entry_set.begin(); it != entry_set.end(); it++) { 1484 for (it = entry_set.begin(); it != entry_set.end(); it++) {
1607 expected_entries.erase(*it); 1485 expected_entries.erase(*it);
1608 } 1486 }
1609 1487
1610 EXPECT_EQ(0U, expected_entries.size()); 1488 EXPECT_EQ(0U, expected_entries.size());
1611 } 1489 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/phone_field_unittest.cc ('k') | chrome/browser/webdata/web_data_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698