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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 | 605 |
606 WebFrame* web_frame = GetMainFrame(); | 606 WebFrame* web_frame = GetMainFrame(); |
607 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 607 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
608 | 608 |
609 FormCache form_cache; | 609 FormCache form_cache; |
610 std::vector<FormData> forms; | 610 std::vector<FormData> forms; |
611 form_cache.ExtractForms(*web_frame, &forms); | 611 form_cache.ExtractForms(*web_frame, &forms); |
612 EXPECT_EQ(0U, forms.size()); | 612 EXPECT_EQ(0U, forms.size()); |
613 } | 613 } |
614 | 614 |
| 615 // We should not report additional forms for empty forms. |
| 616 TEST_F(FormAutofillTest, ExtractFormsSkippedForms) { |
| 617 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 618 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 619 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 620 "</FORM>"); |
| 621 |
| 622 WebFrame* web_frame = GetMainFrame(); |
| 623 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 624 |
| 625 FormCache form_cache; |
| 626 std::vector<FormData> forms; |
| 627 bool has_skipped_forms = form_cache.ExtractFormsAndFormElements(*web_frame, |
| 628 3, |
| 629 &forms, |
| 630 NULL); |
| 631 EXPECT_EQ(0U, forms.size()); |
| 632 EXPECT_TRUE(has_skipped_forms); |
| 633 } |
| 634 |
| 635 // We should not report additional forms for empty forms. |
| 636 TEST_F(FormAutofillTest, ExtractFormsNoFields) { |
| 637 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 638 "</FORM>"); |
| 639 |
| 640 WebFrame* web_frame = GetMainFrame(); |
| 641 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 642 |
| 643 FormCache form_cache; |
| 644 std::vector<FormData> forms; |
| 645 bool has_skipped_forms = form_cache.ExtractFormsAndFormElements(*web_frame, |
| 646 3, |
| 647 &forms, |
| 648 NULL); |
| 649 EXPECT_EQ(0U, forms.size()); |
| 650 EXPECT_FALSE(has_skipped_forms); |
| 651 } |
| 652 |
615 // We should not extract a form if it has too few fillable fields. | 653 // We should not extract a form if it has too few fillable fields. |
616 // Make sure radio and checkbox fields don't count. | 654 // Make sure radio and checkbox fields don't count. |
617 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) { | 655 TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) { |
618 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 656 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
619 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 657 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
620 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 658 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
621 " <INPUT type=\"radio\" id=\"a_radio\" value=\"0\"/>" | 659 " <INPUT type=\"radio\" id=\"a_radio\" value=\"0\"/>" |
622 " <INPUT type=\"checkbox\" id=\"a_check\" value=\"1\"/>" | 660 " <INPUT type=\"checkbox\" id=\"a_check\" value=\"1\"/>" |
623 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 661 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
624 "</FORM>"); | 662 "</FORM>"); |
(...skipping 2432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3057 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3095 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
3058 | 3096 |
3059 expected.name = ASCIIToUTF16("country"); | 3097 expected.name = ASCIIToUTF16("country"); |
3060 expected.value = ASCIIToUTF16("AL"); | 3098 expected.value = ASCIIToUTF16("AL"); |
3061 expected.form_control_type = "select-one"; | 3099 expected.form_control_type = "select-one"; |
3062 expected.max_length = 0; | 3100 expected.max_length = 0; |
3063 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3101 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
3064 } | 3102 } |
3065 | 3103 |
3066 } // namespace autofill | 3104 } // namespace autofill |
OLD | NEW |