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/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2830 expected.value = ASCIIToUTF16("?"); | 2830 expected.value = ASCIIToUTF16("?"); |
2831 expected.form_control_type = "select-one"; | 2831 expected.form_control_type = "select-one"; |
2832 expected.max_length = 0; | 2832 expected.max_length = 0; |
2833 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 2833 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
2834 | 2834 |
2835 // Verify that the cursor position has been updated. | 2835 // Verify that the cursor position has been updated. |
2836 EXPECT_EQ(0, firstname.selectionStart()); | 2836 EXPECT_EQ(0, firstname.selectionStart()); |
2837 EXPECT_EQ(0, firstname.selectionEnd()); | 2837 EXPECT_EQ(0, firstname.selectionEnd()); |
2838 } | 2838 } |
2839 | 2839 |
2840 TEST_F(FormAutofillTest, ClearPreviewedPassword) { | |
2841 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | |
2842 " <INPUT type=\"text\" id=\"username\" value=\"Wyatt\"/>" | |
2843 " <INPUT type=\"password\" id=\"password\" autocomplete=\"off\"/>" | |
2844 " <INPUT type=\"submit\" value=\"Send\"/>" | |
2845 "</FORM>"); | |
2846 | |
2847 WebFrame* web_frame = GetMainFrame(); | |
2848 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | |
2849 | |
2850 // Set the auto-filled attribute. | |
2851 WebInputElement username = | |
2852 web_frame->document().getElementById("username").to<WebInputElement>(); | |
2853 username.setAutofilled(true); | |
2854 WebInputElement password = | |
2855 web_frame->document().getElementById("password").to<WebInputElement>(); | |
2856 password.setAutofilled(true); | |
2857 | |
2858 // Set the suggested values on password. | |
2859 password.setSuggestedValue(ASCIIToUTF16("SuggestedPassword")); | |
2860 | |
2861 // Clear the previewed fields. | |
2862 EXPECT_TRUE(ClearPreviewedFormWithElement(password, REQUIRE_NONE, false, | |
2863 true)); | |
2864 | |
2865 // Fields with empty suggestions are not modified. | |
2866 EXPECT_EQ(ASCIIToUTF16("Wyatt"), username.value()); | |
2867 EXPECT_TRUE(username.suggestedValue().isEmpty()); | |
2868 EXPECT_TRUE(username.isAutofilled()); | |
2869 | |
2870 // Verify the previewed fields are cleared. | |
2871 EXPECT_TRUE(password.value().isEmpty()); | |
2872 EXPECT_TRUE(password.suggestedValue().isEmpty()); | |
2873 EXPECT_FALSE(password.isAutofilled()); | |
Ilya Sherman
2014/03/21 22:35:19
Hmm, why is the password field no longer autofille
ziran.sun
2014/03/25 18:25:26
You are right. There is an error in the test code.
Ilya Sherman
2014/03/25 19:45:27
Yes, I do mean that we should test the renderer co
| |
2874 } | |
2875 | |
2840 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { | 2876 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { |
2841 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2877 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
2842 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 2878 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
2843 " <INPUT type=\"text\" id=\"lastname\"/>" | 2879 " <INPUT type=\"text\" id=\"lastname\"/>" |
2844 " <INPUT type=\"text\" id=\"email\"/>" | 2880 " <INPUT type=\"text\" id=\"email\"/>" |
2845 " <INPUT type=\"email\" id=\"email2\"/>" | 2881 " <INPUT type=\"email\" id=\"email2\"/>" |
2846 " <INPUT type=\"tel\" id=\"phone\"/>" | 2882 " <INPUT type=\"tel\" id=\"phone\"/>" |
2847 " <INPUT type=\"submit\" value=\"Send\"/>" | 2883 " <INPUT type=\"submit\" value=\"Send\"/>" |
2848 "</FORM>"); | 2884 "</FORM>"); |
2849 | 2885 |
(...skipping 22 matching lines...) Expand all Loading... | |
2872 web_frame->document().getElementById("phone").to<WebInputElement>(); | 2908 web_frame->document().getElementById("phone").to<WebInputElement>(); |
2873 phone.setAutofilled(true); | 2909 phone.setAutofilled(true); |
2874 | 2910 |
2875 // Set the suggested values on two of the elements. | 2911 // Set the suggested values on two of the elements. |
2876 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | 2912 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
2877 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 2913 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
2878 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 2914 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
2879 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | 2915 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
2880 | 2916 |
2881 // Clear the previewed fields. | 2917 // Clear the previewed fields. |
2882 EXPECT_TRUE(ClearPreviewedFormWithElement(lastname, false)); | 2918 EXPECT_TRUE(ClearPreviewedFormWithElement(lastname, REQUIRE_AUTOCOMPLETE, |
2919 false, false)); | |
2883 | 2920 |
2884 // Fields with empty suggestions suggestions are not modified. | 2921 // Fields with empty suggestions suggestions are not modified. |
2885 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); | 2922 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); |
2886 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | 2923 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
2887 EXPECT_TRUE(firstname.isAutofilled()); | 2924 EXPECT_TRUE(firstname.isAutofilled()); |
2888 | 2925 |
2889 // Verify the previewed fields are cleared. | 2926 // Verify the previewed fields are cleared. |
2890 EXPECT_TRUE(lastname.value().isEmpty()); | 2927 EXPECT_TRUE(lastname.value().isEmpty()); |
2891 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); | 2928 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); |
2892 EXPECT_FALSE(lastname.isAutofilled()); | 2929 EXPECT_FALSE(lastname.isAutofilled()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2942 | 2979 |
2943 | 2980 |
2944 // Set the suggested values on all of the elements. | 2981 // Set the suggested values on all of the elements. |
2945 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); | 2982 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
2946 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | 2983 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
2947 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 2984 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
2948 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 2985 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
2949 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | 2986 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
2950 | 2987 |
2951 // Clear the previewed fields. | 2988 // Clear the previewed fields. |
2952 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, false)); | 2989 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, REQUIRE_AUTOCOMPLETE, |
2990 false, false)); | |
2953 | 2991 |
2954 // Fields with non-empty values are restored. | 2992 // Fields with non-empty values are restored. |
2955 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); | 2993 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); |
2956 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | 2994 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
2957 EXPECT_FALSE(firstname.isAutofilled()); | 2995 EXPECT_FALSE(firstname.isAutofilled()); |
2958 EXPECT_EQ(1, firstname.selectionStart()); | 2996 EXPECT_EQ(1, firstname.selectionStart()); |
2959 EXPECT_EQ(1, firstname.selectionEnd()); | 2997 EXPECT_EQ(1, firstname.selectionEnd()); |
2960 | 2998 |
2961 // Verify the previewed fields are cleared. | 2999 // Verify the previewed fields are cleared. |
2962 EXPECT_TRUE(lastname.value().isEmpty()); | 3000 EXPECT_TRUE(lastname.value().isEmpty()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3009 phone.setAutofilled(true); | 3047 phone.setAutofilled(true); |
3010 | 3048 |
3011 // Set the suggested values on all of the elements. | 3049 // Set the suggested values on all of the elements. |
3012 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); | 3050 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
3013 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | 3051 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
3014 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3052 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3015 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3053 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3016 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | 3054 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
3017 | 3055 |
3018 // Clear the previewed fields. | 3056 // Clear the previewed fields. |
3019 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, true)); | 3057 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, REQUIRE_AUTOCOMPLETE, |
3058 true, false)); | |
3020 | 3059 |
3021 // Fields with non-empty values are restored. | 3060 // Fields with non-empty values are restored. |
3022 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); | 3061 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); |
3023 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | 3062 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
3024 EXPECT_TRUE(firstname.isAutofilled()); | 3063 EXPECT_TRUE(firstname.isAutofilled()); |
3025 EXPECT_EQ(1, firstname.selectionStart()); | 3064 EXPECT_EQ(1, firstname.selectionStart()); |
3026 EXPECT_EQ(1, firstname.selectionEnd()); | 3065 EXPECT_EQ(1, firstname.selectionEnd()); |
3027 | 3066 |
3028 // Verify the previewed fields are cleared. | 3067 // Verify the previewed fields are cleared. |
3029 EXPECT_TRUE(lastname.value().isEmpty()); | 3068 EXPECT_TRUE(lastname.value().isEmpty()); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3214 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3253 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
3215 | 3254 |
3216 expected.name = ASCIIToUTF16("country"); | 3255 expected.name = ASCIIToUTF16("country"); |
3217 expected.value = ASCIIToUTF16("AL"); | 3256 expected.value = ASCIIToUTF16("AL"); |
3218 expected.form_control_type = "select-one"; | 3257 expected.form_control_type = "select-one"; |
3219 expected.max_length = 0; | 3258 expected.max_length = 0; |
3220 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3259 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
3221 } | 3260 } |
3222 | 3261 |
3223 } // namespace autofill | 3262 } // namespace autofill |
OLD | NEW |