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 <algorithm> | 5 #include <algorithm> |
6 #include <map> | 6 #include <map> |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 old_form_google_.password_element = UTF8ToUTF16("pass"); | 147 old_form_google_.password_element = UTF8ToUTF16("pass"); |
148 old_form_google_.password_value = UTF8ToUTF16("seekrit"); | 148 old_form_google_.password_value = UTF8ToUTF16("seekrit"); |
149 old_form_google_.submit_element = UTF8ToUTF16("submit"); | 149 old_form_google_.submit_element = UTF8ToUTF16("submit"); |
150 old_form_google_.signon_realm = "Google"; | 150 old_form_google_.signon_realm = "Google"; |
151 | 151 |
152 form_google_ = old_form_google_; | 152 form_google_ = old_form_google_; |
153 form_google_.times_used = 3; | 153 form_google_.times_used = 3; |
154 form_google_.type = PasswordForm::TYPE_GENERATED; | 154 form_google_.type = PasswordForm::TYPE_GENERATED; |
155 form_google_.form_data.name = UTF8ToUTF16("form_name"); | 155 form_google_.form_data.name = UTF8ToUTF16("form_name"); |
156 form_google_.form_data.user_submitted = true; | 156 form_google_.form_data.user_submitted = true; |
| 157 form_google_.date_synced = base::Time::Now(); |
157 | 158 |
158 form_isc_.origin = GURL("http://www.isc.org/"); | 159 form_isc_.origin = GURL("http://www.isc.org/"); |
159 form_isc_.action = GURL("http://www.isc.org/auth"); | 160 form_isc_.action = GURL("http://www.isc.org/auth"); |
160 form_isc_.username_element = UTF8ToUTF16("id"); | 161 form_isc_.username_element = UTF8ToUTF16("id"); |
161 form_isc_.username_value = UTF8ToUTF16("janedoe"); | 162 form_isc_.username_value = UTF8ToUTF16("janedoe"); |
162 form_isc_.password_element = UTF8ToUTF16("passwd"); | 163 form_isc_.password_element = UTF8ToUTF16("passwd"); |
163 form_isc_.password_value = UTF8ToUTF16("ihazabukkit"); | 164 form_isc_.password_value = UTF8ToUTF16("ihazabukkit"); |
164 form_isc_.submit_element = UTF8ToUTF16("login"); | 165 form_isc_.submit_element = UTF8ToUTF16("login"); |
165 form_isc_.signon_realm = "ISC"; | 166 form_isc_.signon_realm = "ISC"; |
| 167 form_isc_.date_synced = base::Time::Now(); |
166 } | 168 } |
167 | 169 |
168 static void CheckPasswordForm(const PasswordForm& expected, | 170 static void CheckPasswordForm(const PasswordForm& expected, |
169 const PasswordForm& actual); | 171 const PasswordForm& actual); |
170 static void CheckPasswordChanges(const PasswordStoreChangeList& expected, | 172 static void CheckPasswordChanges(const PasswordStoreChangeList& expected, |
171 const PasswordStoreChangeList& actual); | 173 const PasswordStoreChangeList& actual); |
172 | 174 |
173 PasswordForm old_form_google_; | 175 PasswordForm old_form_google_; |
174 PasswordForm form_google_; | 176 PasswordForm form_google_; |
175 PasswordForm form_isc_; | 177 PasswordForm form_isc_; |
176 }; | 178 }; |
177 | 179 |
178 void NativeBackendKWalletTestBase::CheckPasswordForm( | 180 void NativeBackendKWalletTestBase::CheckPasswordForm( |
179 const PasswordForm& expected, const PasswordForm& actual) { | 181 const PasswordForm& expected, const PasswordForm& actual) { |
180 EXPECT_EQ(expected.origin, actual.origin); | 182 EXPECT_EQ(expected.origin, actual.origin); |
181 EXPECT_EQ(expected.password_value, actual.password_value); | 183 EXPECT_EQ(expected.password_value, actual.password_value); |
182 EXPECT_EQ(expected.action, actual.action); | 184 EXPECT_EQ(expected.action, actual.action); |
183 EXPECT_EQ(expected.username_element, actual.username_element); | 185 EXPECT_EQ(expected.username_element, actual.username_element); |
184 EXPECT_EQ(expected.username_value, actual.username_value); | 186 EXPECT_EQ(expected.username_value, actual.username_value); |
185 EXPECT_EQ(expected.password_element, actual.password_element); | 187 EXPECT_EQ(expected.password_element, actual.password_element); |
186 EXPECT_EQ(expected.submit_element, actual.submit_element); | 188 EXPECT_EQ(expected.submit_element, actual.submit_element); |
187 EXPECT_EQ(expected.signon_realm, actual.signon_realm); | 189 EXPECT_EQ(expected.signon_realm, actual.signon_realm); |
188 EXPECT_EQ(expected.ssl_valid, actual.ssl_valid); | 190 EXPECT_EQ(expected.ssl_valid, actual.ssl_valid); |
189 EXPECT_EQ(expected.preferred, actual.preferred); | 191 EXPECT_EQ(expected.preferred, actual.preferred); |
190 // We don't check the date created. It varies. | 192 // We don't check the date created. It varies. |
191 EXPECT_EQ(expected.blacklisted_by_user, actual.blacklisted_by_user); | 193 EXPECT_EQ(expected.blacklisted_by_user, actual.blacklisted_by_user); |
192 EXPECT_EQ(expected.type, actual.type); | 194 EXPECT_EQ(expected.type, actual.type); |
193 EXPECT_EQ(expected.times_used, actual.times_used); | 195 EXPECT_EQ(expected.times_used, actual.times_used); |
194 EXPECT_EQ(expected.scheme, actual.scheme); | 196 EXPECT_EQ(expected.scheme, actual.scheme); |
| 197 EXPECT_EQ(expected.date_synced, actual.date_synced); |
195 } | 198 } |
196 | 199 |
197 void NativeBackendKWalletTestBase::CheckPasswordChanges( | 200 void NativeBackendKWalletTestBase::CheckPasswordChanges( |
198 const PasswordStoreChangeList& expected, | 201 const PasswordStoreChangeList& expected, |
199 const PasswordStoreChangeList& actual) { | 202 const PasswordStoreChangeList& actual) { |
200 ASSERT_EQ(expected.size(), actual.size()); | 203 ASSERT_EQ(expected.size(), actual.size()); |
201 for (size_t i = 0; i < expected.size(); ++i) { | 204 for (size_t i = 0; i < expected.size(); ++i) { |
202 EXPECT_EQ(expected[i].type(), actual[i].type()); | 205 EXPECT_EQ(expected[i].type(), actual[i].type()); |
203 CheckPasswordForm(expected[i].form(), actual[i].form()); | 206 CheckPasswordForm(expected[i].form(), actual[i].form()); |
204 } | 207 } |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 ExpectationArray expected; | 790 ExpectationArray expected; |
788 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | 791 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); |
789 CheckPasswordForms("Chrome Form Data (42)", expected); | 792 CheckPasswordForms("Chrome Form Data (42)", expected); |
790 } | 793 } |
791 | 794 |
792 // TODO(mdm): add more basic tests here at some point. | 795 // TODO(mdm): add more basic tests here at some point. |
793 // (For example tests for storing >1 password per realm pickle.) | 796 // (For example tests for storing >1 password per realm pickle.) |
794 | 797 |
795 class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase { | 798 class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase { |
796 protected: | 799 protected: |
| 800 void CreateVersion2Pickle(const PasswordForm& form, Pickle* pickle); |
797 void CreateVersion1Pickle(const PasswordForm& form, Pickle* pickle); | 801 void CreateVersion1Pickle(const PasswordForm& form, Pickle* pickle); |
798 void CreateVersion0Pickle(bool size_32, | 802 void CreateVersion0Pickle(bool size_32, |
799 const PasswordForm& form, | 803 const PasswordForm& form, |
800 Pickle* pickle); | 804 Pickle* pickle); |
| 805 void CheckVersion2Pickle(); |
801 void CheckVersion1Pickle(); | 806 void CheckVersion1Pickle(); |
802 void CheckVersion0Pickle(bool size_32, PasswordForm::Scheme scheme); | 807 void CheckVersion0Pickle(bool size_32, PasswordForm::Scheme scheme); |
803 | 808 |
804 private: | 809 private: |
805 void CreatePickle(bool size_32, const PasswordForm& form, Pickle* pickle); | 810 void CreatePickle(bool size_32, const PasswordForm& form, Pickle* pickle); |
806 }; | 811 }; |
807 | 812 |
| 813 void NativeBackendKWalletPickleTest::CreateVersion2Pickle( |
| 814 const PasswordForm& form, Pickle* pickle) { |
| 815 pickle->WriteInt(2); |
| 816 CreatePickle(false, form, pickle); |
| 817 pickle->WriteInt(form.type); |
| 818 pickle->WriteInt(form.times_used); |
| 819 autofill::SerializeFormData(form.form_data, pickle); |
| 820 } |
| 821 |
808 void NativeBackendKWalletPickleTest::CreateVersion1Pickle( | 822 void NativeBackendKWalletPickleTest::CreateVersion1Pickle( |
809 const PasswordForm& form, Pickle* pickle) { | 823 const PasswordForm& form, Pickle* pickle) { |
810 pickle->WriteInt(1); | 824 pickle->WriteInt(1); |
811 CreatePickle(false, form, pickle); | 825 CreatePickle(false, form, pickle); |
812 } | 826 } |
813 | 827 |
814 void NativeBackendKWalletPickleTest::CreateVersion0Pickle( | 828 void NativeBackendKWalletPickleTest::CreateVersion0Pickle( |
815 bool size_32, const PasswordForm& form, Pickle* pickle) { | 829 bool size_32, const PasswordForm& form, Pickle* pickle) { |
816 pickle->WriteInt(0); | 830 pickle->WriteInt(0); |
817 CreatePickle(size_32, form, pickle); | 831 CreatePickle(size_32, form, pickle); |
(...skipping 12 matching lines...) Expand all Loading... |
830 pickle->WriteString16(form.username_value); | 844 pickle->WriteString16(form.username_value); |
831 pickle->WriteString16(form.password_element); | 845 pickle->WriteString16(form.password_element); |
832 pickle->WriteString16(form.password_value); | 846 pickle->WriteString16(form.password_value); |
833 pickle->WriteString16(form.submit_element); | 847 pickle->WriteString16(form.submit_element); |
834 pickle->WriteBool(form.ssl_valid); | 848 pickle->WriteBool(form.ssl_valid); |
835 pickle->WriteBool(form.preferred); | 849 pickle->WriteBool(form.preferred); |
836 pickle->WriteBool(form.blacklisted_by_user); | 850 pickle->WriteBool(form.blacklisted_by_user); |
837 pickle->WriteInt64(form.date_created.ToTimeT()); | 851 pickle->WriteInt64(form.date_created.ToTimeT()); |
838 } | 852 } |
839 | 853 |
840 void NativeBackendKWalletPickleTest::CheckVersion0Pickle( | 854 void NativeBackendKWalletPickleTest::CheckVersion2Pickle() { |
841 bool size_32, PasswordForm::Scheme scheme) { | |
842 Pickle pickle; | 855 Pickle pickle; |
843 PasswordForm form = old_form_google_; | 856 PasswordForm form = form_google_; |
844 form.scheme = scheme; | 857 form.date_synced = base::Time(); |
845 CreateVersion0Pickle(size_32, form, &pickle); | 858 CreateVersion2Pickle(form, &pickle); |
| 859 |
846 std::vector<PasswordForm*> form_list; | 860 std::vector<PasswordForm*> form_list; |
847 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, | 861 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, |
848 pickle, &form_list); | 862 pickle, &form_list); |
| 863 |
| 864 // This will match |old_form_google_| because not all the fields present in |
| 865 // |form_google_| will be deserialized. |
849 EXPECT_EQ(1u, form_list.size()); | 866 EXPECT_EQ(1u, form_list.size()); |
850 if (form_list.size() > 0) | 867 if (form_list.size() > 0) |
851 CheckPasswordForm(form, *form_list[0]); | 868 CheckPasswordForm(form, *form_list[0]); |
852 STLDeleteElements(&form_list); | 869 STLDeleteElements(&form_list); |
853 } | 870 } |
854 | 871 |
855 // Make sure that we can still read version 1 pickles. | 872 // Make sure that we can still read version 1 pickles. |
856 void NativeBackendKWalletPickleTest::CheckVersion1Pickle() { | 873 void NativeBackendKWalletPickleTest::CheckVersion1Pickle() { |
857 Pickle pickle; | 874 Pickle pickle; |
858 PasswordForm form = form_google_; | 875 PasswordForm form = form_google_; |
859 CreateVersion1Pickle(form, &pickle); | 876 CreateVersion1Pickle(form, &pickle); |
860 | 877 |
861 std::vector<PasswordForm*> form_list; | 878 std::vector<PasswordForm*> form_list; |
862 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, | 879 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, |
863 pickle, &form_list); | 880 pickle, &form_list); |
864 | 881 |
865 // This will match |old_form_google_| because not all the fields present in | 882 // This will match |old_form_google_| because not all the fields present in |
866 // |form_google_| will be deserialized. | 883 // |form_google_| will be deserialized. |
867 EXPECT_EQ(1u, form_list.size()); | 884 EXPECT_EQ(1u, form_list.size()); |
868 if (form_list.size() > 0) | 885 if (form_list.size() > 0) |
869 CheckPasswordForm(old_form_google_, *form_list[0]); | 886 CheckPasswordForm(old_form_google_, *form_list[0]); |
870 STLDeleteElements(&form_list); | 887 STLDeleteElements(&form_list); |
871 } | 888 } |
872 | 889 |
| 890 void NativeBackendKWalletPickleTest::CheckVersion0Pickle( |
| 891 bool size_32, PasswordForm::Scheme scheme) { |
| 892 Pickle pickle; |
| 893 PasswordForm form = old_form_google_; |
| 894 form.scheme = scheme; |
| 895 CreateVersion0Pickle(size_32, form, &pickle); |
| 896 std::vector<PasswordForm*> form_list; |
| 897 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, |
| 898 pickle, &form_list); |
| 899 EXPECT_EQ(1u, form_list.size()); |
| 900 if (form_list.size() > 0) |
| 901 CheckPasswordForm(form, *form_list[0]); |
| 902 STLDeleteElements(&form_list); |
| 903 } |
| 904 |
873 // We try both SCHEME_HTML and SCHEME_BASIC since the scheme is stored right | 905 // We try both SCHEME_HTML and SCHEME_BASIC since the scheme is stored right |
874 // after the size in the pickle, so it's what gets read as part of the count | 906 // after the size in the pickle, so it's what gets read as part of the count |
875 // when reading 32-bit pickles on 64-bit systems. SCHEME_HTML is 0 (so we'll | 907 // when reading 32-bit pickles on 64-bit systems. SCHEME_HTML is 0 (so we'll |
876 // detect errors later) while SCHEME_BASIC is 1 (so we'll detect it then). We | 908 // detect errors later) while SCHEME_BASIC is 1 (so we'll detect it then). We |
877 // try both 32-bit and 64-bit pickles since only one will be the "other" size | 909 // try both 32-bit and 64-bit pickles since only one will be the "other" size |
878 // for whatever architecture we're running on, but we want to make sure we can | 910 // for whatever architecture we're running on, but we want to make sure we can |
879 // read all combinations in any event. | 911 // read all combinations in any event. |
880 | 912 |
881 TEST_F(NativeBackendKWalletPickleTest, ReadsOld32BitHTMLPickles) { | 913 TEST_F(NativeBackendKWalletPickleTest, ReadsOld32BitHTMLPickles) { |
882 CheckVersion0Pickle(true, PasswordForm::SCHEME_HTML); | 914 CheckVersion0Pickle(true, PasswordForm::SCHEME_HTML); |
883 } | 915 } |
884 | 916 |
885 TEST_F(NativeBackendKWalletPickleTest, ReadsOld32BitHTTPPickles) { | 917 TEST_F(NativeBackendKWalletPickleTest, ReadsOld32BitHTTPPickles) { |
886 CheckVersion0Pickle(true, PasswordForm::SCHEME_BASIC); | 918 CheckVersion0Pickle(true, PasswordForm::SCHEME_BASIC); |
887 } | 919 } |
888 | 920 |
889 TEST_F(NativeBackendKWalletPickleTest, ReadsOld64BitHTMLPickles) { | 921 TEST_F(NativeBackendKWalletPickleTest, ReadsOld64BitHTMLPickles) { |
890 CheckVersion0Pickle(false, PasswordForm::SCHEME_HTML); | 922 CheckVersion0Pickle(false, PasswordForm::SCHEME_HTML); |
891 } | 923 } |
892 | 924 |
893 TEST_F(NativeBackendKWalletPickleTest, ReadsOld64BitHTTPPickles) { | 925 TEST_F(NativeBackendKWalletPickleTest, ReadsOld64BitHTTPPickles) { |
894 CheckVersion0Pickle(false, PasswordForm::SCHEME_BASIC); | 926 CheckVersion0Pickle(false, PasswordForm::SCHEME_BASIC); |
895 } | 927 } |
896 | 928 |
897 TEST_F(NativeBackendKWalletPickleTest, CheckVersion1Pickle) { | 929 TEST_F(NativeBackendKWalletPickleTest, CheckVersion1Pickle) { |
898 CheckVersion1Pickle(); | 930 CheckVersion1Pickle(); |
899 } | 931 } |
| 932 |
| 933 TEST_F(NativeBackendKWalletPickleTest, CheckVersion2Pickle) { |
| 934 CheckVersion2Pickle(); |
| 935 } |
OLD | NEW |