OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/renderer/form_manager.h" | 7 #include "chrome/renderer/form_manager.h" |
8 #include "chrome/test/render_view_test.h" | 8 #include "chrome/test/render_view_test.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
(...skipping 2860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2871 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 2871 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
2872 | 2872 |
2873 WebElement e = web_frame->document().getElementById("firstname"); | 2873 WebElement e = web_frame->document().getElementById("firstname"); |
2874 WebFormControlElement firstname = e.to<WebFormControlElement>(); | 2874 WebFormControlElement firstname = e.to<WebFormControlElement>(); |
2875 | 2875 |
2876 // Hidden form control element should not have a label set. | 2876 // Hidden form control element should not have a label set. |
2877 FormManager form_manager; | 2877 FormManager form_manager; |
2878 EXPECT_EQ(string16(), form_manager.LabelForElement(firstname)); | 2878 EXPECT_EQ(string16(), form_manager.LabelForElement(firstname)); |
2879 } | 2879 } |
2880 | 2880 |
| 2881 TEST_F(FormManagerTest, SelectOneAsText) { |
| 2882 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 2883 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 2884 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 2885 " <SELECT id=\"country\">" |
| 2886 " <OPTION value=\"AF\">Afghanistan</OPTION>" |
| 2887 " <OPTION value=\"AL\">Albania</OPTION>" |
| 2888 " <OPTION value=\"DZ\">Algeria</OPTION>" |
| 2889 " </SELECT>" |
| 2890 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 2891 "</FORM>"); |
| 2892 |
| 2893 WebFrame* frame = GetMainFrame(); |
| 2894 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 2895 |
| 2896 // Set the value of the select-one. |
| 2897 WebSelectElement select_element = |
| 2898 frame->document().getElementById("country").to<WebSelectElement>(); |
| 2899 select_element.setValue(WebString::fromUTF8("AL")); |
| 2900 |
| 2901 WebVector<WebFormElement> forms; |
| 2902 frame->forms(forms); |
| 2903 ASSERT_EQ(1U, forms.size()); |
| 2904 |
| 2905 FormData form; |
| 2906 |
| 2907 // Extract the country select-one value as text. |
| 2908 EXPECT_TRUE(FormManager::WebFormElementToFormData( |
| 2909 forms[0], FormManager::REQUIRE_NONE, |
| 2910 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE | |
| 2911 FormManager::EXTRACT_OPTION_TEXT), |
| 2912 &form)); |
| 2913 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2914 EXPECT_EQ(GURL(frame->url()), form.origin); |
| 2915 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2916 |
| 2917 const std::vector<FormField>& fields = form.fields; |
| 2918 ASSERT_EQ(4U, fields.size()); |
| 2919 EXPECT_TRUE(fields[0].StrictlyEqualsHack( |
| 2920 FormField(string16(), |
| 2921 ASCIIToUTF16("firstname"), |
| 2922 ASCIIToUTF16("John"), |
| 2923 ASCIIToUTF16("text"), |
| 2924 20))); |
| 2925 EXPECT_TRUE(fields[1].StrictlyEqualsHack( |
| 2926 FormField(string16(), |
| 2927 ASCIIToUTF16("lastname"), |
| 2928 ASCIIToUTF16("Smith"), |
| 2929 ASCIIToUTF16("text"), |
| 2930 20))); |
| 2931 EXPECT_TRUE(fields[2].StrictlyEqualsHack( |
| 2932 FormField(string16(), |
| 2933 ASCIIToUTF16("country"), |
| 2934 ASCIIToUTF16("Albania"), |
| 2935 ASCIIToUTF16("select-one"), |
| 2936 0))); |
| 2937 EXPECT_TRUE(fields[3].StrictlyEqualsHack( |
| 2938 FormField(string16(), |
| 2939 ASCIIToUTF16("reply-send"), |
| 2940 string16(), |
| 2941 ASCIIToUTF16("submit"), |
| 2942 0))); |
| 2943 |
| 2944 form.fields.clear(); |
| 2945 // Extract the country select-one value as value. |
| 2946 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], |
| 2947 FormManager::REQUIRE_NONE, |
| 2948 FormManager::EXTRACT_VALUE, |
| 2949 &form)); |
| 2950 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2951 EXPECT_EQ(GURL(frame->url()), form.origin); |
| 2952 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2953 |
| 2954 ASSERT_EQ(4U, fields.size()); |
| 2955 EXPECT_TRUE(fields[0].StrictlyEqualsHack( |
| 2956 FormField(string16(), |
| 2957 ASCIIToUTF16("firstname"), |
| 2958 ASCIIToUTF16("John"), |
| 2959 ASCIIToUTF16("text"), |
| 2960 20))); |
| 2961 EXPECT_TRUE(fields[1].StrictlyEqualsHack( |
| 2962 FormField(string16(), |
| 2963 ASCIIToUTF16("lastname"), |
| 2964 ASCIIToUTF16("Smith"), |
| 2965 ASCIIToUTF16("text"), |
| 2966 20))); |
| 2967 EXPECT_TRUE(fields[2].StrictlyEqualsHack( |
| 2968 FormField(string16(), |
| 2969 ASCIIToUTF16("country"), |
| 2970 ASCIIToUTF16("AL"), |
| 2971 ASCIIToUTF16("select-one"), |
| 2972 0))); |
| 2973 EXPECT_TRUE(fields[3].StrictlyEqualsHack( |
| 2974 FormField(string16(), |
| 2975 ASCIIToUTF16("reply-send"), |
| 2976 string16(), |
| 2977 ASCIIToUTF16("submit"), |
| 2978 0))); |
| 2979 } |
| 2980 |
2881 } // namespace | 2981 } // namespace |
OLD | NEW |