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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 AutofillMsg_AccountCreationFormsDetected msg(0, forms); 51 AutofillMsg_AccountCreationFormsDetected msg(0, forms);
52 password_generation_->OnMessageReceived(msg); 52 password_generation_->OnMessageReceived(msg);
53 } 53 }
54 54
55 void ExpectPasswordGenerationAvailable(const char* element_id, 55 void ExpectPasswordGenerationAvailable(const char* element_id,
56 bool available) { 56 bool available) {
57 WebDocument document = GetMainFrame()->document(); 57 WebDocument document = GetMainFrame()->document();
58 WebElement element = 58 WebElement element =
59 document.getElementById(WebString::fromUTF8(element_id)); 59 document.getElementById(WebString::fromUTF8(element_id));
60 ASSERT_FALSE(element.isNull()); 60 ASSERT_FALSE(element.isNull());
61 WebInputElement target_element = element.to<WebInputElement>();
62 ExecuteJavaScript( 61 ExecuteJavaScript(
63 base::StringPrintf("document.getElementById('%s').focus();", 62 base::StringPrintf("document.getElementById('%s').focus();",
64 element_id).c_str()); 63 element_id).c_str());
65 if (available) { 64 if (available) {
66 ASSERT_EQ(1u, password_generation_->messages().size()); 65 ASSERT_EQ(1u, password_generation_->messages().size());
67 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 66 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
68 password_generation_->messages()[0]->type()); 67 password_generation_->messages()[0]->type());
69 } else { 68 } else {
70 EXPECT_EQ(0u, password_generation_->messages().size()); 69 EXPECT_EQ(0u, password_generation_->messages().size());
71 } 70 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 ExpectPasswordGenerationAvailable("first_password", false); 248 ExpectPasswordGenerationAvailable("first_password", false);
250 249
251 // Receive the account creation forms detected message. Show password 250 // Receive the account creation forms detected message. Show password
252 // generation icon. 251 // generation icon.
253 LoadHTML(kAccountCreationFormHTML); 252 LoadHTML(kAccountCreationFormHTML);
254 SetNotBlacklistedMessage(kAccountCreationFormHTML); 253 SetNotBlacklistedMessage(kAccountCreationFormHTML);
255 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); 254 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML);
256 ExpectPasswordGenerationAvailable("first_password", true); 255 ExpectPasswordGenerationAvailable("first_password", true);
257 } 256 }
258 257
258 TEST_F(PasswordGenerationAgentTest, MaximumOfferSize) {
259 LoadHTML(kAccountCreationFormHTML);
260 SetNotBlacklistedMessage(kAccountCreationFormHTML);
261 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML);
262 ExpectPasswordGenerationAvailable("first_password", true);
263
264 WebDocument document = GetMainFrame()->document();
265 WebElement element =
266 document.getElementById(WebString::fromUTF8("first_password"));
267 ASSERT_FALSE(element.isNull());
268 WebInputElement first_password_element = element.to<WebInputElement>();
269
270 // 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.
271 first_password_element.setValue(
272 base::ASCIIToUTF16(
273 std::string(password_generation_->kMaximumOfferSize - 1, 'a')));
274 // Cast to WebAutofillClient where textFieldDidChange() is public.
275 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange(
276 first_password_element);
277 // textFieldDidChange posts a task, so we need to wait until it's been
278 // processed.
279 base::MessageLoop::current()->RunUntilIdle();
280 // There should now be a message to show the UI.
281 ASSERT_EQ(1u, password_generation_->messages().size());
282 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
283 password_generation_->messages()[0]->type());
284 password_generation_->clear_messages();
285
286 // Simulate a user typing a password just over maximum offer size.
287 first_password_element.setValue(
288 base::ASCIIToUTF16(
289 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.
290 // Cast to WebAutofillClient where textFieldDidChange() is public.
291 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange(
292 first_password_element);
293 // textFieldDidChange posts a task, so we need to wait until it's been
294 // processed.
295 base::MessageLoop::current()->RunUntilIdle();
296 // There should now be a message to hide the UI.
297 ASSERT_EQ(1u, password_generation_->messages().size());
298 EXPECT_EQ(AutofillHostMsg_HidePasswordGenerationPopup::ID,
299 password_generation_->messages()[0]->type());
300 password_generation_->clear_messages();
301
302 // Simulate the user deleting characters. The generation popup should be shown
303 // again.
304 first_password_element.setValue(
305 base::ASCIIToUTF16(
306 std::string(password_generation_->kMaximumOfferSize - 1, 'a')));
307 // Cast to WebAutofillClient where textFieldDidChange() is public.
308 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange(
309 first_password_element);
310 // textFieldDidChange posts a task, so we need to wait until it's been
311 // processed.
312 base::MessageLoop::current()->RunUntilIdle();
313 // There should now be a message to show the UI.
314 ASSERT_EQ(1u, password_generation_->messages().size());
315 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
316 password_generation_->messages()[0]->type());
317 }
318
259 } // namespace autofill 319 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698