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 2286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2297 ASCIIToUTF16("hidden"), | 2297 ASCIIToUTF16("hidden"), |
2298 0))); | 2298 0))); |
2299 EXPECT_TRUE(fields2[5].StrictlyEqualsHack( | 2299 EXPECT_TRUE(fields2[5].StrictlyEqualsHack( |
2300 FormField(string16(), | 2300 FormField(string16(), |
2301 string16(), | 2301 string16(), |
2302 string16(), | 2302 string16(), |
2303 ASCIIToUTF16("submit"), | 2303 ASCIIToUTF16("submit"), |
2304 0))); | 2304 0))); |
2305 } | 2305 } |
2306 | 2306 |
2307 TEST_F(FormManagerTest, ClearPreviewedForm) { | 2307 TEST_F(FormManagerTest, ClearPreviewedFormWithNode) { |
2308 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2308 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
2309 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 2309 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
2310 " <INPUT type=\"text\" id=\"lastname\"/>" | 2310 " <INPUT type=\"text\" id=\"lastname\"/>" |
2311 " <INPUT type=\"text\" id=\"email\"/>" | 2311 " <INPUT type=\"text\" id=\"email\"/>" |
2312 " <INPUT type=\"submit\" value=\"Send\"/>" | 2312 " <INPUT type=\"submit\" value=\"Send\"/>" |
2313 "</FORM>"); | 2313 "</FORM>"); |
2314 | 2314 |
2315 WebFrame* web_frame = GetMainFrame(); | 2315 WebFrame* web_frame = GetMainFrame(); |
2316 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 2316 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
2317 | 2317 |
(...skipping 14 matching lines...) Expand all Loading... |
2332 lastname.setAutofilled(true); | 2332 lastname.setAutofilled(true); |
2333 WebInputElement email = | 2333 WebInputElement email = |
2334 web_frame->document().getElementById("email").to<WebInputElement>(); | 2334 web_frame->document().getElementById("email").to<WebInputElement>(); |
2335 email.setAutofilled(true); | 2335 email.setAutofilled(true); |
2336 | 2336 |
2337 // Set the suggested values on two of the elements. | 2337 // Set the suggested values on two of the elements. |
2338 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | 2338 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
2339 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 2339 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
2340 | 2340 |
2341 // Clear the previewed fields. | 2341 // Clear the previewed fields. |
2342 EXPECT_TRUE(form_manager.ClearPreviewedForm(forms[0])); | 2342 EXPECT_TRUE(form_manager.ClearPreviewedFormWithNode(firstname)); |
2343 | 2343 |
2344 // Fields with non-empty values are not modified. | 2344 // Fields with non-empty values are not modified. |
2345 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); | 2345 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); |
2346 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | 2346 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
2347 EXPECT_TRUE(firstname.isAutofilled()); | 2347 EXPECT_TRUE(firstname.isAutofilled()); |
2348 | 2348 |
2349 // Verify the previewed fields are cleared. | 2349 // Verify the previewed fields are cleared. |
2350 EXPECT_TRUE(lastname.value().isEmpty()); | 2350 EXPECT_TRUE(lastname.value().isEmpty()); |
2351 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); | 2351 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); |
2352 EXPECT_FALSE(lastname.isAutofilled()); | 2352 EXPECT_FALSE(lastname.isAutofilled()); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2446 | 2446 |
2447 WebElement e = web_frame->document().getElementById("firstname"); | 2447 WebElement e = web_frame->document().getElementById("firstname"); |
2448 WebFormControlElement firstname = e.to<WebFormControlElement>(); | 2448 WebFormControlElement firstname = e.to<WebFormControlElement>(); |
2449 | 2449 |
2450 // Hidden form control element should not have a label set. | 2450 // Hidden form control element should not have a label set. |
2451 FormManager form_manager; | 2451 FormManager form_manager; |
2452 EXPECT_EQ(string16(), form_manager.LabelForElement(firstname)); | 2452 EXPECT_EQ(string16(), form_manager.LabelForElement(firstname)); |
2453 } | 2453 } |
2454 | 2454 |
2455 } // namespace | 2455 } // namespace |
OLD | NEW |