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

Side by Side Diff: chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc

Issue 335893002: Support to remove passwords by date_synced timestamp. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync integration tests Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 form_isc_.password_value = UTF8ToUTF16("ihazabukkit"); 164 form_isc_.password_value = UTF8ToUTF16("ihazabukkit");
165 form_isc_.submit_element = UTF8ToUTF16("login"); 165 form_isc_.submit_element = UTF8ToUTF16("login");
166 form_isc_.signon_realm = "ISC"; 166 form_isc_.signon_realm = "ISC";
167 form_isc_.date_synced = base::Time::Now(); 167 form_isc_.date_synced = base::Time::Now();
168 } 168 }
169 169
170 static void CheckPasswordForm(const PasswordForm& expected, 170 static void CheckPasswordForm(const PasswordForm& expected,
171 const PasswordForm& actual); 171 const PasswordForm& actual);
172 static void CheckPasswordChanges(const PasswordStoreChangeList& expected, 172 static void CheckPasswordChanges(const PasswordStoreChangeList& expected,
173 const PasswordStoreChangeList& actual); 173 const PasswordStoreChangeList& actual);
174 static void CheckPasswordChangesWithResult(
175 const PasswordStoreChangeList* expected,
176 const PasswordStoreChangeList* actual,
177 bool result);
174 178
175 PasswordForm old_form_google_; 179 PasswordForm old_form_google_;
176 PasswordForm form_google_; 180 PasswordForm form_google_;
177 PasswordForm form_isc_; 181 PasswordForm form_isc_;
178 }; 182 };
179 183
184 // static
180 void NativeBackendKWalletTestBase::CheckPasswordForm( 185 void NativeBackendKWalletTestBase::CheckPasswordForm(
181 const PasswordForm& expected, const PasswordForm& actual) { 186 const PasswordForm& expected, const PasswordForm& actual) {
182 EXPECT_EQ(expected.origin, actual.origin); 187 EXPECT_EQ(expected.origin, actual.origin);
183 EXPECT_EQ(expected.password_value, actual.password_value); 188 EXPECT_EQ(expected.password_value, actual.password_value);
184 EXPECT_EQ(expected.action, actual.action); 189 EXPECT_EQ(expected.action, actual.action);
185 EXPECT_EQ(expected.username_element, actual.username_element); 190 EXPECT_EQ(expected.username_element, actual.username_element);
186 EXPECT_EQ(expected.username_value, actual.username_value); 191 EXPECT_EQ(expected.username_value, actual.username_value);
187 EXPECT_EQ(expected.password_element, actual.password_element); 192 EXPECT_EQ(expected.password_element, actual.password_element);
188 EXPECT_EQ(expected.submit_element, actual.submit_element); 193 EXPECT_EQ(expected.submit_element, actual.submit_element);
189 EXPECT_EQ(expected.signon_realm, actual.signon_realm); 194 EXPECT_EQ(expected.signon_realm, actual.signon_realm);
190 EXPECT_EQ(expected.ssl_valid, actual.ssl_valid); 195 EXPECT_EQ(expected.ssl_valid, actual.ssl_valid);
191 EXPECT_EQ(expected.preferred, actual.preferred); 196 EXPECT_EQ(expected.preferred, actual.preferred);
192 // We don't check the date created. It varies. 197 // We don't check the date created. It varies.
193 EXPECT_EQ(expected.blacklisted_by_user, actual.blacklisted_by_user); 198 EXPECT_EQ(expected.blacklisted_by_user, actual.blacklisted_by_user);
194 EXPECT_EQ(expected.type, actual.type); 199 EXPECT_EQ(expected.type, actual.type);
195 EXPECT_EQ(expected.times_used, actual.times_used); 200 EXPECT_EQ(expected.times_used, actual.times_used);
196 EXPECT_EQ(expected.scheme, actual.scheme); 201 EXPECT_EQ(expected.scheme, actual.scheme);
197 EXPECT_EQ(expected.date_synced, actual.date_synced); 202 EXPECT_EQ(expected.date_synced, actual.date_synced);
198 } 203 }
199 204
205 // static
200 void NativeBackendKWalletTestBase::CheckPasswordChanges( 206 void NativeBackendKWalletTestBase::CheckPasswordChanges(
201 const PasswordStoreChangeList& expected, 207 const PasswordStoreChangeList& expected,
202 const PasswordStoreChangeList& actual) { 208 const PasswordStoreChangeList& actual) {
203 ASSERT_EQ(expected.size(), actual.size()); 209 ASSERT_EQ(expected.size(), actual.size());
204 for (size_t i = 0; i < expected.size(); ++i) { 210 for (size_t i = 0; i < expected.size(); ++i) {
205 EXPECT_EQ(expected[i].type(), actual[i].type()); 211 EXPECT_EQ(expected[i].type(), actual[i].type());
206 CheckPasswordForm(expected[i].form(), actual[i].form()); 212 CheckPasswordForm(expected[i].form(), actual[i].form());
207 } 213 }
208 } 214 }
209 215
216 // static
217 void NativeBackendKWalletTestBase::CheckPasswordChangesWithResult(
218 const PasswordStoreChangeList* expected,
219 const PasswordStoreChangeList* actual,
220 bool result) {
221 EXPECT_TRUE(result);
222 CheckPasswordChanges(*expected, *actual);
223 }
224
210 class NativeBackendKWalletTest : public NativeBackendKWalletTestBase { 225 class NativeBackendKWalletTest : public NativeBackendKWalletTestBase {
211 protected: 226 protected:
212 NativeBackendKWalletTest() 227 NativeBackendKWalletTest()
213 : ui_thread_(BrowserThread::UI, &message_loop_), 228 : ui_thread_(BrowserThread::UI, &message_loop_),
214 db_thread_(BrowserThread::DB), klauncher_ret_(0), 229 db_thread_(BrowserThread::DB), klauncher_ret_(0),
215 klauncher_contacted_(false), kwallet_runnable_(true), 230 klauncher_contacted_(false), kwallet_runnable_(true),
216 kwallet_running_(true), kwallet_enabled_(true) { 231 kwallet_running_(true), kwallet_enabled_(true) {
217 } 232 }
218 233
219 virtual void SetUp(); 234 virtual void SetUp();
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 800
786 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); 801 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
787 802
788 std::vector<const PasswordForm*> forms; 803 std::vector<const PasswordForm*> forms;
789 forms.push_back(&form_google_); 804 forms.push_back(&form_google_);
790 ExpectationArray expected; 805 ExpectationArray expected;
791 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 806 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
792 CheckPasswordForms("Chrome Form Data (42)", expected); 807 CheckPasswordForms("Chrome Form Data (42)", expected);
793 } 808 }
794 809
810 TEST_F(NativeBackendKWalletTest, RemoveLoginsSyncedBetween) {
811 NativeBackendKWalletStub backend(42);
812 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
813
814 base::Time now = base::Time::Now();
815 base::Time next_day = now + base::TimeDelta::FromDays(1);
816 form_google_.date_synced = now;
817 form_isc_.date_synced = next_day;
818 form_google_.date_created = base::Time();
819 form_isc_.date_created = base::Time();
820
821 BrowserThread::PostTask(
822 BrowserThread::DB, FROM_HERE,
823 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
824 base::Unretained(&backend), form_google_));
825 BrowserThread::PostTask(
826 BrowserThread::DB, FROM_HERE,
827 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
828 base::Unretained(&backend), form_isc_));
829
830 PasswordStoreChangeList expected_changes;
831 expected_changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE,
832 form_google_));
833 PasswordStoreChangeList changes;
834 BrowserThread::PostTaskAndReplyWithResult(
835 BrowserThread::DB, FROM_HERE,
836 base::Bind(&NativeBackendKWalletStub::RemoveLoginsSyncedBetween,
837 base::Unretained(&backend), base::Time(), next_day, &changes),
838 base::Bind(&NativeBackendKWalletTest::CheckPasswordChangesWithResult,
839 &expected_changes, &changes));
840 RunDBThread();
841
842 std::vector<const PasswordForm*> forms;
843 forms.push_back(&form_isc_);
844 ExpectationArray expected;
845 expected.push_back(make_pair(std::string(form_isc_.signon_realm), forms));
846 CheckPasswordForms("Chrome Form Data (42)", expected);
847
848 // Remove form_isc_.
849 expected_changes.clear();
850 expected_changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE,
851 form_isc_));
852 BrowserThread::PostTaskAndReplyWithResult(
853 BrowserThread::DB, FROM_HERE,
854 base::Bind(&NativeBackendKWalletStub::RemoveLoginsSyncedBetween,
855 base::Unretained(&backend), next_day, base::Time(), &changes),
856 base::Bind(&NativeBackendKWalletTest::CheckPasswordChangesWithResult,
857 &expected_changes, &changes));
858 RunDBThread();
859
860 CheckPasswordForms("Chrome Form Data (42)", ExpectationArray());
861 }
862
795 // TODO(mdm): add more basic tests here at some point. 863 // TODO(mdm): add more basic tests here at some point.
796 // (For example tests for storing >1 password per realm pickle.) 864 // (For example tests for storing >1 password per realm pickle.)
797 865
798 class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase { 866 class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase {
799 protected: 867 protected:
800 void CreateVersion2Pickle(const PasswordForm& form, Pickle* pickle); 868 void CreateVersion2Pickle(const PasswordForm& form, Pickle* pickle);
801 void CreateVersion1Pickle(const PasswordForm& form, Pickle* pickle); 869 void CreateVersion1Pickle(const PasswordForm& form, Pickle* pickle);
802 void CreateVersion0Pickle(bool size_32, 870 void CreateVersion0Pickle(bool size_32,
803 const PasswordForm& form, 871 const PasswordForm& form,
804 Pickle* pickle); 872 Pickle* pickle);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 CheckVersion0Pickle(false, PasswordForm::SCHEME_BASIC); 994 CheckVersion0Pickle(false, PasswordForm::SCHEME_BASIC);
927 } 995 }
928 996
929 TEST_F(NativeBackendKWalletPickleTest, CheckVersion1Pickle) { 997 TEST_F(NativeBackendKWalletPickleTest, CheckVersion1Pickle) {
930 CheckVersion1Pickle(); 998 CheckVersion1Pickle();
931 } 999 }
932 1000
933 TEST_F(NativeBackendKWalletPickleTest, CheckVersion2Pickle) { 1001 TEST_F(NativeBackendKWalletPickleTest, CheckVersion2Pickle) {
934 CheckVersion2Pickle(); 1002 CheckVersion2Pickle();
935 } 1003 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698