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

Side by Side Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 257803004: Add a test for toggling logging in PasswordAutofillAgent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Testing API rather than implementation Created 6 years, 7 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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() {
vabr (Chromium) 2014/04/28 14:31:10 Here I'm piggybacking on PasswordAutofillAgentTest
Ilya Sherman 2014/04/28 21:13:41 It would be nice to someday get rid of the friend
vabr (Chromium) 2014/04/29 07:45:18 I agree with both -- getting rid of the friend dec
184 password_autofill_->SendPasswordForms(GetMainFrame(),
185 /*only_visible=*/true);
Ilya Sherman 2014/04/28 21:13:41 Optional nit: I'd write this as "true /* only_visi
vabr (Chromium) 2014/04/29 07:45:18 Done.
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
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, OnChangeLoggingStateNoMessage) {
Ilya Sherman 2014/04/28 21:13:41 Optional nit: I'd name this "OnChangeLoggingState_
vabr (Chromium) 2014/04/29 07:45:18 Done.
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, OnChangeLoggingStateActivated) {
1066 // Up-cast to access OnMessageReceived, which is private in the agent.
1067 IPC::Listener* const agent_listener(password_autofill_);
Ilya Sherman 2014/04/28 21:13:41 nit: Please use a static_cast for casting.
vabr (Chromium) 2014/04/29 07:45:18 Done.
1068
1069 // Turn the logging on.
1070 AutofillMsg_ChangeLoggingState msg_activate(0, true);
1071 EXPECT_TRUE(agent_listener->OnMessageReceived(msg_activate));
1072
1073 render_thread_->sink().ClearMessages();
1074 SendVisiblePasswordForms();
1075 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
1076 AutofillHostMsg_RecordSavePasswordProgress::ID);
1077 EXPECT_TRUE(message);
1078 }
1079
1080 // Test that logging can be turned off by a message.
1081 TEST_F(PasswordAutofillAgentTest, OnChangeLoggingStateDeactivated) {
1082 // Up-cast to access OnMessageReceived, which is private in the agent.
1083 IPC::Listener* const agent_listener(password_autofill_);
1084
1085 // Turn the logging on and then off.
1086 AutofillMsg_ChangeLoggingState msg_activate(0, /*active=*/true);
1087 EXPECT_TRUE(agent_listener->OnMessageReceived(msg_activate));
1088 AutofillMsg_ChangeLoggingState msg_deactivate(0, /*active=*/false);
1089 EXPECT_TRUE(agent_listener->OnMessageReceived(msg_deactivate));
1090
1091 render_thread_->sink().ClearMessages();
1092 SendVisiblePasswordForms();
1093 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
1094 AutofillHostMsg_RecordSavePasswordProgress::ID);
1095 EXPECT_FALSE(message);
1096 }
1097
1050 } // namespace autofill 1098 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698