| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" |
| 11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/test/base/chrome_render_view_test.h" | 15 #include "chrome/test/base/chrome_render_view_test.h" |
| 15 #include "components/autofill/content/renderer/form_autofill_util.h" | 16 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 16 #include "components/autofill/content/renderer/form_cache.h" | 17 #include "components/autofill/content/renderer/form_cache.h" |
| 17 #include "components/autofill/core/common/autofill_data_validation.h" | 18 #include "components/autofill/core/common/autofill_data_validation.h" |
| 18 #include "components/autofill/core/common/form_data.h" | 19 #include "components/autofill/core/common/form_data.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "third_party/WebKit/public/platform/WebString.h" | 21 #include "third_party/WebKit/public/platform/WebString.h" |
| (...skipping 2443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2464 forms = form_cache.ExtractNewForms(); | 2465 forms = form_cache.ExtractNewForms(); |
| 2465 ASSERT_TRUE(forms.empty()); | 2466 ASSERT_TRUE(forms.empty()); |
| 2466 | 2467 |
| 2467 // Append to the current form will re-extract. | 2468 // Append to the current form will re-extract. |
| 2468 ExecuteJavaScriptForTests( | 2469 ExecuteJavaScriptForTests( |
| 2469 "var newInput = document.createElement('input');" | 2470 "var newInput = document.createElement('input');" |
| 2470 "newInput.setAttribute('type', 'text');" | 2471 "newInput.setAttribute('type', 'text');" |
| 2471 "newInput.setAttribute('id', 'telephone');" | 2472 "newInput.setAttribute('id', 'telephone');" |
| 2472 "newInput.value = '12345';" | 2473 "newInput.value = '12345';" |
| 2473 "document.getElementById('testform').appendChild(newInput);"); | 2474 "document.getElementById('testform').appendChild(newInput);"); |
| 2474 msg_loop_.RunUntilIdle(); | 2475 base::RunLoop().RunUntilIdle(); |
| 2475 | 2476 |
| 2476 forms = form_cache.ExtractNewForms(); | 2477 forms = form_cache.ExtractNewForms(); |
| 2477 ASSERT_EQ(1U, forms.size()); | 2478 ASSERT_EQ(1U, forms.size()); |
| 2478 | 2479 |
| 2479 const std::vector<FormFieldData>& fields = forms[0].fields; | 2480 const std::vector<FormFieldData>& fields = forms[0].fields; |
| 2480 ASSERT_EQ(4U, fields.size()); | 2481 ASSERT_EQ(4U, fields.size()); |
| 2481 | 2482 |
| 2482 FormFieldData expected; | 2483 FormFieldData expected; |
| 2483 expected.form_control_type = "text"; | 2484 expected.form_control_type = "text"; |
| 2484 expected.max_length = WebInputElement::defaultMaxLength(); | 2485 expected.max_length = WebInputElement::defaultMaxLength(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2520 "newLastname.setAttribute('id', 'second_lastname');" | 2521 "newLastname.setAttribute('id', 'second_lastname');" |
| 2521 "newLastname.value = 'Hope';" | 2522 "newLastname.value = 'Hope';" |
| 2522 "var newEmail=document.createElement('input');" | 2523 "var newEmail=document.createElement('input');" |
| 2523 "newEmail.setAttribute('type', 'text');" | 2524 "newEmail.setAttribute('type', 'text');" |
| 2524 "newEmail.setAttribute('id', 'second_email');" | 2525 "newEmail.setAttribute('id', 'second_email');" |
| 2525 "newEmail.value = 'bobhope@example.com';" | 2526 "newEmail.value = 'bobhope@example.com';" |
| 2526 "newForm.appendChild(newFirstname);" | 2527 "newForm.appendChild(newFirstname);" |
| 2527 "newForm.appendChild(newLastname);" | 2528 "newForm.appendChild(newLastname);" |
| 2528 "newForm.appendChild(newEmail);" | 2529 "newForm.appendChild(newEmail);" |
| 2529 "document.body.appendChild(newForm);"); | 2530 "document.body.appendChild(newForm);"); |
| 2530 msg_loop_.RunUntilIdle(); | 2531 base::RunLoop().RunUntilIdle(); |
| 2531 | 2532 |
| 2532 web_frame = GetMainFrame(); | 2533 web_frame = GetMainFrame(); |
| 2533 forms = form_cache.ExtractNewForms(); | 2534 forms = form_cache.ExtractNewForms(); |
| 2534 ASSERT_EQ(1U, forms.size()); | 2535 ASSERT_EQ(1U, forms.size()); |
| 2535 | 2536 |
| 2536 const std::vector<FormFieldData>& fields2 = forms[0].fields; | 2537 const std::vector<FormFieldData>& fields2 = forms[0].fields; |
| 2537 ASSERT_EQ(3U, fields2.size()); | 2538 ASSERT_EQ(3U, fields2.size()); |
| 2538 | 2539 |
| 2539 expected.name = ASCIIToUTF16("second_firstname"); | 2540 expected.name = ASCIIToUTF16("second_firstname"); |
| 2540 expected.value = ASCIIToUTF16("Bob"); | 2541 expected.value = ASCIIToUTF16("Bob"); |
| (...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4607 | 4608 |
| 4608 if (test_case.has_extracted_form) { | 4609 if (test_case.has_extracted_form) { |
| 4609 EXPECT_EQ(test_case.is_form_tag, forms[0].is_form_tag); | 4610 EXPECT_EQ(test_case.is_form_tag, forms[0].is_form_tag); |
| 4610 EXPECT_EQ(test_case.is_formless_checkout, forms[0].is_formless_checkout); | 4611 EXPECT_EQ(test_case.is_formless_checkout, forms[0].is_formless_checkout); |
| 4611 } | 4612 } |
| 4612 } | 4613 } |
| 4613 } | 4614 } |
| 4614 | 4615 |
| 4615 } // namespace form_util | 4616 } // namespace form_util |
| 4616 } // namespace autofill | 4617 } // namespace autofill |
| OLD | NEW |