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 "testing/gmock/include/gmock/gmock.h" | 5 #include "testing/gmock/include/gmock/gmock.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 MOCK_METHOD1(OnGetPasswordStoreResults, | 36 MOCK_METHOD1(OnGetPasswordStoreResults, |
37 void(const std::vector<content::PasswordForm*>&)); | 37 void(const std::vector<content::PasswordForm*>&)); |
38 }; | 38 }; |
39 | 39 |
40 ACTION(STLDeleteElements0) { | 40 ACTION(STLDeleteElements0) { |
41 STLDeleteContainerPointers(arg0.begin(), arg0.end()); | 41 STLDeleteContainerPointers(arg0.begin(), arg0.end()); |
42 } | 42 } |
43 | 43 |
44 ACTION(QuitUIMessageLoop) { | 44 ACTION(QuitUIMessageLoop) { |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
46 MessageLoop::current()->Quit(); | 46 base::MessageLoop::current()->Quit(); |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 #pragma mark - | 51 #pragma mark - |
52 | 52 |
53 class PasswordStoreMacInternalsTest : public testing::Test { | 53 class PasswordStoreMacInternalsTest : public testing::Test { |
54 public: | 54 public: |
55 virtual void SetUp() { | 55 virtual void SetUp() { |
56 MockAppleKeychain::KeychainTestData test_data[] = { | 56 MockAppleKeychain::KeychainTestData test_data[] = { |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 ASSERT_TRUE(login_db_->Init(db_file)); | 910 ASSERT_TRUE(login_db_->Init(db_file)); |
911 | 911 |
912 keychain_ = new MockAppleKeychain(); | 912 keychain_ = new MockAppleKeychain(); |
913 | 913 |
914 store_ = new PasswordStoreMac(keychain_, login_db_); | 914 store_ = new PasswordStoreMac(keychain_, login_db_); |
915 ASSERT_TRUE(store_->Init()); | 915 ASSERT_TRUE(store_->Init()); |
916 } | 916 } |
917 | 917 |
918 virtual void TearDown() { | 918 virtual void TearDown() { |
919 store_->ShutdownOnUIThread(); | 919 store_->ShutdownOnUIThread(); |
920 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 920 base::MessageLoop::current()->PostTask(FROM_HERE, |
921 MessageLoop::current()->Run(); | 921 base::MessageLoop::QuitClosure()); |
| 922 base::MessageLoop::current()->Run(); |
922 } | 923 } |
923 | 924 |
924 protected: | 925 protected: |
925 MessageLoopForUI message_loop_; | 926 base::MessageLoopForUI message_loop_; |
926 content::TestBrowserThread ui_thread_; | 927 content::TestBrowserThread ui_thread_; |
927 | 928 |
928 MockAppleKeychain* keychain_; // Owned by store_. | 929 MockAppleKeychain* keychain_; // Owned by store_. |
929 LoginDatabase* login_db_; // Owned by store_. | 930 LoginDatabase* login_db_; // Owned by store_. |
930 scoped_refptr<PasswordStoreMac> store_; | 931 scoped_refptr<PasswordStoreMac> store_; |
931 base::ScopedTempDir db_dir_; | 932 base::ScopedTempDir db_dir_; |
932 }; | 933 }; |
933 | 934 |
934 TEST_F(PasswordStoreMacTest, TestStoreUpdate) { | 935 TEST_F(PasswordStoreMacTest, TestStoreUpdate) { |
935 // Insert a password into both the database and the keychain. | 936 // Insert a password into both the database and the keychain. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 store_->UpdateLogin(*form); | 997 store_->UpdateLogin(*form); |
997 } | 998 } |
998 | 999 |
999 // Do a store-level query to wait for all the operations above to be done. | 1000 // Do a store-level query to wait for all the operations above to be done. |
1000 MockPasswordStoreConsumer consumer; | 1001 MockPasswordStoreConsumer consumer; |
1001 ON_CALL(consumer, OnGetPasswordStoreResults(_)).WillByDefault( | 1002 ON_CALL(consumer, OnGetPasswordStoreResults(_)).WillByDefault( |
1002 QuitUIMessageLoop()); | 1003 QuitUIMessageLoop()); |
1003 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_)).WillOnce( | 1004 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_)).WillOnce( |
1004 DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | 1005 DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); |
1005 store_->GetLogins(*joint_form, &consumer); | 1006 store_->GetLogins(*joint_form, &consumer); |
1006 MessageLoop::current()->Run(); | 1007 base::MessageLoop::current()->Run(); |
1007 | 1008 |
1008 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); | 1009 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); |
1009 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(updates); ++i) { | 1010 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(updates); ++i) { |
1010 scoped_ptr<PasswordForm> query_form( | 1011 scoped_ptr<PasswordForm> query_form( |
1011 CreatePasswordFormFromData(updates[i].form_data)); | 1012 CreatePasswordFormFromData(updates[i].form_data)); |
1012 | 1013 |
1013 std::vector<PasswordForm*> matching_items = | 1014 std::vector<PasswordForm*> matching_items = |
1014 keychain_adapter.PasswordsFillingForm(*query_form); | 1015 keychain_adapter.PasswordsFillingForm(*query_form); |
1015 if (updates[i].password) { | 1016 if (updates[i].password) { |
1016 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; | 1017 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; |
1017 if (matching_items.size() >= 1) | 1018 if (matching_items.size() >= 1) |
1018 EXPECT_EQ(ASCIIToUTF16(updates[i].password), | 1019 EXPECT_EQ(ASCIIToUTF16(updates[i].password), |
1019 matching_items[0]->password_value) << "iteration " << i; | 1020 matching_items[0]->password_value) << "iteration " << i; |
1020 } else { | 1021 } else { |
1021 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; | 1022 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; |
1022 } | 1023 } |
1023 STLDeleteElements(&matching_items); | 1024 STLDeleteElements(&matching_items); |
1024 | 1025 |
1025 login_db_->GetLogins(*query_form, &matching_items); | 1026 login_db_->GetLogins(*query_form, &matching_items); |
1026 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) | 1027 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) |
1027 << "iteration " << i; | 1028 << "iteration " << i; |
1028 STLDeleteElements(&matching_items); | 1029 STLDeleteElements(&matching_items); |
1029 } | 1030 } |
1030 } | 1031 } |
OLD | NEW |