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

Side by Side Diff: chrome/browser/sync/profile_sync_service_password_unittest.cc

Issue 6878038: [Sync] Ensure we don't hold a transaction when we access password store. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rearrange Created 9 years, 8 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/sync/glue/password_model_associator.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <vector> 5 #include <vector>
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/task.h" 10 #include "base/task.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 ACTION_P3(MakePasswordSyncComponents, service, ps, dtc) { 76 ACTION_P3(MakePasswordSyncComponents, service, ps, dtc) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
78 PasswordModelAssociator* model_associator = 78 PasswordModelAssociator* model_associator =
79 new PasswordModelAssociator(service, ps); 79 new PasswordModelAssociator(service, ps);
80 PasswordChangeProcessor* change_processor = 80 PasswordChangeProcessor* change_processor =
81 new PasswordChangeProcessor(model_associator, ps, dtc); 81 new PasswordChangeProcessor(model_associator, ps, dtc);
82 return ProfileSyncFactory::SyncComponents(model_associator, 82 return ProfileSyncFactory::SyncComponents(model_associator,
83 change_processor); 83 change_processor);
84 } 84 }
85 85
86 ACTION_P(AcquireSyncTransaction, password_test_service) {
87 // Check to make sure we can aquire a transaction (will crash if a transaction
88 // is already held by this thread, deadlock if held by another thread).
89 sync_api::WriteTransaction trans(password_test_service->GetUserShare());
90 VLOG(1) << "Sync transaction acquired.";
91 }
92
86 static void QuitMessageLoop() { 93 static void QuitMessageLoop() {
87 MessageLoop::current()->Quit(); 94 MessageLoop::current()->Quit();
88 } 95 }
89 96
90 class MockPasswordStore : public PasswordStore { 97 class MockPasswordStore : public PasswordStore {
91 public: 98 public:
92 MOCK_METHOD1(RemoveLogin, void(const PasswordForm&)); 99 MOCK_METHOD1(RemoveLogin, void(const PasswordForm&));
93 MOCK_METHOD2(GetLogins, int(const PasswordForm&, PasswordStoreConsumer*)); 100 MOCK_METHOD2(GetLogins, int(const PasswordForm&, PasswordStoreConsumer*));
94 MOCK_METHOD1(AddLogin, void(const PasswordForm&)); 101 MOCK_METHOD1(AddLogin, void(const PasswordForm&));
95 MOCK_METHOD1(UpdateLogin, void(const PasswordForm&)); 102 MOCK_METHOD1(UpdateLogin, void(const PasswordForm&));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 137 }
131 138
132 TestProfileSyncService::OnPassphraseAccepted(); 139 TestProfileSyncService::OnPassphraseAccepted();
133 } 140 }
134 141
135 private: 142 private:
136 Task* passphrase_accept_task_; 143 Task* passphrase_accept_task_;
137 }; 144 };
138 145
139 class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { 146 class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest {
147 public:
148 sync_api::UserShare* GetUserShare() {
149 return service_->GetUserShare();
150 }
140 protected: 151 protected:
141 ProfileSyncServicePasswordTest() 152 ProfileSyncServicePasswordTest()
142 : db_thread_(BrowserThread::DB) { 153 : db_thread_(BrowserThread::DB) {
143 } 154 }
144 155
145 virtual void SetUp() { 156 virtual void SetUp() {
146 profile_.CreateRequestContext(); 157 profile_.CreateRequestContext();
147 password_store_ = new MockPasswordStore(); 158 password_store_ = new MockPasswordStore();
148 db_thread_.Start(); 159 db_thread_.Start();
149 160
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 StartSyncService(&root_task, &node_task); 481 StartSyncService(&root_task, &node_task);
471 482
472 std::vector<PasswordForm> new_sync_forms; 483 std::vector<PasswordForm> new_sync_forms;
473 GetPasswordEntriesFromSyncDB(&new_sync_forms); 484 GetPasswordEntriesFromSyncDB(&new_sync_forms);
474 485
475 EXPECT_EQ(2U, new_sync_forms.size()); 486 EXPECT_EQ(2U, new_sync_forms.size());
476 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); 487 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0]));
477 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1])); 488 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1]));
478 } 489 }
479 490
491 // Same as HasNativeHasEmptyNoMerge, but we attempt to aquire a sync transaction
492 // every time the password store is accessed.
493 TEST_F(ProfileSyncServicePasswordTest, EnsureNoTransactions) {
494 std::vector<PasswordForm*> native_forms;
495 std::vector<PasswordForm> sync_forms;
496 std::vector<PasswordForm> expected_forms;
497 {
498 PasswordForm* new_form = new PasswordForm;
499 new_form->scheme = PasswordForm::SCHEME_HTML;
500 new_form->signon_realm = "pie";
501 new_form->origin = GURL("http://pie.com");
502 new_form->action = GURL("http://pie.com/submit");
503 new_form->username_element = UTF8ToUTF16("name");
504 new_form->username_value = UTF8ToUTF16("tom");
505 new_form->password_element = UTF8ToUTF16("cork");
506 new_form->password_value = UTF8ToUTF16("password1");
507 new_form->ssl_valid = true;
508 new_form->preferred = false;
509 new_form->date_created = base::Time::FromInternalValue(1234);
510 new_form->blacklisted_by_user = false;
511
512 native_forms.push_back(new_form);
513 expected_forms.push_back(*new_form);
514 }
515
516 {
517 PasswordForm new_form;
518 new_form.scheme = PasswordForm::SCHEME_HTML;
519 new_form.signon_realm = "pie2";
520 new_form.origin = GURL("http://pie2.com");
521 new_form.action = GURL("http://pie2.com/submit");
522 new_form.username_element = UTF8ToUTF16("name2");
523 new_form.username_value = UTF8ToUTF16("tom2");
524 new_form.password_element = UTF8ToUTF16("cork2");
525 new_form.password_value = UTF8ToUTF16("password12");
526 new_form.ssl_valid = false;
527 new_form.preferred = true;
528 new_form.date_created = base::Time::FromInternalValue(12345);
529 new_form.blacklisted_by_user = false;
530 sync_forms.push_back(new_form);
531 expected_forms.push_back(new_form);
532 }
533
534 EXPECT_CALL(*password_store_, FillAutofillableLogins(_))
535 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms),
536 AcquireSyncTransaction(this),
537 Return(true)));
538 EXPECT_CALL(*password_store_, FillBlacklistLogins(_))
539 .WillOnce(DoAll(AcquireSyncTransaction(this),
540 Return(true)));
541 EXPECT_CALL(*password_store_, AddLoginImpl(_))
542 .WillOnce(AcquireSyncTransaction(this));
543
544 CreateRootTask root_task(this, syncable::PASSWORDS);
545 AddPasswordEntriesTask node_task(this, sync_forms);
546 StartSyncService(&root_task, &node_task);
547
548 std::vector<PasswordForm> new_sync_forms;
549 GetPasswordEntriesFromSyncDB(&new_sync_forms);
550
551 EXPECT_EQ(2U, new_sync_forms.size());
552 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0]));
553 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1]));
554 }
555
480 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncMergeEntry) { 556 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncMergeEntry) {
481 std::vector<PasswordForm*> native_forms; 557 std::vector<PasswordForm*> native_forms;
482 std::vector<PasswordForm> sync_forms; 558 std::vector<PasswordForm> sync_forms;
483 std::vector<PasswordForm> expected_forms; 559 std::vector<PasswordForm> expected_forms;
484 { 560 {
485 PasswordForm* new_form = new PasswordForm; 561 PasswordForm* new_form = new PasswordForm;
486 new_form->scheme = PasswordForm::SCHEME_HTML; 562 new_form->scheme = PasswordForm::SCHEME_HTML;
487 new_form->signon_realm = "pie"; 563 new_form->signon_realm = "pie";
488 new_form->origin = GURL("http://pie.com"); 564 new_form->origin = GURL("http://pie.com");
489 new_form->action = GURL("http://pie.com/submit"); 565 new_form->action = GURL("http://pie.com/submit");
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 AddPasswordEntriesTask node_task(this, sync_forms); 618 AddPasswordEntriesTask node_task(this, sync_forms);
543 619
544 StartSyncService(&root_task, &node_task); 620 StartSyncService(&root_task, &node_task);
545 621
546 std::vector<PasswordForm> new_sync_forms; 622 std::vector<PasswordForm> new_sync_forms;
547 GetPasswordEntriesFromSyncDB(&new_sync_forms); 623 GetPasswordEntriesFromSyncDB(&new_sync_forms);
548 624
549 EXPECT_EQ(1U, new_sync_forms.size()); 625 EXPECT_EQ(1U, new_sync_forms.size());
550 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); 626 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0]));
551 } 627 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/password_model_associator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698