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

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

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

Powered by Google App Engine
This is Rietveld 408576698