| 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 "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/test/base/chrome_render_view_test.h" | 7 #include "chrome/test/base/chrome_render_view_test.h" |
| 8 #include "components/autofill/content/common/autofill_messages.h" | 8 #include "components/autofill/content/common/autofill_messages.h" |
| 9 #include "components/autofill/content/renderer/autofill_agent.h" | 9 #include "components/autofill/content/renderer/autofill_agent.h" |
| 10 #include "components/autofill/content/renderer/form_autofill_util.h" | 10 #include "components/autofill/content/renderer/form_autofill_util.h" |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 WebFrame* input_frame, | 255 WebFrame* input_frame, |
| 256 WebInputElement& username_input) { | 256 WebInputElement& username_input) { |
| 257 username_input.setValue(WebString::fromUTF8(username)); | 257 username_input.setValue(WebString::fromUTF8(username)); |
| 258 // The field must have focus or AutofillAgent will think the | 258 // The field must have focus or AutofillAgent will think the |
| 259 // change should be ignored. | 259 // change should be ignored. |
| 260 while (!username_input.focused()) | 260 while (!username_input.focused()) |
| 261 input_frame->document().frame()->view()->advanceFocus(false); | 261 input_frame->document().frame()->view()->advanceFocus(false); |
| 262 if (move_caret_to_end) | 262 if (move_caret_to_end) |
| 263 username_input.setSelectionRange(username.length(), username.length()); | 263 username_input.setSelectionRange(username.length(), username.length()); |
| 264 autofill_agent_->textFieldDidChange(username_input); | 264 autofill_agent_->textFieldDidChange(username_input); |
| 265 // Processing is delayed because of a WebKit bug, see | 265 // Processing is delayed because of a Blink bug: |
| 266 // PasswordAutocompleteManager::TextDidChangeInTextField() for details. | 266 // https://bugs.webkit.org/show_bug.cgi?id=16976 |
| 267 // See PasswordAutofillAgent::TextDidChangeInTextField() for details. |
| 268 |
| 269 // Autocomplete will trigger a style recalculation when we put up the next |
| 270 // frame, but we don't want to wait that long. Instead, trigger a style |
| 271 // recalcuation manually after TextFieldDidChangeImpl runs. |
| 272 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 273 &PasswordAutofillAgentTest::LayoutMainFrame, base::Unretained(this))); |
| 274 |
| 267 base::MessageLoop::current()->RunUntilIdle(); | 275 base::MessageLoop::current()->RunUntilIdle(); |
| 268 } | 276 } |
| 269 | 277 |
| 278 void LayoutMainFrame() { |
| 279 GetMainFrame()->view()->layout(); |
| 280 } |
| 281 |
| 270 void SimulateUsernameChange(const std::string& username, | 282 void SimulateUsernameChange(const std::string& username, |
| 271 bool move_caret_to_end) { | 283 bool move_caret_to_end) { |
| 272 SimulateUsernameChangeForElement(username, move_caret_to_end, | 284 SimulateUsernameChangeForElement(username, move_caret_to_end, |
| 273 GetMainFrame(), username_element_); | 285 GetMainFrame(), username_element_); |
| 274 } | 286 } |
| 275 | 287 |
| 276 // Tests that no suggestion popup is generated when the username_element_ is | 288 // Tests that no suggestion popup is generated when the username_element_ is |
| 277 // edited. | 289 // edited. |
| 278 void ExpectNoSuggestionsPopup() { | 290 void ExpectNoSuggestionsPopup() { |
| 279 // The first test below ensures that the suggestions have been handled by | 291 // The first test below ensures that the suggestions have been handled by |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 &username_onchange_called)); | 1001 &username_onchange_called)); |
| 990 EXPECT_EQ(1, username_onchange_called); | 1002 EXPECT_EQ(1, username_onchange_called); |
| 991 ASSERT_TRUE( | 1003 ASSERT_TRUE( |
| 992 ExecuteJavaScriptAndReturnIntValue( | 1004 ExecuteJavaScriptAndReturnIntValue( |
| 993 ASCIIToUTF16("passwordOnchangeCalled ? 1 : 0"), | 1005 ASCIIToUTF16("passwordOnchangeCalled ? 1 : 0"), |
| 994 &password_onchange_called)); | 1006 &password_onchange_called)); |
| 995 EXPECT_EQ(1, password_onchange_called); | 1007 EXPECT_EQ(1, password_onchange_called); |
| 996 } | 1008 } |
| 997 | 1009 |
| 998 } // namespace autofill | 1010 } // namespace autofill |
| OLD | NEW |