| OLD | NEW |
| 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 Loading... |
| 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 ExecuteJavaScript( | 54 ExecuteJavaScriptForTests( |
| 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 Loading... |
| 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 ExecuteJavaScript("document.getElementById('username').focus();"); | 421 ExecuteJavaScriptForTests("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 ExecuteJavaScript("document.getElementById('first_password').focus();"); | 426 ExecuteJavaScriptForTests( |
| 427 "document.getElementById('first_password').focus();"); |
| 427 ASSERT_EQ(1u, password_generation_->messages().size()); | 428 ASSERT_EQ(1u, password_generation_->messages().size()); |
| 428 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, | 429 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, |
| 429 password_generation_->messages()[0]->type()); | 430 password_generation_->messages()[0]->type()); |
| 430 password_generation_->clear_messages(); | 431 password_generation_->clear_messages(); |
| 431 | 432 |
| 432 // Loading a different page triggers UMA stat upload. Verify that only one | 433 // Loading a different page triggers UMA stat upload. Verify that only one |
| 433 // display event is sent even though | 434 // display event is sent even though |
| 434 LoadHTMLWithUserGesture(kSigninFormHTML); | 435 LoadHTMLWithUserGesture(kSigninFormHTML); |
| 435 | 436 |
| 436 histogram_tester.ExpectBucketCount( | 437 histogram_tester.ExpectBucketCount( |
| 437 "PasswordGeneration.Event", | 438 "PasswordGeneration.Event", |
| 438 autofill::password_generation::GENERATION_POPUP_SHOWN, | 439 autofill::password_generation::GENERATION_POPUP_SHOWN, |
| 439 1); | 440 1); |
| 440 } | 441 } |
| 441 | 442 |
| 442 TEST_F(PasswordGenerationAgentTest, DynamicFormTest) { | 443 TEST_F(PasswordGenerationAgentTest, DynamicFormTest) { |
| 443 LoadHTMLWithUserGesture(kSigninFormHTML); | 444 LoadHTMLWithUserGesture(kSigninFormHTML); |
| 444 SetNotBlacklistedMessage(password_generation_, kSigninFormHTML); | 445 SetNotBlacklistedMessage(password_generation_, kSigninFormHTML); |
| 445 | 446 |
| 446 ExecuteJavaScript( | 447 ExecuteJavaScriptForTests( |
| 447 "var form = document.createElement('form');" | 448 "var form = document.createElement('form');" |
| 448 "var username = document.createElement('input');" | 449 "var username = document.createElement('input');" |
| 449 "username.type = 'text';" | 450 "username.type = 'text';" |
| 450 "username.id = 'dynamic_username';" | 451 "username.id = 'dynamic_username';" |
| 451 "var first_password = document.createElement('input');" | 452 "var first_password = document.createElement('input');" |
| 452 "first_password.type = 'password';" | 453 "first_password.type = 'password';" |
| 453 "first_password.id = 'first_password';" | 454 "first_password.id = 'first_password';" |
| 454 "first_password.name = 'first_password';" | 455 "first_password.name = 'first_password';" |
| 455 "var second_password = document.createElement('input');" | 456 "var second_password = document.createElement('input');" |
| 456 "second_password.type = 'password';" | 457 "second_password.type = 'password';" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 ExpectGenerationAvailable("first_password", false); | 546 ExpectGenerationAvailable("first_password", false); |
| 546 | 547 |
| 547 LoadHTMLWithUserGesture(kNewPasswordAutocompleteAttributeFormHTML); | 548 LoadHTMLWithUserGesture(kNewPasswordAutocompleteAttributeFormHTML); |
| 548 SetNotBlacklistedMessage(password_generation_, | 549 SetNotBlacklistedMessage(password_generation_, |
| 549 kNewPasswordAutocompleteAttributeFormHTML); | 550 kNewPasswordAutocompleteAttributeFormHTML); |
| 550 | 551 |
| 551 ExpectGenerationAvailable("first_password", false); | 552 ExpectGenerationAvailable("first_password", false); |
| 552 } | 553 } |
| 553 | 554 |
| 554 } // namespace autofill | 555 } // namespace autofill |
| OLD | NEW |