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

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

Issue 1257603003: Revert of Add ExecuteJavaScriptForTest and make all tests use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
10 #include "chrome/renderer/autofill/password_generation_test_utils.h" 10 #include "chrome/renderer/autofill/password_generation_test_utils.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 // Enable show-ime event when element is focused by indicating that a user 44 // Enable show-ime event when element is focused by indicating that a user
45 // gesture has been processed since load. 45 // gesture has been processed since load.
46 EXPECT_TRUE(SimulateElementClick("dummy")); 46 EXPECT_TRUE(SimulateElementClick("dummy"));
47 } 47 }
48 48
49 void FocusField(const char* element_id) { 49 void FocusField(const char* element_id) {
50 WebDocument document = GetMainFrame()->document(); 50 WebDocument document = GetMainFrame()->document();
51 blink::WebElement element = 51 blink::WebElement element =
52 document.getElementById(blink::WebString::fromUTF8(element_id)); 52 document.getElementById(blink::WebString::fromUTF8(element_id));
53 ASSERT_FALSE(element.isNull()); 53 ASSERT_FALSE(element.isNull());
54 ExecuteJavaScriptForTests( 54 ExecuteJavaScript(
55 base::StringPrintf("document.getElementById('%s').focus();", 55 base::StringPrintf("document.getElementById('%s').focus();",
56 element_id).c_str()); 56 element_id).c_str());
57 } 57 }
58 58
59 void ExpectGenerationAvailable(const char* element_id, 59 void ExpectGenerationAvailable(const char* element_id,
60 bool available) { 60 bool available) {
61 FocusField(element_id); 61 FocusField(element_id);
62 ExpectPasswordGenerationAvailable(password_generation_, 62 ExpectPasswordGenerationAvailable(password_generation_,
63 available); 63 available);
64 } 64 }
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 // again. 411 // again.
412 SimulateUserTypingASCIICharacter(ui::VKEY_BACK, true); 412 SimulateUserTypingASCIICharacter(ui::VKEY_BACK, true);
413 // There should now be a message to show the UI. 413 // There should now be a message to show the UI.
414 ASSERT_EQ(1u, password_generation_->messages().size()); 414 ASSERT_EQ(1u, password_generation_->messages().size());
415 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 415 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
416 password_generation_->messages()[0]->type()); 416 password_generation_->messages()[0]->type());
417 password_generation_->clear_messages(); 417 password_generation_->clear_messages();
418 418
419 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent, 419 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent,
420 // so no messages are sent. 420 // so no messages are sent.
421 ExecuteJavaScriptForTests("document.getElementById('username').focus();"); 421 ExecuteJavaScript("document.getElementById('username').focus();");
422 EXPECT_EQ(0u, password_generation_->messages().size()); 422 EXPECT_EQ(0u, password_generation_->messages().size());
423 password_generation_->clear_messages(); 423 password_generation_->clear_messages();
424 424
425 // Focusing the password field will bring up the generation UI again. 425 // Focusing the password field will bring up the generation UI again.
426 ExecuteJavaScriptForTests( 426 ExecuteJavaScript("document.getElementById('first_password').focus();");
427 "document.getElementById('first_password').focus();");
428 ASSERT_EQ(1u, password_generation_->messages().size()); 427 ASSERT_EQ(1u, password_generation_->messages().size());
429 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 428 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
430 password_generation_->messages()[0]->type()); 429 password_generation_->messages()[0]->type());
431 password_generation_->clear_messages(); 430 password_generation_->clear_messages();
432 431
433 // Loading a different page triggers UMA stat upload. Verify that only one 432 // Loading a different page triggers UMA stat upload. Verify that only one
434 // display event is sent even though 433 // display event is sent even though
435 LoadHTMLWithUserGesture(kSigninFormHTML); 434 LoadHTMLWithUserGesture(kSigninFormHTML);
436 435
437 histogram_tester.ExpectBucketCount( 436 histogram_tester.ExpectBucketCount(
438 "PasswordGeneration.Event", 437 "PasswordGeneration.Event",
439 autofill::password_generation::GENERATION_POPUP_SHOWN, 438 autofill::password_generation::GENERATION_POPUP_SHOWN,
440 1); 439 1);
441 } 440 }
442 441
443 TEST_F(PasswordGenerationAgentTest, DynamicFormTest) { 442 TEST_F(PasswordGenerationAgentTest, DynamicFormTest) {
444 LoadHTMLWithUserGesture(kSigninFormHTML); 443 LoadHTMLWithUserGesture(kSigninFormHTML);
445 SetNotBlacklistedMessage(password_generation_, kSigninFormHTML); 444 SetNotBlacklistedMessage(password_generation_, kSigninFormHTML);
446 445
447 ExecuteJavaScriptForTests( 446 ExecuteJavaScript(
448 "var form = document.createElement('form');" 447 "var form = document.createElement('form');"
449 "var username = document.createElement('input');" 448 "var username = document.createElement('input');"
450 "username.type = 'text';" 449 "username.type = 'text';"
451 "username.id = 'dynamic_username';" 450 "username.id = 'dynamic_username';"
452 "var first_password = document.createElement('input');" 451 "var first_password = document.createElement('input');"
453 "first_password.type = 'password';" 452 "first_password.type = 'password';"
454 "first_password.id = 'first_password';" 453 "first_password.id = 'first_password';"
455 "first_password.name = 'first_password';" 454 "first_password.name = 'first_password';"
456 "var second_password = document.createElement('input');" 455 "var second_password = document.createElement('input');"
457 "second_password.type = 'password';" 456 "second_password.type = 'password';"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 ExpectGenerationAvailable("first_password", false); 545 ExpectGenerationAvailable("first_password", false);
547 546
548 LoadHTMLWithUserGesture(kNewPasswordAutocompleteAttributeFormHTML); 547 LoadHTMLWithUserGesture(kNewPasswordAutocompleteAttributeFormHTML);
549 SetNotBlacklistedMessage(password_generation_, 548 SetNotBlacklistedMessage(password_generation_,
550 kNewPasswordAutocompleteAttributeFormHTML); 549 kNewPasswordAutocompleteAttributeFormHTML);
551 550
552 ExpectGenerationAvailable("first_password", false); 551 ExpectGenerationAvailable("first_password", false);
553 } 552 }
554 553
555 } // namespace autofill 554 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698