| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/task.h" | 9 #include "base/task.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 password_store_.get(), | 137 password_store_.get(), |
| 138 data_type_controller)); | 138 data_type_controller)); |
| 139 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 139 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
| 140 WillOnce(MakeDataTypeManager(&backend_)); | 140 WillOnce(MakeDataTypeManager(&backend_)); |
| 141 | 141 |
| 142 EXPECT_CALL(profile_, GetPasswordStore(_)). | 142 EXPECT_CALL(profile_, GetPasswordStore(_)). |
| 143 WillOnce(Return(password_store_.get())); | 143 WillOnce(Return(password_store_.get())); |
| 144 | 144 |
| 145 // State changes once for the backend init and once for startup done. | 145 // State changes once for the backend init and once for startup done. |
| 146 EXPECT_CALL(observer_, OnStateChanged()). | 146 EXPECT_CALL(observer_, OnStateChanged()). |
| 147 WillOnce(Return()). |
| 148 WillOnce(Return()). |
| 149 WillOnce(QuitUIMessageLoop()); |
| 150 |
| 151 service_->RegisterDataTypeController(data_type_controller); |
| 152 service_->Initialize(); |
| 153 MessageLoop::current()->Run(); |
| 154 |
| 155 EXPECT_CALL(observer_, OnStateChanged()). |
| 147 WillOnce(InvokeTask(task)). | 156 WillOnce(InvokeTask(task)). |
| 148 WillOnce(Return()). | 157 WillOnce(Return()). |
| 149 WillOnce(QuitUIMessageLoop()); | 158 WillOnce(QuitUIMessageLoop()); |
| 150 service_->RegisterDataTypeController(data_type_controller); | 159 |
| 151 service_->Initialize(); | 160 service_->SetPassphrase("foo"); |
| 152 MessageLoop::current()->Run(); | 161 MessageLoop::current()->Run(); |
| 153 } | 162 } |
| 154 } | 163 } |
| 155 | 164 |
| 156 void CreatePasswordRoot() { | 165 void CreatePasswordRoot() { |
| 157 UserShare* user_share = service_->backend()->GetUserShareHandle(); | 166 UserShare* user_share = service_->backend()->GetUserShareHandle(); |
| 158 DirectoryManager* dir_manager = user_share->dir_manager.get(); | 167 DirectoryManager* dir_manager = user_share->dir_manager.get(); |
| 159 | 168 |
| 160 ScopedDirLookup dir(dir_manager, user_share->authenticated_name); | 169 ScopedDirLookup dir(dir_manager, user_share->authenticated_name); |
| 161 ASSERT_TRUE(dir.good()); | 170 ASSERT_TRUE(dir.good()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 void GetPasswordEntriesFromSyncDB(std::vector<PasswordForm>* entries) { | 205 void GetPasswordEntriesFromSyncDB(std::vector<PasswordForm>* entries) { |
| 197 sync_api::ReadTransaction trans(service_->backend()->GetUserShareHandle()); | 206 sync_api::ReadTransaction trans(service_->backend()->GetUserShareHandle()); |
| 198 sync_api::ReadNode password_root(&trans); | 207 sync_api::ReadNode password_root(&trans); |
| 199 ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag)); | 208 ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag)); |
| 200 | 209 |
| 201 int64 child_id = password_root.GetFirstChildId(); | 210 int64 child_id = password_root.GetFirstChildId(); |
| 202 while (child_id != sync_api::kInvalidId) { | 211 while (child_id != sync_api::kInvalidId) { |
| 203 sync_api::ReadNode child_node(&trans); | 212 sync_api::ReadNode child_node(&trans); |
| 204 ASSERT_TRUE(child_node.InitByIdLookup(child_id)); | 213 ASSERT_TRUE(child_node.InitByIdLookup(child_id)); |
| 205 | 214 |
| 206 sync_pb::PasswordSpecificsData password; | 215 const sync_pb::PasswordSpecificsData& password = |
| 207 ASSERT_TRUE(child_node.GetPasswordSpecifics(&password)); | 216 child_node.GetPasswordSpecifics(); |
| 208 | 217 |
| 209 PasswordForm form; | 218 PasswordForm form; |
| 210 PasswordModelAssociator::CopyPassword(password, &form); | 219 PasswordModelAssociator::CopyPassword(password, &form); |
| 211 | 220 |
| 212 entries->push_back(form); | 221 entries->push_back(form); |
| 213 | 222 |
| 214 child_id = child_node.GetSuccessorId(); | 223 child_id = child_node.GetSuccessorId(); |
| 215 } | 224 } |
| 216 } | 225 } |
| 217 | 226 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 292 } |
| 284 | 293 |
| 285 private: | 294 private: |
| 286 ProfileSyncServicePasswordTest* test_; | 295 ProfileSyncServicePasswordTest* test_; |
| 287 const std::vector<PasswordForm>& entries_; | 296 const std::vector<PasswordForm>& entries_; |
| 288 }; | 297 }; |
| 289 | 298 |
| 290 TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { | 299 TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { |
| 291 // Backend will be paused but not resumed. | 300 // Backend will be paused but not resumed. |
| 292 EXPECT_CALL(backend_, RequestPause()). | 301 EXPECT_CALL(backend_, RequestPause()). |
| 293 WillOnce(testing::DoAll(Notify(NotificationType::SYNC_PAUSED), | 302 WillRepeatedly(testing::DoAll(Notify(NotificationType::SYNC_PAUSED), |
| 294 testing::Return(true))); | 303 testing::Return(true))); |
| 295 // Don't create the root password node so startup fails. | 304 // Don't create the root password node so startup fails. |
| 296 StartSyncService(NULL); | 305 StartSyncService(NULL); |
| 297 EXPECT_TRUE(service_->unrecoverable_error_detected()); | 306 EXPECT_TRUE(service_->unrecoverable_error_detected()); |
| 298 } | 307 } |
| 299 | 308 |
| 300 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { | 309 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { |
| 301 EXPECT_CALL(*(password_store_.get()), FillAutofillableLogins(_)) | 310 EXPECT_CALL(*(password_store_.get()), FillAutofillableLogins(_)) |
| 302 .WillOnce(Return(true)); | 311 .WillOnce(Return(true)); |
| 303 EXPECT_CALL(*(password_store_.get()), FillBlacklistLogins(_)) | 312 EXPECT_CALL(*(password_store_.get()), FillBlacklistLogins(_)) |
| 304 .WillOnce(Return(true)); | 313 .WillOnce(Return(true)); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 527 |
| 519 EXPECT_CALL(*(password_store_.get()), UpdateLoginImpl(_)).Times(1); | 528 EXPECT_CALL(*(password_store_.get()), UpdateLoginImpl(_)).Times(1); |
| 520 StartSyncService(&task); | 529 StartSyncService(&task); |
| 521 | 530 |
| 522 std::vector<PasswordForm> new_sync_forms; | 531 std::vector<PasswordForm> new_sync_forms; |
| 523 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 532 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
| 524 | 533 |
| 525 EXPECT_EQ(1U, new_sync_forms.size()); | 534 EXPECT_EQ(1U, new_sync_forms.size()); |
| 526 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 535 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
| 527 } | 536 } |
| OLD | NEW |