| OLD | NEW |
| 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 "components/autofill/core/browser/autofill_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 | 567 |
| 568 // Resets the run loop so that it can wait for an asynchronous form | 568 // Resets the run loop so that it can wait for an asynchronous form |
| 569 // submission to complete. | 569 // submission to complete. |
| 570 void ResetRunLoop() { run_loop_.reset(new base::RunLoop()); } | 570 void ResetRunLoop() { run_loop_.reset(new base::RunLoop()); } |
| 571 | 571 |
| 572 // Wait for the asynchronous calls within StartUploadProcess() to complete. | 572 // Wait for the asynchronous calls within StartUploadProcess() to complete. |
| 573 void WaitForAsyncUploadProcess() { run_loop_->Run(); } | 573 void WaitForAsyncUploadProcess() { run_loop_->Run(); } |
| 574 | 574 |
| 575 void UploadFormData(const FormStructure& submitted_form, | 575 void UploadFormData(const FormStructure& submitted_form, |
| 576 bool observed_submission) override { | 576 bool observed_submission) override { |
| 577 submitted_form_signature_ = submitted_form.FormSignature(); | 577 submitted_form_signature_ = submitted_form.FormSignatureAsStr(); |
| 578 } | 578 } |
| 579 | 579 |
| 580 const std::string GetSubmittedFormSignature() { | 580 const std::string GetSubmittedFormSignature() { |
| 581 return submitted_form_signature_; | 581 return submitted_form_signature_; |
| 582 } | 582 } |
| 583 | 583 |
| 584 AutofillProfile* GetProfileWithGUID(const char* guid) { | 584 AutofillProfile* GetProfileWithGUID(const char* guid) { |
| 585 return personal_data_->GetProfileWithGUID(guid); | 585 return personal_data_->GetProfileWithGUID(guid); |
| 586 } | 586 } |
| 587 | 587 |
| (...skipping 2654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3242 response.add_field()->set_autofill_type(2); | 3242 response.add_field()->set_autofill_type(2); |
| 3243 response.add_field()->set_autofill_type(61); | 3243 response.add_field()->set_autofill_type(61); |
| 3244 response.add_field()->set_autofill_type(5); | 3244 response.add_field()->set_autofill_type(5); |
| 3245 response.add_field()->set_autofill_type(4); | 3245 response.add_field()->set_autofill_type(4); |
| 3246 response.add_field()->set_autofill_type(35); | 3246 response.add_field()->set_autofill_type(35); |
| 3247 | 3247 |
| 3248 std::string response_string; | 3248 std::string response_string; |
| 3249 ASSERT_TRUE(response.SerializeToString(&response_string)); | 3249 ASSERT_TRUE(response.SerializeToString(&response_string)); |
| 3250 | 3250 |
| 3251 std::vector<std::string> signatures; | 3251 std::vector<std::string> signatures; |
| 3252 signatures.push_back(form_structure->FormSignature()); | 3252 signatures.push_back(form_structure->FormSignatureAsStr()); |
| 3253 signatures.push_back(form_structure2->FormSignature()); | 3253 signatures.push_back(form_structure2->FormSignatureAsStr()); |
| 3254 | 3254 |
| 3255 base::HistogramTester histogram_tester; | 3255 base::HistogramTester histogram_tester; |
| 3256 autofill_manager_->OnLoadedServerPredictions(response_string, signatures); | 3256 autofill_manager_->OnLoadedServerPredictions(response_string, signatures); |
| 3257 // Verify that FormStructure::ParseQueryResponse was called (here and below). | 3257 // Verify that FormStructure::ParseQueryResponse was called (here and below). |
| 3258 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", | 3258 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", |
| 3259 AutofillMetrics::QUERY_RESPONSE_RECEIVED, | 3259 AutofillMetrics::QUERY_RESPONSE_RECEIVED, |
| 3260 1); | 3260 1); |
| 3261 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", | 3261 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", |
| 3262 AutofillMetrics::QUERY_RESPONSE_PARSED, | 3262 AutofillMetrics::QUERY_RESPONSE_PARSED, |
| 3263 1); | 3263 1); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3292 response.add_field()->set_autofill_type(0); | 3292 response.add_field()->set_autofill_type(0); |
| 3293 } | 3293 } |
| 3294 response.add_field()->set_autofill_type(3); | 3294 response.add_field()->set_autofill_type(3); |
| 3295 response.add_field()->set_autofill_type(2); | 3295 response.add_field()->set_autofill_type(2); |
| 3296 response.add_field()->set_autofill_type(61); | 3296 response.add_field()->set_autofill_type(61); |
| 3297 | 3297 |
| 3298 std::string response_string; | 3298 std::string response_string; |
| 3299 ASSERT_TRUE(response.SerializeToString(&response_string)); | 3299 ASSERT_TRUE(response.SerializeToString(&response_string)); |
| 3300 | 3300 |
| 3301 std::vector<std::string> signatures; | 3301 std::vector<std::string> signatures; |
| 3302 signatures.push_back(form_structure->FormSignature()); | 3302 signatures.push_back(form_structure->FormSignatureAsStr()); |
| 3303 | 3303 |
| 3304 // Reset the manager (such as during a navigation). | 3304 // Reset the manager (such as during a navigation). |
| 3305 autofill_manager_->Reset(); | 3305 autofill_manager_->Reset(); |
| 3306 | 3306 |
| 3307 base::HistogramTester histogram_tester; | 3307 base::HistogramTester histogram_tester; |
| 3308 autofill_manager_->OnLoadedServerPredictions(response_string, signatures); | 3308 autofill_manager_->OnLoadedServerPredictions(response_string, signatures); |
| 3309 | 3309 |
| 3310 // Verify that FormStructure::ParseQueryResponse was NOT called. | 3310 // Verify that FormStructure::ParseQueryResponse was NOT called. |
| 3311 histogram_tester.ExpectTotalCount("Autofill.ServerQueryResponse", 0); | 3311 histogram_tester.ExpectTotalCount("Autofill.ServerQueryResponse", 0); |
| 3312 } | 3312 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3394 // Test that the form signature for an uploaded form always matches the form | 3394 // Test that the form signature for an uploaded form always matches the form |
| 3395 // signature from the query. | 3395 // signature from the query. |
| 3396 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) { | 3396 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) { |
| 3397 // Set up our form data. | 3397 // Set up our form data. |
| 3398 FormData form; | 3398 FormData form; |
| 3399 test::CreateTestAddressFormData(&form); | 3399 test::CreateTestAddressFormData(&form); |
| 3400 std::vector<FormData> forms(1, form); | 3400 std::vector<FormData> forms(1, form); |
| 3401 FormsSeen(forms); | 3401 FormsSeen(forms); |
| 3402 | 3402 |
| 3403 // Cache the expected form signature. | 3403 // Cache the expected form signature. |
| 3404 std::string signature = FormStructure(form).FormSignature(); | 3404 std::string signature = FormStructure(form).FormSignatureAsStr(); |
| 3405 | 3405 |
| 3406 // Change the structure of the form prior to submission. | 3406 // Change the structure of the form prior to submission. |
| 3407 // Websites would typically invoke JavaScript either on page load or on form | 3407 // Websites would typically invoke JavaScript either on page load or on form |
| 3408 // submit to achieve this. | 3408 // submit to achieve this. |
| 3409 form.fields.pop_back(); | 3409 form.fields.pop_back(); |
| 3410 FormFieldData field = form.fields[3]; | 3410 FormFieldData field = form.fields[3]; |
| 3411 form.fields[3] = form.fields[7]; | 3411 form.fields[3] = form.fields[7]; |
| 3412 form.fields[7] = field; | 3412 form.fields[7] = field; |
| 3413 | 3413 |
| 3414 // Simulate form submission. | 3414 // Simulate form submission. |
| (...skipping 1798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5213 FormsSeen(mixed_forms); | 5213 FormsSeen(mixed_forms); |
| 5214 | 5214 |
| 5215 // Suggestions should always be displayed. | 5215 // Suggestions should always be displayed. |
| 5216 for (const FormFieldData& field : mixed_form.fields) { | 5216 for (const FormFieldData& field : mixed_form.fields) { |
| 5217 GetAutofillSuggestions(mixed_form, field); | 5217 GetAutofillSuggestions(mixed_form, field); |
| 5218 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); | 5218 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 5219 } | 5219 } |
| 5220 } | 5220 } |
| 5221 | 5221 |
| 5222 } // namespace autofill | 5222 } // namespace autofill |
| OLD | NEW |