| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_util.h" | 5 #include "base/string_util.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/common/autofill_messages.h" |
| 7 #include "chrome/renderer/autofill_helper.h" | 8 #include "chrome/renderer/autofill_helper.h" |
| 8 #include "chrome/renderer/password_autocomplete_manager.h" | 9 #include "chrome/renderer/password_autocomplete_manager.h" |
| 9 #include "chrome/test/render_view_test.h" | 10 #include "chrome/test/render_view_test.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 class PasswordAutocompleteManagerTest : public RenderViewTest { | 56 class PasswordAutocompleteManagerTest : public RenderViewTest { |
| 56 public: | 57 public: |
| 57 PasswordAutocompleteManagerTest() { | 58 PasswordAutocompleteManagerTest() { |
| 58 } | 59 } |
| 59 | 60 |
| 60 // Simulates the fill password form message being sent to the renderer. | 61 // Simulates the fill password form message being sent to the renderer. |
| 61 // We use that so we don't have to make RenderView::OnFillPasswordForm() | 62 // We use that so we don't have to make RenderView::OnFillPasswordForm() |
| 62 // protected. | 63 // protected. |
| 63 void SimulateOnFillPasswordForm( | 64 void SimulateOnFillPasswordForm( |
| 64 const PasswordFormFillData& fill_data) { | 65 const PasswordFormFillData& fill_data) { |
| 65 ViewMsg_FillPasswordForm msg(0, fill_data); | 66 AutoFillMsg_FillPasswordForm msg(0, fill_data); |
| 66 password_autocomplete_->OnMessageReceived(msg); | 67 password_autocomplete_->OnMessageReceived(msg); |
| 67 } | 68 } |
| 68 | 69 |
| 69 virtual void SetUp() { | 70 virtual void SetUp() { |
| 70 RenderViewTest::SetUp(); | 71 RenderViewTest::SetUp(); |
| 71 | 72 |
| 72 // Add a preferred login and an additional login to the FillData. | 73 // Add a preferred login and an additional login to the FillData. |
| 73 username1_ = ASCIIToUTF16(kAliceUsername); | 74 username1_ = ASCIIToUTF16(kAliceUsername); |
| 74 password1_ = ASCIIToUTF16(kAlicePassword); | 75 password1_ = ASCIIToUTF16(kAlicePassword); |
| 75 username2_ = ASCIIToUTF16(kBobUsername); | 76 username2_ = ASCIIToUTF16(kBobUsername); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 /* | 170 /* |
| 170 * Right now we are not sending the message to the browser because we are | 171 * Right now we are not sending the message to the browser because we are |
| 171 * loading a data URL and the security origin canAccessPasswordManager() | 172 * loading a data URL and the security origin canAccessPasswordManager() |
| 172 * returns false. May be we should mock URL loading to cirmcuvent this? | 173 * returns false. May be we should mock URL loading to cirmcuvent this? |
| 173 TODO(jcivelli): find a way to make the security origin not deny access to the | 174 TODO(jcivelli): find a way to make the security origin not deny access to the |
| 174 password manager and then reenable this code. | 175 password manager and then reenable this code. |
| 175 | 176 |
| 176 // The form has been loaded, we should have sent the browser a message about | 177 // The form has been loaded, we should have sent the browser a message about |
| 177 // the form. | 178 // the form. |
| 178 const IPC::Message* msg = render_thread_.sink().GetFirstMessageMatching( | 179 const IPC::Message* msg = render_thread_.sink().GetFirstMessageMatching( |
| 179 ViewHostMsg_PasswordFormsFound::ID); | 180 AutoFillHostMsg_PasswordFormsFound::ID); |
| 180 ASSERT_TRUE(msg != NULL); | 181 ASSERT_TRUE(msg != NULL); |
| 181 | 182 |
| 182 Tuple1<std::vector<PasswordForm> > forms; | 183 Tuple1<std::vector<PasswordForm> > forms; |
| 183 ViewHostMsg_PasswordFormsFound::Read(msg, &forms); | 184 AutoFillHostMsg_PasswordFormsFound::Read(msg, &forms); |
| 184 ASSERT_EQ(1U, forms.a.size()); | 185 ASSERT_EQ(1U, forms.a.size()); |
| 185 PasswordForm password_form = forms.a[0]; | 186 PasswordForm password_form = forms.a[0]; |
| 186 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form.scheme); | 187 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form.scheme); |
| 187 EXPECT_EQ(ASCIIToUTF16(kUsernameName), password_form.username_element); | 188 EXPECT_EQ(ASCIIToUTF16(kUsernameName), password_form.username_element); |
| 188 EXPECT_EQ(ASCIIToUTF16(kPasswordName), password_form.password_element); | 189 EXPECT_EQ(ASCIIToUTF16(kPasswordName), password_form.password_element); |
| 189 */ | 190 */ |
| 190 | 191 |
| 191 // Simulate the browser sending back the login info, it triggers the | 192 // Simulate the browser sending back the login info, it triggers the |
| 192 // autocomplete. | 193 // autocomplete. |
| 193 SimulateOnFillPasswordForm(fill_data_); | 194 SimulateOnFillPasswordForm(fill_data_); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 // WebView does: it sets the element value then calls | 328 // WebView does: it sets the element value then calls |
| 328 // didSelectAutoFillSuggestion on the renderer. | 329 // didSelectAutoFillSuggestion on the renderer. |
| 329 autofill_helper_->didSelectAutoFillSuggestion(username_element_, | 330 autofill_helper_->didSelectAutoFillSuggestion(username_element_, |
| 330 ASCIIToUTF16(kAliceUsername), | 331 ASCIIToUTF16(kAliceUsername), |
| 331 WebKit::WebString(), | 332 WebKit::WebString(), |
| 332 0); | 333 0); |
| 333 | 334 |
| 334 // Autocomplete should have kicked in. | 335 // Autocomplete should have kicked in. |
| 335 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); | 336 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); |
| 336 } | 337 } |
| OLD | NEW |