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

Side by Side Diff: chrome/browser/password_manager/native_backend_gnome_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: vabr's comments 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 <stdarg.h> 5 #include <stdarg.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // We don't check the date created. It varies due to bug in the 302 // We don't check the date created. It varies due to bug in the
303 // serialization. Integer seconds are saved instead of microseconds. 303 // serialization. Integer seconds are saved instead of microseconds.
304 EXPECT_EQ(expected.blacklisted_by_user, actual.blacklisted_by_user); 304 EXPECT_EQ(expected.blacklisted_by_user, actual.blacklisted_by_user);
305 EXPECT_EQ(expected.type, actual.type); 305 EXPECT_EQ(expected.type, actual.type);
306 EXPECT_EQ(expected.times_used, actual.times_used); 306 EXPECT_EQ(expected.times_used, actual.times_used);
307 EXPECT_EQ(expected.scheme, actual.scheme); 307 EXPECT_EQ(expected.scheme, actual.scheme);
308 EXPECT_EQ(expected.date_synced, actual.date_synced); 308 EXPECT_EQ(expected.date_synced, actual.date_synced);
309 } 309 }
310 } 310 }
311 311
312 void CheckPasswordChangesWithResult(const PasswordStoreChangeList* expected,
313 const PasswordStoreChangeList* actual,
314 bool result) {
315 EXPECT_TRUE(result);
316 CheckPasswordChanges(*expected, *actual);
317 }
318
312 } // anonymous namespace 319 } // anonymous namespace
313 320
314 class NativeBackendGnomeTest : public testing::Test { 321 class NativeBackendGnomeTest : public testing::Test {
315 protected: 322 protected:
316 enum UpdateType { // Used in CheckPSLUpdate(). 323 enum UpdateType { // Used in CheckPSLUpdate().
317 UPDATE_BY_UPDATELOGIN, 324 UPDATE_BY_UPDATELOGIN,
318 UPDATE_BY_ADDLOGIN, 325 UPDATE_BY_ADDLOGIN,
319 }; 326 };
320 327
321 NativeBackendGnomeTest() 328 NativeBackendGnomeTest()
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 948
942 // Quick check that we got two results back. 949 // Quick check that we got two results back.
943 EXPECT_EQ(2u, form_list.size()); 950 EXPECT_EQ(2u, form_list.size());
944 STLDeleteElements(&form_list); 951 STLDeleteElements(&form_list);
945 952
946 EXPECT_EQ(1u, mock_keyring_items.size()); 953 EXPECT_EQ(1u, mock_keyring_items.size());
947 if (mock_keyring_items.size() > 0) 954 if (mock_keyring_items.size() > 0)
948 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 955 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
949 } 956 }
950 957
958 TEST_F(NativeBackendGnomeTest, RemoveLoginsSyncedBetween) {
959 NativeBackendGnome backend(42);
960 backend.Init();
961
962 base::Time now = base::Time::Now();
963 base::Time next_day = now + base::TimeDelta::FromDays(1);
964 form_google_.date_synced = now;
965 form_isc_.date_synced = next_day;
966 form_google_.date_created = base::Time();
967 form_isc_.date_created = base::Time();
968
969 BrowserThread::PostTask(
970 BrowserThread::DB,
971 FROM_HERE,
972 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
973 base::Unretained(&backend),
974 form_google_));
975 BrowserThread::PostTask(
976 BrowserThread::DB,
977 FROM_HERE,
978 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
979 base::Unretained(&backend),
980 form_isc_));
981
982 PasswordStoreChangeList expected_changes;
983 expected_changes.push_back(
984 PasswordStoreChange(PasswordStoreChange::REMOVE, form_google_));
985 PasswordStoreChangeList changes;
986 BrowserThread::PostTaskAndReplyWithResult(
987 BrowserThread::DB,
988 FROM_HERE,
989 base::Bind(&NativeBackendGnome::RemoveLoginsSyncedBetween,
990 base::Unretained(&backend),
991 base::Time(),
992 next_day,
993 &changes),
994 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
995 RunBothThreads();
996
997 EXPECT_EQ(1u, mock_keyring_items.size());
998 if (mock_keyring_items.size() > 0)
999 CheckMockKeyringItem(&mock_keyring_items[0], form_isc_, "chrome-42");
1000
1001 // Remove form_isc_.
1002 expected_changes.clear();
1003 expected_changes.push_back(
1004 PasswordStoreChange(PasswordStoreChange::REMOVE, form_isc_));
1005 BrowserThread::PostTaskAndReplyWithResult(
1006 BrowserThread::DB,
1007 FROM_HERE,
1008 base::Bind(&NativeBackendGnome::RemoveLoginsSyncedBetween,
1009 base::Unretained(&backend),
1010 next_day,
1011 base::Time(),
1012 &changes),
1013 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
1014 RunBothThreads();
1015
1016 EXPECT_EQ(0u, mock_keyring_items.size());
1017 }
1018
951 // TODO(mdm): add more basic tests here at some point. 1019 // TODO(mdm): add more basic tests here at some point.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698