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

Side by Side Diff: components/autofill/core/browser/autofill_download_manager_unittest.cc

Issue 2609703002: Remove ScopedVector from autofill. (Closed)
Patch Set: drop the using Created 3 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/autofill/core/browser/autofill_download_manager.h" 5 #include "components/autofill/core/browser/autofill_download_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <list> 9 #include <list>
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 #include <vector>
12 13
14 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h" 15 #include "base/run_loop.h"
14 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
17 #include "base/test/histogram_tester.h" 19 #include "base/test/histogram_tester.h"
18 #include "base/test/test_timeouts.h" 20 #include "base/test/test_timeouts.h"
19 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
20 #include "components/autofill/core/browser/autofill_field.h" 22 #include "components/autofill/core/browser/autofill_field.h"
21 #include "components/autofill/core/browser/autofill_metrics.h" 23 #include "components/autofill/core/browser/autofill_metrics.h"
22 #include "components/autofill/core/browser/autofill_type.h" 24 #include "components/autofill/core/browser/autofill_type.h"
(...skipping 19 matching lines...) Expand all
42 int response_code, 44 int response_code,
43 const std::string& response_body) { 45 const std::string& response_body) {
44 fetcher->set_url(GURL()); 46 fetcher->set_url(GURL());
45 fetcher->set_status(net::URLRequestStatus()); 47 fetcher->set_status(net::URLRequestStatus());
46 fetcher->set_response_code(response_code); 48 fetcher->set_response_code(response_code);
47 fetcher->SetResponseString(response_body); 49 fetcher->SetResponseString(response_body);
48 50
49 fetcher->delegate()->OnURLFetchComplete(fetcher); 51 fetcher->delegate()->OnURLFetchComplete(fetcher);
50 } 52 }
51 53
54 std::vector<FormStructure*> ToRawPointerVector(
55 const std::vector<std::unique_ptr<FormStructure>>& list) {
56 std::vector<FormStructure*> result;
57 for (const auto& item : list)
58 result.push_back(item.get());
59 return result;
60 }
61
52 } // namespace 62 } // namespace
53 63
54 // This tests AutofillDownloadManager. AutofillDownloadManagerTest implements 64 // This tests AutofillDownloadManager. AutofillDownloadManagerTest implements
55 // AutofillDownloadManager::Observer and creates an instance of 65 // AutofillDownloadManager::Observer and creates an instance of
56 // AutofillDownloadManager. Then it records responses to different initiated 66 // AutofillDownloadManager. Then it records responses to different initiated
57 // requests, which are verified later. To mock network requests 67 // requests, which are verified later. To mock network requests
58 // TestURLFetcherFactory is used, which creates URLFetchers that do not 68 // TestURLFetcherFactory is used, which creates URLFetchers that do not
59 // go over the wire, but allow calling back HTTP responses directly. 69 // go over the wire, but allow calling back HTTP responses directly.
60 // The responses in test are out of order and verify: successful query request, 70 // The responses in test are out of order and verify: successful query request,
61 // successful upload request, failed upload request. 71 // successful upload request, failed upload request.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 field.label = ASCIIToUTF16("password"); 169 field.label = ASCIIToUTF16("password");
160 field.name = ASCIIToUTF16("password"); 170 field.name = ASCIIToUTF16("password");
161 field.form_control_type = "password"; 171 field.form_control_type = "password";
162 form.fields.push_back(field); 172 form.fields.push_back(field);
163 173
164 field.label = base::string16(); 174 field.label = base::string16();
165 field.name = ASCIIToUTF16("Submit"); 175 field.name = ASCIIToUTF16("Submit");
166 field.form_control_type = "submit"; 176 field.form_control_type = "submit";
167 form.fields.push_back(field); 177 form.fields.push_back(field);
168 178
169 FormStructure* form_structure = new FormStructure(form); 179 std::vector<std::unique_ptr<FormStructure>> form_structures;
170 ScopedVector<FormStructure> form_structures; 180 form_structures.push_back(base::MakeUnique<FormStructure>(form));
171 form_structures.push_back(form_structure);
172 181
173 form.fields.clear(); 182 form.fields.clear();
174 183
175 field.label = ASCIIToUTF16("address"); 184 field.label = ASCIIToUTF16("address");
176 field.name = ASCIIToUTF16("address"); 185 field.name = ASCIIToUTF16("address");
177 field.form_control_type = "text"; 186 field.form_control_type = "text";
178 form.fields.push_back(field); 187 form.fields.push_back(field);
179 188
180 field.label = ASCIIToUTF16("address2"); 189 field.label = ASCIIToUTF16("address2");
181 field.name = ASCIIToUTF16("address2"); 190 field.name = ASCIIToUTF16("address2");
182 field.form_control_type = "text"; 191 field.form_control_type = "text";
183 form.fields.push_back(field); 192 form.fields.push_back(field);
184 193
185 field.label = ASCIIToUTF16("city"); 194 field.label = ASCIIToUTF16("city");
186 field.name = ASCIIToUTF16("city"); 195 field.name = ASCIIToUTF16("city");
187 field.form_control_type = "text"; 196 field.form_control_type = "text";
188 form.fields.push_back(field); 197 form.fields.push_back(field);
189 198
190 field.label = base::string16(); 199 field.label = base::string16();
191 field.name = ASCIIToUTF16("Submit"); 200 field.name = ASCIIToUTF16("Submit");
192 field.form_control_type = "submit"; 201 field.form_control_type = "submit";
193 form.fields.push_back(field); 202 form.fields.push_back(field);
194 203
195 form_structure = new FormStructure(form); 204 form_structures.push_back(base::MakeUnique<FormStructure>(form));
196 form_structures.push_back(form_structure);
197 205
198 form.fields.clear(); 206 form.fields.clear();
199 207
200 field.label = ASCIIToUTF16("username"); 208 field.label = ASCIIToUTF16("username");
201 field.name = ASCIIToUTF16("username"); 209 field.name = ASCIIToUTF16("username");
202 field.form_control_type = "text"; 210 field.form_control_type = "text";
203 form.fields.push_back(field); 211 form.fields.push_back(field);
204 212
205 field.label = ASCIIToUTF16("password"); 213 field.label = ASCIIToUTF16("password");
206 field.name = ASCIIToUTF16("password"); 214 field.name = ASCIIToUTF16("password");
207 field.form_control_type = "password"; 215 field.form_control_type = "password";
208 form.fields.push_back(field); 216 form.fields.push_back(field);
209 217
210 field.label = base::string16(); 218 field.label = base::string16();
211 field.name = ASCIIToUTF16("Submit"); 219 field.name = ASCIIToUTF16("Submit");
212 field.form_control_type = "submit"; 220 field.form_control_type = "submit";
213 form.fields.push_back(field); 221 form.fields.push_back(field);
214 222
215 form_structure = new FormStructure(form); 223 form_structures.push_back(base::MakeUnique<FormStructure>(form));
216 form_structures.push_back(form_structure);
217 224
218 // Request with id 0. 225 // Request with id 0.
219 base::HistogramTester histogram; 226 base::HistogramTester histogram;
220 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get())); 227 EXPECT_TRUE(
228 download_manager_.StartQueryRequest(ToRawPointerVector(form_structures)));
221 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse", 229 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse",
222 AutofillMetrics::QUERY_SENT, 1); 230 AutofillMetrics::QUERY_SENT, 1);
223 231
224 // Request with id 1. 232 // Request with id 1.
225 EXPECT_TRUE(download_manager_.StartUploadRequest( 233 EXPECT_TRUE(download_manager_.StartUploadRequest(
226 *(form_structures[0]), true, ServerFieldTypeSet(), std::string(), true)); 234 *(form_structures[0]), true, ServerFieldTypeSet(), std::string(), true));
227 // Request with id 2. 235 // Request with id 2.
228 EXPECT_TRUE(download_manager_.StartUploadRequest( 236 EXPECT_TRUE(download_manager_.StartUploadRequest(
229 *(form_structures[1]), false, ServerFieldTypeSet(), std::string(), true)); 237 *(form_structures[1]), false, ServerFieldTypeSet(), std::string(), true));
230 // Request with id 3. Upload request with a non-empty additional password form 238 // Request with id 3. Upload request with a non-empty additional password form
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 EXPECT_EQ(0, responses_.front().error); 297 EXPECT_EQ(0, responses_.front().error);
290 EXPECT_EQ(std::string(), responses_.front().signature); 298 EXPECT_EQ(std::string(), responses_.front().signature);
291 EXPECT_EQ(responses[0], responses_.front().response); 299 EXPECT_EQ(responses[0], responses_.front().response);
292 responses_.pop_front(); 300 responses_.pop_front();
293 301
294 // Modify form structures to miss the cache. 302 // Modify form structures to miss the cache.
295 field.label = ASCIIToUTF16("Address line 2"); 303 field.label = ASCIIToUTF16("Address line 2");
296 field.name = ASCIIToUTF16("address2"); 304 field.name = ASCIIToUTF16("address2");
297 field.form_control_type = "text"; 305 field.form_control_type = "text";
298 form.fields.push_back(field); 306 form.fields.push_back(field);
299 form_structure = new FormStructure(form); 307 form_structures.push_back(base::MakeUnique<FormStructure>(form));
300 form_structures.push_back(form_structure);
301 308
302 // Request with id 4, not successful. 309 // Request with id 4, not successful.
303 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get())); 310 EXPECT_TRUE(
311 download_manager_.StartQueryRequest(ToRawPointerVector(form_structures)));
304 fetcher = factory.GetFetcherByID(4); 312 fetcher = factory.GetFetcherByID(4);
305 ASSERT_TRUE(fetcher); 313 ASSERT_TRUE(fetcher);
306 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse", 314 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse",
307 AutofillMetrics::QUERY_SENT, 2); 315 AutofillMetrics::QUERY_SENT, 2);
308 FakeOnURLFetchComplete(fetcher, net::HTTP_INTERNAL_SERVER_ERROR, 316 FakeOnURLFetchComplete(fetcher, net::HTTP_INTERNAL_SERVER_ERROR,
309 std::string(responses[0])); 317 std::string(responses[0]));
310 318
311 // Check Request 4. 319 // Check Request 4.
312 EXPECT_EQ(AutofillDownloadManagerTest::REQUEST_QUERY_FAILED, 320 EXPECT_EQ(AutofillDownloadManagerTest::REQUEST_QUERY_FAILED,
313 responses_.front().type_of_response); 321 responses_.front().type_of_response);
(...skipping 22 matching lines...) Expand all
336 field.label = ASCIIToUTF16("city"); 344 field.label = ASCIIToUTF16("city");
337 field.name = ASCIIToUTF16("city"); 345 field.name = ASCIIToUTF16("city");
338 field.form_control_type = "text"; 346 field.form_control_type = "text";
339 form.fields.push_back(field); 347 form.fields.push_back(field);
340 348
341 field.label = base::string16(); 349 field.label = base::string16();
342 field.name = ASCIIToUTF16("Submit"); 350 field.name = ASCIIToUTF16("Submit");
343 field.form_control_type = "submit"; 351 field.form_control_type = "submit";
344 form.fields.push_back(field); 352 form.fields.push_back(field);
345 353
346 FormStructure* form_structure = new FormStructure(form); 354 std::vector<std::unique_ptr<FormStructure>> form_structures;
347 ScopedVector<FormStructure> form_structures; 355 form_structures.push_back(base::MakeUnique<FormStructure>(form));
348 form_structures.push_back(form_structure);
349 356
350 // Request with id 0. 357 // Request with id 0.
351 base::HistogramTester histogram; 358 base::HistogramTester histogram;
352 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get())); 359 EXPECT_TRUE(
360 download_manager_.StartQueryRequest(ToRawPointerVector(form_structures)));
353 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse", 361 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse",
354 AutofillMetrics::QUERY_SENT, 1); 362 AutofillMetrics::QUERY_SENT, 1);
355 363
356 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 364 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
357 ASSERT_TRUE(fetcher); 365 ASSERT_TRUE(fetcher);
358 366
359 // Request error incurs a retry after 1 second. 367 // Request error incurs a retry after 1 second.
360 FakeOnURLFetchComplete(fetcher, net::HTTP_NOT_FOUND, "<html></html>"); 368 FakeOnURLFetchComplete(fetcher, net::HTTP_NOT_FOUND, "<html></html>");
361 EXPECT_EQ(1U, responses_.size()); 369 EXPECT_EQ(1U, responses_.size());
362 EXPECT_LT(download_manager_.fetcher_backoff_.GetTimeUntilRelease(), 370 EXPECT_LT(download_manager_.fetcher_backoff_.GetTimeUntilRelease(),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 field.label = ASCIIToUTF16("city"); 404 field.label = ASCIIToUTF16("city");
397 field.name = ASCIIToUTF16("city"); 405 field.name = ASCIIToUTF16("city");
398 field.form_control_type = "text"; 406 field.form_control_type = "text";
399 form.fields.push_back(field); 407 form.fields.push_back(field);
400 408
401 field.label = base::string16(); 409 field.label = base::string16();
402 field.name = ASCIIToUTF16("Submit"); 410 field.name = ASCIIToUTF16("Submit");
403 field.form_control_type = "submit"; 411 field.form_control_type = "submit";
404 form.fields.push_back(field); 412 form.fields.push_back(field);
405 413
406 std::unique_ptr<FormStructure> form_structure(new FormStructure(form)); 414 auto form_structure = base::MakeUnique<FormStructure>(form);
407 415
408 // Request with id 0. 416 // Request with id 0.
409 EXPECT_TRUE(download_manager_.StartUploadRequest( 417 EXPECT_TRUE(download_manager_.StartUploadRequest(
410 *form_structure, true, ServerFieldTypeSet(), std::string(), true)); 418 *form_structure, true, ServerFieldTypeSet(), std::string(), true));
411 419
412 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 420 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
413 ASSERT_TRUE(fetcher); 421 ASSERT_TRUE(fetcher);
414 422
415 // Error incurs a retry after 1 second. 423 // Error incurs a retry after 1 second.
416 FakeOnURLFetchComplete(fetcher, net::HTTP_NOT_FOUND, "<html></html>"); 424 FakeOnURLFetchComplete(fetcher, net::HTTP_NOT_FOUND, "<html></html>");
(...skipping 28 matching lines...) Expand all
445 EXPECT_EQ(std::string(), responses_.front().response); 453 EXPECT_EQ(std::string(), responses_.front().response);
446 responses_.pop_front(); 454 responses_.pop_front();
447 } 455 }
448 456
449 TEST_F(AutofillDownloadManagerTest, QueryTooManyFieldsTest) { 457 TEST_F(AutofillDownloadManagerTest, QueryTooManyFieldsTest) {
450 // Create and register factory. 458 // Create and register factory.
451 net::TestURLFetcherFactory factory; 459 net::TestURLFetcherFactory factory;
452 460
453 // Create a query that contains too many fields for the server. 461 // Create a query that contains too many fields for the server.
454 std::vector<FormData> forms(21); 462 std::vector<FormData> forms(21);
455 ScopedVector<FormStructure> form_structures; 463 std::vector<std::unique_ptr<FormStructure>> form_structures;
456 for (auto& form : forms) { 464 for (auto& form : forms) {
457 for (size_t i = 0; i < 5; ++i) { 465 for (size_t i = 0; i < 5; ++i) {
458 FormFieldData field; 466 FormFieldData field;
459 field.label = base::IntToString16(i); 467 field.label = base::IntToString16(i);
460 field.name = base::IntToString16(i); 468 field.name = base::IntToString16(i);
461 field.form_control_type = "text"; 469 field.form_control_type = "text";
462 form.fields.push_back(field); 470 form.fields.push_back(field);
463 } 471 }
464 FormStructure* form_structure = new FormStructure(form); 472 form_structures.push_back(base::MakeUnique<FormStructure>(form));
465 form_structures.push_back(form_structure);
466 } 473 }
467 474
468 // Check whether the query is aborted. 475 // Check whether the query is aborted.
469 EXPECT_FALSE(download_manager_.StartQueryRequest(form_structures.get())); 476 EXPECT_FALSE(
477 download_manager_.StartQueryRequest(ToRawPointerVector(form_structures)));
470 } 478 }
471 479
472 TEST_F(AutofillDownloadManagerTest, QueryNotTooManyFieldsTest) { 480 TEST_F(AutofillDownloadManagerTest, QueryNotTooManyFieldsTest) {
473 // Create and register factory. 481 // Create and register factory.
474 net::TestURLFetcherFactory factory; 482 net::TestURLFetcherFactory factory;
475 483
476 // Create a query that contains a lot of fields, but not too many for the 484 // Create a query that contains a lot of fields, but not too many for the
477 // server. 485 // server.
478 std::vector<FormData> forms(25); 486 std::vector<FormData> forms(25);
479 ScopedVector<FormStructure> form_structures; 487 std::vector<std::unique_ptr<FormStructure>> form_structures;
480 for (auto& form : forms) { 488 for (auto& form : forms) {
481 for (size_t i = 0; i < 4; ++i) { 489 for (size_t i = 0; i < 4; ++i) {
482 FormFieldData field; 490 FormFieldData field;
483 field.label = base::IntToString16(i); 491 field.label = base::IntToString16(i);
484 field.name = base::IntToString16(i); 492 field.name = base::IntToString16(i);
485 field.form_control_type = "text"; 493 field.form_control_type = "text";
486 form.fields.push_back(field); 494 form.fields.push_back(field);
487 } 495 }
488 FormStructure* form_structure = new FormStructure(form); 496 form_structures.push_back(base::MakeUnique<FormStructure>(form));
489 form_structures.push_back(form_structure);
490 } 497 }
491 498
492 // Check that the query is not aborted. 499 // Check that the query is not aborted.
493 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures.get())); 500 EXPECT_TRUE(
501 download_manager_.StartQueryRequest(ToRawPointerVector(form_structures)));
494 } 502 }
495 503
496 TEST_F(AutofillDownloadManagerTest, CacheQueryTest) { 504 TEST_F(AutofillDownloadManagerTest, CacheQueryTest) {
497 // Create and register factory. 505 // Create and register factory.
498 net::TestURLFetcherFactory factory; 506 net::TestURLFetcherFactory factory;
499 507
500 FormData form; 508 FormData form;
501 509
502 FormFieldData field; 510 FormFieldData field;
503 field.form_control_type = "text"; 511 field.form_control_type = "text";
504 512
505 field.label = ASCIIToUTF16("username"); 513 field.label = ASCIIToUTF16("username");
506 field.name = ASCIIToUTF16("username"); 514 field.name = ASCIIToUTF16("username");
507 form.fields.push_back(field); 515 form.fields.push_back(field);
508 516
509 field.label = ASCIIToUTF16("First Name"); 517 field.label = ASCIIToUTF16("First Name");
510 field.name = ASCIIToUTF16("firstname"); 518 field.name = ASCIIToUTF16("firstname");
511 form.fields.push_back(field); 519 form.fields.push_back(field);
512 520
513 field.label = ASCIIToUTF16("Last Name"); 521 field.label = ASCIIToUTF16("Last Name");
514 field.name = ASCIIToUTF16("lastname"); 522 field.name = ASCIIToUTF16("lastname");
515 form.fields.push_back(field); 523 form.fields.push_back(field);
516 524
517 FormStructure* form_structure = new FormStructure(form); 525 std::vector<std::unique_ptr<FormStructure>> form_structures0;
518 ScopedVector<FormStructure> form_structures0; 526 form_structures0.push_back(base::MakeUnique<FormStructure>(form));
519 form_structures0.push_back(form_structure);
520 527
521 // Add a slightly different form, which should result in a different request. 528 // Add a slightly different form, which should result in a different request.
522 field.label = ASCIIToUTF16("email"); 529 field.label = ASCIIToUTF16("email");
523 field.name = ASCIIToUTF16("email"); 530 field.name = ASCIIToUTF16("email");
524 form.fields.push_back(field); 531 form.fields.push_back(field);
525 form_structure = new FormStructure(form); 532 std::vector<std::unique_ptr<FormStructure>> form_structures1;
526 ScopedVector<FormStructure> form_structures1; 533 form_structures1.push_back(base::MakeUnique<FormStructure>(form));
527 form_structures1.push_back(form_structure);
528 534
529 // Add another slightly different form, which should also result in a 535 // Add another slightly different form, which should also result in a
530 // different request. 536 // different request.
531 field.label = ASCIIToUTF16("email2"); 537 field.label = ASCIIToUTF16("email2");
532 field.name = ASCIIToUTF16("email2"); 538 field.name = ASCIIToUTF16("email2");
533 form.fields.push_back(field); 539 form.fields.push_back(field);
534 form_structure = new FormStructure(form); 540 std::vector<std::unique_ptr<FormStructure>> form_structures2;
535 ScopedVector<FormStructure> form_structures2; 541 form_structures2.push_back(base::MakeUnique<FormStructure>(form));
536 form_structures2.push_back(form_structure);
537 542
538 // Limit cache to two forms. 543 // Limit cache to two forms.
539 LimitCache(2); 544 LimitCache(2);
540 545
541 const char *responses[] = { 546 const char *responses[] = {
542 "<autofillqueryresponse>" 547 "<autofillqueryresponse>"
543 "<field autofilltype=\"0\" />" 548 "<field autofilltype=\"0\" />"
544 "<field autofilltype=\"3\" />" 549 "<field autofilltype=\"3\" />"
545 "<field autofilltype=\"5\" />" 550 "<field autofilltype=\"5\" />"
546 "</autofillqueryresponse>", 551 "</autofillqueryresponse>",
547 "<autofillqueryresponse>" 552 "<autofillqueryresponse>"
548 "<field autofilltype=\"0\" />" 553 "<field autofilltype=\"0\" />"
549 "<field autofilltype=\"3\" />" 554 "<field autofilltype=\"3\" />"
550 "<field autofilltype=\"5\" />" 555 "<field autofilltype=\"5\" />"
551 "<field autofilltype=\"9\" />" 556 "<field autofilltype=\"9\" />"
552 "</autofillqueryresponse>", 557 "</autofillqueryresponse>",
553 "<autofillqueryresponse>" 558 "<autofillqueryresponse>"
554 "<field autofilltype=\"0\" />" 559 "<field autofilltype=\"0\" />"
555 "<field autofilltype=\"3\" />" 560 "<field autofilltype=\"3\" />"
556 "<field autofilltype=\"5\" />" 561 "<field autofilltype=\"5\" />"
557 "<field autofilltype=\"9\" />" 562 "<field autofilltype=\"9\" />"
558 "<field autofilltype=\"0\" />" 563 "<field autofilltype=\"0\" />"
559 "</autofillqueryresponse>", 564 "</autofillqueryresponse>",
560 }; 565 };
561 566
562 base::HistogramTester histogram; 567 base::HistogramTester histogram;
563 // Request with id 0. 568 // Request with id 0.
564 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures0.get())); 569 EXPECT_TRUE(download_manager_.StartQueryRequest(
570 ToRawPointerVector(form_structures0)));
565 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse", 571 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse",
566 AutofillMetrics::QUERY_SENT, 1); 572 AutofillMetrics::QUERY_SENT, 1);
567 573
568 // No responses yet 574 // No responses yet
569 EXPECT_EQ(0U, responses_.size()); 575 EXPECT_EQ(0U, responses_.size());
570 576
571 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 577 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
572 ASSERT_TRUE(fetcher); 578 ASSERT_TRUE(fetcher);
573 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0])); 579 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0]));
574 ASSERT_EQ(1U, responses_.size()); 580 ASSERT_EQ(1U, responses_.size());
575 EXPECT_EQ(responses[0], responses_.front().response); 581 EXPECT_EQ(responses[0], responses_.front().response);
576 582
577 responses_.clear(); 583 responses_.clear();
578 584
579 // No actual request - should be a cache hit. 585 // No actual request - should be a cache hit.
580 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures0.get())); 586 EXPECT_TRUE(download_manager_.StartQueryRequest(
587 ToRawPointerVector(form_structures0)));
581 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse", 588 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse",
582 AutofillMetrics::QUERY_SENT, 2); 589 AutofillMetrics::QUERY_SENT, 2);
583 // Data is available immediately from cache - no over-the-wire trip. 590 // Data is available immediately from cache - no over-the-wire trip.
584 ASSERT_EQ(1U, responses_.size()); 591 ASSERT_EQ(1U, responses_.size());
585 EXPECT_EQ(responses[0], responses_.front().response); 592 EXPECT_EQ(responses[0], responses_.front().response);
586 responses_.clear(); 593 responses_.clear();
587 594
588 // Request with id 1. 595 // Request with id 1.
589 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures1.get())); 596 EXPECT_TRUE(download_manager_.StartQueryRequest(
597 ToRawPointerVector(form_structures1)));
590 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse", 598 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse",
591 AutofillMetrics::QUERY_SENT, 3); 599 AutofillMetrics::QUERY_SENT, 3);
592 // No responses yet 600 // No responses yet
593 EXPECT_EQ(0U, responses_.size()); 601 EXPECT_EQ(0U, responses_.size());
594 602
595 fetcher = factory.GetFetcherByID(1); 603 fetcher = factory.GetFetcherByID(1);
596 ASSERT_TRUE(fetcher); 604 ASSERT_TRUE(fetcher);
597 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[1])); 605 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[1]));
598 ASSERT_EQ(1U, responses_.size()); 606 ASSERT_EQ(1U, responses_.size());
599 EXPECT_EQ(responses[1], responses_.front().response); 607 EXPECT_EQ(responses[1], responses_.front().response);
600 608
601 responses_.clear(); 609 responses_.clear();
602 610
603 // Request with id 2. 611 // Request with id 2.
604 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures2.get())); 612 EXPECT_TRUE(download_manager_.StartQueryRequest(
613 ToRawPointerVector(form_structures2)));
605 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse", 614 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse",
606 AutofillMetrics::QUERY_SENT, 4); 615 AutofillMetrics::QUERY_SENT, 4);
607 616
608 fetcher = factory.GetFetcherByID(2); 617 fetcher = factory.GetFetcherByID(2);
609 ASSERT_TRUE(fetcher); 618 ASSERT_TRUE(fetcher);
610 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[2])); 619 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[2]));
611 ASSERT_EQ(1U, responses_.size()); 620 ASSERT_EQ(1U, responses_.size());
612 EXPECT_EQ(responses[2], responses_.front().response); 621 EXPECT_EQ(responses[2], responses_.front().response);
613 622
614 responses_.clear(); 623 responses_.clear();
615 624
616 // No actual requests - should be a cache hit. 625 // No actual requests - should be a cache hit.
617 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures1.get())); 626 EXPECT_TRUE(download_manager_.StartQueryRequest(
627 ToRawPointerVector(form_structures1)));
618 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse", 628 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse",
619 AutofillMetrics::QUERY_SENT, 5); 629 AutofillMetrics::QUERY_SENT, 5);
620 630
621 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures2.get())); 631 EXPECT_TRUE(download_manager_.StartQueryRequest(
632 ToRawPointerVector(form_structures2)));
622 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse", 633 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse",
623 AutofillMetrics::QUERY_SENT, 6); 634 AutofillMetrics::QUERY_SENT, 6);
624 635
625 ASSERT_EQ(2U, responses_.size()); 636 ASSERT_EQ(2U, responses_.size());
626 EXPECT_EQ(responses[1], responses_.front().response); 637 EXPECT_EQ(responses[1], responses_.front().response);
627 EXPECT_EQ(responses[2], responses_.back().response); 638 EXPECT_EQ(responses[2], responses_.back().response);
628 responses_.clear(); 639 responses_.clear();
629 640
630 // The first structure should've expired. 641 // The first structure should've expired.
631 // Request with id 3. 642 // Request with id 3.
632 EXPECT_TRUE(download_manager_.StartQueryRequest(form_structures0.get())); 643 EXPECT_TRUE(download_manager_.StartQueryRequest(
644 ToRawPointerVector(form_structures0)));
633 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse", 645 histogram.ExpectUniqueSample("Autofill.ServerQueryResponse",
634 AutofillMetrics::QUERY_SENT, 7); 646 AutofillMetrics::QUERY_SENT, 7);
635 // No responses yet 647 // No responses yet
636 EXPECT_EQ(0U, responses_.size()); 648 EXPECT_EQ(0U, responses_.size());
637 649
638 fetcher = factory.GetFetcherByID(3); 650 fetcher = factory.GetFetcherByID(3);
639 ASSERT_TRUE(fetcher); 651 ASSERT_TRUE(fetcher);
640 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0])); 652 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0]));
641 ASSERT_EQ(1U, responses_.size()); 653 ASSERT_EQ(1U, responses_.size());
642 EXPECT_EQ(responses[0], responses_.front().response); 654 EXPECT_EQ(responses[0], responses_.front().response);
643 } 655 }
644 656
645 } // namespace autofill 657 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/address_field_unittest.cc ('k') | components/autofill/core/browser/autofill_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698