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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 event->Signal(); | 248 event->Signal(); |
249 } | 249 } |
250 | 250 |
251 // Utilities to help verify sets of expectations. | 251 // Utilities to help verify sets of expectations. |
252 typedef std::vector< | 252 typedef std::vector< |
253 std::pair<std::string, | 253 std::pair<std::string, |
254 std::vector<const PasswordForm*> > > ExpectationArray; | 254 std::vector<const PasswordForm*> > > ExpectationArray; |
255 void CheckPasswordForms(const std::string& folder, | 255 void CheckPasswordForms(const std::string& folder, |
256 const ExpectationArray& sorted_expected); | 256 const ExpectationArray& sorted_expected); |
257 | 257 |
| 258 enum RemoveBetweenMethod { |
| 259 CREATED, |
| 260 SYNCED, |
| 261 }; |
| 262 |
| 263 // Tests RemoveLoginsCreatedBetween or RemoveLoginsSyncedBetween. |
| 264 void TestRemoveLoginsBetween(RemoveBetweenMethod date_to_test); |
| 265 |
258 base::MessageLoopForUI message_loop_; | 266 base::MessageLoopForUI message_loop_; |
259 content::TestBrowserThread ui_thread_; | 267 content::TestBrowserThread ui_thread_; |
260 content::TestBrowserThread db_thread_; | 268 content::TestBrowserThread db_thread_; |
261 | 269 |
262 scoped_refptr<dbus::MockBus> mock_session_bus_; | 270 scoped_refptr<dbus::MockBus> mock_session_bus_; |
263 scoped_refptr<dbus::MockObjectProxy> mock_klauncher_proxy_; | 271 scoped_refptr<dbus::MockObjectProxy> mock_klauncher_proxy_; |
264 scoped_refptr<dbus::MockObjectProxy> mock_kwallet_proxy_; | 272 scoped_refptr<dbus::MockObjectProxy> mock_kwallet_proxy_; |
265 | 273 |
266 int klauncher_ret_; | 274 int klauncher_ret_; |
267 std::string klauncher_error_; | 275 std::string klauncher_error_; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 .WillRepeatedly(Return()); | 325 .WillRepeatedly(Return()); |
318 } | 326 } |
319 | 327 |
320 void NativeBackendKWalletTest::TearDown() { | 328 void NativeBackendKWalletTest::TearDown() { |
321 base::MessageLoop::current()->PostTask(FROM_HERE, | 329 base::MessageLoop::current()->PostTask(FROM_HERE, |
322 base::MessageLoop::QuitClosure()); | 330 base::MessageLoop::QuitClosure()); |
323 base::MessageLoop::current()->Run(); | 331 base::MessageLoop::current()->Run(); |
324 db_thread_.Stop(); | 332 db_thread_.Stop(); |
325 } | 333 } |
326 | 334 |
| 335 void NativeBackendKWalletTest::TestRemoveLoginsBetween( |
| 336 RemoveBetweenMethod date_to_test) { |
| 337 NativeBackendKWalletStub backend(42); |
| 338 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); |
| 339 |
| 340 form_google_.date_synced = base::Time(); |
| 341 form_isc_.date_synced = base::Time(); |
| 342 form_google_.date_created = base::Time(); |
| 343 form_isc_.date_created = base::Time(); |
| 344 base::Time now = base::Time::Now(); |
| 345 base::Time next_day = now + base::TimeDelta::FromDays(1); |
| 346 if (date_to_test == CREATED) { |
| 347 // crbug/374132. Remove the next line once it's fixed. |
| 348 next_day = base::Time::FromTimeT(next_day.ToTimeT()); |
| 349 form_google_.date_created = now; |
| 350 form_isc_.date_created = next_day; |
| 351 } else { |
| 352 form_google_.date_synced = now; |
| 353 form_isc_.date_synced = next_day; |
| 354 } |
| 355 |
| 356 BrowserThread::PostTask( |
| 357 BrowserThread::DB, |
| 358 FROM_HERE, |
| 359 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), |
| 360 base::Unretained(&backend), |
| 361 form_google_)); |
| 362 BrowserThread::PostTask( |
| 363 BrowserThread::DB, |
| 364 FROM_HERE, |
| 365 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), |
| 366 base::Unretained(&backend), |
| 367 form_isc_)); |
| 368 |
| 369 PasswordStoreChangeList expected_changes; |
| 370 expected_changes.push_back( |
| 371 PasswordStoreChange(PasswordStoreChange::REMOVE, form_google_)); |
| 372 PasswordStoreChangeList changes; |
| 373 bool (NativeBackendKWallet::*method)( |
| 374 base::Time, base::Time, password_manager::PasswordStoreChangeList*) = |
| 375 date_to_test == CREATED |
| 376 ? &NativeBackendKWalletStub::RemoveLoginsCreatedBetween |
| 377 : &NativeBackendKWalletStub::RemoveLoginsSyncedBetween; |
| 378 BrowserThread::PostTaskAndReplyWithResult( |
| 379 BrowserThread::DB, |
| 380 FROM_HERE, |
| 381 base::Bind( |
| 382 method, base::Unretained(&backend), base::Time(), next_day, &changes), |
| 383 base::Bind(&NativeBackendKWalletTest::CheckPasswordChangesWithResult, |
| 384 &expected_changes, |
| 385 &changes)); |
| 386 RunDBThread(); |
| 387 |
| 388 std::vector<const PasswordForm*> forms; |
| 389 forms.push_back(&form_isc_); |
| 390 ExpectationArray expected; |
| 391 expected.push_back(make_pair(std::string(form_isc_.signon_realm), forms)); |
| 392 CheckPasswordForms("Chrome Form Data (42)", expected); |
| 393 |
| 394 // Remove form_isc_. |
| 395 expected_changes.clear(); |
| 396 expected_changes.push_back( |
| 397 PasswordStoreChange(PasswordStoreChange::REMOVE, form_isc_)); |
| 398 BrowserThread::PostTaskAndReplyWithResult( |
| 399 BrowserThread::DB, |
| 400 FROM_HERE, |
| 401 base::Bind( |
| 402 method, base::Unretained(&backend), next_day, base::Time(), &changes), |
| 403 base::Bind(&NativeBackendKWalletTest::CheckPasswordChangesWithResult, |
| 404 &expected_changes, |
| 405 &changes)); |
| 406 RunDBThread(); |
| 407 |
| 408 CheckPasswordForms("Chrome Form Data (42)", ExpectationArray()); |
| 409 } |
| 410 |
327 dbus::Response* NativeBackendKWalletTest::KLauncherMethodCall( | 411 dbus::Response* NativeBackendKWalletTest::KLauncherMethodCall( |
328 dbus::MethodCall* method_call, testing::Unused) { | 412 dbus::MethodCall* method_call, testing::Unused) { |
329 EXPECT_EQ("org.kde.KLauncher", method_call->GetInterface()); | 413 EXPECT_EQ("org.kde.KLauncher", method_call->GetInterface()); |
330 EXPECT_EQ("start_service_by_desktop_name", method_call->GetMember()); | 414 EXPECT_EQ("start_service_by_desktop_name", method_call->GetMember()); |
331 | 415 |
332 klauncher_contacted_ = true; | 416 klauncher_contacted_ = true; |
333 | 417 |
334 dbus::MessageReader reader(method_call); | 418 dbus::MessageReader reader(method_call); |
335 std::string service_name; | 419 std::string service_name; |
336 std::vector<std::string> urls; | 420 std::vector<std::string> urls; |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 | 884 |
801 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); | 885 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); |
802 | 886 |
803 std::vector<const PasswordForm*> forms; | 887 std::vector<const PasswordForm*> forms; |
804 forms.push_back(&form_google_); | 888 forms.push_back(&form_google_); |
805 ExpectationArray expected; | 889 ExpectationArray expected; |
806 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | 890 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); |
807 CheckPasswordForms("Chrome Form Data (42)", expected); | 891 CheckPasswordForms("Chrome Form Data (42)", expected); |
808 } | 892 } |
809 | 893 |
| 894 TEST_F(NativeBackendKWalletTest, RemoveLoginsCreatedBetween) { |
| 895 TestRemoveLoginsBetween(CREATED); |
| 896 } |
| 897 |
810 TEST_F(NativeBackendKWalletTest, RemoveLoginsSyncedBetween) { | 898 TEST_F(NativeBackendKWalletTest, RemoveLoginsSyncedBetween) { |
811 NativeBackendKWalletStub backend(42); | 899 TestRemoveLoginsBetween(SYNCED); |
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, | |
823 FROM_HERE, | |
824 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | |
825 base::Unretained(&backend), | |
826 form_google_)); | |
827 BrowserThread::PostTask( | |
828 BrowserThread::DB, | |
829 FROM_HERE, | |
830 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | |
831 base::Unretained(&backend), | |
832 form_isc_)); | |
833 | |
834 PasswordStoreChangeList expected_changes; | |
835 expected_changes.push_back( | |
836 PasswordStoreChange(PasswordStoreChange::REMOVE, form_google_)); | |
837 PasswordStoreChangeList changes; | |
838 BrowserThread::PostTaskAndReplyWithResult( | |
839 BrowserThread::DB, | |
840 FROM_HERE, | |
841 base::Bind(&NativeBackendKWalletStub::RemoveLoginsSyncedBetween, | |
842 base::Unretained(&backend), | |
843 base::Time(), | |
844 next_day, | |
845 &changes), | |
846 base::Bind(&NativeBackendKWalletTest::CheckPasswordChangesWithResult, | |
847 &expected_changes, | |
848 &changes)); | |
849 RunDBThread(); | |
850 | |
851 std::vector<const PasswordForm*> forms; | |
852 forms.push_back(&form_isc_); | |
853 ExpectationArray expected; | |
854 expected.push_back(make_pair(std::string(form_isc_.signon_realm), forms)); | |
855 CheckPasswordForms("Chrome Form Data (42)", expected); | |
856 | |
857 // Remove form_isc_. | |
858 expected_changes.clear(); | |
859 expected_changes.push_back( | |
860 PasswordStoreChange(PasswordStoreChange::REMOVE, form_isc_)); | |
861 BrowserThread::PostTaskAndReplyWithResult( | |
862 BrowserThread::DB, | |
863 FROM_HERE, | |
864 base::Bind(&NativeBackendKWalletStub::RemoveLoginsSyncedBetween, | |
865 base::Unretained(&backend), | |
866 next_day, | |
867 base::Time(), | |
868 &changes), | |
869 base::Bind(&NativeBackendKWalletTest::CheckPasswordChangesWithResult, | |
870 &expected_changes, | |
871 &changes)); | |
872 RunDBThread(); | |
873 | |
874 CheckPasswordForms("Chrome Form Data (42)", ExpectationArray()); | |
875 } | 900 } |
876 | 901 |
877 // TODO(mdm): add more basic tests here at some point. | 902 // TODO(mdm): add more basic tests here at some point. |
878 // (For example tests for storing >1 password per realm pickle.) | 903 // (For example tests for storing >1 password per realm pickle.) |
879 | 904 |
880 class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase { | 905 class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase { |
881 protected: | 906 protected: |
882 void CreateVersion2Pickle(const PasswordForm& form, Pickle* pickle); | 907 void CreateVersion2Pickle(const PasswordForm& form, Pickle* pickle); |
883 void CreateVersion1Pickle(const PasswordForm& form, Pickle* pickle); | 908 void CreateVersion1Pickle(const PasswordForm& form, Pickle* pickle); |
884 void CreateVersion0Pickle(bool size_32, | 909 void CreateVersion0Pickle(bool size_32, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 CheckVersion0Pickle(false, PasswordForm::SCHEME_BASIC); | 1033 CheckVersion0Pickle(false, PasswordForm::SCHEME_BASIC); |
1009 } | 1034 } |
1010 | 1035 |
1011 TEST_F(NativeBackendKWalletPickleTest, CheckVersion1Pickle) { | 1036 TEST_F(NativeBackendKWalletPickleTest, CheckVersion1Pickle) { |
1012 CheckVersion1Pickle(); | 1037 CheckVersion1Pickle(); |
1013 } | 1038 } |
1014 | 1039 |
1015 TEST_F(NativeBackendKWalletPickleTest, CheckVersion2Pickle) { | 1040 TEST_F(NativeBackendKWalletPickleTest, CheckVersion2Pickle) { |
1016 CheckVersion2Pickle(); | 1041 CheckVersion2Pickle(); |
1017 } | 1042 } |
OLD | NEW |