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/test/base/chrome_render_view_test.h" | 10 #include "chrome/test/base/chrome_render_view_test.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 void ExpectPasswordGenerationAvailable(const char* element_id, | 57 void ExpectPasswordGenerationAvailable(const char* element_id, |
58 bool available) { | 58 bool available) { |
59 WebDocument document = GetMainFrame()->document(); | 59 WebDocument document = GetMainFrame()->document(); |
60 WebElement element = | 60 WebElement element = |
61 document.getElementById(WebString::fromUTF8(element_id)); | 61 document.getElementById(WebString::fromUTF8(element_id)); |
62 ASSERT_FALSE(element.isNull()); | 62 ASSERT_FALSE(element.isNull()); |
63 ExecuteJavaScript( | 63 ExecuteJavaScript( |
64 base::StringPrintf("document.getElementById('%s').focus();", | 64 base::StringPrintf("document.getElementById('%s').focus();", |
65 element_id).c_str()); | 65 element_id).c_str()); |
| 66 SimulateFocusChangeCompleteMessageReceived(); |
66 if (available) { | 67 if (available) { |
67 ASSERT_EQ(1u, password_generation_->messages().size()); | 68 ASSERT_EQ(1u, password_generation_->messages().size()); |
68 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, | 69 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, |
69 password_generation_->messages()[0]->type()); | 70 password_generation_->messages()[0]->type()); |
70 } else { | 71 } else { |
71 EXPECT_EQ(0u, password_generation_->messages().size()); | 72 EXPECT_EQ(0u, password_generation_->messages().size()); |
72 } | 73 } |
73 password_generation_->clear_messages(); | 74 password_generation_->clear_messages(); |
74 } | 75 } |
75 | 76 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); | 260 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); |
260 ExpectPasswordGenerationAvailable("first_password", false); | 261 ExpectPasswordGenerationAvailable("first_password", false); |
261 | 262 |
262 // Receive one not blacklisted message for non account creation form. Don't | 263 // Receive one not blacklisted message for non account creation form. Don't |
263 // show password generation icon. | 264 // show password generation icon. |
264 LoadHTML(kAccountCreationFormHTML); | 265 LoadHTML(kAccountCreationFormHTML); |
265 SetNotBlacklistedMessage(kSigninFormHTML); | 266 SetNotBlacklistedMessage(kSigninFormHTML); |
266 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); | 267 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); |
267 ExpectPasswordGenerationAvailable("first_password", false); | 268 ExpectPasswordGenerationAvailable("first_password", false); |
268 | 269 |
269 // Receive one not blackliste message for account creation form. Show password | 270 // Receive one not blacklisted message for account creation form. Show |
270 // generation icon. | 271 // password generation icon. |
271 LoadHTML(kAccountCreationFormHTML); | 272 LoadHTML(kAccountCreationFormHTML); |
272 SetNotBlacklistedMessage(kAccountCreationFormHTML); | 273 SetNotBlacklistedMessage(kAccountCreationFormHTML); |
273 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); | 274 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); |
274 ExpectPasswordGenerationAvailable("first_password", true); | 275 ExpectPasswordGenerationAvailable("first_password", true); |
275 | 276 |
276 // Receive two not blacklisted messages, one is for account creation form and | 277 // Receive two not blacklisted messages, one is for account creation form and |
277 // the other is not. Show password generation icon. | 278 // the other is not. Show password generation icon. |
278 LoadHTML(kAccountCreationFormHTML); | 279 LoadHTML(kAccountCreationFormHTML); |
279 SetNotBlacklistedMessage(kAccountCreationFormHTML); | 280 SetNotBlacklistedMessage(kAccountCreationFormHTML); |
280 SetNotBlacklistedMessage(kSigninFormHTML); | 281 SetNotBlacklistedMessage(kSigninFormHTML); |
281 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); | 282 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); |
282 ExpectPasswordGenerationAvailable("first_password", true); | 283 ExpectPasswordGenerationAvailable("first_password", true); |
283 } | 284 } |
284 | 285 |
285 TEST_F(PasswordGenerationAgentTest, AccountCreationFormsDetectedTest) { | 286 TEST_F(PasswordGenerationAgentTest, AccountCreationFormsDetectedTest) { |
286 // Did not receive account creation forms detected messege. Don't show | 287 // Did not receive account creation forms detected message. Don't show |
287 // password generation icon. | 288 // password generation icon. |
288 LoadHTML(kAccountCreationFormHTML); | 289 LoadHTML(kAccountCreationFormHTML); |
289 SetNotBlacklistedMessage(kAccountCreationFormHTML); | 290 SetNotBlacklistedMessage(kAccountCreationFormHTML); |
290 ExpectPasswordGenerationAvailable("first_password", false); | 291 ExpectPasswordGenerationAvailable("first_password", false); |
291 | 292 |
292 // Receive the account creation forms detected message. Show password | 293 // Receive the account creation forms detected message. Show password |
293 // generation icon. | 294 // generation icon. |
294 LoadHTML(kAccountCreationFormHTML); | 295 LoadHTML(kAccountCreationFormHTML); |
295 SetNotBlacklistedMessage(kAccountCreationFormHTML); | 296 SetNotBlacklistedMessage(kAccountCreationFormHTML); |
296 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); | 297 SetAccountCreationFormsDetectedMessage(kAccountCreationFormHTML); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 base::MessageLoop::current()->RunUntilIdle(); | 357 base::MessageLoop::current()->RunUntilIdle(); |
357 // There should now be a message to show the UI. | 358 // There should now be a message to show the UI. |
358 ASSERT_EQ(1u, password_generation_->messages().size()); | 359 ASSERT_EQ(1u, password_generation_->messages().size()); |
359 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, | 360 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, |
360 password_generation_->messages()[0]->type()); | 361 password_generation_->messages()[0]->type()); |
361 password_generation_->clear_messages(); | 362 password_generation_->clear_messages(); |
362 | 363 |
363 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent, | 364 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent, |
364 // so no messages are sent. | 365 // so no messages are sent. |
365 ExecuteJavaScript("document.getElementById('username').focus();"); | 366 ExecuteJavaScript("document.getElementById('username').focus();"); |
| 367 SimulateFocusChangeCompleteMessageReceived(); |
366 EXPECT_EQ(0u, password_generation_->messages().size()); | 368 EXPECT_EQ(0u, password_generation_->messages().size()); |
367 password_generation_->clear_messages(); | 369 password_generation_->clear_messages(); |
368 | 370 |
369 // Focusing the password field will bring up the generation UI again. | 371 // Focusing the password field will bring up the generation UI again. |
370 ExecuteJavaScript("document.getElementById('first_password').focus();"); | 372 ExecuteJavaScript("document.getElementById('first_password').focus();"); |
371 EXPECT_EQ(1u, password_generation_->messages().size()); | 373 SimulateFocusChangeCompleteMessageReceived(); |
| 374 ASSERT_EQ(1u, password_generation_->messages().size()); |
372 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, | 375 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, |
373 password_generation_->messages()[0]->type()); | 376 password_generation_->messages()[0]->type()); |
374 password_generation_->clear_messages(); | 377 password_generation_->clear_messages(); |
375 | 378 |
376 // Loading a different page triggers UMA stat upload. Verify that only one | 379 // Loading a different page triggers UMA stat upload. Verify that only one |
377 // display event is sent even though | 380 // display event is sent even though |
378 LoadHTML(kSigninFormHTML); | 381 LoadHTML(kSigninFormHTML); |
379 | 382 |
380 histogram_tester.ExpectBucketCount( | 383 histogram_tester.ExpectBucketCount( |
381 "PasswordGeneration.Event", | 384 "PasswordGeneration.Event", |
(...skipping 17 matching lines...) Expand all Loading... |
399 "first_password.name = 'first_password';" | 402 "first_password.name = 'first_password';" |
400 "var second_password = document.createElement('input');" | 403 "var second_password = document.createElement('input');" |
401 "second_password.type = 'password';" | 404 "second_password.type = 'password';" |
402 "second_password.id = 'second_password';" | 405 "second_password.id = 'second_password';" |
403 "second_password.name = 'second_password';" | 406 "second_password.name = 'second_password';" |
404 "form.appendChild(username);" | 407 "form.appendChild(username);" |
405 "form.appendChild(first_password);" | 408 "form.appendChild(first_password);" |
406 "form.appendChild(second_password);" | 409 "form.appendChild(second_password);" |
407 "document.body.appendChild(form);"); | 410 "document.body.appendChild(form);"); |
408 ProcessPendingMessages(); | 411 ProcessPendingMessages(); |
409 // TODO(gcasto): I'm slighty worried about flakes in this test where | 412 // TODO(gcasto): I'm slightly worried about flakes in this test where |
410 // didAssociateFormControls() isn't called. If this turns out to be a problem | 413 // didAssociateFormControls() isn't called. If this turns out to be a problem |
411 // adding a call to OnDynamicFormsSeen(GetMainFrame()) will fix it, though | 414 // adding a call to OnDynamicFormsSeen(GetMainFrame()) will fix it, though |
412 // it will weaken the test. | 415 // it will weaken the test. |
413 ExpectPasswordGenerationAvailable("first_password", true); | 416 ExpectPasswordGenerationAvailable("first_password", true); |
414 } | 417 } |
415 | 418 |
416 } // namespace autofill | 419 } // namespace autofill |
OLD | NEW |