| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/common/autofill_messages.h" | 10 #include "chrome/common/autofill_messages.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 " <INPUT type = 'text' id = 'username'/> " | 99 " <INPUT type = 'text' id = 'username'/> " |
| 100 " <INPUT type = 'password' id = 'password'/> " | 100 " <INPUT type = 'password' id = 'password'/> " |
| 101 " <INPUT type = 'submit' value = 'LOGIN' />" | 101 " <INPUT type = 'submit' value = 'LOGIN' />" |
| 102 "</FORM>"; | 102 "</FORM>"; |
| 103 | 103 |
| 104 const char kAccountCreationFormHTML[] = | 104 const char kAccountCreationFormHTML[] = |
| 105 "<FORM name = 'blah' action = 'http://www.random.com/'> " | 105 "<FORM name = 'blah' action = 'http://www.random.com/'> " |
| 106 " <INPUT type = 'text' id = 'username'/> " | 106 " <INPUT type = 'text' id = 'username'/> " |
| 107 " <INPUT type = 'password' id = 'first_password' size=5/> " | 107 " <INPUT type = 'password' id = 'first_password' size=5/> " |
| 108 " <INPUT type = 'password' id = 'second_password' size=5/> " | 108 " <INPUT type = 'password' id = 'second_password' size=5/> " |
| 109 " <INPUT type = 'text' id = 'address'/> " |
| 109 " <INPUT type = 'submit' value = 'LOGIN' />" | 110 " <INPUT type = 'submit' value = 'LOGIN' />" |
| 110 "</FORM>"; | 111 "</FORM>"; |
| 111 | 112 |
| 112 const char kHiddenPasswordAccountCreationFormHTML[] = | 113 const char kHiddenPasswordAccountCreationFormHTML[] = |
| 113 "<FORM name = 'blah' action = 'http://www.random.com/'> " | 114 "<FORM name = 'blah' action = 'http://www.random.com/'> " |
| 114 " <INPUT type = 'text' id = 'username'/> " | 115 " <INPUT type = 'text' id = 'username'/> " |
| 115 " <INPUT type = 'password' id = 'first_password'/> " | 116 " <INPUT type = 'password' id = 'first_password'/> " |
| 116 " <INPUT type = 'password' id = 'second_password' style='display:none'/> " | 117 " <INPUT type = 'password' id = 'second_password' style='display:none'/> " |
| 117 " <INPUT type = 'submit' value = 'LOGIN' />" | 118 " <INPUT type = 'submit' value = 'LOGIN' />" |
| 118 "</FORM>"; | 119 "</FORM>"; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 204 |
| 204 string16 password = ASCIIToUTF16("random_password"); | 205 string16 password = ASCIIToUTF16("random_password"); |
| 205 AutofillMsg_GeneratedPasswordAccepted msg(0, password); | 206 AutofillMsg_GeneratedPasswordAccepted msg(0, password); |
| 206 generation_manager_->OnMessageReceived(msg); | 207 generation_manager_->OnMessageReceived(msg); |
| 207 | 208 |
| 208 // Password fields are filled out and set as being autofilled. | 209 // Password fields are filled out and set as being autofilled. |
| 209 EXPECT_EQ(password, first_password_element.value()); | 210 EXPECT_EQ(password, first_password_element.value()); |
| 210 EXPECT_EQ(password, second_password_element.value()); | 211 EXPECT_EQ(password, second_password_element.value()); |
| 211 EXPECT_TRUE(first_password_element.isAutofilled()); | 212 EXPECT_TRUE(first_password_element.isAutofilled()); |
| 212 EXPECT_TRUE(second_password_element.isAutofilled()); | 213 EXPECT_TRUE(second_password_element.isAutofilled()); |
| 214 |
| 215 // Focus moved to the next input field. |
| 216 // TODO(zysxqn): Change this back to the address element once Bug 90224 |
| 217 // https://bugs.webkit.org/show_bug.cgi?id=90224 has been fixed. |
| 218 element = document.getElementById(WebString::fromUTF8("first_password")); |
| 219 ASSERT_FALSE(element.isNull()); |
| 220 EXPECT_EQ(element, document.focusedNode()); |
| 213 } | 221 } |
| 214 | 222 |
| 215 TEST_F(PasswordGenerationManagerTest, BlacklistedTest) { | 223 TEST_F(PasswordGenerationManagerTest, BlacklistedTest) { |
| 216 // Make sure password generation is enabled. | 224 // Make sure password generation is enabled. |
| 217 AutofillMsg_PasswordGenerationEnabled enabled_msg(0, true); | 225 AutofillMsg_PasswordGenerationEnabled enabled_msg(0, true); |
| 218 generation_manager_->OnMessageReceived(enabled_msg); | 226 generation_manager_->OnMessageReceived(enabled_msg); |
| 219 | 227 |
| 220 // Did not receive not blacklisted message. Don't show password generation | 228 // Did not receive not blacklisted message. Don't show password generation |
| 221 // icon. | 229 // icon. |
| 222 LoadHTML(kAccountCreationFormHTML); | 230 LoadHTML(kAccountCreationFormHTML); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 ASSERT_FALSE(element.isNull()); | 269 ASSERT_FALSE(element.isNull()); |
| 262 first_password_element = element.to<WebInputElement>(); | 270 first_password_element = element.to<WebInputElement>(); |
| 263 EXPECT_TRUE(DecorationIsVisible(&first_password_element)); | 271 EXPECT_TRUE(DecorationIsVisible(&first_password_element)); |
| 264 SimulateClickOnDecoration(&first_password_element); | 272 SimulateClickOnDecoration(&first_password_element); |
| 265 EXPECT_EQ(2u, generation_manager_->messages().size()); | 273 EXPECT_EQ(2u, generation_manager_->messages().size()); |
| 266 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, | 274 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, |
| 267 generation_manager_->messages()[1]->type()); | 275 generation_manager_->messages()[1]->type()); |
| 268 } | 276 } |
| 269 | 277 |
| 270 } // namespace autofill | 278 } // namespace autofill |
| OLD | NEW |