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

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

Issue 360343002: PasswordStoreMac::RemoveLoginsCreatedBetween() shouldn't affect other profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
« no previous file with comments | « chrome/browser/password_manager/password_store_mac.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory/scoped_vector.h"
10 #include "base/path_service.h" 11 #include "base/path_service.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/password_manager/password_store_mac.h" 15 #include "chrome/browser/password_manager/password_store_mac.h"
15 #include "chrome/browser/password_manager/password_store_mac_internal.h" 16 #include "chrome/browser/password_manager/password_store_mac_internal.h"
16 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
17 #include "components/password_manager/core/browser/password_store_consumer.h" 18 #include "components/password_manager/core/browser/password_store_consumer.h"
18 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
19 #include "crypto/mock_apple_keychain.h" 20 #include "crypto/mock_apple_keychain.h"
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 keychain_, 1073 keychain_,
1073 login_db_); 1074 login_db_);
1074 ASSERT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); 1075 ASSERT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare()));
1075 } 1076 }
1076 1077
1077 virtual void TearDown() { 1078 virtual void TearDown() {
1078 store_->Shutdown(); 1079 store_->Shutdown();
1079 EXPECT_FALSE(store_->GetBackgroundTaskRunner()); 1080 EXPECT_FALSE(store_->GetBackgroundTaskRunner());
1080 } 1081 }
1081 1082
1082 void WaitForStoreUpdate() { 1083 void WaitForStoreUpdate(scoped_refptr<TestPasswordStoreMac> store) {
vabr (Chromium) 2014/07/02 07:41:49 It looks like you always call this with |store_|,
vasilii 2014/07/02 12:34:03 Done.
1083 // Do a store-level query to wait for all the operations above to be done. 1084 // Do a store-level query to wait for all the operations above to be done.
1084 MockPasswordStoreConsumer consumer; 1085 MockPasswordStoreConsumer consumer;
1085 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_)) 1086 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_))
1086 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); 1087 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop()));
1087 store_->GetLogins(PasswordForm(), PasswordStore::ALLOW_PROMPT, &consumer); 1088 store->GetLogins(PasswordForm(), PasswordStore::ALLOW_PROMPT, &consumer);
1088 base::MessageLoop::current()->Run(); 1089 base::MessageLoop::current()->Run();
1089 } 1090 }
1090 1091
1092 void WaitForStoreUpdate() {
1093 return WaitForStoreUpdate(store_);
1094 }
1095
1091 protected: 1096 protected:
1092 base::MessageLoopForUI message_loop_; 1097 base::MessageLoopForUI message_loop_;
1093 content::TestBrowserThread ui_thread_; 1098 content::TestBrowserThread ui_thread_;
1094 1099
1095 MockAppleKeychain* keychain_; // Owned by store_. 1100 MockAppleKeychain* keychain_; // Owned by store_.
1096 LoginDatabase* login_db_; // Owned by store_. 1101 LoginDatabase* login_db_; // Owned by store_.
1097 scoped_refptr<TestPasswordStoreMac> store_; 1102 scoped_refptr<TestPasswordStoreMac> store_;
1098 base::ScopedTempDir db_dir_; 1103 base::ScopedTempDir db_dir_;
1099 }; 1104 };
1100 1105
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 EXPECT_EQ(0u, matching_items.size()); 1252 EXPECT_EQ(0u, matching_items.size());
1248 login_db_->GetLogins(*www_form, &matching_items); 1253 login_db_->GetLogins(*www_form, &matching_items);
1249 EXPECT_EQ(0u, matching_items.size()); 1254 EXPECT_EQ(0u, matching_items.size());
1250 // No trace of m.facebook.com. 1255 // No trace of m.facebook.com.
1251 matching_items = owned_keychain_adapter.PasswordsFillingForm( 1256 matching_items = owned_keychain_adapter.PasswordsFillingForm(
1252 m_form.signon_realm, m_form.scheme); 1257 m_form.signon_realm, m_form.scheme);
1253 EXPECT_EQ(0u, matching_items.size()); 1258 EXPECT_EQ(0u, matching_items.size());
1254 login_db_->GetLogins(m_form, &matching_items); 1259 login_db_->GetLogins(m_form, &matching_items);
1255 EXPECT_EQ(0u, matching_items.size()); 1260 EXPECT_EQ(0u, matching_items.size());
1256 } 1261 }
1262
1263 TEST_F(PasswordStoreMacTest, TestRemoveLoginsCreatedBetween) {
1264 // Make sure that RemoveLoginsCreatedBetween does affect only the correct
1265 // profile.
1266
1267 // Add a third-party password.
1268 MockAppleKeychain::KeychainTestData joint_keychain_data = {
1269 kSecAuthenticationTypeHTMLForm, "some.domain.com",
1270 kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "20020601171500Z",
1271 "joe_user", "sekrit", false };
1272 keychain_->AddTestItem(joint_keychain_data);
1273
1274 // Add a password from another profile.
1275 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_);
1276 owned_keychain_adapter.SetFindsOnlyOwnedItems(true);
1277 PasswordFormData www_form_data1 = {
1278 PasswordForm::SCHEME_HTML, "http://www.facebook.com/",
1279 "http://www.facebook.com/index.html", "login", L"username", L"password",
1280 L"submit", L"joe_user", L"sekrit", true, false, 1 };
1281 scoped_ptr<PasswordForm> www_form(CreatePasswordFormFromData(www_form_data1));
1282 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*www_form));
1283
1284 // Add a password from the current profile.
1285 PasswordFormData www_form_data2 = {
1286 PasswordForm::SCHEME_HTML, "http://www.facebook.com/",
1287 "http://www.facebook.com/index.html", "login", L"username", L"password",
1288 L"submit", L"not_joe_user", L"12345", true, false, 1 };
1289 www_form.reset(CreatePasswordFormFromData(www_form_data2));
1290 store_->AddLogin(*www_form);
1291 WaitForStoreUpdate();
1292
1293 ScopedVector<PasswordForm> matching_items;
1294 login_db_->GetLogins(*www_form, &matching_items.get());
1295 EXPECT_EQ(1u, matching_items.size());
1296 matching_items.clear();
1297
1298 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time());
1299 WaitForStoreUpdate();
1300
1301 // Check the second facebook form is gone.
1302 login_db_->GetLogins(*www_form, &matching_items.get());
1303 EXPECT_EQ(0u, matching_items.size());
1304
1305 // Check the first facebook form is still there.
1306 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm(
1307 www_form->signon_realm, www_form->scheme);
1308 ASSERT_EQ(1u, matching_items.size());
1309 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value);
1310 matching_items.clear();
1311
1312 // Check the third-party password is still there.
1313 owned_keychain_adapter.SetFindsOnlyOwnedItems(false);
1314 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm(
1315 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML);
1316 ASSERT_EQ(1u, matching_items.size());
1317 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698