This source file includes following definitions.
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "base/time/time.h"
#include "chrome/test/base/chrome_render_view_test.h"
#include "components/autofill/content/common/autofill_messages.h"
#include "components/autofill/core/common/form_data.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURLError.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFormElement.h"
using blink::WebFrame;
using blink::WebString;
using blink::WebURLError;
typedef ChromeRenderViewTest FormAutocompleteTest;
namespace autofill {
TEST_F(FormAutocompleteTest, NormalFormSubmit) {
LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>"
"<input name='lname' value='Deckard'/></form></html>");
ExecuteJavaScript("document.getElementById('myForm').submit();");
ProcessPendingMessages();
const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
AutofillHostMsg_FormSubmitted::ID);
ASSERT_TRUE(message != NULL);
Tuple2<FormData, base::TimeTicks> forms;
AutofillHostMsg_FormSubmitted::Read(message, &forms);
ASSERT_EQ(2U, forms.a.fields.size());
FormFieldData& form_field = forms.a.fields[0];
EXPECT_EQ(WebString("fname"), form_field.name);
EXPECT_EQ(WebString("Rick"), form_field.value);
form_field = forms.a.fields[1];
EXPECT_EQ(WebString("lname"), form_field.name);
EXPECT_EQ(WebString("Deckard"), form_field.value);
}
TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) {
LoadHTML("<html><form id='myForm' autocomplete='off'>"
"<input name='fname' value='Rick'/>"
"<input name='lname' value='Deckard'/>"
"</form></html>");
ExecuteJavaScript("document.getElementById('myForm').submit();");
ProcessPendingMessages();
EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
AutofillHostMsg_FormSubmitted::ID));
}
TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) {
LoadHTML("<html><form id='myForm'>"
"<input name='fname' value='Rick'/>"
"<input name='lname' value='Deckard' autocomplete='off'/>"
"</form></html>");
ExecuteJavaScript("document.getElementById('myForm').submit();");
ProcessPendingMessages();
const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
AutofillHostMsg_FormSubmitted::ID);
ASSERT_TRUE(message != NULL);
Tuple2<FormData, base::TimeTicks> forms;
AutofillHostMsg_FormSubmitted::Read(message, &forms);
ASSERT_EQ(1U, forms.a.fields.size());
FormFieldData& form_field = forms.a.fields[0];
EXPECT_EQ(WebString("fname"), form_field.name);
EXPECT_EQ(WebString("Rick"), form_field.value);
}
TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) {
LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>"
"<input name='lname' value='Deckard'/></form></html>");
blink::WebElement element =
GetMainFrame()->document().getElementById(blink::WebString("myForm"));
ASSERT_FALSE(element.isNull());
blink::WebFormElement form = element.to<blink::WebFormElement>();
EXPECT_TRUE(form.autoComplete());
ExecuteJavaScript("document.getElementById('myForm')."
"setAttribute('autocomplete', 'off');");
ProcessPendingMessages();
EXPECT_FALSE(form.autoComplete());
ExecuteJavaScript("document.getElementById('myForm').submit();");
ProcessPendingMessages();
EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
AutofillHostMsg_FormSubmitted::ID));
}
}