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 <tuple> | 5 #include <tuple> |
6 | 6 |
7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/renderer/autofill/password_generation_test_utils.h" | 11 #include "chrome/renderer/autofill/password_generation_test_utils.h" |
12 #include "chrome/test/base/chrome_render_view_test.h" | 12 #include "chrome/test/base/chrome_render_view_test.h" |
13 #include "components/autofill/content/common/autofill_messages.h" | 13 #include "components/autofill/content/common/autofill_messages.h" |
14 #include "components/autofill/content/renderer/autofill_agent.h" | 14 #include "components/autofill/content/renderer/autofill_agent.h" |
15 #include "components/autofill/content/renderer/form_autofill_util.h" | 15 #include "components/autofill/content/renderer/form_autofill_util.h" |
16 #include "components/autofill/content/renderer/password_autofill_agent.h" | 16 #include "components/autofill/content/renderer/password_autofill_agent.h" |
17 #include "components/autofill/content/renderer/test_password_autofill_agent.h" | 17 #include "components/autofill/content/renderer/test_password_autofill_agent.h" |
18 #include "components/autofill/content/renderer/test_password_generation_agent.h" | 18 #include "components/autofill/content/renderer/test_password_generation_agent.h" |
19 #include "components/autofill/core/common/autofill_constants.h" | 19 #include "components/autofill/core/common/autofill_constants.h" |
20 #include "components/autofill/core/common/form_data.h" | 20 #include "components/autofill/core/common/form_data.h" |
21 #include "components/autofill/core/common/form_field_data.h" | 21 #include "components/autofill/core/common/form_field_data.h" |
22 #include "components/autofill/core/common/password_form_field_prediction_map.h" | 22 #include "components/autofill/core/common/password_form_field_prediction_map.h" |
23 #include "components/password_manager/core/common/password_manager_features.h" | 23 #include "components/password_manager/core/common/password_manager_features.h" |
24 #include "content/public/renderer/render_frame.h" | 24 #include "content/public/renderer/render_frame.h" |
| 25 #include "mojo/common/common_type_converters.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "third_party/WebKit/public/platform/WebString.h" | 27 #include "third_party/WebKit/public/platform/WebString.h" |
27 #include "third_party/WebKit/public/platform/WebVector.h" | 28 #include "third_party/WebKit/public/platform/WebVector.h" |
28 #include "third_party/WebKit/public/web/WebDocument.h" | 29 #include "third_party/WebKit/public/web/WebDocument.h" |
29 #include "third_party/WebKit/public/web/WebElement.h" | 30 #include "third_party/WebKit/public/web/WebElement.h" |
30 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 31 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
31 #include "third_party/WebKit/public/web/WebFormElement.h" | 32 #include "third_party/WebKit/public/web/WebFormElement.h" |
32 #include "third_party/WebKit/public/web/WebInputElement.h" | 33 #include "third_party/WebKit/public/web/WebInputElement.h" |
33 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 34 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
34 #include "third_party/WebKit/public/web/WebNode.h" | 35 #include "third_party/WebKit/public/web/WebNode.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 249 |
249 // As above, but fills for an iframe. | 250 // As above, but fills for an iframe. |
250 void SimulateOnFillPasswordFormForFrame( | 251 void SimulateOnFillPasswordFormForFrame( |
251 WebFrame* frame, | 252 WebFrame* frame, |
252 const PasswordFormFillData& fill_data) { | 253 const PasswordFormFillData& fill_data) { |
253 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); | 254 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); |
254 content::RenderFrame::FromWebFrame(frame)->OnMessageReceived(msg); | 255 content::RenderFrame::FromWebFrame(frame)->OnMessageReceived(msg); |
255 } | 256 } |
256 | 257 |
257 // Simulates the show initial password account suggestions message being sent | 258 // Simulates the show initial password account suggestions message being sent |
258 // to the renderer. We use that so we don't have to make | 259 // to the renderer. |
259 // RenderView::OnShowInitialPasswordAccountSuggestions() protected. | |
260 void SimulateOnShowInitialPasswordAccountSuggestions( | 260 void SimulateOnShowInitialPasswordAccountSuggestions( |
261 const PasswordFormFillData& fill_data) { | 261 const PasswordFormFillData& fill_data) { |
262 AutofillMsg_ShowInitialPasswordAccountSuggestions msg( | 262 autofill_agent_->ShowInitialPasswordAccountSuggestions( |
263 0, kPasswordFillFormDataId, fill_data); | 263 kPasswordFillFormDataId, fill_data); |
264 static_cast<content::RenderFrameObserver*>(autofill_agent_) | |
265 ->OnMessageReceived(msg); | |
266 } | 264 } |
267 | 265 |
268 void SendVisiblePasswordForms() { | 266 void SendVisiblePasswordForms() { |
269 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 267 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
270 ->DidFinishLoad(); | 268 ->DidFinishLoad(); |
271 } | 269 } |
272 | 270 |
273 void SetUp() override { | 271 void SetUp() override { |
274 ChromeRenderViewTest::SetUp(); | 272 ChromeRenderViewTest::SetUp(); |
275 | 273 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 void SimulateSuggestionChoiceOfUsernameAndPassword( | 378 void SimulateSuggestionChoiceOfUsernameAndPassword( |
381 WebInputElement& input, | 379 WebInputElement& input, |
382 const base::string16& username, | 380 const base::string16& username, |
383 const base::string16& password) { | 381 const base::string16& password) { |
384 // This call is necessary to setup the autofill agent appropriate for the | 382 // This call is necessary to setup the autofill agent appropriate for the |
385 // user selection; simulates the menu actually popping up. | 383 // user selection; simulates the menu actually popping up. |
386 render_thread_->sink().ClearMessages(); | 384 render_thread_->sink().ClearMessages(); |
387 static_cast<autofill::PageClickListener*>(autofill_agent_) | 385 static_cast<autofill::PageClickListener*>(autofill_agent_) |
388 ->FormControlElementClicked(input, false); | 386 ->FormControlElementClicked(input, false); |
389 | 387 |
390 AutofillMsg_FillPasswordSuggestion msg(0, username, password); | 388 autofill_agent_->FillPasswordSuggestion(mojo::String::From(username), |
391 static_cast<content::RenderFrameObserver*>(autofill_agent_) | 389 mojo::String::From(password)); |
392 ->OnMessageReceived(msg); | |
393 } | 390 } |
394 | 391 |
395 void SimulateUsernameChange(const std::string& username) { | 392 void SimulateUsernameChange(const std::string& username) { |
396 SimulateUserInputChangeForElement(&username_element_, username); | 393 SimulateUserInputChangeForElement(&username_element_, username); |
397 } | 394 } |
398 | 395 |
399 void SimulatePasswordChange(const std::string& password) { | 396 void SimulatePasswordChange(const std::string& password) { |
400 SimulateUserInputChangeForElement(&password_element_, password); | 397 SimulateUserInputChangeForElement(&password_element_, password); |
401 } | 398 } |
402 | 399 |
(...skipping 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2374 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 2371 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
2375 AutofillHostMsg_ShowPasswordSuggestions::ID)); | 2372 AutofillHostMsg_ShowPasswordSuggestions::ID)); |
2376 | 2373 |
2377 // But when the user clicks on the autofilled password field again it should | 2374 // But when the user clicks on the autofilled password field again it should |
2378 // still produce a suggestion dropdown. | 2375 // still produce a suggestion dropdown. |
2379 SimulateElementClick("password"); | 2376 SimulateElementClick("password"); |
2380 CheckSuggestions("", false); | 2377 CheckSuggestions("", false); |
2381 } | 2378 } |
2382 | 2379 |
2383 } // namespace autofill | 2380 } // namespace autofill |
OLD | NEW |