OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
Ilya Sherman
2013/06/19 09:40:54
nit: 2013, and please omit the "(c)".
nyquist
2013/06/19 22:56:06
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/utf_string_conversions.h" | |
6 #include "components/autofill/common/password_form_fill_data.h" | |
Ilya Sherman
2013/06/19 09:40:54
nit: This include should precede all the others, j
nyquist
2013/06/19 22:56:06
Oops. Done.
| |
7 #include "content/public/common/password_form.h" | |
8 #include "testing/gmock/include/gmock/gmock.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 using autofill::PasswordFormFillData; | |
Ilya Sherman
2013/06/19 09:40:54
nit: Please wrap all the test code in the autofill
nyquist
2013/06/19 22:56:06
Done.
| |
12 using content::PasswordForm; | |
13 using content::PasswordFormMap; | |
14 | |
15 class PasswordFormFillDataTest : public testing::Test {}; | |
Ilya Sherman
2013/06/19 09:40:54
nit: You can omit this line, and just replace all
nyquist
2013/06/19 22:56:06
Done.
| |
16 | |
17 TEST_F(PasswordFormFillDataTest, TestSinglePreferredMatch) { | |
Ilya Sherman
2013/06/19 09:40:54
nit: Please add a comment describing what this is
nyquist
2013/06/19 22:56:06
Done.
| |
18 // Create the current form on the page. | |
19 PasswordForm form_on_page; | |
20 form_on_page.origin = GURL("https://foo.com/"); | |
21 form_on_page.action = GURL("https://foo.com/login"); | |
22 form_on_page.username_element = ASCIIToUTF16("username"); | |
23 form_on_page.username_value = ASCIIToUTF16("test@gmail.com"); | |
24 form_on_page.password_element = ASCIIToUTF16("password"); | |
25 form_on_page.password_value = ASCIIToUTF16("test"); | |
26 form_on_page.submit_element = ASCIIToUTF16(""); | |
27 form_on_page.signon_realm = "https://foo.com/"; | |
28 form_on_page.ssl_valid = true; | |
29 form_on_page.preferred = false; | |
30 form_on_page.scheme = PasswordForm::SCHEME_HTML; | |
31 | |
32 // Create an exact match in the database. | |
33 PasswordForm preferred_match; | |
34 preferred_match.origin = GURL("https://foo.com/"); | |
35 preferred_match.action = GURL("https://foo.com/login"); | |
36 preferred_match.username_element = ASCIIToUTF16("username"); | |
37 preferred_match.username_value = ASCIIToUTF16("test@gmail.com"); | |
38 preferred_match.password_element = ASCIIToUTF16("password"); | |
39 preferred_match.password_value = ASCIIToUTF16("test"); | |
40 preferred_match.submit_element = ASCIIToUTF16(""); | |
41 preferred_match.signon_realm = "https://foo.com/"; | |
42 preferred_match.ssl_valid = true; | |
43 preferred_match.preferred = true; | |
44 preferred_match.scheme = PasswordForm::SCHEME_HTML; | |
45 | |
46 PasswordFormMap matches; | |
47 | |
48 PasswordFormFillData result; | |
49 InitPasswordFormFillData(form_on_page, | |
50 matches, | |
51 &preferred_match, | |
52 true, | |
53 false, | |
54 &result); | |
55 EXPECT_TRUE(result.wait_for_username); | |
Ilya Sherman
2013/06/19 09:40:54
Why is wait_for_username true for an exact match?
nyquist
2013/06/19 22:56:06
Added a comment about this and also added a test o
| |
56 // The preferred realm should match the signon realm from the preferred match. | |
57 EXPECT_EQ(result.preferred_realm, ASCIIToUTF16(preferred_match.signon_realm)); | |
58 } | |
59 | |
60 TEST_F(PasswordFormFillDataTest, TestPublicSuffixDomainMatching) { | |
Ilya Sherman
2013/06/19 09:40:54
nit: Please add a comment describing what this is
nyquist
2013/06/19 22:56:06
Done.
| |
61 // Create the current form on the page. | |
62 PasswordForm form_on_page; | |
63 form_on_page.origin = GURL("https://foo.com/"); | |
64 form_on_page.action = GURL("https://foo.com/login"); | |
65 form_on_page.username_element = ASCIIToUTF16("username"); | |
66 form_on_page.username_value = ASCIIToUTF16("test@gmail.com"); | |
67 form_on_page.password_element = ASCIIToUTF16("password"); | |
68 form_on_page.password_value = ASCIIToUTF16("test"); | |
69 form_on_page.submit_element = ASCIIToUTF16(""); | |
70 form_on_page.signon_realm = "https://foo.com/"; | |
71 form_on_page.ssl_valid = true; | |
72 form_on_page.preferred = false; | |
73 form_on_page.scheme = PasswordForm::SCHEME_HTML; | |
74 | |
75 // Create a match from the database that matches using public suffix. | |
76 PasswordForm preferred_match; | |
77 preferred_match.origin = GURL("https://mobile.foo.com/"); | |
78 preferred_match.action = GURL("https://mobile.foo.com/login"); | |
79 preferred_match.username_element = ASCIIToUTF16("username"); | |
80 preferred_match.username_value = ASCIIToUTF16("test@gmail.com"); | |
81 preferred_match.password_element = ASCIIToUTF16("password"); | |
82 preferred_match.password_value = ASCIIToUTF16("test"); | |
83 preferred_match.submit_element = ASCIIToUTF16(""); | |
84 preferred_match.signon_realm = "https://mobile.foo.com/"; | |
85 preferred_match.original_signon_realm = "https://foo.com/"; | |
86 preferred_match.ssl_valid = true; | |
87 preferred_match.preferred = true; | |
88 preferred_match.scheme = PasswordForm::SCHEME_HTML; | |
89 | |
90 // Create a match that matches exactly, so |original_signon_realm| is not set. | |
91 PasswordForm exact_match; | |
92 exact_match.origin = GURL("https://foo.com/"); | |
93 exact_match.action = GURL("https://foo.com/login"); | |
94 exact_match.username_element = ASCIIToUTF16("username"); | |
95 exact_match.username_value = ASCIIToUTF16("test1@gmail.com"); | |
96 exact_match.password_element = ASCIIToUTF16("password"); | |
97 exact_match.password_value = ASCIIToUTF16("test"); | |
98 exact_match.submit_element = ASCIIToUTF16(""); | |
99 exact_match.signon_realm = "https://foo.com/"; | |
100 exact_match.ssl_valid = true; | |
101 exact_match.preferred = false; | |
102 exact_match.scheme = PasswordForm::SCHEME_HTML; | |
103 | |
104 // Create a match that was matched using public suffix, so | |
105 // |original_signon_realm| is set to where the result came from. | |
106 PasswordForm public_suffix_match; | |
107 public_suffix_match.origin = GURL("https://foo.com/"); | |
108 public_suffix_match.action = GURL("https://foo.com/login"); | |
109 public_suffix_match.username_element = ASCIIToUTF16("username"); | |
110 public_suffix_match.username_value = ASCIIToUTF16("test2@gmail.com"); | |
111 public_suffix_match.password_element = ASCIIToUTF16("password"); | |
112 public_suffix_match.password_value = ASCIIToUTF16("test"); | |
113 public_suffix_match.submit_element = ASCIIToUTF16(""); | |
114 public_suffix_match.signon_realm = "https://foo.com/"; | |
115 public_suffix_match.ssl_valid = true; | |
116 public_suffix_match.preferred = false; | |
117 public_suffix_match.scheme = PasswordForm::SCHEME_HTML; | |
118 | |
119 // Add one exact match and one public suffix match. | |
120 PasswordFormMap matches; | |
121 matches[exact_match.username_value] = &exact_match; | |
122 matches[public_suffix_match.username_value] = &public_suffix_match; | |
123 | |
124 PasswordFormFillData result; | |
125 InitPasswordFormFillData(form_on_page, | |
126 matches, | |
127 &preferred_match, | |
128 true, | |
129 false, | |
130 &result); | |
131 EXPECT_TRUE(result.wait_for_username); | |
132 // The preferred realm should match the original signon realm from the | |
133 // preferred match so the user can see where the result came from. | |
134 EXPECT_EQ(result.preferred_realm, | |
135 ASCIIToUTF16(preferred_match.original_signon_realm)); | |
136 | |
137 // The realm of the exact match should be the same as the realm from the | |
138 // match. | |
139 PasswordFormFillData::LoginCollection::const_iterator iter = | |
140 result.additional_logins.find(exact_match.username_value); | |
141 EXPECT_EQ(iter->second.realm, ASCIIToUTF16(exact_match.signon_realm)); | |
142 | |
143 // The realm of the public suffix match should be set to the original signon | |
144 // realm so the user can see where the result came from. | |
145 iter = result.additional_logins.find(public_suffix_match.username_value); | |
146 EXPECT_EQ(iter->second.realm, ASCIIToUTF16(public_suffix_match.signon_realm)); | |
147 } | |
OLD | NEW |