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

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

Issue 563313004: [Password Manager] Unfriend PasswordAutofillAgentTest from PasswordAutofillAgent (clean-up). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated review comments. Created 6 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string.h> 5 #include <string.h>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/test/base/chrome_render_view_test.h" 9 #include "chrome/test/base/chrome_render_view_test.h"
10 #include "components/autofill/content/common/autofill_messages.h" 10 #include "components/autofill/content/common/autofill_messages.h"
11 #include "components/autofill/content/renderer/autofill_agent.h" 11 #include "components/autofill/content/renderer/test_autofill_agent.h"
12 #include "components/autofill/content/renderer/test_password_generation_agent.h" 12 #include "components/autofill/content/renderer/test_password_generation_agent.h"
13 #include "components/autofill/core/common/form_data.h" 13 #include "components/autofill/core/common/form_data.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/public/platform/WebString.h" 15 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 16 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" 17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 #include "third_party/WebKit/public/web/WebWidget.h" 18 #include "third_party/WebKit/public/web/WebWidget.h"
19 19
20 using blink::WebDocument; 20 using blink::WebDocument;
21 using blink::WebElement; 21 using blink::WebElement;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 password_generation_->OnMessageReceived(msg); 193 password_generation_->OnMessageReceived(msg);
194 194
195 // Passwords start out the same. 195 // Passwords start out the same.
196 EXPECT_EQ(password, first_password_element.value()); 196 EXPECT_EQ(password, first_password_element.value());
197 EXPECT_EQ(password, second_password_element.value()); 197 EXPECT_EQ(password, second_password_element.value());
198 198
199 // After editing the first field they are still the same. 199 // After editing the first field they are still the same.
200 base::string16 edited_password = base::ASCIIToUTF16("edited_password"); 200 base::string16 edited_password = base::ASCIIToUTF16("edited_password");
201 first_password_element.setValue(edited_password); 201 first_password_element.setValue(edited_password);
202 // Cast to WebAutofillClient where textFieldDidChange() is public. 202 // Cast to WebAutofillClient where textFieldDidChange() is public.
203 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( 203 static_cast<blink::WebAutofillClient*>(autofill_agent_)
204 first_password_element); 204 ->textFieldDidChange(first_password_element);
205 // textFieldDidChange posts a task, so we need to wait until it's been 205 // textFieldDidChange posts a task, so we need to wait until it's been
206 // processed. 206 // processed.
207 base::MessageLoop::current()->RunUntilIdle(); 207 base::MessageLoop::current()->RunUntilIdle();
208 208
209 EXPECT_EQ(edited_password, first_password_element.value()); 209 EXPECT_EQ(edited_password, first_password_element.value());
210 EXPECT_EQ(edited_password, second_password_element.value()); 210 EXPECT_EQ(edited_password, second_password_element.value());
211 } 211 }
212 212
213 TEST_F(PasswordGenerationAgentTest, BlacklistedTest) { 213 TEST_F(PasswordGenerationAgentTest, BlacklistedTest) {
214 // Did not receive not blacklisted message. Don't show password generation 214 // Did not receive not blacklisted message. Don't show password generation
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 WebElement element = 265 WebElement element =
266 document.getElementById(WebString::fromUTF8("first_password")); 266 document.getElementById(WebString::fromUTF8("first_password"));
267 ASSERT_FALSE(element.isNull()); 267 ASSERT_FALSE(element.isNull());
268 WebInputElement first_password_element = element.to<WebInputElement>(); 268 WebInputElement first_password_element = element.to<WebInputElement>();
269 269
270 // Make a password just under maximum offer size. 270 // Make a password just under maximum offer size.
271 first_password_element.setValue( 271 first_password_element.setValue(
272 base::ASCIIToUTF16( 272 base::ASCIIToUTF16(
273 std::string(password_generation_->kMaximumOfferSize - 1, 'a'))); 273 std::string(password_generation_->kMaximumOfferSize - 1, 'a')));
274 // Cast to WebAutofillClient where textFieldDidChange() is public. 274 // Cast to WebAutofillClient where textFieldDidChange() is public.
275 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( 275 static_cast<blink::WebAutofillClient*>(autofill_agent_)
276 first_password_element); 276 ->textFieldDidChange(first_password_element);
277 // textFieldDidChange posts a task, so we need to wait until it's been 277 // textFieldDidChange posts a task, so we need to wait until it's been
278 // processed. 278 // processed.
279 base::MessageLoop::current()->RunUntilIdle(); 279 base::MessageLoop::current()->RunUntilIdle();
280 // There should now be a message to show the UI. 280 // There should now be a message to show the UI.
281 ASSERT_EQ(1u, password_generation_->messages().size()); 281 ASSERT_EQ(1u, password_generation_->messages().size());
282 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 282 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
283 password_generation_->messages()[0]->type()); 283 password_generation_->messages()[0]->type());
284 password_generation_->clear_messages(); 284 password_generation_->clear_messages();
285 285
286 // Simulate a user typing a password just over maximum offer size. 286 // Simulate a user typing a password just over maximum offer size.
287 first_password_element.setValue( 287 first_password_element.setValue(
288 base::ASCIIToUTF16( 288 base::ASCIIToUTF16(
289 std::string(password_generation_->kMaximumOfferSize + 1, 'a'))); 289 std::string(password_generation_->kMaximumOfferSize + 1, 'a')));
290 // Cast to WebAutofillClient where textFieldDidChange() is public. 290 // Cast to WebAutofillClient where textFieldDidChange() is public.
291 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( 291 static_cast<blink::WebAutofillClient*>(autofill_agent_)
292 first_password_element); 292 ->textFieldDidChange(first_password_element);
293 // textFieldDidChange posts a task, so we need to wait until it's been 293 // textFieldDidChange posts a task, so we need to wait until it's been
294 // processed. 294 // processed.
295 base::MessageLoop::current()->RunUntilIdle(); 295 base::MessageLoop::current()->RunUntilIdle();
296 // There should now be a message to hide the UI. 296 // There should now be a message to hide the UI.
297 ASSERT_EQ(1u, password_generation_->messages().size()); 297 ASSERT_EQ(1u, password_generation_->messages().size());
298 EXPECT_EQ(AutofillHostMsg_HidePasswordGenerationPopup::ID, 298 EXPECT_EQ(AutofillHostMsg_HidePasswordGenerationPopup::ID,
299 password_generation_->messages()[0]->type()); 299 password_generation_->messages()[0]->type());
300 password_generation_->clear_messages(); 300 password_generation_->clear_messages();
301 301
302 // Simulate the user deleting characters. The generation popup should be shown 302 // Simulate the user deleting characters. The generation popup should be shown
303 // again. 303 // again.
304 first_password_element.setValue( 304 first_password_element.setValue(
305 base::ASCIIToUTF16( 305 base::ASCIIToUTF16(
306 std::string(password_generation_->kMaximumOfferSize, 'a'))); 306 std::string(password_generation_->kMaximumOfferSize, 'a')));
307 // Cast to WebAutofillClient where textFieldDidChange() is public. 307 // Cast to WebAutofillClient where textFieldDidChange() is public.
308 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( 308 static_cast<blink::WebAutofillClient*>(autofill_agent_)
309 first_password_element); 309 ->textFieldDidChange(first_password_element);
310 // textFieldDidChange posts a task, so we need to wait until it's been 310 // textFieldDidChange posts a task, so we need to wait until it's been
311 // processed. 311 // processed.
312 base::MessageLoop::current()->RunUntilIdle(); 312 base::MessageLoop::current()->RunUntilIdle();
313 // There should now be a message to show the UI. 313 // There should now be a message to show the UI.
314 ASSERT_EQ(1u, password_generation_->messages().size()); 314 ASSERT_EQ(1u, password_generation_->messages().size());
315 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 315 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
316 password_generation_->messages()[0]->type()); 316 password_generation_->messages()[0]->type());
317 password_generation_->clear_messages(); 317 password_generation_->clear_messages();
318 318
319 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent, 319 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent,
320 // so no messages are sent. 320 // so no messages are sent.
321 ExecuteJavaScript("document.getElementById('username').focus();"); 321 ExecuteJavaScript("document.getElementById('username').focus();");
322 EXPECT_EQ(0u, password_generation_->messages().size()); 322 EXPECT_EQ(0u, password_generation_->messages().size());
323 password_generation_->clear_messages(); 323 password_generation_->clear_messages();
324 324
325 // Focusing the password field will bring up the generation UI again. 325 // Focusing the password field will bring up the generation UI again.
326 ExecuteJavaScript("document.getElementById('first_password').focus();"); 326 ExecuteJavaScript("document.getElementById('first_password').focus();");
327 EXPECT_EQ(1u, password_generation_->messages().size()); 327 EXPECT_EQ(1u, password_generation_->messages().size());
328 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 328 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
329 password_generation_->messages()[0]->type()); 329 password_generation_->messages()[0]->type());
330 password_generation_->clear_messages(); 330 password_generation_->clear_messages();
331 } 331 }
332 332
333 } // namespace autofill 333 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698