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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | webkit/glue/form_field_values.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/form_autocomplete_unittest.cc
===================================================================
--- chrome/renderer/form_autocomplete_unittest.cc (revision 0)
+++ chrome/renderer/form_autocomplete_unittest.cc (revision 0)
@@ -0,0 +1,120 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/render_messages.h"
+#include "chrome/test/render_view_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
+
+using WebKit::WebCompositionCommand;
+using WebKit::WebFrame;
+using WebKit::WebString;
+using WebKit::WebTextDirection;
+using WebKit::WebURLError;
+
+class FormAutocompleteTest : public RenderViewTest {
+};
+
+// Tests that submitting a form generates a FormFieldValuesSubmitted message
+// with the form fields.
+TEST_F(FormAutocompleteTest, NormalFormSubmit) {
+ // Load a form.
+ LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>"
+ "<input name='lname' value='Deckard'/></form></html>");
+
+ // Submit the form.
+ ExecuteJavaScript("document.getElementById('myForm').submit();");
+ ProcessPendingMessages();
+
+ const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching(
+ ViewHostMsg_FormFieldValuesSubmitted::ID);
+ ASSERT_TRUE(message != NULL);
+
+ Tuple1<webkit_glue::FormFieldValues> form_fields;
+ ViewHostMsg_FormFieldValuesSubmitted::Read(message, &form_fields);
+ ASSERT_EQ(2U, form_fields.a.elements.size());
+
+ webkit_glue::FormField& form_field = form_fields.a.elements[0];
+ EXPECT_EQ(WebString("fname"), form_field.name());
+ EXPECT_EQ(WebString("Rick"), form_field.value());
+
+ form_field = form_fields.a.elements[1];
+ EXPECT_EQ(WebString("lname"), form_field.name());
+ EXPECT_EQ(WebString("Deckard"), form_field.value());
+}
+
+// Tests that submitting a form that has autocomplete="off" does not generate a
+// FormFieldValuesSubmitted message.
+TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) {
+ // Load a form.
+ LoadHTML("<html><form id='myForm' autocomplete='off'>"
+ "<input name='fname' value='Rick'/>"
+ "<input name='lname' value='Deckard'/>"
+ "</form></html>");
+
+ // Submit the form.
+ ExecuteJavaScript("document.getElementById('myForm').submit();");
+ ProcessPendingMessages();
+
+ // No FormFieldValuesSubmitted message should have been sent.
+ EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching(
+ ViewHostMsg_FormFieldValuesSubmitted::ID));
+}
+
+// Tests that fields with autocomplete off are not submitted.
+TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) {
+ // Load a form.
+ LoadHTML("<html><form id='myForm'>"
+ "<input name='fname' value='Rick'/>"
+ "<input name='lname' value='Deckard' autocomplete='off'/>"
+ "</form></html>");
+
+ // Submit the form.
+ ExecuteJavaScript("document.getElementById('myForm').submit();");
+ ProcessPendingMessages();
+
+ // No FormFieldValuesSubmitted message should have been sent.
+ const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching(
+ ViewHostMsg_FormFieldValuesSubmitted::ID);
+ ASSERT_TRUE(message != NULL);
+
+ Tuple1<webkit_glue::FormFieldValues> form_fields;
+ ViewHostMsg_FormFieldValuesSubmitted::Read(message, &form_fields);
+ ASSERT_EQ(1U, form_fields.a.elements.size());
+
+ webkit_glue::FormField& form_field = form_fields.a.elements[0];
+ EXPECT_EQ(WebString("fname"), form_field.name());
+ EXPECT_EQ(WebString("Rick"), form_field.value());
+}
+
+// Tests that submitting a form that has been dynamically set as autocomplete
+// off does not generate a FormFieldValuesSubmitted message.
+// http://crbug.com/36520
+// TODO(jcampan): reenable when WebKit bug 35823 is fixed.
+TEST_F(FormAutocompleteTest, DISABLED_DynamicAutoCompleteOffFormSubmit) {
+ LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>"
+ "<input name='lname' value='Deckard'/></form></html>");
+
+ WebKit::WebElement element =
+ GetMainFrame()->document().getElementById(WebKit::WebString("myForm"));
+ ASSERT_FALSE(element.isNull());
+ WebKit::WebFormElement form = element.toElement<WebKit::WebFormElement>();
+ EXPECT_TRUE(form.autoComplete());
+
+ // Dynamically mark the form as autocomplete off.
+ ExecuteJavaScript("document.getElementById('myForm').autocomplete='off';");
+ ProcessPendingMessages();
+ EXPECT_FALSE(form.autoComplete());
+
+ // Submit the form.
+ ExecuteJavaScript("document.getElementById('myForm').submit();");
+ ProcessPendingMessages();
+
+ // No FormFieldValuesSubmitted message should have been sent.
+ EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching(
+ ViewHostMsg_FormFieldValuesSubmitted::ID));
+}
+
Property changes on: chrome\renderer\form_autocomplete_unittest.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« 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