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

Side by Side Diff: components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc

Issue 249153002: Rewrite functions from WebPasswordFormData and WebPasswordFormUtils in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update code as per review comments. Created 6 years, 8 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 | « components/autofill/content/renderer/password_form_conversion_utils.cc ('k') | no next file » | 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 "base/strings/string16.h" 5 #include "base/strings/string16.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "components/autofill/content/renderer/password_form_conversion_utils.h" 7 #include "components/autofill/content/renderer/password_form_conversion_utils.h"
8 #include "components/autofill/core/common/password_form.h" 8 #include "components/autofill/core/common/password_form.h"
9 #include "content/public/test/render_view_test.h" 9 #include "content/public/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/public/platform/WebVector.h" 11 #include "third_party/WebKit/public/platform/WebVector.h"
12 #include "third_party/WebKit/public/web/WebDocument.h" 12 #include "third_party/WebKit/public/web/WebDocument.h"
13 #include "third_party/WebKit/public/web/WebFormElement.h" 13 #include "third_party/WebKit/public/web/WebFormElement.h"
14 #include "third_party/WebKit/public/web/WebLocalFrame.h" 14 #include "third_party/WebKit/public/web/WebLocalFrame.h"
15 #include "third_party/WebKit/public/web/WebPasswordFormData.h"
16 15
17 using blink::WebFormElement; 16 using blink::WebFormElement;
18 using blink::WebFrame; 17 using blink::WebFrame;
19 using blink::WebPasswordFormData;
20 using blink::WebVector; 18 using blink::WebVector;
21 19
22 namespace autofill { 20 namespace autofill {
23 namespace { 21 namespace {
24 22
25 class PasswordFormConversionUtilsTest : public content::RenderViewTest { 23 class PasswordFormConversionUtilsTest : public content::RenderViewTest {
26 public: 24 public:
27 PasswordFormConversionUtilsTest() : content::RenderViewTest() {} 25 PasswordFormConversionUtilsTest() : content::RenderViewTest() {}
28 virtual ~PasswordFormConversionUtilsTest() {} 26 virtual ~PasswordFormConversionUtilsTest() {}
29 27
(...skipping 11 matching lines...) Expand all
41 " <INPUT type=\"password\" name=\"password\" id=\"password\" " 39 " <INPUT type=\"password\" name=\"password\" id=\"password\" "
42 " value=\"secret\"/>" 40 " value=\"secret\"/>"
43 "</FORM>"); 41 "</FORM>");
44 42
45 WebFrame* frame = GetMainFrame(); 43 WebFrame* frame = GetMainFrame();
46 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); 44 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
47 45
48 WebVector<WebFormElement> forms; 46 WebVector<WebFormElement> forms;
49 frame->document().forms(forms); 47 frame->document().forms(forms);
50 ASSERT_EQ(1U, forms.size()); 48 ASSERT_EQ(1U, forms.size());
51 WebPasswordFormData web_password_form(forms[0]);
52 ASSERT_TRUE(web_password_form.isValid());
53 49
54 scoped_ptr<PasswordForm> password_form = CreatePasswordForm(forms[0]); 50 scoped_ptr<PasswordForm> password_form = CreatePasswordForm(forms[0]);
55 ASSERT_NE(static_cast<PasswordForm*>(NULL), password_form.get()); 51 ASSERT_NE(static_cast<PasswordForm*>(NULL), password_form.get());
56 52
57 EXPECT_EQ("data:", password_form->signon_realm); 53 EXPECT_EQ("data:", password_form->signon_realm);
58 EXPECT_EQ(GURL("http://cnn.com"), password_form->action); 54 EXPECT_EQ(GURL("http://cnn.com"), password_form->action);
59 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); 55 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element);
60 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); 56 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value);
61 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); 57 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element);
62 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); 58 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value);
(...skipping 12 matching lines...) Expand all
75 " <INPUT type=\"password\" name=\"password\" id=\"password\" " 71 " <INPUT type=\"password\" name=\"password\" id=\"password\" "
76 " value=\"secret\"/>" 72 " value=\"secret\"/>"
77 "</FORM>"); 73 "</FORM>");
78 74
79 WebFrame* frame = GetMainFrame(); 75 WebFrame* frame = GetMainFrame();
80 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); 76 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
81 77
82 WebVector<WebFormElement> forms; 78 WebVector<WebFormElement> forms;
83 frame->document().forms(forms); 79 frame->document().forms(forms);
84 ASSERT_EQ(1U, forms.size()); 80 ASSERT_EQ(1U, forms.size());
85 WebPasswordFormData web_password_form(forms[0]);
86 ASSERT_FALSE(web_password_form.isValid());
87 81
88 scoped_ptr<PasswordForm> password_form = CreatePasswordForm(forms[0]); 82 scoped_ptr<PasswordForm> password_form = CreatePasswordForm(forms[0]);
89 EXPECT_EQ(static_cast<PasswordForm*>(NULL), password_form.get()); 83 EXPECT_EQ(static_cast<PasswordForm*>(NULL), password_form.get());
90 } 84 }
91 85
86 TEST_F(PasswordFormConversionUtilsTest,
87 WebFormWithMultipleUseNameAndPassWordFieldsToPasswordForm) {
88 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
89 " <INPUT type=\"text\" name=\"username1\" "
90 " id=\"username1\" value=\"John\"/>"
91 " <INPUT type=\"password\" name=\"password1\" id=\"password1\" "
92 " value=\"encrypted\"/>"
93 " <INPUT type=\"text\" name=\"username2\" "
94 " id=\"username2\" value=\"Smith\"/>"
95 " <INPUT type=\"password\" name=\"password2\" id=\"password2\" "
96 " value=\"secret\"/>"
97 " <INPUT type=\"text\" name=\"username3\" "
98 " id=\"username3\" value=\"JohnSmith\"/>"
99 " <INPUT type=\"password\" name=\"password3\" id=\"password3\" "
100 " value=\"secret\"/>"
101 " <INPUT type=\"submit\" name=\"submit\" value=\"Submit\"/>"
102 "</FORM>");
103
104 WebFrame* frame = GetMainFrame();
105 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
106
107 WebVector<WebFormElement> forms;
108 frame->document().forms(forms);
109 ASSERT_EQ(1U, forms.size());
110
111 scoped_ptr<PasswordForm> password_form = CreatePasswordForm(forms[0]);
112 ASSERT_NE(static_cast<PasswordForm*>(NULL), password_form.get());
113
114 EXPECT_EQ("data:", password_form->signon_realm);
115 EXPECT_EQ(GURL("http://cnn.com"), password_form->action);
116 EXPECT_EQ(base::UTF8ToUTF16("username1"), password_form->username_element);
117 EXPECT_EQ(base::UTF8ToUTF16("John"), password_form->username_value);
118 EXPECT_EQ(base::UTF8ToUTF16("password2"), password_form->password_element);
119 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value);
120 EXPECT_EQ(base::UTF8ToUTF16("password1"),
121 password_form->old_password_element);
122 EXPECT_EQ(base::UTF8ToUTF16("encrypted"), password_form->old_password_value);
123 EXPECT_EQ(base::UTF8ToUTF16("Smith"),
124 password_form->other_possible_usernames[0]);
125 EXPECT_EQ(base::UTF8ToUTF16("JohnSmith"),
126 password_form->other_possible_usernames[1]);
127 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form->scheme);
128 EXPECT_FALSE(password_form->ssl_valid);
129 EXPECT_FALSE(password_form->preferred);
130 EXPECT_FALSE(password_form->blacklisted_by_user);
131 EXPECT_EQ(PasswordForm::TYPE_MANUAL, password_form->type);
132 }
133
134 TEST_F(PasswordFormConversionUtilsTest,
135 WebFormwithThreeDifferentPasswordsToPasswordForm) {
136 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
137 " <INPUT type=\"text\" name=\"username\" "
138 " id=\"username\" value=\"John\"/>"
139 " <INPUT type=\"password\" name=\"password1\" id=\"password1\" "
140 " value=\"secret\"/>"
141 " <INPUT type=\"password\" name=\"password2\" id=\"password2\" "
142 " value=\"encrypted\"/>"
143 " <INPUT type=\"password\" name=\"password3\" id=\"password3\" "
144 " value=\"key\"/>"
145 " <INPUT type=\"submit\" name=\"submit\" value=\"Submit\"/>"
146 "</FORM>");
147
148 WebFrame* frame = GetMainFrame();
149 ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
150
151 WebVector<WebFormElement> forms;
152 frame->document().forms(forms);
153 ASSERT_EQ(1U, forms.size());
154
155 scoped_ptr<PasswordForm> password_form = CreatePasswordForm(forms[0]);
156 ASSERT_EQ(static_cast<PasswordForm*>(NULL), password_form.get());
157 }
158
92 } // namespace autofill 159 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/password_form_conversion_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698