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

Unified Diff: chrome/renderer/autofill/password_generation_agent_browsertest.cc

Issue 447873004: [Password Generation] Wait longer to dismiss suggestion UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
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..60bdaa3efa8a9c77e86dc2d7997968038f342b55 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,79 @@ 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 just under maximum offer size.
+ 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')));
+ // 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, '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();
+
+ // Change focus. Bubble should be hidden, but that is handled by AutofilAgent,
+ // so no messages are sent.
+ ExecuteJavaScript("document.getElementById('username').focus();");
+ EXPECT_EQ(0u, password_generation_->messages().size());
+ password_generation_->clear_messages();
+
+ // Focusing the password field will bring up the generation UI again.
+ ExecuteJavaScript("document.getElementById('first_password').focus();");
+ EXPECT_EQ(1u, password_generation_->messages().size());
+ EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
+ password_generation_->messages()[0]->type());
+ password_generation_->clear_messages();
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698