OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/test/base/chrome_render_view_test.h" | 7 #include "chrome/test/base/chrome_render_view_test.h" |
8 #include "components/autofill/content/common/autofill_messages.h" | 8 #include "components/autofill/content/common/autofill_messages.h" |
9 #include "components/autofill/content/renderer/autofill_agent.h" | 9 #include "components/autofill/content/renderer/autofill_agent.h" |
10 #include "components/autofill/content/renderer/form_autofill_util.h" | 10 #include "components/autofill/content/renderer/form_autofill_util.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 173 |
174 // Simulates the fill password form message being sent to the renderer. | 174 // Simulates the fill password form message being sent to the renderer. |
175 // We use that so we don't have to make RenderView::OnFillPasswordForm() | 175 // We use that so we don't have to make RenderView::OnFillPasswordForm() |
176 // protected. | 176 // protected. |
177 void SimulateOnFillPasswordForm( | 177 void SimulateOnFillPasswordForm( |
178 const PasswordFormFillData& fill_data) { | 178 const PasswordFormFillData& fill_data) { |
179 AutofillMsg_FillPasswordForm msg(0, fill_data); | 179 AutofillMsg_FillPasswordForm msg(0, fill_data); |
180 password_autofill_->OnMessageReceived(msg); | 180 password_autofill_->OnMessageReceived(msg); |
181 } | 181 } |
182 | 182 |
| 183 void SendVisiblePasswordForms() { |
| 184 password_autofill_->SendPasswordForms(GetMainFrame(), |
| 185 true /* only_visible */); |
| 186 } |
| 187 |
183 virtual void SetUp() { | 188 virtual void SetUp() { |
184 ChromeRenderViewTest::SetUp(); | 189 ChromeRenderViewTest::SetUp(); |
185 | 190 |
186 // Add a preferred login and an additional login to the FillData. | 191 // Add a preferred login and an additional login to the FillData. |
187 username1_ = ASCIIToUTF16(kAliceUsername); | 192 username1_ = ASCIIToUTF16(kAliceUsername); |
188 password1_ = ASCIIToUTF16(kAlicePassword); | 193 password1_ = ASCIIToUTF16(kAlicePassword); |
189 username2_ = ASCIIToUTF16(kBobUsername); | 194 username2_ = ASCIIToUTF16(kBobUsername); |
190 password2_ = ASCIIToUTF16(kBobPassword); | 195 password2_ = ASCIIToUTF16(kBobPassword); |
191 username3_ = ASCIIToUTF16(kCarolUsername); | 196 username3_ = ASCIIToUTF16(kCarolUsername); |
192 password3_ = ASCIIToUTF16(kCarolPassword); | 197 password3_ = ASCIIToUTF16(kCarolPassword); |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 username_element_, kAliceUsername, kAlicePassword)); | 1045 username_element_, kAliceUsername, kAlicePassword)); |
1041 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | 1046 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
1042 | 1047 |
1043 // Try accepting a suggestion with a password different from the one that was | 1048 // Try accepting a suggestion with a password different from the one that was |
1044 // initially sent to the renderer. | 1049 // initially sent to the renderer. |
1045 EXPECT_TRUE(password_autofill_->AcceptSuggestion( | 1050 EXPECT_TRUE(password_autofill_->AcceptSuggestion( |
1046 username_element_, kBobUsername, kCarolPassword)); | 1051 username_element_, kBobUsername, kCarolPassword)); |
1047 CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true); | 1052 CheckTextFieldsDOMState(kBobUsername, true, kCarolPassword, true); |
1048 } | 1053 } |
1049 | 1054 |
| 1055 // Tests that logging is off by default. |
| 1056 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_NoMessage) { |
| 1057 render_thread_->sink().ClearMessages(); |
| 1058 SendVisiblePasswordForms(); |
| 1059 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
| 1060 AutofillHostMsg_RecordSavePasswordProgress::ID); |
| 1061 EXPECT_FALSE(message); |
| 1062 } |
| 1063 |
| 1064 // Test that logging can be turned on by a message. |
| 1065 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Activated) { |
| 1066 // Turn the logging on. |
| 1067 AutofillMsg_ChangeLoggingState msg_activate(0, true); |
| 1068 // Up-cast to access OnMessageReceived, which is private in the agent. |
| 1069 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_) |
| 1070 ->OnMessageReceived(msg_activate)); |
| 1071 |
| 1072 render_thread_->sink().ClearMessages(); |
| 1073 SendVisiblePasswordForms(); |
| 1074 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
| 1075 AutofillHostMsg_RecordSavePasswordProgress::ID); |
| 1076 EXPECT_TRUE(message); |
| 1077 } |
| 1078 |
| 1079 // Test that logging can be turned off by a message. |
| 1080 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingState_Deactivated) { |
| 1081 // Turn the logging on and then off. |
| 1082 AutofillMsg_ChangeLoggingState msg_activate(0, /*active=*/true); |
| 1083 // Up-cast to access OnMessageReceived, which is private in the agent. |
| 1084 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_) |
| 1085 ->OnMessageReceived(msg_activate)); |
| 1086 AutofillMsg_ChangeLoggingState msg_deactivate(0, /*active=*/false); |
| 1087 EXPECT_TRUE(static_cast<IPC::Listener*>(password_autofill_) |
| 1088 ->OnMessageReceived(msg_deactivate)); |
| 1089 |
| 1090 render_thread_->sink().ClearMessages(); |
| 1091 SendVisiblePasswordForms(); |
| 1092 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
| 1093 AutofillHostMsg_RecordSavePasswordProgress::ID); |
| 1094 EXPECT_FALSE(message); |
| 1095 } |
| 1096 |
1050 } // namespace autofill | 1097 } // namespace autofill |
OLD | NEW |