OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/keyboard_codes.h" | |
6 #include "base/string_util.h" | 5 #include "base/string_util.h" |
7 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
8 #include "chrome/renderer/password_autocomplete_manager.h" | 7 #include "chrome/renderer/password_autocomplete_manager.h" |
9 #include "chrome/test/render_view_test.h" | 8 #include "chrome/test/render_view_test.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" |
13 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" |
14 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
15 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
16 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
17 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
| 17 #include "ui/base/keycodes/keyboard_codes.h" |
18 #include "webkit/glue/form_data.h" | 18 #include "webkit/glue/form_data.h" |
19 #include "webkit/glue/form_field.h" | 19 #include "webkit/glue/form_field.h" |
20 | 20 |
21 using webkit_glue::FormField; | 21 using webkit_glue::FormField; |
22 using webkit_glue::PasswordFormFillData; | 22 using webkit_glue::PasswordFormFillData; |
23 using webkit_glue::PasswordForm; | 23 using webkit_glue::PasswordForm; |
24 using webkit_glue::PasswordFormDomManager; | 24 using webkit_glue::PasswordFormDomManager; |
25 using WebKit::WebDocument; | 25 using WebKit::WebDocument; |
26 using WebKit::WebElement; | 26 using WebKit::WebElement; |
27 using WebKit::WebFrame; | 27 using WebKit::WebFrame; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 username_element_.setValue(WebString::fromUTF8(username)); | 117 username_element_.setValue(WebString::fromUTF8(username)); |
118 if (move_caret_to_end) | 118 if (move_caret_to_end) |
119 username_element_.setSelectionRange(username.length(), username.length()); | 119 username_element_.setSelectionRange(username.length(), username.length()); |
120 view_->textFieldDidChange(username_element_); | 120 view_->textFieldDidChange(username_element_); |
121 // Processing is delayed because of a WebKit bug, see | 121 // Processing is delayed because of a WebKit bug, see |
122 // PasswordAutocompleteManager::TextDidChangeInTextField() for details. | 122 // PasswordAutocompleteManager::TextDidChangeInTextField() for details. |
123 MessageLoop::current()->RunAllPending(); | 123 MessageLoop::current()->RunAllPending(); |
124 } | 124 } |
125 | 125 |
126 void SimulateKeyDownEvent(const WebInputElement& element, | 126 void SimulateKeyDownEvent(const WebInputElement& element, |
127 app::KeyboardCode key_code) { | 127 ui::KeyboardCode key_code) { |
128 WebKit::WebKeyboardEvent key_event; | 128 WebKit::WebKeyboardEvent key_event; |
129 key_event.windowsKeyCode = key_code; | 129 key_event.windowsKeyCode = key_code; |
130 view_->textFieldDidReceiveKeyDown(element, key_event); | 130 view_->textFieldDidReceiveKeyDown(element, key_event); |
131 } | 131 } |
132 | 132 |
133 void CheckTextFieldsState(const std::string& username, | 133 void CheckTextFieldsState(const std::string& username, |
134 bool username_autofilled, | 134 bool username_autofilled, |
135 const std::string& password, | 135 const std::string& password, |
136 bool password_autofilled) { | 136 bool password_autofilled) { |
137 EXPECT_EQ(username, | 137 EXPECT_EQ(username, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 CheckUsernameSelection(1, 5); | 273 CheckUsernameSelection(1, 5); |
274 | 274 |
275 // Now the user types the next letter of the same username, 'l'. | 275 // Now the user types the next letter of the same username, 'l'. |
276 SimulateUsernameChange("al", true); | 276 SimulateUsernameChange("al", true); |
277 // Now the fields should have the same value, but the selection should have a | 277 // Now the fields should have the same value, but the selection should have a |
278 // different start value. | 278 // different start value. |
279 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 279 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
280 CheckUsernameSelection(2, 5); | 280 CheckUsernameSelection(2, 5); |
281 | 281 |
282 // Test that deleting does not trigger autocomplete. | 282 // Test that deleting does not trigger autocomplete. |
283 SimulateKeyDownEvent(username_element_, app::VKEY_BACK); | 283 SimulateKeyDownEvent(username_element_, ui::VKEY_BACK); |
284 SimulateUsernameChange("alic", true); | 284 SimulateUsernameChange("alic", true); |
285 CheckTextFieldsState("alic", false, "", false); | 285 CheckTextFieldsState("alic", false, "", false); |
286 CheckUsernameSelection(4, 4); // No selection. | 286 CheckUsernameSelection(4, 4); // No selection. |
287 // Reset the last pressed key to something other than backspace. | 287 // Reset the last pressed key to something other than backspace. |
288 SimulateKeyDownEvent(username_element_, app::VKEY_A); | 288 SimulateKeyDownEvent(username_element_, ui::VKEY_A); |
289 | 289 |
290 // Now lets say the user goes astray from the stored username and types the | 290 // Now lets say the user goes astray from the stored username and types the |
291 // letter 'f', spelling 'alf'. We don't know alf (that's just sad), so in | 291 // letter 'f', spelling 'alf'. We don't know alf (that's just sad), so in |
292 // practice the username should no longer be 'alice' and the selected range | 292 // practice the username should no longer be 'alice' and the selected range |
293 // should be empty. | 293 // should be empty. |
294 SimulateUsernameChange("alf", true); | 294 SimulateUsernameChange("alf", true); |
295 CheckTextFieldsState("alf", false, "", false); | 295 CheckTextFieldsState("alf", false, "", false); |
296 CheckUsernameSelection(3, 3); // No selection. | 296 CheckUsernameSelection(3, 3); // No selection. |
297 | 297 |
298 // Ok, so now the user removes all the text and enters the letter 'b'. | 298 // Ok, so now the user removes all the text and enters the letter 'b'. |
(...skipping 25 matching lines...) Expand all Loading... |
324 | 324 |
325 // To simulate a selection in the suggestion drop-down we just mimick what the | 325 // To simulate a selection in the suggestion drop-down we just mimick what the |
326 // WebView does: it sets the element value then calls | 326 // WebView does: it sets the element value then calls |
327 // didAcceptAutocompleteSuggestion on the renderer. | 327 // didAcceptAutocompleteSuggestion on the renderer. |
328 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); | 328 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); |
329 view_->didAcceptAutocompleteSuggestion(username_element_); | 329 view_->didAcceptAutocompleteSuggestion(username_element_); |
330 | 330 |
331 // Autocomplete should have kicked in. | 331 // Autocomplete should have kicked in. |
332 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 332 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
333 } | 333 } |
OLD | NEW |