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" | 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" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 namespace { | 31 namespace { |
32 | 32 |
33 // The name of the username/password element in the form. | 33 // The name of the username/password element in the form. |
34 const char* const kUsernameName = "username"; | 34 const char* const kUsernameName = "username"; |
35 const char* const kPasswordName = "password"; | 35 const char* const kPasswordName = "password"; |
36 | 36 |
37 const char* const kAliceUsername = "alice"; | 37 const char* const kAliceUsername = "alice"; |
38 const char* const kAlicePassword = "password"; | 38 const char* const kAlicePassword = "password"; |
39 const char* const kBobUsername = "bob"; | 39 const char* const kBobUsername = "bob"; |
40 const char* const kBobPassword = "secret"; | 40 const char* const kBobPassword = "secret"; |
41 const char* const kChrisUsername = "Chris"; | |
Ilya Sherman
2010/11/23 07:16:52
nit: In the spirit of cryptographic silliness, ple
| |
42 const char* const kChrisPassword = "test"; | |
43 | |
41 | 44 |
42 const char* const kFormHTML = | 45 const char* const kFormHTML = |
43 "<FORM name='LoginTestForm' action='http://www.bidule.com'>" | 46 "<FORM name='LoginTestForm' action='http://www.bidule.com'>" |
44 " <INPUT type='text' id='username'/>" | 47 " <INPUT type='text' id='username'/>" |
45 " <INPUT type='password' id='password'/>" | 48 " <INPUT type='password' id='password'/>" |
46 " <INPUT type='submit' value='Login'/>" | 49 " <INPUT type='submit' value='Login'/>" |
47 "</FORM>"; | 50 "</FORM>"; |
48 | 51 |
49 class PasswordAutocompleteManagerTest : public RenderViewTest { | 52 class PasswordAutocompleteManagerTest : public RenderViewTest { |
50 public: | 53 public: |
(...skipping 10 matching lines...) Expand all Loading... | |
61 } | 64 } |
62 | 65 |
63 virtual void SetUp() { | 66 virtual void SetUp() { |
64 RenderViewTest::SetUp(); | 67 RenderViewTest::SetUp(); |
65 | 68 |
66 // Add a preferred login and an additional login to the FillData. | 69 // Add a preferred login and an additional login to the FillData. |
67 username1_ = ASCIIToUTF16(kAliceUsername); | 70 username1_ = ASCIIToUTF16(kAliceUsername); |
68 password1_ = ASCIIToUTF16(kAlicePassword); | 71 password1_ = ASCIIToUTF16(kAlicePassword); |
69 username2_ = ASCIIToUTF16(kBobUsername); | 72 username2_ = ASCIIToUTF16(kBobUsername); |
70 password2_ = ASCIIToUTF16(kBobPassword); | 73 password2_ = ASCIIToUTF16(kBobPassword); |
74 username3_ = ASCIIToUTF16(kChrisUsername); | |
75 password3_ = ASCIIToUTF16(kChrisPassword); | |
71 | 76 |
72 fill_data_.basic_data.fields.push_back( | 77 fill_data_.basic_data.fields.push_back( |
73 FormField(string16(), ASCIIToUTF16(kUsernameName), | 78 FormField(string16(), ASCIIToUTF16(kUsernameName), |
74 username1_, string16(), 0)); | 79 username1_, string16(), 0)); |
75 fill_data_.basic_data.fields.push_back( | 80 fill_data_.basic_data.fields.push_back( |
76 FormField(string16(), ASCIIToUTF16(kPasswordName), | 81 FormField(string16(), ASCIIToUTF16(kPasswordName), |
77 password1_, string16(), 0)); | 82 password1_, string16(), 0)); |
78 fill_data_.additional_logins[username2_] = password2_; | 83 fill_data_.additional_logins[username2_] = password2_; |
84 fill_data_.additional_logins[username3_] = password3_; | |
79 | 85 |
80 // We need to set the origin so it matches the frame URL and the action so | 86 // We need to set the origin so it matches the frame URL and the action so |
81 // it matches the form action, otherwise we won't autocomplete. | 87 // it matches the form action, otherwise we won't autocomplete. |
82 std::string origin("data:text/html;charset=utf-8,"); | 88 std::string origin("data:text/html;charset=utf-8,"); |
83 origin += kFormHTML; | 89 origin += kFormHTML; |
84 fill_data_.basic_data.origin = GURL(origin); | 90 fill_data_.basic_data.origin = GURL(origin); |
85 fill_data_.basic_data.action = GURL("http://www.bidule.com"); | 91 fill_data_.basic_data.action = GURL("http://www.bidule.com"); |
86 | 92 |
87 LoadHTML(kFormHTML); | 93 LoadHTML(kFormHTML); |
88 | 94 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 EXPECT_EQ(password_autofilled, password_element_.isAutofilled()); | 140 EXPECT_EQ(password_autofilled, password_element_.isAutofilled()); |
135 } | 141 } |
136 | 142 |
137 void CheckUsernameSelection(int start, int end) { | 143 void CheckUsernameSelection(int start, int end) { |
138 EXPECT_EQ(start, username_element_.selectionStart()); | 144 EXPECT_EQ(start, username_element_.selectionStart()); |
139 EXPECT_EQ(end, username_element_.selectionEnd()); | 145 EXPECT_EQ(end, username_element_.selectionEnd()); |
140 } | 146 } |
141 | 147 |
142 string16 username1_; | 148 string16 username1_; |
143 string16 username2_; | 149 string16 username2_; |
150 string16 username3_; | |
144 string16 password1_; | 151 string16 password1_; |
145 string16 password2_; | 152 string16 password2_; |
153 string16 password3_; | |
146 PasswordFormFillData fill_data_; | 154 PasswordFormFillData fill_data_; |
147 | 155 |
148 WebInputElement username_element_; | 156 WebInputElement username_element_; |
149 WebInputElement password_element_; | 157 WebInputElement password_element_; |
150 | 158 |
151 private: | 159 private: |
152 DISALLOW_COPY_AND_ASSIGN(PasswordAutocompleteManagerTest); | 160 DISALLOW_COPY_AND_ASSIGN(PasswordAutocompleteManagerTest); |
153 }; | 161 }; |
154 | 162 |
155 // Tests that the password login is autocompleted as expected when the browser | 163 // Tests that the password login is autocompleted as expected when the browser |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 SimulateKeyDownEvent(username_element_, app::VKEY_A); | 286 SimulateKeyDownEvent(username_element_, app::VKEY_A); |
279 | 287 |
280 // Now lets say the user goes astray from the stored username and types the | 288 // Now lets say the user goes astray from the stored username and types the |
281 // letter 'f', spelling 'alf'. We don't know alf (that's just sad), so in | 289 // letter 'f', spelling 'alf'. We don't know alf (that's just sad), so in |
282 // practice the username should no longer be 'alice' and the selected range | 290 // practice the username should no longer be 'alice' and the selected range |
283 // should be empty. | 291 // should be empty. |
284 SimulateUsernameChange("alf", true); | 292 SimulateUsernameChange("alf", true); |
285 CheckTextFieldsState("alf", false, "", false); | 293 CheckTextFieldsState("alf", false, "", false); |
286 CheckUsernameSelection(3, 3); // No selection. | 294 CheckUsernameSelection(3, 3); // No selection. |
287 | 295 |
296 // Test case sensetive autocompletion. Check Chris is completed iff the start | |
297 // charactoer is 'C'. | |
Ilya Sherman
2010/11/23 07:16:52
nit: This comment would match the surrounding comm
| |
298 SimulateUsernameChange("C", true); | |
299 CheckTextFieldsState(kChrisUsername, true, kChrisPassword, true); | |
300 CheckUsernameSelection(1, 5); | |
301 // And completion is not triggered if the start is 'c'. | |
302 SimulateUsernameChange("c", true); | |
303 CheckTextFieldsState("c", false, "", false); | |
304 CheckUsernameSelection(1, 1); | |
305 | |
288 // 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'. |
289 SimulateUsernameChange("b", true); | 307 SimulateUsernameChange("b", true); |
290 // The username and password fields should match the 'bob' entry. | 308 // The username and password fields should match the 'bob' entry. |
291 CheckTextFieldsState(kBobUsername, true, kBobPassword, true); | 309 CheckTextFieldsState(kBobUsername, true, kBobPassword, true); |
292 CheckUsernameSelection(1, 3); | 310 CheckUsernameSelection(1, 3); |
293 } | 311 } |
294 | 312 |
295 // Tests that selecting and item in the suggestion drop-down works. | 313 // Tests that selecting and item in the suggestion drop-down works. |
296 TEST_F(PasswordAutocompleteManagerTest, SuggestionSelect) { | 314 TEST_F(PasswordAutocompleteManagerTest, SuggestionSelect) { |
297 // Simulate the browser sending back the login info. | 315 // Simulate the browser sending back the login info. |
298 SimulateOnFillPasswordForm(fill_data_); | 316 SimulateOnFillPasswordForm(fill_data_); |
299 | 317 |
300 // Clear the textfields to start fresh. | 318 // Clear the textfields to start fresh. |
301 ClearUsernameAndPasswordFields(); | 319 ClearUsernameAndPasswordFields(); |
302 | 320 |
303 // To simulate a selection in the suggestion drop-down we just mimick what the | 321 // To simulate a selection in the suggestion drop-down we just mimick what the |
304 // WebView does: it sets the element value then calls | 322 // WebView does: it sets the element value then calls |
305 // didAcceptAutocompleteSuggestion on the renderer. | 323 // didAcceptAutocompleteSuggestion on the renderer. |
306 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); | 324 username_element_.setValue(ASCIIToUTF16(kAliceUsername)); |
307 view_->didAcceptAutocompleteSuggestion(username_element_); | 325 view_->didAcceptAutocompleteSuggestion(username_element_); |
308 | 326 |
309 // Autocomplete should have kicked in. | 327 // Autocomplete should have kicked in. |
310 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 328 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
311 } | 329 } |
312 | 330 |
313 } // namespace | 331 } |
OLD | NEW |