OLD | NEW |
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 <list> | 7 #include <list> |
8 | 8 |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 download_manager_(&driver_, prefs_.get(), this) { | 74 download_manager_(&driver_, prefs_.get(), this) { |
75 driver_.SetURLRequestContext(request_context_.get()); | 75 driver_.SetURLRequestContext(request_context_.get()); |
76 } | 76 } |
77 | 77 |
78 void LimitCache(size_t cache_size) { | 78 void LimitCache(size_t cache_size) { |
79 download_manager_.set_max_form_cache_size(cache_size); | 79 download_manager_.set_max_form_cache_size(cache_size); |
80 } | 80 } |
81 | 81 |
82 // AutofillDownloadManager::Observer implementation. | 82 // AutofillDownloadManager::Observer implementation. |
83 void OnLoadedServerPredictions( | 83 void OnLoadedServerPredictions( |
84 const std::string& response_xml, | 84 std::string response_xml, |
85 const std::vector<std::string>& form_signatures) override { | 85 const std::vector<std::string>& form_signatures) override { |
86 ResponseData response; | 86 ResponseData response; |
87 response.response = response_xml; | 87 response.response = std::move(response_xml); |
88 response.type_of_response = QUERY_SUCCESSFULL; | 88 response.type_of_response = QUERY_SUCCESSFULL; |
89 responses_.push_back(response); | 89 responses_.push_back(response); |
90 } | 90 } |
91 | 91 |
92 void OnUploadedPossibleFieldTypes() override { | 92 void OnUploadedPossibleFieldTypes() override { |
93 ResponseData response; | 93 ResponseData response; |
94 response.type_of_response = UPLOAD_SUCCESSFULL; | 94 response.type_of_response = UPLOAD_SUCCESSFULL; |
95 responses_.push_back(response); | 95 responses_.push_back(response); |
96 } | 96 } |
97 | 97 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 field.label = ASCIIToUTF16("password"); | 166 field.label = ASCIIToUTF16("password"); |
167 field.name = ASCIIToUTF16("password"); | 167 field.name = ASCIIToUTF16("password"); |
168 field.form_control_type = "password"; | 168 field.form_control_type = "password"; |
169 form.fields.push_back(field); | 169 form.fields.push_back(field); |
170 | 170 |
171 field.label = base::string16(); | 171 field.label = base::string16(); |
172 field.name = ASCIIToUTF16("Submit"); | 172 field.name = ASCIIToUTF16("Submit"); |
173 field.form_control_type = "submit"; | 173 field.form_control_type = "submit"; |
174 form.fields.push_back(field); | 174 form.fields.push_back(field); |
175 | 175 |
176 FormStructure *form_structure = new FormStructure(form); | 176 FormStructure* form_structure = new FormStructure(form); |
177 ScopedVector<FormStructure> form_structures; | 177 ScopedVector<FormStructure> form_structures; |
178 form_structures.push_back(form_structure); | 178 form_structures.push_back(form_structure); |
179 | 179 |
180 form.fields.clear(); | 180 form.fields.clear(); |
181 | 181 |
182 field.label = ASCIIToUTF16("address"); | 182 field.label = ASCIIToUTF16("address"); |
183 field.name = ASCIIToUTF16("address"); | 183 field.name = ASCIIToUTF16("address"); |
184 field.form_control_type = "text"; | 184 field.form_control_type = "text"; |
185 form.fields.push_back(field); | 185 form.fields.push_back(field); |
186 | 186 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 form.fields.push_back(field); | 424 form.fields.push_back(field); |
425 | 425 |
426 field.label = ASCIIToUTF16("First Name"); | 426 field.label = ASCIIToUTF16("First Name"); |
427 field.name = ASCIIToUTF16("firstname"); | 427 field.name = ASCIIToUTF16("firstname"); |
428 form.fields.push_back(field); | 428 form.fields.push_back(field); |
429 | 429 |
430 field.label = ASCIIToUTF16("Last Name"); | 430 field.label = ASCIIToUTF16("Last Name"); |
431 field.name = ASCIIToUTF16("lastname"); | 431 field.name = ASCIIToUTF16("lastname"); |
432 form.fields.push_back(field); | 432 form.fields.push_back(field); |
433 | 433 |
434 FormStructure *form_structure = new FormStructure(form); | 434 FormStructure* form_structure = new FormStructure(form); |
435 ScopedVector<FormStructure> form_structures0; | 435 ScopedVector<FormStructure> form_structures0; |
436 form_structures0.push_back(form_structure); | 436 form_structures0.push_back(form_structure); |
437 | 437 |
438 // Add a slightly different form, which should result in a different request. | 438 // Add a slightly different form, which should result in a different request. |
439 field.label = ASCIIToUTF16("email"); | 439 field.label = ASCIIToUTF16("email"); |
440 field.name = ASCIIToUTF16("email"); | 440 field.name = ASCIIToUTF16("email"); |
441 form.fields.push_back(field); | 441 form.fields.push_back(field); |
442 form_structure = new FormStructure(form); | 442 form_structure = new FormStructure(form); |
443 ScopedVector<FormStructure> form_structures1; | 443 ScopedVector<FormStructure> form_structures1; |
444 form_structures1.push_back(form_structure); | 444 form_structures1.push_back(form_structure); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 fetcher = factory.GetFetcherByID(3); | 555 fetcher = factory.GetFetcherByID(3); |
556 ASSERT_TRUE(fetcher); | 556 ASSERT_TRUE(fetcher); |
557 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0])); | 557 FakeOnURLFetchComplete(fetcher, 200, std::string(responses[0])); |
558 ASSERT_EQ(1U, responses_.size()); | 558 ASSERT_EQ(1U, responses_.size()); |
559 EXPECT_EQ(responses[0], responses_.front().response); | 559 EXPECT_EQ(responses[0], responses_.front().response); |
560 } | 560 } |
561 | 561 |
562 TEST_F(AutofillDownloadTest, QueryRequestIsGzipped) { | 562 TEST_F(AutofillDownloadTest, QueryRequestIsGzipped) { |
563 // Expected query (uncompressed for visual verification). | 563 // Expected query (uncompressed for visual verification). |
564 const char* kExpectedQueryXml = | 564 const char* kExpectedQueryXml = |
565 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 565 "<?xml version=\"1.0\"?>\n" |
566 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" | 566 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
567 "<form signature=\"14546501144368603154\">" | 567 "<form signature=\"14546501144368603154\">" |
568 "<field signature=\"239111655\"/>" | 568 "<field signature=\"239111655\"/>" |
569 "<field signature=\"3763331450\"/>" | 569 "<field signature=\"3763331450\"/>" |
570 "<field signature=\"3494530716\"/>" | 570 "<field signature=\"3494530716\"/>" |
571 "</form></autofillquery>"; | 571 "</form></autofillquery>\n"; |
572 | 572 |
573 // Create and register factory. | 573 // Create and register factory. |
574 net::TestURLFetcherFactory factory; | 574 net::TestURLFetcherFactory factory; |
575 | 575 |
576 FormData form; | 576 FormData form; |
577 | 577 |
578 FormFieldData field; | 578 FormFieldData field; |
579 field.form_control_type = "text"; | 579 field.form_control_type = "text"; |
580 | 580 |
581 field.label = ASCIIToUTF16("username"); | 581 field.label = ASCIIToUTF16("username"); |
(...skipping 24 matching lines...) Expand all Loading... |
606 EXPECT_EQ(Compress(kExpectedQueryXml), fetcher->upload_data()); | 606 EXPECT_EQ(Compress(kExpectedQueryXml), fetcher->upload_data()); |
607 | 607 |
608 // Proper content-encoding header is defined. | 608 // Proper content-encoding header is defined. |
609 net::HttpRequestHeaders headers; | 609 net::HttpRequestHeaders headers; |
610 fetcher->GetExtraRequestHeaders(&headers); | 610 fetcher->GetExtraRequestHeaders(&headers); |
611 std::string header; | 611 std::string header; |
612 EXPECT_TRUE(headers.GetHeader("content-encoding", &header)); | 612 EXPECT_TRUE(headers.GetHeader("content-encoding", &header)); |
613 EXPECT_EQ("gzip", header); | 613 EXPECT_EQ("gzip", header); |
614 | 614 |
615 // Expect that the compression is logged. | 615 // Expect that the compression is logged. |
616 histogram.ExpectUniqueSample("Autofill.PayloadCompressionRatio.Query", 73, 1); | 616 histogram.ExpectUniqueSample("Autofill.PayloadCompressionRatio.Query", 72, 1); |
617 } | 617 } |
618 | 618 |
619 TEST_F(AutofillDownloadTest, UploadRequestIsGzipped) { | 619 TEST_F(AutofillDownloadTest, UploadRequestIsGzipped) { |
620 // Expected upload (uncompressed for visual verification). | 620 // Expected upload (uncompressed for visual verification). |
621 const char* kExpectedUploadXml = | 621 const char* kExpectedUploadXml = |
622 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 622 "<?xml version=\"1.0\"?>\n" |
623 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" | 623 "<autofillupload clientversion=\"6.1.1715.1442/en (GGLL)\"" |
624 " formsignature=\"14546501144368603154\" autofillused=\"true\"" | 624 " formsignature=\"14546501144368603154\" autofillused=\"true\"" |
625 " datapresent=\"\"/>"; | 625 " datapresent=\"\"/>\n"; |
626 | 626 |
627 // Create and register factory. | 627 // Create and register factory. |
628 net::TestURLFetcherFactory factory; | 628 net::TestURLFetcherFactory factory; |
629 | 629 |
630 FormData form; | 630 FormData form; |
631 | 631 |
632 FormFieldData field; | 632 FormFieldData field; |
633 field.form_control_type = "text"; | 633 field.form_control_type = "text"; |
634 | 634 |
635 field.label = ASCIIToUTF16("username"); | 635 field.label = ASCIIToUTF16("username"); |
(...skipping 27 matching lines...) Expand all Loading... |
663 EXPECT_EQ(Compress(kExpectedUploadXml), fetcher->upload_data()); | 663 EXPECT_EQ(Compress(kExpectedUploadXml), fetcher->upload_data()); |
664 | 664 |
665 // Proper content-encoding header is defined. | 665 // Proper content-encoding header is defined. |
666 net::HttpRequestHeaders headers; | 666 net::HttpRequestHeaders headers; |
667 fetcher->GetExtraRequestHeaders(&headers); | 667 fetcher->GetExtraRequestHeaders(&headers); |
668 std::string header; | 668 std::string header; |
669 EXPECT_TRUE(headers.GetHeader("content-encoding", &header)); | 669 EXPECT_TRUE(headers.GetHeader("content-encoding", &header)); |
670 EXPECT_EQ("gzip", header); | 670 EXPECT_EQ("gzip", header); |
671 | 671 |
672 // Expect that the compression is logged. | 672 // Expect that the compression is logged. |
673 histogram.ExpectUniqueSample("Autofill.PayloadCompressionRatio.Upload", 92, | 673 histogram.ExpectUniqueSample("Autofill.PayloadCompressionRatio.Upload", 95, |
674 1); | 674 1); |
675 } | 675 } |
676 | 676 |
677 } // namespace autofill | 677 } // namespace autofill |
OLD | NEW |