Chromium Code Reviews| Index: chrome/renderer/autofill/password_generation_agent_browsertest.cc |
| diff --git a/chrome/renderer/autofill/password_generation_agent_browsertest.cc b/chrome/renderer/autofill/password_generation_agent_browsertest.cc |
| index 35eae491ecb4ef11908e0757102af02f032b30b4..07f03756a6024d2028e88c72a5609f7e55ae4281 100644 |
| --- a/chrome/renderer/autofill/password_generation_agent_browsertest.cc |
| +++ b/chrome/renderer/autofill/password_generation_agent_browsertest.cc |
| @@ -58,7 +58,6 @@ class PasswordGenerationAgentTest : public ChromeRenderViewTest { |
| WebElement element = |
| document.getElementById(WebString::fromUTF8(element_id)); |
| ASSERT_FALSE(element.isNull()); |
| - WebInputElement target_element = element.to<WebInputElement>(); |
| ExecuteJavaScript( |
| base::StringPrintf("document.getElementById('%s').focus();", |
| element_id).c_str()); |
| @@ -256,4 +255,65 @@ TEST_F(PasswordGenerationAgentTest, AccountCreationFormsDetectedTest) { |
| ExpectPasswordGenerationAvailable("first_password", true); |
| } |
| +TEST_F(PasswordGenerationAgentTest, MaximumOfferSize) { |
| + LoadHTML(kAccountCreationFormHTML); |
| + SetNotBlacklistedMessage(kAccountCreationFormHTML); |
| + SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); |
| + ExpectPasswordGenerationAvailable("first_password", true); |
| + |
| + WebDocument document = GetMainFrame()->document(); |
| + WebElement element = |
| + document.getElementById(WebString::fromUTF8("first_password")); |
| + ASSERT_FALSE(element.isNull()); |
| + WebInputElement first_password_element = element.to<WebInputElement>(); |
| + |
| + // Make a password small just under maximum offer size. |
|
Ilya Sherman
2014/08/06 22:25:08
nit: This wording feels a little odd. Mind rephra
Garrett Casto
2014/08/08 18:19:19
Typo, cleaned up.
|
| + first_password_element.setValue( |
| + base::ASCIIToUTF16( |
| + std::string(password_generation_->kMaximumOfferSize - 1, 'a'))); |
| + // Cast to WebAutofillClient where textFieldDidChange() is public. |
| + static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( |
| + first_password_element); |
| + // textFieldDidChange posts a task, so we need to wait until it's been |
| + // processed. |
| + base::MessageLoop::current()->RunUntilIdle(); |
| + // There should now be a message to show the UI. |
| + ASSERT_EQ(1u, password_generation_->messages().size()); |
| + EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, |
| + password_generation_->messages()[0]->type()); |
| + password_generation_->clear_messages(); |
| + |
| + // Simulate a user typing a password just over maximum offer size. |
| + first_password_element.setValue( |
| + base::ASCIIToUTF16( |
| + std::string(password_generation_->kMaximumOfferSize + 1, 'a'))); |
|
Ilya Sherman
2014/08/06 22:25:08
You have tests for |kMaximumOfferSize - 1| and |kM
Garrett Casto
2014/08/08 18:19:19
Done.
|
| + // Cast to WebAutofillClient where textFieldDidChange() is public. |
| + static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( |
| + first_password_element); |
| + // textFieldDidChange posts a task, so we need to wait until it's been |
| + // processed. |
| + base::MessageLoop::current()->RunUntilIdle(); |
| + // There should now be a message to hide the UI. |
| + ASSERT_EQ(1u, password_generation_->messages().size()); |
| + EXPECT_EQ(AutofillHostMsg_HidePasswordGenerationPopup::ID, |
| + password_generation_->messages()[0]->type()); |
| + password_generation_->clear_messages(); |
| + |
| + // Simulate the user deleting characters. The generation popup should be shown |
| + // again. |
| + first_password_element.setValue( |
| + base::ASCIIToUTF16( |
| + std::string(password_generation_->kMaximumOfferSize - 1, 'a'))); |
| + // Cast to WebAutofillClient where textFieldDidChange() is public. |
| + static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( |
| + first_password_element); |
| + // textFieldDidChange posts a task, so we need to wait until it's been |
| + // processed. |
| + base::MessageLoop::current()->RunUntilIdle(); |
| + // There should now be a message to show the UI. |
| + ASSERT_EQ(1u, password_generation_->messages().size()); |
| + EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, |
| + password_generation_->messages()[0]->type()); |
| +} |
| + |
| } // namespace autofill |