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

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

Issue 680413004: [Password Generation] Send onchange event when password is filled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | components/autofill/content/renderer/password_generation_agent.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 "</FORM>"; 103 "</FORM>";
104 104
105 const char kInvalidActionAccountCreationFormHTML[] = 105 const char kInvalidActionAccountCreationFormHTML[] =
106 "<FORM name = 'blah' action = 'invalid'> " 106 "<FORM name = 'blah' action = 'invalid'> "
107 " <INPUT type = 'text' id = 'username'/> " 107 " <INPUT type = 'text' id = 'username'/> "
108 " <INPUT type = 'password' id = 'first_password'/> " 108 " <INPUT type = 'password' id = 'first_password'/> "
109 " <INPUT type = 'password' id = 'second_password'/> " 109 " <INPUT type = 'password' id = 'second_password'/> "
110 " <INPUT type = 'submit' value = 'LOGIN' />" 110 " <INPUT type = 'submit' value = 'LOGIN' />"
111 "</FORM>"; 111 "</FORM>";
112 112
113 const char ChangeDetectionScript[] =
114 "<script>"
115 " firstOnChangeCalled = false;"
116 " secondOnChangeCalled = false;"
117 " document.getElementById('first_password').onchange = function() {"
118 " firstOnChangeCalled = true;"
119 " };"
120 " document.getElementById('second_password').onchange = function() {"
121 " secondOnChangeCalled = true;"
122 " };"
123 "</script>";
124
113 TEST_F(PasswordGenerationAgentTest, DetectionTest) { 125 TEST_F(PasswordGenerationAgentTest, DetectionTest) {
114 // Don't shown the icon for non account creation forms. 126 // Don't shown the icon for non account creation forms.
115 LoadHTML(kSigninFormHTML); 127 LoadHTML(kSigninFormHTML);
116 ExpectPasswordGenerationAvailable("password", false); 128 ExpectPasswordGenerationAvailable("password", false);
117 129
118 // We don't show the decoration yet because the feature isn't enabled. 130 // We don't show the decoration yet because the feature isn't enabled.
119 LoadHTML(kAccountCreationFormHTML); 131 LoadHTML(kAccountCreationFormHTML);
120 ExpectPasswordGenerationAvailable("first_password", false); 132 ExpectPasswordGenerationAvailable("first_password", false);
121 133
122 // Pretend like We have received message indicating site is not blacklisted, 134 // Pretend like We have received message indicating site is not blacklisted,
(...skipping 13 matching lines...) Expand all
136 148
137 // This doesn't trigger because the form action is invalid. 149 // This doesn't trigger because the form action is invalid.
138 LoadHTML(kInvalidActionAccountCreationFormHTML); 150 LoadHTML(kInvalidActionAccountCreationFormHTML);
139 SetNotBlacklistedMessage(kInvalidActionAccountCreationFormHTML); 151 SetNotBlacklistedMessage(kInvalidActionAccountCreationFormHTML);
140 SetAccountCreationFormsDetectedMessage(kInvalidActionAccountCreationFormHTML); 152 SetAccountCreationFormsDetectedMessage(kInvalidActionAccountCreationFormHTML);
141 ExpectPasswordGenerationAvailable("first_password", false); 153 ExpectPasswordGenerationAvailable("first_password", false);
142 } 154 }
143 155
144 TEST_F(PasswordGenerationAgentTest, FillTest) { 156 TEST_F(PasswordGenerationAgentTest, FillTest) {
145 // Make sure that we are enabled before loading HTML. 157 // Make sure that we are enabled before loading HTML.
146 LoadHTML(kAccountCreationFormHTML); 158 std::string html = std::string(kAccountCreationFormHTML) +
159 ChangeDetectionScript;
160 LoadHTML(html.c_str());
147 161
148 WebDocument document = GetMainFrame()->document(); 162 WebDocument document = GetMainFrame()->document();
149 WebElement element = 163 WebElement element =
150 document.getElementById(WebString::fromUTF8("first_password")); 164 document.getElementById(WebString::fromUTF8("first_password"));
151 ASSERT_FALSE(element.isNull()); 165 ASSERT_FALSE(element.isNull());
152 WebInputElement first_password_element = element.to<WebInputElement>(); 166 WebInputElement first_password_element = element.to<WebInputElement>();
153 element = document.getElementById(WebString::fromUTF8("second_password")); 167 element = document.getElementById(WebString::fromUTF8("second_password"));
154 ASSERT_FALSE(element.isNull()); 168 ASSERT_FALSE(element.isNull());
155 WebInputElement second_password_element = element.to<WebInputElement>(); 169 WebInputElement second_password_element = element.to<WebInputElement>();
156 170
157 // Both password fields should be empty. 171 // Both password fields should be empty.
158 EXPECT_TRUE(first_password_element.value().isNull()); 172 EXPECT_TRUE(first_password_element.value().isNull());
159 EXPECT_TRUE(second_password_element.value().isNull()); 173 EXPECT_TRUE(second_password_element.value().isNull());
160 174
161 base::string16 password = base::ASCIIToUTF16("random_password"); 175 base::string16 password = base::ASCIIToUTF16("random_password");
162 AutofillMsg_GeneratedPasswordAccepted msg(0, password); 176 AutofillMsg_GeneratedPasswordAccepted msg(0, password);
163 password_generation_->OnMessageReceived(msg); 177 password_generation_->OnMessageReceived(msg);
164 178
165 // Password fields are filled out and set as being autofilled. 179 // Password fields are filled out and set as being autofilled.
166 EXPECT_EQ(password, first_password_element.value()); 180 EXPECT_EQ(password, first_password_element.value());
167 EXPECT_EQ(password, second_password_element.value()); 181 EXPECT_EQ(password, second_password_element.value());
168 EXPECT_TRUE(first_password_element.isAutofilled()); 182 EXPECT_TRUE(first_password_element.isAutofilled());
169 EXPECT_TRUE(second_password_element.isAutofilled()); 183 EXPECT_TRUE(second_password_element.isAutofilled());
170 184
185 // Make sure onchange events are called.
186 int first_onchange_called = -1;
187 int second_onchange_called = -1;
188 ASSERT_TRUE(
189 ExecuteJavaScriptAndReturnIntValue(
190 base::ASCIIToUTF16("firstOnChangeCalled ? 1 : 0"),
191 &first_onchange_called));
192 EXPECT_EQ(1, first_onchange_called);
193 ASSERT_TRUE(
194 ExecuteJavaScriptAndReturnIntValue(
195 base::ASCIIToUTF16("secondOnChangeCalled ? 1 : 0"),
196 &second_onchange_called));
197 EXPECT_EQ(1, second_onchange_called);
198
171 // Focus moved to the next input field. 199 // Focus moved to the next input field.
172 // TODO(zysxqn): Change this back to the address element once Bug 90224 200 // TODO(zysxqn): Change this back to the address element once Bug 90224
173 // https://bugs.webkit.org/show_bug.cgi?id=90224 has been fixed. 201 // https://bugs.webkit.org/show_bug.cgi?id=90224 has been fixed.
174 element = document.getElementById(WebString::fromUTF8("first_password")); 202 element = document.getElementById(WebString::fromUTF8("first_password"));
175 ASSERT_FALSE(element.isNull()); 203 ASSERT_FALSE(element.isNull());
176 EXPECT_EQ(element, document.focusedElement()); 204 EXPECT_EQ(element, document.focusedElement());
177 } 205 }
178 206
179 TEST_F(PasswordGenerationAgentTest, EditingTest) { 207 TEST_F(PasswordGenerationAgentTest, EditingTest) {
180 LoadHTML(kAccountCreationFormHTML); 208 LoadHTML(kAccountCreationFormHTML);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 "document.body.appendChild(form);"); 407 "document.body.appendChild(form);");
380 ProcessPendingMessages(); 408 ProcessPendingMessages();
381 // TODO(gcasto): I'm slighty worried about flakes in this test where 409 // TODO(gcasto): I'm slighty worried about flakes in this test where
382 // didAssociateFormControls() isn't called. If this turns out to be a problem 410 // didAssociateFormControls() isn't called. If this turns out to be a problem
383 // adding a call to OnDynamicFormsSeen(GetMainFrame()) will fix it, though 411 // adding a call to OnDynamicFormsSeen(GetMainFrame()) will fix it, though
384 // it will weaken the test. 412 // it will weaken the test.
385 ExpectPasswordGenerationAvailable("first_password", true); 413 ExpectPasswordGenerationAvailable("first_password", true);
386 } 414 }
387 415
388 } // namespace autofill 416 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/renderer/password_generation_agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698