Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/renderer/autofill/password_generation_agent_browsertest.cc

Issue 2728353002: [Password Generation] Process CONFIRMATION_PASSWORD votes on the client side (Closed)
Patch Set: Changed usage of base::Optional Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_types.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string.h> 5 #include <string.h>
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/test/histogram_tester.h" 13 #include "base/test/histogram_tester.h"
14 #include "chrome/renderer/autofill/fake_content_password_manager_driver.h" 14 #include "chrome/renderer/autofill/fake_content_password_manager_driver.h"
15 #include "chrome/renderer/autofill/fake_password_manager_client.h" 15 #include "chrome/renderer/autofill/fake_password_manager_client.h"
16 #include "chrome/renderer/autofill/password_generation_test_utils.h" 16 #include "chrome/renderer/autofill/password_generation_test_utils.h"
17 #include "chrome/test/base/chrome_render_view_test.h" 17 #include "chrome/test/base/chrome_render_view_test.h"
18 #include "components/autofill/content/renderer/autofill_agent.h" 18 #include "components/autofill/content/renderer/autofill_agent.h"
19 #include "components/autofill/content/renderer/form_autofill_util.h"
19 #include "components/autofill/content/renderer/test_password_generation_agent.h" 20 #include "components/autofill/content/renderer/test_password_generation_agent.h"
20 #include "components/autofill/core/common/form_data.h" 21 #include "components/autofill/core/common/form_data.h"
21 #include "components/autofill/core/common/password_generation_util.h" 22 #include "components/autofill/core/common/password_generation_util.h"
22 #include "content/public/common/associated_interface_provider.h" 23 #include "content/public/common/associated_interface_provider.h"
23 #include "content/public/renderer/render_frame.h" 24 #include "content/public/renderer/render_frame.h"
24 #include "content/public/renderer/render_view.h" 25 #include "content/public/renderer/render_view.h"
25 #include "services/service_manager/public/cpp/interface_provider.h" 26 #include "services/service_manager/public/cpp/interface_provider.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 #include "third_party/WebKit/public/platform/WebString.h" 28 #include "third_party/WebKit/public/platform/WebString.h"
28 #include "third_party/WebKit/public/web/WebDocument.h" 29 #include "third_party/WebKit/public/web/WebDocument.h"
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 ExpectFormClassifierVoteReceived(true /* vote is expected */, 717 ExpectFormClassifierVoteReceived(true /* vote is expected */,
717 base::string16()); 718 base::string16());
718 } 719 }
719 720
720 TEST_F(PasswordGenerationAgentTest, FormClassifierDisabled) { 721 TEST_F(PasswordGenerationAgentTest, FormClassifierDisabled) {
721 LoadHTMLWithUserGesture(kSigninFormHTML); 722 LoadHTMLWithUserGesture(kSigninFormHTML);
722 ExpectFormClassifierVoteReceived(false /* vote is not expected */, 723 ExpectFormClassifierVoteReceived(false /* vote is not expected */,
723 base::string16()); 724 base::string16());
724 } 725 }
725 726
727 TEST_F(PasswordGenerationAgentTest, ConfirmationFieldVoteFromServer) {
728 LoadHTMLWithUserGesture(kPasswordChangeFormHTML);
729 SetNotBlacklistedMessage(password_generation_, kPasswordChangeFormHTML);
730
731 WebDocument document = GetMainFrame()->document();
732 blink::WebVector<blink::WebFormElement> web_forms;
733 document.forms(web_forms);
734 autofill::FormData form_data;
735 WebFormElementToFormData(web_forms[0], blink::WebFormControlElement(),
736 nullptr, form_util::EXTRACT_NONE, &form_data,
737 nullptr /* FormFieldData */);
738
739 std::vector<autofill::PasswordFormGenerationData> forms;
740 autofill::PasswordFormGenerationData generation_data(
741 CalculateFormSignature(form_data),
742 CalculateFieldSignatureForField(form_data.fields[1]));
743 generation_data.confirmation_field_signature.emplace(
744 CalculateFieldSignatureForField(form_data.fields[3]));
745 forms.push_back(generation_data);
746 password_generation_->FoundFormsEligibleForGeneration(forms);
747
748 WebElement element =
749 document.getElementById(WebString::fromUTF16(form_data.fields[1].name));
750 ASSERT_FALSE(element.isNull());
751 WebInputElement generation_element = element.to<WebInputElement>();
752 element =
753 document.getElementById(WebString::fromUTF16(form_data.fields[2].name));
754 ASSERT_FALSE(element.isNull());
755 WebInputElement ignored_password_element = element.to<WebInputElement>();
756 element =
757 document.getElementById(WebString::fromUTF16(form_data.fields[3].name));
758 ASSERT_FALSE(element.isNull());
759 WebInputElement confirmation_password_element = element.to<WebInputElement>();
760
761 base::string16 password = base::ASCIIToUTF16("random_password");
762 password_generation_->GeneratedPasswordAccepted(password);
763 EXPECT_EQ(password, generation_element.value().utf16());
764 // Check that the generated password was copied according to the server's
765 // response.
766 EXPECT_EQ(base::string16(), ignored_password_element.value().utf16());
767 EXPECT_EQ(password, confirmation_password_element.value().utf16());
768 }
769
726 } // namespace autofill 770 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_types.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698