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

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

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

Powered by Google App Engine
This is Rietveld 408576698