| 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 <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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/password_manager/mock_password_store.h" |
| 15 #include "chrome/browser/password_manager/password_store.h" | 16 #include "chrome/browser/password_manager/password_store.h" |
| 17 #include "chrome/browser/password_manager/password_store_factory.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/signin/signin_manager.h" | 19 #include "chrome/browser/signin/signin_manager.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 20 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/browser/signin/token_service_factory.h" | 21 #include "chrome/browser/signin/token_service_factory.h" |
| 20 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | 22 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
| 21 #include "chrome/browser/sync/glue/password_change_processor.h" | 23 #include "chrome/browser/sync/glue/password_change_processor.h" |
| 22 #include "chrome/browser/sync/glue/password_data_type_controller.h" | 24 #include "chrome/browser/sync/glue/password_data_type_controller.h" |
| 23 #include "chrome/browser/sync/glue/password_model_associator.h" | 25 #include "chrome/browser/sync/glue/password_model_associator.h" |
| 24 #include "chrome/browser/sync/internal_api/read_node.h" | 26 #include "chrome/browser/sync/internal_api/read_node.h" |
| 25 #include "chrome/browser/sync/internal_api/read_transaction.h" | 27 #include "chrome/browser/sync/internal_api/read_transaction.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // is already held by this thread, deadlock if held by another thread). | 95 // is already held by this thread, deadlock if held by another thread). |
| 94 sync_api::WriteTransaction trans( | 96 sync_api::WriteTransaction trans( |
| 95 FROM_HERE, password_test_service->GetUserShare()); | 97 FROM_HERE, password_test_service->GetUserShare()); |
| 96 DVLOG(1) << "Sync transaction acquired."; | 98 DVLOG(1) << "Sync transaction acquired."; |
| 97 } | 99 } |
| 98 | 100 |
| 99 static void QuitMessageLoop() { | 101 static void QuitMessageLoop() { |
| 100 MessageLoop::current()->Quit(); | 102 MessageLoop::current()->Quit(); |
| 101 } | 103 } |
| 102 | 104 |
| 103 class MockPasswordStore : public PasswordStore { | |
| 104 public: | |
| 105 MOCK_METHOD1(RemoveLogin, void(const PasswordForm&)); | |
| 106 MOCK_METHOD2(GetLogins, int(const PasswordForm&, PasswordStoreConsumer*)); | |
| 107 MOCK_METHOD1(AddLogin, void(const PasswordForm&)); | |
| 108 MOCK_METHOD1(UpdateLogin, void(const PasswordForm&)); | |
| 109 MOCK_METHOD0(ReportMetrics, void()); | |
| 110 MOCK_METHOD0(ReportMetricsImpl, void()); | |
| 111 MOCK_METHOD1(AddLoginImpl, void(const PasswordForm&)); | |
| 112 MOCK_METHOD1(UpdateLoginImpl, void(const PasswordForm&)); | |
| 113 MOCK_METHOD1(RemoveLoginImpl, void(const PasswordForm&)); | |
| 114 MOCK_METHOD2(RemoveLoginsCreatedBetweenImpl, void(const base::Time&, | |
| 115 const base::Time&)); | |
| 116 MOCK_METHOD2(GetLoginsImpl, void(GetLoginsRequest*, const PasswordForm&)); | |
| 117 MOCK_METHOD1(GetAutofillableLoginsImpl, void(GetLoginsRequest*)); | |
| 118 MOCK_METHOD1(GetBlacklistLoginsImpl, void(GetLoginsRequest*)); | |
| 119 MOCK_METHOD1(FillAutofillableLogins, | |
| 120 bool(std::vector<PasswordForm*>*)); | |
| 121 MOCK_METHOD1(FillBlacklistLogins, | |
| 122 bool(std::vector<PasswordForm*>*)); | |
| 123 }; | |
| 124 | |
| 125 class PasswordTestProfileSyncService : public TestProfileSyncService { | 105 class PasswordTestProfileSyncService : public TestProfileSyncService { |
| 126 public: | 106 public: |
| 127 PasswordTestProfileSyncService( | 107 PasswordTestProfileSyncService( |
| 128 ProfileSyncComponentsFactory* factory, | 108 ProfileSyncComponentsFactory* factory, |
| 129 Profile* profile, | 109 Profile* profile, |
| 130 SigninManager* signin, | 110 SigninManager* signin, |
| 131 bool synchronous_backend_initialization, | 111 bool synchronous_backend_initialization, |
| 132 const base::Closure& initial_condition_setup_cb, | 112 const base::Closure& initial_condition_setup_cb, |
| 133 const base::Closure& passphrase_accept_cb) | 113 const base::Closure& passphrase_accept_cb) |
| 134 : TestProfileSyncService(factory, | 114 : TestProfileSyncService(factory, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 tag)); | 150 tag)); |
| 171 PasswordModelAssociator::WriteToSyncNode(entry, &node); | 151 PasswordModelAssociator::WriteToSyncNode(entry, &node); |
| 172 } | 152 } |
| 173 | 153 |
| 174 protected: | 154 protected: |
| 175 ProfileSyncServicePasswordTest() {} | 155 ProfileSyncServicePasswordTest() {} |
| 176 | 156 |
| 177 virtual void SetUp() { | 157 virtual void SetUp() { |
| 178 AbstractProfileSyncServiceTest::SetUp(); | 158 AbstractProfileSyncServiceTest::SetUp(); |
| 179 profile_.CreateRequestContext(); | 159 profile_.CreateRequestContext(); |
| 180 password_store_ = new MockPasswordStore(); | 160 password_store_ = static_cast<MockPasswordStore*>( |
| 161 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( |
| 162 &profile_, MockPasswordStore::Build)); |
| 181 | 163 |
| 182 registrar_.Add(&observer_, | 164 registrar_.Add(&observer_, |
| 183 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, | 165 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
| 184 content::NotificationService::AllSources()); | 166 content::NotificationService::AllSources()); |
| 185 registrar_.Add(&observer_, | 167 registrar_.Add(&observer_, |
| 186 chrome::NOTIFICATION_SYNC_CONFIGURE_BLOCKED, | 168 chrome::NOTIFICATION_SYNC_CONFIGURE_BLOCKED, |
| 187 content::NotificationService::AllSources()); | 169 content::NotificationService::AllSources()); |
| 188 } | 170 } |
| 189 | 171 |
| 190 virtual void TearDown() { | 172 virtual void TearDown() { |
| 191 password_store_->Shutdown(); | 173 password_store_->ShutdownOnUIThread(); |
| 192 service_.reset(); | 174 service_.reset(); |
| 193 profile_.ResetRequestContext(); | 175 profile_.ResetRequestContext(); |
| 194 AbstractProfileSyncServiceTest::TearDown(); | 176 AbstractProfileSyncServiceTest::TearDown(); |
| 195 } | 177 } |
| 196 | 178 |
| 197 static void SignalEvent(base::WaitableEvent* done) { | 179 static void SignalEvent(base::WaitableEvent* done) { |
| 198 done->Signal(); | 180 done->Signal(); |
| 199 } | 181 } |
| 200 | 182 |
| 201 void FlushLastDBTask() { | 183 void FlushLastDBTask() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 WillRepeatedly(MakePasswordSyncComponents(service_.get(), | 216 WillRepeatedly(MakePasswordSyncComponents(service_.get(), |
| 235 password_store_.get(), | 217 password_store_.get(), |
| 236 data_type_controller)); | 218 data_type_controller)); |
| 237 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)). | 219 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)). |
| 238 WillOnce(ReturnNewDataTypeManager()); | 220 WillOnce(ReturnNewDataTypeManager()); |
| 239 | 221 |
| 240 // We need tokens to get the tests going | 222 // We need tokens to get the tests going |
| 241 token_service_->IssueAuthTokenForTest( | 223 token_service_->IssueAuthTokenForTest( |
| 242 GaiaConstants::kSyncService, "token"); | 224 GaiaConstants::kSyncService, "token"); |
| 243 | 225 |
| 244 EXPECT_CALL(profile_, GetPasswordStore(_)). | |
| 245 Times(AtLeast(2)). // Can be more if we hit NEEDS_CRYPTO. | |
| 246 WillRepeatedly(Return(password_store_.get())); | |
| 247 | |
| 248 EXPECT_CALL(observer_, | 226 EXPECT_CALL(observer_, |
| 249 Observe( | 227 Observe( |
| 250 int(chrome::NOTIFICATION_SYNC_CONFIGURE_DONE),_,_)); | 228 int(chrome::NOTIFICATION_SYNC_CONFIGURE_DONE),_,_)); |
| 251 EXPECT_CALL(observer_, | 229 EXPECT_CALL(observer_, |
| 252 Observe( | 230 Observe( |
| 253 int( | 231 int( |
| 254 chrome::NOTIFICATION_SYNC_CONFIGURE_BLOCKED),_,_)) | 232 chrome::NOTIFICATION_SYNC_CONFIGURE_BLOCKED),_,_)) |
| 255 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 233 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
| 256 | 234 |
| 257 service_->RegisterDataTypeController(data_type_controller); | 235 service_->RegisterDataTypeController(data_type_controller); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 CreateRootHelper create_root(this, syncable::PASSWORDS); | 588 CreateRootHelper create_root(this, syncable::PASSWORDS); |
| 611 StartSyncService(create_root.callback(), | 589 StartSyncService(create_root.callback(), |
| 612 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); | 590 base::Bind(&AddPasswordEntriesCallback, this, sync_forms)); |
| 613 | 591 |
| 614 std::vector<PasswordForm> new_sync_forms; | 592 std::vector<PasswordForm> new_sync_forms; |
| 615 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 593 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
| 616 | 594 |
| 617 EXPECT_EQ(1U, new_sync_forms.size()); | 595 EXPECT_EQ(1U, new_sync_forms.size()); |
| 618 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 596 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
| 619 } | 597 } |
| OLD | NEW |