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 <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 Loading... |
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 Loading... |
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, FROM_HERE, |
| 971 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 972 base::Unretained(&backend), form_google_)); |
| 973 BrowserThread::PostTask( |
| 974 BrowserThread::DB, FROM_HERE, |
| 975 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 976 base::Unretained(&backend), form_isc_)); |
| 977 |
| 978 PasswordStoreChangeList expected_changes; |
| 979 expected_changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, |
| 980 form_google_)); |
| 981 PasswordStoreChangeList changes; |
| 982 BrowserThread::PostTaskAndReplyWithResult( |
| 983 BrowserThread::DB, FROM_HERE, |
| 984 base::Bind(&NativeBackendGnome::RemoveLoginsSyncedBetween, |
| 985 base::Unretained(&backend), base::Time(), next_day, &changes), |
| 986 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes)); |
| 987 RunBothThreads(); |
| 988 |
| 989 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 990 if (mock_keyring_items.size() > 0) |
| 991 CheckMockKeyringItem(&mock_keyring_items[0], form_isc_, "chrome-42"); |
| 992 |
| 993 // Remove form_isc_. |
| 994 expected_changes.clear(); |
| 995 expected_changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, |
| 996 form_isc_)); |
| 997 BrowserThread::PostTaskAndReplyWithResult( |
| 998 BrowserThread::DB, FROM_HERE, |
| 999 base::Bind(&NativeBackendGnome::RemoveLoginsSyncedBetween, |
| 1000 base::Unretained(&backend), next_day, base::Time(), &changes), |
| 1001 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes)); |
| 1002 RunBothThreads(); |
| 1003 |
| 1004 EXPECT_EQ(0u, mock_keyring_items.size()); |
| 1005 } |
| 1006 |
951 // TODO(mdm): add more basic tests here at some point. | 1007 // TODO(mdm): add more basic tests here at some point. |
OLD | NEW |