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

Side by Side Diff: chrome/renderer/form_autocomplete_unittest.cc

Issue 668208: Don't send form data that is marked autocomplete off to the browser.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | webkit/glue/form_field_values.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/common/render_messages.h"
6 #include "chrome/test/render_view_test.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
9 #include "third_party/WebKit/WebKit/chromium/public/WebString.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
11
12 using WebKit::WebCompositionCommand;
13 using WebKit::WebFrame;
14 using WebKit::WebString;
15 using WebKit::WebTextDirection;
16 using WebKit::WebURLError;
17
18 class FormAutocompleteTest : public RenderViewTest {
19 };
20
21 // Tests that submitting a form generates a FormFieldValuesSubmitted message
22 // with the form fields.
23 TEST_F(FormAutocompleteTest, NormalFormSubmit) {
24 // Load a form.
25 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>"
26 "<input name='lname' value='Deckard'/></form></html>");
27
28 // Submit the form.
29 ExecuteJavaScript("document.getElementById('myForm').submit();");
30 ProcessPendingMessages();
31
32 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching(
33 ViewHostMsg_FormFieldValuesSubmitted::ID);
34 ASSERT_TRUE(message != NULL);
35
36 Tuple1<webkit_glue::FormFieldValues> form_fields;
37 ViewHostMsg_FormFieldValuesSubmitted::Read(message, &form_fields);
38 ASSERT_EQ(2U, form_fields.a.elements.size());
39
40 webkit_glue::FormField& form_field = form_fields.a.elements[0];
41 EXPECT_EQ(WebString("fname"), form_field.name());
42 EXPECT_EQ(WebString("Rick"), form_field.value());
43
44 form_field = form_fields.a.elements[1];
45 EXPECT_EQ(WebString("lname"), form_field.name());
46 EXPECT_EQ(WebString("Deckard"), form_field.value());
47 }
48
49 // Tests that submitting a form that has autocomplete="off" does not generate a
50 // FormFieldValuesSubmitted message.
51 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) {
52 // Load a form.
53 LoadHTML("<html><form id='myForm' autocomplete='off'>"
54 "<input name='fname' value='Rick'/>"
55 "<input name='lname' value='Deckard'/>"
56 "</form></html>");
57
58 // Submit the form.
59 ExecuteJavaScript("document.getElementById('myForm').submit();");
60 ProcessPendingMessages();
61
62 // No FormFieldValuesSubmitted message should have been sent.
63 EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching(
64 ViewHostMsg_FormFieldValuesSubmitted::ID));
65 }
66
67 // Tests that fields with autocomplete off are not submitted.
68 TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) {
69 // Load a form.
70 LoadHTML("<html><form id='myForm'>"
71 "<input name='fname' value='Rick'/>"
72 "<input name='lname' value='Deckard' autocomplete='off'/>"
73 "</form></html>");
74
75 // Submit the form.
76 ExecuteJavaScript("document.getElementById('myForm').submit();");
77 ProcessPendingMessages();
78
79 // No FormFieldValuesSubmitted message should have been sent.
80 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching(
81 ViewHostMsg_FormFieldValuesSubmitted::ID);
82 ASSERT_TRUE(message != NULL);
83
84 Tuple1<webkit_glue::FormFieldValues> form_fields;
85 ViewHostMsg_FormFieldValuesSubmitted::Read(message, &form_fields);
86 ASSERT_EQ(1U, form_fields.a.elements.size());
87
88 webkit_glue::FormField& form_field = form_fields.a.elements[0];
89 EXPECT_EQ(WebString("fname"), form_field.name());
90 EXPECT_EQ(WebString("Rick"), form_field.value());
91 }
92
93 // Tests that submitting a form that has been dynamically set as autocomplete
94 // off does not generate a FormFieldValuesSubmitted message.
95 // http://crbug.com/36520
96 // TODO(jcampan): reenable when WebKit bug 35823 is fixed.
97 TEST_F(FormAutocompleteTest, DISABLED_DynamicAutoCompleteOffFormSubmit) {
98 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>"
99 "<input name='lname' value='Deckard'/></form></html>");
100
101 WebKit::WebElement element =
102 GetMainFrame()->document().getElementById(WebKit::WebString("myForm"));
103 ASSERT_FALSE(element.isNull());
104 WebKit::WebFormElement form = element.toElement<WebKit::WebFormElement>();
105 EXPECT_TRUE(form.autoComplete());
106
107 // Dynamically mark the form as autocomplete off.
108 ExecuteJavaScript("document.getElementById('myForm').autocomplete='off';");
109 ProcessPendingMessages();
110 EXPECT_FALSE(form.autoComplete());
111
112 // Submit the form.
113 ExecuteJavaScript("document.getElementById('myForm').submit();");
114 ProcessPendingMessages();
115
116 // No FormFieldValuesSubmitted message should have been sent.
117 EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching(
118 ViewHostMsg_FormFieldValuesSubmitted::ID));
119 }
120
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | webkit/glue/form_field_values.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698