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" |
11 #include "components/autofill/content/renderer/password_autofill_agent.h" | 11 #include "components/autofill/content/renderer/password_autofill_agent.h" |
12 #include "components/autofill/content/renderer/test_password_autofill_agent.h" | 12 #include "components/autofill/content/renderer/test_password_autofill_agent.h" |
13 #include "components/autofill/core/common/form_data.h" | 13 #include "components/autofill/core/common/form_data.h" |
14 #include "components/autofill/core/common/form_field_data.h" | 14 #include "components/autofill/core/common/form_field_data.h" |
| 15 #include "components/autofill/core/common/password_autofill_util.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
17 #include "third_party/WebKit/public/platform/WebVector.h" | 18 #include "third_party/WebKit/public/platform/WebVector.h" |
18 #include "third_party/WebKit/public/web/WebDocument.h" | 19 #include "third_party/WebKit/public/web/WebDocument.h" |
19 #include "third_party/WebKit/public/web/WebElement.h" | 20 #include "third_party/WebKit/public/web/WebElement.h" |
20 #include "third_party/WebKit/public/web/WebFormElement.h" | 21 #include "third_party/WebKit/public/web/WebFormElement.h" |
21 #include "third_party/WebKit/public/web/WebFrame.h" | 22 #include "third_party/WebKit/public/web/WebFrame.h" |
22 #include "third_party/WebKit/public/web/WebInputElement.h" | 23 #include "third_party/WebKit/public/web/WebInputElement.h" |
23 #include "third_party/WebKit/public/web/WebNode.h" | 24 #include "third_party/WebKit/public/web/WebNode.h" |
24 #include "third_party/WebKit/public/web/WebView.h" | 25 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 // the browser was generated. | 295 // the browser was generated. |
295 // | 296 // |
296 // This is interesting in the specific case of an autocomplete='off' form | 297 // This is interesting in the specific case of an autocomplete='off' form |
297 // that also has a remembered username and password | 298 // that also has a remembered username and password |
298 // (http://crbug.com/326679). To fix the DCHECK that this case used to hit, | 299 // (http://crbug.com/326679). To fix the DCHECK that this case used to hit, |
299 // |true| is returned from ShowSuggestions for all forms with valid | 300 // |true| is returned from ShowSuggestions for all forms with valid |
300 // usersnames that are autocomplete='off', prentending that a selection box | 301 // usersnames that are autocomplete='off', prentending that a selection box |
301 // has been shown to the user. Of course, it hasn't, so a message is never | 302 // has been shown to the user. Of course, it hasn't, so a message is never |
302 // sent to the browser on acceptance, and the DCHECK isn't hit (and nothing | 303 // sent to the browser on acceptance, and the DCHECK isn't hit (and nothing |
303 // is filled). | 304 // is filled). |
304 EXPECT_TRUE(autofill_agent_->password_autofill_agent_->ShowSuggestions( | 305 // |
305 username_element_)); | 306 // These tests only make sense in the context of not ignoring |
| 307 // autocomplete='off', so only test them if the disable autocomplete='off' |
| 308 // flag is not enabled. |
| 309 // TODO(jww): Remove this function and callers once autocomplete='off' is |
| 310 // permanently ignored. |
| 311 if (!ShouldIgnoreAutocompleteOffForPasswordFields()) { |
| 312 EXPECT_TRUE(autofill_agent_->password_autofill_agent_->ShowSuggestions( |
| 313 username_element_)); |
306 | 314 |
307 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 315 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
308 AutofillHostMsg_ShowPasswordSuggestions::ID)); | 316 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
| 317 } |
309 } | 318 } |
310 | 319 |
311 void SimulateKeyDownEvent(const WebInputElement& element, | 320 void SimulateKeyDownEvent(const WebInputElement& element, |
312 ui::KeyboardCode key_code) { | 321 ui::KeyboardCode key_code) { |
313 blink::WebKeyboardEvent key_event; | 322 blink::WebKeyboardEvent key_event; |
314 key_event.windowsKeyCode = key_code; | 323 key_event.windowsKeyCode = key_code; |
315 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); | 324 autofill_agent_->textFieldDidReceiveKeyDown(element, key_event); |
316 } | 325 } |
317 | 326 |
318 void CheckTextFieldsStateForElements(const WebInputElement& username_element, | 327 void CheckTextFieldsStateForElements(const WebInputElement& username_element, |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 &username_onchange_called)); | 1010 &username_onchange_called)); |
1002 EXPECT_EQ(1, username_onchange_called); | 1011 EXPECT_EQ(1, username_onchange_called); |
1003 ASSERT_TRUE( | 1012 ASSERT_TRUE( |
1004 ExecuteJavaScriptAndReturnIntValue( | 1013 ExecuteJavaScriptAndReturnIntValue( |
1005 ASCIIToUTF16("passwordOnchangeCalled ? 1 : 0"), | 1014 ASCIIToUTF16("passwordOnchangeCalled ? 1 : 0"), |
1006 &password_onchange_called)); | 1015 &password_onchange_called)); |
1007 EXPECT_EQ(1, password_onchange_called); | 1016 EXPECT_EQ(1, password_onchange_called); |
1008 } | 1017 } |
1009 | 1018 |
1010 } // namespace autofill | 1019 } // namespace autofill |
OLD | NEW |