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

Side by Side Diff: chrome/renderer/autofill/form_autofill_browsertest.cc

Issue 208453002: Add "previewing on hover" support for password field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update code as per Ilya's comment. Created 6 years, 9 months 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 (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
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, ClearPreviewedPasswordWithPasswordAutofilled) {
2841 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2842 " <INPUT type=\"text\" id=\"username\"/>"
2843 " <INPUT type=\"password\" id=\"password\" value=\"s\"/>"
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 username.setSuggestedValue(ASCIIToUTF16("Wyatt"));
2859 password.setSuggestedValue(ASCIIToUTF16("secret"));
2860
2861 EXPECT_TRUE(ClearPreviewedFormWithElement(username, REQUIRE_NONE, false,
2862 true));
2863
2864 EXPECT_TRUE(username.value().isEmpty());
2865 EXPECT_TRUE(username.suggestedValue().isEmpty());
2866 EXPECT_FALSE(username.isAutofilled());
2867
2868 EXPECT_EQ(ASCIIToUTF16("s"), password.value());
2869 EXPECT_TRUE(password.suggestedValue().isEmpty());
2870 EXPECT_TRUE(password.isAutofilled());
2871 }
2872
2873 TEST_F(FormAutofillTest, ClearPreviewedPasswordWithUserNameAutofilled) {
2874 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2875 " <INPUT type=\"text\" id=\"username\" value=\"W\"/>"
2876 " <INPUT type=\"password\" id=\"password\"/>"
2877 " <INPUT type=\"submit\" value=\"Send\"/>"
2878 "</FORM>");
2879
2880 WebFrame* web_frame = GetMainFrame();
2881 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2882
2883 WebInputElement username =
2884 web_frame->document().getElementById("username").to<WebInputElement>();
2885 username.setAutofilled(true);
2886 WebInputElement password =
2887 web_frame->document().getElementById("password").to<WebInputElement>();
2888 password.setAutofilled(true);
2889
2890 username.setSuggestedValue(ASCIIToUTF16("Wyatt"));
2891 password.setSuggestedValue(ASCIIToUTF16("secret"));
2892
2893 EXPECT_TRUE(ClearPreviewedFormWithElement(username, REQUIRE_NONE, true,
2894 false));
2895
2896 EXPECT_EQ(ASCIIToUTF16("W"), username.value());
2897 EXPECT_TRUE(username.suggestedValue().isEmpty());
2898 EXPECT_TRUE(username.isAutofilled());
2899
2900 EXPECT_TRUE(password.value().isEmpty());
2901 EXPECT_TRUE(password.suggestedValue().isEmpty());
2902 EXPECT_FALSE(password.isAutofilled());
2903 }
2904
2905 TEST_F(FormAutofillTest,
2906 ClearPreviewedPasswordWithAutofilledUserNameAndPassword) {
2907 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2908 " <INPUT type=\"text\" id=\"username\" value=\"W\"/>"
2909 " <INPUT type=\"password\" id=\"password\" value=\"s\"/>"
2910 " <INPUT type=\"submit\" value=\"Send\"/>"
2911 "</FORM>");
2912
2913 WebFrame* web_frame = GetMainFrame();
2914 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2915
2916 WebInputElement username =
2917 web_frame->document().getElementById("username").to<WebInputElement>();
2918 username.setAutofilled(true);
2919 WebInputElement password =
2920 web_frame->document().getElementById("password").to<WebInputElement>();
2921 password.setAutofilled(true);
2922
2923 username.setSuggestedValue(ASCIIToUTF16("Wyatt"));
2924 password.setSuggestedValue(ASCIIToUTF16("secret"));
2925
2926 EXPECT_TRUE(ClearPreviewedFormWithElement(username, REQUIRE_NONE, true,
2927 true));
2928
2929 EXPECT_EQ(ASCIIToUTF16("W"), username.value());
2930 EXPECT_TRUE(username.suggestedValue().isEmpty());
2931 EXPECT_TRUE(username.isAutofilled());
2932
2933 EXPECT_EQ(ASCIIToUTF16("s"), password.value());
2934 EXPECT_TRUE(password.suggestedValue().isEmpty());
2935 EXPECT_TRUE(password.isAutofilled());
2936 }
2937
2938 TEST_F(FormAutofillTest,
2939 ClearPreviewedPasswordWithNotAutofilledUserNameAndPassword) {
2940 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2941 " <INPUT type=\"text\" id=\"username\"/>"
2942 " <INPUT type=\"password\" id=\"password\"/>"
2943 " <INPUT type=\"submit\" value=\"Send\"/>"
2944 "</FORM>");
2945
2946 WebFrame* web_frame = GetMainFrame();
2947 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2948
2949 // Set the auto-filled attribute.
2950 WebInputElement username =
2951 web_frame->document().getElementById("username").to<WebInputElement>();
2952 username.setAutofilled(true);
2953 WebInputElement password =
2954 web_frame->document().getElementById("password").to<WebInputElement>();
2955 password.setAutofilled(true);
2956
2957 username.setSuggestedValue(ASCIIToUTF16("Wyatt"));
2958 password.setSuggestedValue(ASCIIToUTF16("secret"));
2959
2960 // Clear the previewed fields.
2961 EXPECT_TRUE(ClearPreviewedFormWithElement(username, REQUIRE_NONE, false,
2962 false));
2963
2964 EXPECT_TRUE(username.value().isEmpty());
2965 EXPECT_TRUE(username.suggestedValue().isEmpty());
2966 EXPECT_FALSE(username.isAutofilled());
2967
2968 EXPECT_TRUE(password.value().isEmpty());
2969 EXPECT_TRUE(password.suggestedValue().isEmpty());
2970 EXPECT_FALSE(password.isAutofilled());
2971 }
2972
2973 TEST_F(FormAutofillTest,
2974 ClearPreviewedPasswordWithEmptyUserNameSuggestion) {
2975 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2976 " <INPUT type=\"text\" id=\"username\"/>"
2977 " <INPUT type=\"password\" id=\"password\"/>"
2978 " <INPUT type=\"submit\" value=\"Send\"/>"
2979 "</FORM>");
2980
2981 WebFrame* web_frame = GetMainFrame();
2982 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
2983
2984 WebInputElement username =
2985 web_frame->document().getElementById("username").to<WebInputElement>();
2986 username.setAutofilled(true);
2987 WebInputElement password =
2988 web_frame->document().getElementById("password").to<WebInputElement>();
2989 password.setAutofilled(true);
2990
2991 username.setSuggestedValue(base::string16());
2992
2993 EXPECT_TRUE(ClearPreviewedFormWithElement(username, REQUIRE_NONE, false,
2994 false));
2995 EXPECT_TRUE(username.value().isEmpty());
2996 EXPECT_TRUE(username.suggestedValue().isEmpty());
2997 EXPECT_TRUE(username.isAutofilled());
2998
2999 EXPECT_TRUE(password.value().isEmpty());
3000 EXPECT_TRUE(password.suggestedValue().isEmpty());
3001 EXPECT_TRUE(password.isAutofilled());
3002 }
3003
2840 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { 3004 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) {
2841 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" 3005 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
2842 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" 3006 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
2843 " <INPUT type=\"text\" id=\"lastname\"/>" 3007 " <INPUT type=\"text\" id=\"lastname\"/>"
2844 " <INPUT type=\"text\" id=\"email\"/>" 3008 " <INPUT type=\"text\" id=\"email\"/>"
2845 " <INPUT type=\"email\" id=\"email2\"/>" 3009 " <INPUT type=\"email\" id=\"email2\"/>"
2846 " <INPUT type=\"tel\" id=\"phone\"/>" 3010 " <INPUT type=\"tel\" id=\"phone\"/>"
2847 " <INPUT type=\"submit\" value=\"Send\"/>" 3011 " <INPUT type=\"submit\" value=\"Send\"/>"
2848 "</FORM>"); 3012 "</FORM>");
2849 3013
(...skipping 22 matching lines...) Expand all
2872 web_frame->document().getElementById("phone").to<WebInputElement>(); 3036 web_frame->document().getElementById("phone").to<WebInputElement>();
2873 phone.setAutofilled(true); 3037 phone.setAutofilled(true);
2874 3038
2875 // Set the suggested values on two of the elements. 3039 // Set the suggested values on two of the elements.
2876 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); 3040 lastname.setSuggestedValue(ASCIIToUTF16("Earp"));
2877 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); 3041 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
2878 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); 3042 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
2879 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); 3043 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999"));
2880 3044
2881 // Clear the previewed fields. 3045 // Clear the previewed fields.
2882 EXPECT_TRUE(ClearPreviewedFormWithElement(lastname, false)); 3046 EXPECT_TRUE(ClearPreviewedFormWithElement(lastname, REQUIRE_AUTOCOMPLETE,
3047 false, false));
2883 3048
2884 // Fields with empty suggestions suggestions are not modified. 3049 // Fields with empty suggestions suggestions are not modified.
2885 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); 3050 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value());
2886 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); 3051 EXPECT_TRUE(firstname.suggestedValue().isEmpty());
2887 EXPECT_TRUE(firstname.isAutofilled()); 3052 EXPECT_TRUE(firstname.isAutofilled());
2888 3053
2889 // Verify the previewed fields are cleared. 3054 // Verify the previewed fields are cleared.
2890 EXPECT_TRUE(lastname.value().isEmpty()); 3055 EXPECT_TRUE(lastname.value().isEmpty());
2891 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); 3056 EXPECT_TRUE(lastname.suggestedValue().isEmpty());
2892 EXPECT_FALSE(lastname.isAutofilled()); 3057 EXPECT_FALSE(lastname.isAutofilled());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2942 3107
2943 3108
2944 // Set the suggested values on all of the elements. 3109 // Set the suggested values on all of the elements.
2945 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); 3110 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt"));
2946 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); 3111 lastname.setSuggestedValue(ASCIIToUTF16("Earp"));
2947 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); 3112 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
2948 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); 3113 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
2949 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); 3114 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999"));
2950 3115
2951 // Clear the previewed fields. 3116 // Clear the previewed fields.
2952 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, false)); 3117 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, REQUIRE_AUTOCOMPLETE,
3118 false, false));
2953 3119
2954 // Fields with non-empty values are restored. 3120 // Fields with non-empty values are restored.
2955 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); 3121 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value());
2956 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); 3122 EXPECT_TRUE(firstname.suggestedValue().isEmpty());
2957 EXPECT_FALSE(firstname.isAutofilled()); 3123 EXPECT_FALSE(firstname.isAutofilled());
2958 EXPECT_EQ(1, firstname.selectionStart()); 3124 EXPECT_EQ(1, firstname.selectionStart());
2959 EXPECT_EQ(1, firstname.selectionEnd()); 3125 EXPECT_EQ(1, firstname.selectionEnd());
2960 3126
2961 // Verify the previewed fields are cleared. 3127 // Verify the previewed fields are cleared.
2962 EXPECT_TRUE(lastname.value().isEmpty()); 3128 EXPECT_TRUE(lastname.value().isEmpty());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3009 phone.setAutofilled(true); 3175 phone.setAutofilled(true);
3010 3176
3011 // Set the suggested values on all of the elements. 3177 // Set the suggested values on all of the elements.
3012 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); 3178 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt"));
3013 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); 3179 lastname.setSuggestedValue(ASCIIToUTF16("Earp"));
3014 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); 3180 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
3015 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); 3181 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com"));
3016 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); 3182 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999"));
3017 3183
3018 // Clear the previewed fields. 3184 // Clear the previewed fields.
3019 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, true)); 3185 EXPECT_TRUE(ClearPreviewedFormWithElement(firstname, REQUIRE_AUTOCOMPLETE,
3186 true, false));
3020 3187
3021 // Fields with non-empty values are restored. 3188 // Fields with non-empty values are restored.
3022 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value()); 3189 EXPECT_EQ(ASCIIToUTF16("W"), firstname.value());
3023 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); 3190 EXPECT_TRUE(firstname.suggestedValue().isEmpty());
3024 EXPECT_TRUE(firstname.isAutofilled()); 3191 EXPECT_TRUE(firstname.isAutofilled());
3025 EXPECT_EQ(1, firstname.selectionStart()); 3192 EXPECT_EQ(1, firstname.selectionStart());
3026 EXPECT_EQ(1, firstname.selectionEnd()); 3193 EXPECT_EQ(1, firstname.selectionEnd());
3027 3194
3028 // Verify the previewed fields are cleared. 3195 // Verify the previewed fields are cleared.
3029 EXPECT_TRUE(lastname.value().isEmpty()); 3196 EXPECT_TRUE(lastname.value().isEmpty());
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
3214 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); 3381 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
3215 3382
3216 expected.name = ASCIIToUTF16("country"); 3383 expected.name = ASCIIToUTF16("country");
3217 expected.value = ASCIIToUTF16("AL"); 3384 expected.value = ASCIIToUTF16("AL");
3218 expected.form_control_type = "select-one"; 3385 expected.form_control_type = "select-one";
3219 expected.max_length = 0; 3386 expected.max_length = 0;
3220 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 3387 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
3221 } 3388 }
3222 3389
3223 } // namespace autofill 3390 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698