| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/time.h" |
| 5 #include "chrome/common/autofill_messages.h" | 6 #include "chrome/common/autofill_messages.h" |
| 6 #include "chrome/test/base/render_view_test.h" | 7 #include "chrome/test/base/render_view_test.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
| 12 #include "webkit/glue/form_data.h" | 13 #include "webkit/glue/form_data.h" |
| 13 #include "webkit/glue/web_io_operators.h" | 14 #include "webkit/glue/web_io_operators.h" |
| 14 | 15 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 28 "<input name='lname' value='Deckard'/></form></html>"); | 29 "<input name='lname' value='Deckard'/></form></html>"); |
| 29 | 30 |
| 30 // Submit the form. | 31 // Submit the form. |
| 31 ExecuteJavaScript("document.getElementById('myForm').submit();"); | 32 ExecuteJavaScript("document.getElementById('myForm').submit();"); |
| 32 ProcessPendingMessages(); | 33 ProcessPendingMessages(); |
| 33 | 34 |
| 34 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( | 35 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( |
| 35 AutofillHostMsg_FormSubmitted::ID); | 36 AutofillHostMsg_FormSubmitted::ID); |
| 36 ASSERT_TRUE(message != NULL); | 37 ASSERT_TRUE(message != NULL); |
| 37 | 38 |
| 38 Tuple1<FormData> forms; | 39 // The tuple also includes a timestamp, which is ignored. |
| 40 Tuple2<FormData, base::TimeTicks> forms; |
| 39 AutofillHostMsg_FormSubmitted::Read(message, &forms); | 41 AutofillHostMsg_FormSubmitted::Read(message, &forms); |
| 40 ASSERT_EQ(2U, forms.a.fields.size()); | 42 ASSERT_EQ(2U, forms.a.fields.size()); |
| 41 | 43 |
| 42 webkit_glue::FormField& form_field = forms.a.fields[0]; | 44 webkit_glue::FormField& form_field = forms.a.fields[0]; |
| 43 EXPECT_EQ(WebString("fname"), form_field.name); | 45 EXPECT_EQ(WebString("fname"), form_field.name); |
| 44 EXPECT_EQ(WebString("Rick"), form_field.value); | 46 EXPECT_EQ(WebString("Rick"), form_field.value); |
| 45 | 47 |
| 46 form_field = forms.a.fields[1]; | 48 form_field = forms.a.fields[1]; |
| 47 EXPECT_EQ(WebString("lname"), form_field.name); | 49 EXPECT_EQ(WebString("lname"), form_field.name); |
| 48 EXPECT_EQ(WebString("Deckard"), form_field.value); | 50 EXPECT_EQ(WebString("Deckard"), form_field.value); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 76 | 78 |
| 77 // Submit the form. | 79 // Submit the form. |
| 78 ExecuteJavaScript("document.getElementById('myForm').submit();"); | 80 ExecuteJavaScript("document.getElementById('myForm').submit();"); |
| 79 ProcessPendingMessages(); | 81 ProcessPendingMessages(); |
| 80 | 82 |
| 81 // No FormSubmitted message should have been sent. | 83 // No FormSubmitted message should have been sent. |
| 82 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( | 84 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( |
| 83 AutofillHostMsg_FormSubmitted::ID); | 85 AutofillHostMsg_FormSubmitted::ID); |
| 84 ASSERT_TRUE(message != NULL); | 86 ASSERT_TRUE(message != NULL); |
| 85 | 87 |
| 86 Tuple1<FormData> forms; | 88 // The tuple also includes a timestamp, which is ignored. |
| 89 Tuple2<FormData, base::TimeTicks> forms; |
| 87 AutofillHostMsg_FormSubmitted::Read(message, &forms); | 90 AutofillHostMsg_FormSubmitted::Read(message, &forms); |
| 88 ASSERT_EQ(1U, forms.a.fields.size()); | 91 ASSERT_EQ(1U, forms.a.fields.size()); |
| 89 | 92 |
| 90 webkit_glue::FormField& form_field = forms.a.fields[0]; | 93 webkit_glue::FormField& form_field = forms.a.fields[0]; |
| 91 EXPECT_EQ(WebString("fname"), form_field.name); | 94 EXPECT_EQ(WebString("fname"), form_field.name); |
| 92 EXPECT_EQ(WebString("Rick"), form_field.value); | 95 EXPECT_EQ(WebString("Rick"), form_field.value); |
| 93 } | 96 } |
| 94 | 97 |
| 95 // Tests that submitting a form that has been dynamically set as autocomplete | 98 // Tests that submitting a form that has been dynamically set as autocomplete |
| 96 // off does not generate a FormSubmitted message. | 99 // off does not generate a FormSubmitted message. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 112 EXPECT_FALSE(form.autoComplete()); | 115 EXPECT_FALSE(form.autoComplete()); |
| 113 | 116 |
| 114 // Submit the form. | 117 // Submit the form. |
| 115 ExecuteJavaScript("document.getElementById('myForm').submit();"); | 118 ExecuteJavaScript("document.getElementById('myForm').submit();"); |
| 116 ProcessPendingMessages(); | 119 ProcessPendingMessages(); |
| 117 | 120 |
| 118 // No FormSubmitted message should have been sent. | 121 // No FormSubmitted message should have been sent. |
| 119 EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( | 122 EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( |
| 120 AutofillHostMsg_FormSubmitted::ID)); | 123 AutofillHostMsg_FormSubmitted::ID)); |
| 121 } | 124 } |
| OLD | NEW |