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 "base/keyboard_codes.h" | 5 #include "app/keyboard_codes.h" |
6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/renderer/password_autocomplete_manager.h" | 8 #include "chrome/renderer/password_autocomplete_manager.h" |
9 #include "chrome/test/render_view_test.h" | 9 #include "chrome/test/render_view_test.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" |
13 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" |
14 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
15 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 username_element_.setValue(WebString::fromUTF8(username)); | 109 username_element_.setValue(WebString::fromUTF8(username)); |
110 if (move_caret_to_end) | 110 if (move_caret_to_end) |
111 username_element_.setSelectionRange(username.length(), username.length()); | 111 username_element_.setSelectionRange(username.length(), username.length()); |
112 view_->textFieldDidChange(username_element_); | 112 view_->textFieldDidChange(username_element_); |
113 // Processing is delayed because of a WebKit bug, see | 113 // Processing is delayed because of a WebKit bug, see |
114 // PasswordAutocompleteManager::TextDidChangeInTextField() for details. | 114 // PasswordAutocompleteManager::TextDidChangeInTextField() for details. |
115 MessageLoop::current()->RunAllPending(); | 115 MessageLoop::current()->RunAllPending(); |
116 } | 116 } |
117 | 117 |
118 void SimulateKeyDownEvent(const WebInputElement& element, | 118 void SimulateKeyDownEvent(const WebInputElement& element, |
119 base::KeyboardCode key_code) { | 119 app::KeyboardCode key_code) { |
120 WebKit::WebKeyboardEvent key_event; | 120 WebKit::WebKeyboardEvent key_event; |
121 key_event.windowsKeyCode = key_code; | 121 key_event.windowsKeyCode = key_code; |
122 view_->textFieldDidReceiveKeyDown(element, key_event); | 122 view_->textFieldDidReceiveKeyDown(element, key_event); |
123 } | 123 } |
124 | 124 |
125 void CheckTextFieldsState(const std::string& username, | 125 void CheckTextFieldsState(const std::string& username, |
126 bool username_autofilled, | 126 bool username_autofilled, |
127 const std::string& password, | 127 const std::string& password, |
128 bool password_autofilled) { | 128 bool password_autofilled) { |
129 EXPECT_EQ(username, | 129 EXPECT_EQ(username, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 CheckUsernameSelection(1, 5); | 281 CheckUsernameSelection(1, 5); |
282 | 282 |
283 // Now the user types the next letter of the same username, 'l'. | 283 // Now the user types the next letter of the same username, 'l'. |
284 SimulateUsernameChange("al", true); | 284 SimulateUsernameChange("al", true); |
285 // Now the fields should have the same value, but the selection should have a | 285 // Now the fields should have the same value, but the selection should have a |
286 // different start value. | 286 // different start value. |
287 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 287 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
288 CheckUsernameSelection(2, 5); | 288 CheckUsernameSelection(2, 5); |
289 | 289 |
290 // Test that deleting does not trigger autocomplete. | 290 // Test that deleting does not trigger autocomplete. |
291 SimulateKeyDownEvent(username_element_, base::VKEY_BACK); | 291 SimulateKeyDownEvent(username_element_, app::VKEY_BACK); |
292 SimulateUsernameChange("alic", true); | 292 SimulateUsernameChange("alic", true); |
293 CheckTextFieldsState("alic", false, "", false); | 293 CheckTextFieldsState("alic", false, "", false); |
294 CheckUsernameSelection(4, 4); // No selection. | 294 CheckUsernameSelection(4, 4); // No selection. |
295 // Reset the last pressed key to something other than backspace. | 295 // Reset the last pressed key to something other than backspace. |
296 SimulateKeyDownEvent(username_element_, base::VKEY_A); | 296 SimulateKeyDownEvent(username_element_, app::VKEY_A); |
297 | 297 |
298 // Now lets say the user goes astray from the stored username and types the | 298 // Now lets say the user goes astray from the stored username and types the |
299 // letter 'f', spelling 'alf'. We don't know alf (that's just sad), so in | 299 // letter 'f', spelling 'alf'. We don't know alf (that's just sad), so in |
300 // practice the username should no longer be 'alice' and the selected range | 300 // practice the username should no longer be 'alice' and the selected range |
301 // should be empty. | 301 // should be empty. |
302 SimulateUsernameChange("alf", true); | 302 SimulateUsernameChange("alf", true); |
303 CheckTextFieldsState("alf", false, "", false); | 303 CheckTextFieldsState("alf", false, "", false); |
304 CheckUsernameSelection(3, 3); // No selection. | 304 CheckUsernameSelection(3, 3); // No selection. |
305 | 305 |
306 // Ok, so now the user removes all the text and enters the letter 'b'. | 306 // Ok, so now the user removes all the text and enters the letter 'b'. |
(...skipping 15 matching lines...) Expand all Loading... |
322 // WebView does: it sets the element value then calls | 322 // WebView does: it sets the element value then calls |
323 // didAcceptAutocompleteSuggestion on the renderer. | 323 // didAcceptAutocompleteSuggestion on the renderer. |
324 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); | 324 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); |
325 view_->didAcceptAutocompleteSuggestion(username_element_); | 325 view_->didAcceptAutocompleteSuggestion(username_element_); |
326 | 326 |
327 // Autocomplete should have kicked in. | 327 // Autocomplete should have kicked in. |
328 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 328 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
329 } | 329 } |
330 | 330 |
331 } // namespace | 331 } // namespace |
OLD | NEW |