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

Side by Side Diff: chrome/renderer/autofill/password_generation_agent_browsertest.cc

Issue 715733002: [Android] Show autofill popup after animation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add zoomed page click test. Created 5 years, 11 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
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 "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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 if (available) { 78 if (available) {
79 ASSERT_EQ(1u, password_generation_->messages().size()); 79 ASSERT_EQ(1u, password_generation_->messages().size());
80 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 80 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
81 password_generation_->messages()[0]->type()); 81 password_generation_->messages()[0]->type());
82 } else { 82 } else {
83 EXPECT_EQ(0u, password_generation_->messages().size()); 83 EXPECT_EQ(0u, password_generation_->messages().size());
84 } 84 }
85 password_generation_->clear_messages(); 85 password_generation_->clear_messages();
86 } 86 }
87 87
88 void LoadHTMLWithUserGesture(const char* html) {
89 LoadHTML(html);
90
91 // Enable show-ime event when element is focused by indicating that a user
92 // gesture has been processed since load.
93 EXPECT_TRUE(SimulateElementClick("dummy"));
94 }
95
88 private: 96 private:
89 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgentTest); 97 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgentTest);
90 }; 98 };
91 99
92 const char kSigninFormHTML[] = 100 const char kSigninFormHTML[] =
93 "<FORM name = 'blah' action = 'http://www.random.com/'> " 101 "<FORM name = 'blah' action = 'http://www.random.com/'> "
94 " <INPUT type = 'text' id = 'username'/> " 102 " <INPUT type = 'text' id = 'username'/> "
95 " <INPUT type = 'password' id = 'password'/> " 103 " <INPUT type = 'password' id = 'password'/> "
104 " <INPUT type = 'button' id = 'dummy'/> "
96 " <INPUT type = 'submit' value = 'LOGIN' />" 105 " <INPUT type = 'submit' value = 'LOGIN' />"
97 "</FORM>"; 106 "</FORM>";
98 107
99 const char kAccountCreationFormHTML[] = 108 const char kAccountCreationFormHTML[] =
100 "<FORM name = 'blah' action = 'http://www.random.com/'> " 109 "<FORM name = 'blah' action = 'http://www.random.com/'> "
101 " <INPUT type = 'text' id = 'username'/> " 110 " <INPUT type = 'text' id = 'username'/> "
102 " <INPUT type = 'password' id = 'first_password' " 111 " <INPUT type = 'password' id = 'first_password' "
103 " autocomplete = 'off' size = 5/>" 112 " autocomplete = 'off' size = 5/>"
104 " <INPUT type = 'password' id = 'second_password' size = 5/> " 113 " <INPUT type = 'password' id = 'second_password' size = 5/> "
105 " <INPUT type = 'text' id = 'address'/> " 114 " <INPUT type = 'text' id = 'address'/> "
115 " <INPUT type = 'button' id = 'dummy'/> "
106 " <INPUT type = 'submit' value = 'LOGIN' />" 116 " <INPUT type = 'submit' value = 'LOGIN' />"
107 "</FORM>"; 117 "</FORM>";
108 118
109 const char kHiddenPasswordAccountCreationFormHTML[] = 119 const char kHiddenPasswordAccountCreationFormHTML[] =
110 "<FORM name = 'blah' action = 'http://www.random.com/'> " 120 "<FORM name = 'blah' action = 'http://www.random.com/'> "
111 " <INPUT type = 'text' id = 'username'/> " 121 " <INPUT type = 'text' id = 'username'/> "
112 " <INPUT type = 'password' id = 'first_password'/> " 122 " <INPUT type = 'password' id = 'first_password'/> "
113 " <INPUT type = 'password' id = 'second_password' style='display:none'/> " 123 " <INPUT type = 'password' id = 'second_password' style='display:none'/> "
124 " <INPUT type = 'button' id = 'dummy'/> "
114 " <INPUT type = 'submit' value = 'LOGIN' />" 125 " <INPUT type = 'submit' value = 'LOGIN' />"
115 "</FORM>"; 126 "</FORM>";
116 127
117 const char kInvalidActionAccountCreationFormHTML[] = 128 const char kInvalidActionAccountCreationFormHTML[] =
118 "<FORM name = 'blah' action = 'invalid'> " 129 "<FORM name = 'blah' action = 'invalid'> "
119 " <INPUT type = 'text' id = 'username'/> " 130 " <INPUT type = 'text' id = 'username'/> "
120 " <INPUT type = 'password' id = 'first_password'/> " 131 " <INPUT type = 'password' id = 'first_password'/> "
121 " <INPUT type = 'password' id = 'second_password'/> " 132 " <INPUT type = 'password' id = 'second_password'/> "
133 " <INPUT type = 'button' id = 'dummy'/> "
122 " <INPUT type = 'submit' value = 'LOGIN' />" 134 " <INPUT type = 'submit' value = 'LOGIN' />"
123 "</FORM>"; 135 "</FORM>";
124 136
125 const char kMultipleAccountCreationFormHTML[] = 137 const char kMultipleAccountCreationFormHTML[] =
126 "<FORM name = 'login' action = 'http://www.random.com/'> " 138 "<FORM name = 'login' action = 'http://www.random.com/'> "
127 " <INPUT type = 'text' id = 'random'/> " 139 " <INPUT type = 'text' id = 'random'/> "
128 " <INPUT type = 'text' id = 'username'/> " 140 " <INPUT type = 'text' id = 'username'/> "
129 " <INPUT type = 'password' id = 'password'/> " 141 " <INPUT type = 'password' id = 'password'/> "
142 " <INPUT type = 'button' id = 'dummy'/> "
130 " <INPUT type = 'submit' value = 'LOGIN' />" 143 " <INPUT type = 'submit' value = 'LOGIN' />"
131 "</FORM>" 144 "</FORM>"
132 "<FORM name = 'signup' action = 'http://www.random.com/signup'> " 145 "<FORM name = 'signup' action = 'http://www.random.com/signup'> "
133 " <INPUT type = 'text' id = 'username'/> " 146 " <INPUT type = 'text' id = 'username'/> "
134 " <INPUT type = 'password' id = 'first_password' " 147 " <INPUT type = 'password' id = 'first_password' "
135 " autocomplete = 'off' size = 5/>" 148 " autocomplete = 'off' size = 5/>"
136 " <INPUT type = 'password' id = 'second_password' size = 5/> " 149 " <INPUT type = 'password' id = 'second_password' size = 5/> "
137 " <INPUT type = 'text' id = 'address'/> " 150 " <INPUT type = 'text' id = 'address'/> "
138 " <INPUT type = 'submit' value = 'LOGIN' />" 151 " <INPUT type = 'submit' value = 'LOGIN' />"
139 "</FORM>"; 152 "</FORM>";
140 153
141 const char ChangeDetectionScript[] = 154 const char ChangeDetectionScript[] =
142 "<script>" 155 "<script>"
143 " firstOnChangeCalled = false;" 156 " firstOnChangeCalled = false;"
144 " secondOnChangeCalled = false;" 157 " secondOnChangeCalled = false;"
145 " document.getElementById('first_password').onchange = function() {" 158 " document.getElementById('first_password').onchange = function() {"
146 " firstOnChangeCalled = true;" 159 " firstOnChangeCalled = true;"
147 " };" 160 " };"
148 " document.getElementById('second_password').onchange = function() {" 161 " document.getElementById('second_password').onchange = function() {"
149 " secondOnChangeCalled = true;" 162 " secondOnChangeCalled = true;"
150 " };" 163 " };"
151 "</script>"; 164 "</script>";
152 165
153 TEST_F(PasswordGenerationAgentTest, DetectionTest) { 166 TEST_F(PasswordGenerationAgentTest, DetectionTest) {
154 // Don't shown the icon for non account creation forms. 167 // Don't shown the icon for non account creation forms.
155 LoadHTML(kSigninFormHTML); 168 LoadHTMLWithUserGesture(kSigninFormHTML);
156 ExpectPasswordGenerationAvailable("password", false); 169 ExpectPasswordGenerationAvailable("password", false);
157 170
158 // We don't show the decoration yet because the feature isn't enabled. 171 // We don't show the decoration yet because the feature isn't enabled.
159 LoadHTML(kAccountCreationFormHTML); 172 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
160 ExpectPasswordGenerationAvailable("first_password", false); 173 ExpectPasswordGenerationAvailable("first_password", false);
161 174
162 // Pretend like We have received message indicating site is not blacklisted, 175 // Pretend like We have received message indicating site is not blacklisted,
163 // and we have received message indicating the form is classified as 176 // and we have received message indicating the form is classified as
164 // ACCOUNT_CREATION_FORM form Autofill server. We should show the icon. 177 // ACCOUNT_CREATION_FORM form Autofill server. We should show the icon.
165 LoadHTML(kAccountCreationFormHTML); 178 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
166 SetNotBlacklistedMessage(kAccountCreationFormHTML); 179 SetNotBlacklistedMessage(kAccountCreationFormHTML);
167 SetAccountCreationFormsDetectedMessage(0); 180 SetAccountCreationFormsDetectedMessage(0);
168 ExpectPasswordGenerationAvailable("first_password", true); 181 ExpectPasswordGenerationAvailable("first_password", true);
169 182
170 // Hidden fields are not treated differently. 183 // Hidden fields are not treated differently.
171 LoadHTML(kHiddenPasswordAccountCreationFormHTML); 184 LoadHTMLWithUserGesture(kHiddenPasswordAccountCreationFormHTML);
172 SetNotBlacklistedMessage(kHiddenPasswordAccountCreationFormHTML); 185 SetNotBlacklistedMessage(kHiddenPasswordAccountCreationFormHTML);
173 SetAccountCreationFormsDetectedMessage(0); 186 SetAccountCreationFormsDetectedMessage(0);
174 ExpectPasswordGenerationAvailable("first_password", true); 187 ExpectPasswordGenerationAvailable("first_password", true);
175 188
176 // This doesn't trigger because the form action is invalid. 189 // This doesn't trigger because the form action is invalid.
177 LoadHTML(kInvalidActionAccountCreationFormHTML); 190 LoadHTMLWithUserGesture(kInvalidActionAccountCreationFormHTML);
178 SetNotBlacklistedMessage(kInvalidActionAccountCreationFormHTML); 191 SetNotBlacklistedMessage(kInvalidActionAccountCreationFormHTML);
179 SetAccountCreationFormsDetectedMessage(0); 192 SetAccountCreationFormsDetectedMessage(0);
180 ExpectPasswordGenerationAvailable("first_password", false); 193 ExpectPasswordGenerationAvailable("first_password", false);
181 } 194 }
182 195
183 TEST_F(PasswordGenerationAgentTest, FillTest) { 196 TEST_F(PasswordGenerationAgentTest, FillTest) {
184 // Make sure that we are enabled before loading HTML. 197 // Make sure that we are enabled before loading HTML.
185 std::string html = std::string(kAccountCreationFormHTML) + 198 std::string html = std::string(kAccountCreationFormHTML) +
186 ChangeDetectionScript; 199 ChangeDetectionScript;
187 LoadHTML(html.c_str()); 200 LoadHTMLWithUserGesture(html.c_str());
188 SetNotBlacklistedMessage(html.c_str()); 201 SetNotBlacklistedMessage(html.c_str());
189 SetAccountCreationFormsDetectedMessage(0); 202 SetAccountCreationFormsDetectedMessage(0);
190 203
191 WebDocument document = GetMainFrame()->document(); 204 WebDocument document = GetMainFrame()->document();
192 WebElement element = 205 WebElement element =
193 document.getElementById(WebString::fromUTF8("first_password")); 206 document.getElementById(WebString::fromUTF8("first_password"));
194 ASSERT_FALSE(element.isNull()); 207 ASSERT_FALSE(element.isNull());
195 WebInputElement first_password_element = element.to<WebInputElement>(); 208 WebInputElement first_password_element = element.to<WebInputElement>();
196 element = document.getElementById(WebString::fromUTF8("second_password")); 209 element = document.getElementById(WebString::fromUTF8("second_password"));
197 ASSERT_FALSE(element.isNull()); 210 ASSERT_FALSE(element.isNull());
(...skipping 29 matching lines...) Expand all
227 240
228 // Focus moved to the next input field. 241 // Focus moved to the next input field.
229 // TODO(zysxqn): Change this back to the address element once Bug 90224 242 // TODO(zysxqn): Change this back to the address element once Bug 90224
230 // https://bugs.webkit.org/show_bug.cgi?id=90224 has been fixed. 243 // https://bugs.webkit.org/show_bug.cgi?id=90224 has been fixed.
231 element = document.getElementById(WebString::fromUTF8("first_password")); 244 element = document.getElementById(WebString::fromUTF8("first_password"));
232 ASSERT_FALSE(element.isNull()); 245 ASSERT_FALSE(element.isNull());
233 EXPECT_EQ(element, document.focusedElement()); 246 EXPECT_EQ(element, document.focusedElement());
234 } 247 }
235 248
236 TEST_F(PasswordGenerationAgentTest, EditingTest) { 249 TEST_F(PasswordGenerationAgentTest, EditingTest) {
237 LoadHTML(kAccountCreationFormHTML); 250 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
238 SetNotBlacklistedMessage(kAccountCreationFormHTML); 251 SetNotBlacklistedMessage(kAccountCreationFormHTML);
239 SetAccountCreationFormsDetectedMessage(0); 252 SetAccountCreationFormsDetectedMessage(0);
240 253
241 WebDocument document = GetMainFrame()->document(); 254 WebDocument document = GetMainFrame()->document();
242 WebElement element = 255 WebElement element =
243 document.getElementById(WebString::fromUTF8("first_password")); 256 document.getElementById(WebString::fromUTF8("first_password"));
244 ASSERT_FALSE(element.isNull()); 257 ASSERT_FALSE(element.isNull());
245 WebInputElement first_password_element = element.to<WebInputElement>(); 258 WebInputElement first_password_element = element.to<WebInputElement>();
246 element = document.getElementById(WebString::fromUTF8("second_password")); 259 element = document.getElementById(WebString::fromUTF8("second_password"));
247 ASSERT_FALSE(element.isNull()); 260 ASSERT_FALSE(element.isNull());
(...skipping 29 matching lines...) Expand all
277 // textFieldDidChange posts a task, so we need to wait until it's been 290 // textFieldDidChange posts a task, so we need to wait until it's been
278 // processed. 291 // processed.
279 base::MessageLoop::current()->RunUntilIdle(); 292 base::MessageLoop::current()->RunUntilIdle();
280 EXPECT_EQ(empty_password, first_password_element.value()); 293 EXPECT_EQ(empty_password, first_password_element.value());
281 EXPECT_EQ(empty_password, second_password_element.value()); 294 EXPECT_EQ(empty_password, second_password_element.value());
282 } 295 }
283 296
284 TEST_F(PasswordGenerationAgentTest, BlacklistedTest) { 297 TEST_F(PasswordGenerationAgentTest, BlacklistedTest) {
285 // Did not receive not blacklisted message. Don't show password generation 298 // Did not receive not blacklisted message. Don't show password generation
286 // icon. 299 // icon.
287 LoadHTML(kAccountCreationFormHTML); 300 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
288 SetAccountCreationFormsDetectedMessage(0); 301 SetAccountCreationFormsDetectedMessage(0);
289 ExpectPasswordGenerationAvailable("first_password", false); 302 ExpectPasswordGenerationAvailable("first_password", false);
290 303
291 // Receive one not blacklisted message for non account creation form. Don't 304 // Receive one not blacklisted message for non account creation form. Don't
292 // show password generation icon. 305 // show password generation icon.
293 LoadHTML(kAccountCreationFormHTML); 306 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
294 SetNotBlacklistedMessage(kSigninFormHTML); 307 SetNotBlacklistedMessage(kSigninFormHTML);
295 SetAccountCreationFormsDetectedMessage(0); 308 SetAccountCreationFormsDetectedMessage(0);
296 ExpectPasswordGenerationAvailable("first_password", false); 309 ExpectPasswordGenerationAvailable("first_password", false);
297 310
298 // Receive one not blackliste message for account creation form. Show password 311 // Receive one not blacklisted message for account creation form. Show
299 // generation icon. 312 // password generation icon.
300 LoadHTML(kAccountCreationFormHTML); 313 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
301 SetNotBlacklistedMessage(kAccountCreationFormHTML); 314 SetNotBlacklistedMessage(kAccountCreationFormHTML);
302 SetAccountCreationFormsDetectedMessage(0); 315 SetAccountCreationFormsDetectedMessage(0);
303 ExpectPasswordGenerationAvailable("first_password", true); 316 ExpectPasswordGenerationAvailable("first_password", true);
304 317
305 // Receive two not blacklisted messages, one is for account creation form and 318 // Receive two not blacklisted messages, one is for account creation form and
306 // the other is not. Show password generation icon. 319 // the other is not. Show password generation icon.
307 LoadHTML(kAccountCreationFormHTML); 320 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
308 SetNotBlacklistedMessage(kAccountCreationFormHTML); 321 SetNotBlacklistedMessage(kAccountCreationFormHTML);
309 SetNotBlacklistedMessage(kSigninFormHTML); 322 SetNotBlacklistedMessage(kSigninFormHTML);
310 SetAccountCreationFormsDetectedMessage(0); 323 SetAccountCreationFormsDetectedMessage(0);
311 ExpectPasswordGenerationAvailable("first_password", true); 324 ExpectPasswordGenerationAvailable("first_password", true);
312 } 325 }
313 326
314 TEST_F(PasswordGenerationAgentTest, AccountCreationFormsDetectedTest) { 327 TEST_F(PasswordGenerationAgentTest, AccountCreationFormsDetectedTest) {
315 // Did not receive account creation forms detected messege. Don't show 328 // Did not receive account creation forms detected message. Don't show
316 // password generation icon. 329 // password generation icon.
317 LoadHTML(kAccountCreationFormHTML); 330 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
318 SetNotBlacklistedMessage(kAccountCreationFormHTML); 331 SetNotBlacklistedMessage(kAccountCreationFormHTML);
319 ExpectPasswordGenerationAvailable("first_password", false); 332 ExpectPasswordGenerationAvailable("first_password", false);
320 333
321 // Receive the account creation forms detected message. Show password 334 // Receive the account creation forms detected message. Show password
322 // generation icon. 335 // generation icon.
323 LoadHTML(kAccountCreationFormHTML); 336 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
324 SetNotBlacklistedMessage(kAccountCreationFormHTML); 337 SetNotBlacklistedMessage(kAccountCreationFormHTML);
325 SetAccountCreationFormsDetectedMessage(0); 338 SetAccountCreationFormsDetectedMessage(0);
326 ExpectPasswordGenerationAvailable("first_password", true); 339 ExpectPasswordGenerationAvailable("first_password", true);
327 } 340 }
328 341
329 TEST_F(PasswordGenerationAgentTest, MaximumOfferSize) { 342 TEST_F(PasswordGenerationAgentTest, MaximumOfferSize) {
330 base::HistogramTester histogram_tester; 343 base::HistogramTester histogram_tester;
331 344
332 LoadHTML(kAccountCreationFormHTML); 345 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
333 SetNotBlacklistedMessage(kAccountCreationFormHTML); 346 SetNotBlacklistedMessage(kAccountCreationFormHTML);
334 SetAccountCreationFormsDetectedMessage(0); 347 SetAccountCreationFormsDetectedMessage(0);
335 ExpectPasswordGenerationAvailable("first_password", true); 348 ExpectPasswordGenerationAvailable("first_password", true);
336 349
337 WebDocument document = GetMainFrame()->document(); 350 WebDocument document = GetMainFrame()->document();
338 WebElement element = 351 WebElement element =
339 document.getElementById(WebString::fromUTF8("first_password")); 352 document.getElementById(WebString::fromUTF8("first_password"));
340 ASSERT_FALSE(element.isNull()); 353 ASSERT_FALSE(element.isNull());
341 WebInputElement first_password_element = element.to<WebInputElement>(); 354 WebInputElement first_password_element = element.to<WebInputElement>();
342 355
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 password_generation_->clear_messages(); 403 password_generation_->clear_messages();
391 404
392 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent, 405 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent,
393 // so no messages are sent. 406 // so no messages are sent.
394 ExecuteJavaScript("document.getElementById('username').focus();"); 407 ExecuteJavaScript("document.getElementById('username').focus();");
395 EXPECT_EQ(0u, password_generation_->messages().size()); 408 EXPECT_EQ(0u, password_generation_->messages().size());
396 password_generation_->clear_messages(); 409 password_generation_->clear_messages();
397 410
398 // Focusing the password field will bring up the generation UI again. 411 // Focusing the password field will bring up the generation UI again.
399 ExecuteJavaScript("document.getElementById('first_password').focus();"); 412 ExecuteJavaScript("document.getElementById('first_password').focus();");
400 EXPECT_EQ(1u, password_generation_->messages().size()); 413 ASSERT_EQ(1u, password_generation_->messages().size());
401 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 414 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
402 password_generation_->messages()[0]->type()); 415 password_generation_->messages()[0]->type());
403 password_generation_->clear_messages(); 416 password_generation_->clear_messages();
404 417
405 // Loading a different page triggers UMA stat upload. Verify that only one 418 // Loading a different page triggers UMA stat upload. Verify that only one
406 // display event is sent even though 419 // display event is sent even though
407 LoadHTML(kSigninFormHTML); 420 LoadHTMLWithUserGesture(kSigninFormHTML);
408 421
409 histogram_tester.ExpectBucketCount( 422 histogram_tester.ExpectBucketCount(
410 "PasswordGeneration.Event", 423 "PasswordGeneration.Event",
411 autofill::password_generation::GENERATION_POPUP_SHOWN, 424 autofill::password_generation::GENERATION_POPUP_SHOWN,
412 1); 425 1);
413 } 426 }
414 427
415 TEST_F(PasswordGenerationAgentTest, DynamicFormTest) { 428 TEST_F(PasswordGenerationAgentTest, DynamicFormTest) {
416 LoadHTML(kSigninFormHTML); 429 LoadHTMLWithUserGesture(kSigninFormHTML);
417 SetNotBlacklistedMessage(kSigninFormHTML); 430 SetNotBlacklistedMessage(kSigninFormHTML);
418 431
419 ExecuteJavaScript( 432 ExecuteJavaScript(
420 "var form = document.createElement('form');" 433 "var form = document.createElement('form');"
421 "var username = document.createElement('input');" 434 "var username = document.createElement('input');"
422 "username.type = 'text';" 435 "username.type = 'text';"
423 "username.id = 'dynamic_username';" 436 "username.id = 'dynamic_username';"
424 "var first_password = document.createElement('input');" 437 "var first_password = document.createElement('input');"
425 "first_password.type = 'password';" 438 "first_password.type = 'password';"
426 "first_password.id = 'first_password';" 439 "first_password.id = 'first_password';"
427 "first_password.name = 'first_password';" 440 "first_password.name = 'first_password';"
428 "var second_password = document.createElement('input');" 441 "var second_password = document.createElement('input');"
429 "second_password.type = 'password';" 442 "second_password.type = 'password';"
430 "second_password.id = 'second_password';" 443 "second_password.id = 'second_password';"
431 "second_password.name = 'second_password';" 444 "second_password.name = 'second_password';"
432 "form.appendChild(username);" 445 "form.appendChild(username);"
433 "form.appendChild(first_password);" 446 "form.appendChild(first_password);"
434 "form.appendChild(second_password);" 447 "form.appendChild(second_password);"
435 "document.body.appendChild(form);"); 448 "document.body.appendChild(form);");
436 ProcessPendingMessages(); 449 ProcessPendingMessages();
437 450
438 // This needs to come after the DOM has been modified. 451 // This needs to come after the DOM has been modified.
439 SetAccountCreationFormsDetectedMessage(1); 452 SetAccountCreationFormsDetectedMessage(1);
440 453
441 // TODO(gcasto): I'm slighty worried about flakes in this test where 454 // TODO(gcasto): I'm slightly worried about flakes in this test where
442 // didAssociateFormControls() isn't called. If this turns out to be a problem 455 // didAssociateFormControls() isn't called. If this turns out to be a problem
443 // adding a call to OnDynamicFormsSeen(GetMainFrame()) will fix it, though 456 // adding a call to OnDynamicFormsSeen(GetMainFrame()) will fix it, though
444 // it will weaken the test. 457 // it will weaken the test.
445 ExpectPasswordGenerationAvailable("first_password", true); 458 ExpectPasswordGenerationAvailable("first_password", true);
446 } 459 }
447 460
448 TEST_F(PasswordGenerationAgentTest, MultiplePasswordFormsTest) { 461 TEST_F(PasswordGenerationAgentTest, MultiplePasswordFormsTest) {
449 // If two forms on the page looks like possible account creation forms, make 462 // If two forms on the page looks like possible account creation forms, make
450 // sure to trigger on the one that is specified from Autofill. 463 // sure to trigger on the one that is specified from Autofill.
451 LoadHTML(kMultipleAccountCreationFormHTML); 464 LoadHTMLWithUserGesture(kMultipleAccountCreationFormHTML);
452 SetNotBlacklistedMessage(kMultipleAccountCreationFormHTML); 465 SetNotBlacklistedMessage(kMultipleAccountCreationFormHTML);
453 466
454 // Should trigger on the second form. 467 // Should trigger on the second form.
455 SetAccountCreationFormsDetectedMessage(1); 468 SetAccountCreationFormsDetectedMessage(1);
456 469
457 ExpectPasswordGenerationAvailable("password", false); 470 ExpectPasswordGenerationAvailable("password", false);
458 ExpectPasswordGenerationAvailable("first_password", true); 471 ExpectPasswordGenerationAvailable("first_password", true);
459 } 472 }
460 473
461 TEST_F(PasswordGenerationAgentTest, MessagesAfterAccountSignupFormFound) { 474 TEST_F(PasswordGenerationAgentTest, MessagesAfterAccountSignupFormFound) {
462 LoadHTML(kAccountCreationFormHTML); 475 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
463 SetNotBlacklistedMessage(kAccountCreationFormHTML); 476 SetNotBlacklistedMessage(kAccountCreationFormHTML);
464 SetAccountCreationFormsDetectedMessage(0); 477 SetAccountCreationFormsDetectedMessage(0);
465 478
466 // Generation should be enabled. 479 // Generation should be enabled.
467 ExpectPasswordGenerationAvailable("first_password", true); 480 ExpectPasswordGenerationAvailable("first_password", true);
468 481
469 // Extra not blacklisted messages can be sent. Make sure that they are handled 482 // Extra not blacklisted messages can be sent. Make sure that they are handled
470 // correctly (generation should still be available). 483 // correctly (generation should still be available).
471 SetNotBlacklistedMessage(kAccountCreationFormHTML); 484 SetNotBlacklistedMessage(kAccountCreationFormHTML);
472 485
473 // Need to focus another field first for verification to work. 486 // Need to focus another field first for verification to work.
474 ExpectPasswordGenerationAvailable("second_password", false); 487 ExpectPasswordGenerationAvailable("second_password", false);
475 ExpectPasswordGenerationAvailable("first_password", true); 488 ExpectPasswordGenerationAvailable("first_password", true);
476 } 489 }
477 490
478 } // namespace autofill 491 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698