| 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" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/password_manager/password_store.h" | 12 #include "chrome/browser/password_manager/password_store.h" |
| 13 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | 13 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
| 14 #include "chrome/browser/sync/engine/syncapi.h" | 14 #include "chrome/browser/sync/engine/syncapi.h" |
| 15 #include "chrome/browser/sync/glue/password_change_processor.h" | 15 #include "chrome/browser/sync/glue/password_change_processor.h" |
| 16 #include "chrome/browser/sync/glue/password_data_type_controller.h" | 16 #include "chrome/browser/sync/glue/password_data_type_controller.h" |
| 17 #include "chrome/browser/sync/glue/password_model_associator.h" | 17 #include "chrome/browser/sync/glue/password_model_associator.h" |
| 18 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" | 18 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" |
| 19 #include "chrome/browser/sync/profile_sync_factory.h" | 19 #include "chrome/browser/sync/profile_sync_factory.h" |
| 20 #include "chrome/browser/sync/profile_sync_factory_mock.h" | 20 #include "chrome/browser/sync/profile_sync_factory_mock.h" |
| 21 #include "chrome/browser/sync/profile_sync_service.h" | 21 #include "chrome/browser/sync/profile_sync_service.h" |
| 22 #include "chrome/browser/sync/profile_sync_test_util.h" | 22 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 23 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 23 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 24 #include "chrome/browser/sync/syncable/directory_manager.h" | 24 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 25 #include "chrome/browser/sync/syncable/syncable.h" | 25 #include "chrome/browser/sync/syncable/syncable.h" |
| 26 #include "chrome/browser/sync/test_profile_sync_service.h" | 26 #include "chrome/browser/sync/test_profile_sync_service.h" |
| 27 #include "chrome/common/net/gaia/gaia_constants.h" |
| 27 #include "chrome/common/notification_observer_mock.h" | 28 #include "chrome/common/notification_observer_mock.h" |
| 28 #include "chrome/common/notification_source.h" | 29 #include "chrome/common/notification_source.h" |
| 29 #include "chrome/common/notification_type.h" | 30 #include "chrome/common/notification_type.h" |
| 30 #include "chrome/test/sync/engine/test_id_factory.h" | 31 #include "chrome/test/sync/engine/test_id_factory.h" |
| 31 #include "chrome/test/profile_mock.h" | 32 #include "chrome/test/profile_mock.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "webkit/glue/password_form.h" | 34 #include "webkit/glue/password_form.h" |
| 34 | 35 |
| 35 using base::Time; | 36 using base::Time; |
| 36 using browser_sync::PasswordChangeProcessor; | 37 using browser_sync::PasswordChangeProcessor; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 134 |
| 134 void StartSyncService(Task* root_task, Task* node_task) { | 135 void StartSyncService(Task* root_task, Task* node_task) { |
| 135 StartSyncService(root_task, node_task, 2, 2); | 136 StartSyncService(root_task, node_task, 2, 2); |
| 136 } | 137 } |
| 137 | 138 |
| 138 void StartSyncService(Task* root_task, Task* node_task, | 139 void StartSyncService(Task* root_task, Task* node_task, |
| 139 int num_resume_expectations, | 140 int num_resume_expectations, |
| 140 int num_pause_expectations) { | 141 int num_pause_expectations) { |
| 141 if (!service_.get()) { | 142 if (!service_.get()) { |
| 142 service_.reset(new TestProfileSyncService(&factory_, &profile_, | 143 service_.reset(new TestProfileSyncService(&factory_, &profile_, |
| 143 false, false, root_task)); | 144 "test_user", false, root_task)); |
| 144 service_->set_num_expected_resumes(num_resume_expectations); | 145 service_->set_num_expected_resumes(num_resume_expectations); |
| 145 service_->set_num_expected_pauses(num_pause_expectations); | 146 service_->set_num_expected_pauses(num_pause_expectations); |
| 146 PasswordDataTypeController* data_type_controller = | 147 PasswordDataTypeController* data_type_controller = |
| 147 new PasswordDataTypeController(&factory_, | 148 new PasswordDataTypeController(&factory_, |
| 148 &profile_, | 149 &profile_, |
| 149 service_.get()); | 150 service_.get()); |
| 150 | 151 |
| 151 EXPECT_CALL(factory_, CreatePasswordSyncComponents(_, _, _)). | 152 EXPECT_CALL(factory_, CreatePasswordSyncComponents(_, _, _)). |
| 152 WillOnce(MakePasswordSyncComponents(service_.get(), | 153 WillOnce(MakePasswordSyncComponents(service_.get(), |
| 153 password_store_.get(), | 154 password_store_.get(), |
| 154 data_type_controller)); | 155 data_type_controller)); |
| 155 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 156 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
| 156 WillOnce(ReturnNewDataTypeManager()); | 157 WillOnce(ReturnNewDataTypeManager()); |
| 157 | 158 |
| 159 // We need tokens to get the tests going |
| 160 token_service_.IssueAuthTokenForTest( |
| 161 GaiaConstants::kSyncService, "token"); |
| 162 |
| 163 EXPECT_CALL(profile_, GetTokenService()). |
| 164 WillRepeatedly(Return(&token_service_)); |
| 165 |
| 158 // Creating model safe workers will request the history service and | 166 // Creating model safe workers will request the history service and |
| 159 // password store. I couldn't manage to convince gmock that splitting up | 167 // password store. I couldn't manage to convince gmock that splitting up |
| 160 // the expectations to match the class responsibilities was a good thing, | 168 // the expectations to match the class responsibilities was a good thing, |
| 161 // so we set them all together here. | 169 // so we set them all together here. |
| 162 EXPECT_CALL(profile_, GetHistoryService(_)). | 170 EXPECT_CALL(profile_, GetHistoryService(_)). |
| 163 WillOnce(Return(static_cast<HistoryService*>(NULL))); | 171 WillOnce(Return(static_cast<HistoryService*>(NULL))); |
| 164 | 172 |
| 165 EXPECT_CALL(profile_, GetPasswordStore(_)). | 173 EXPECT_CALL(profile_, GetPasswordStore(_)). |
| 166 Times(2). | 174 Times(2). |
| 167 WillRepeatedly(Return(password_store_.get())); | 175 WillRepeatedly(Return(password_store_.get())); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 AddPasswordEntriesTask node_task(this, sync_forms); | 531 AddPasswordEntriesTask node_task(this, sync_forms); |
| 524 | 532 |
| 525 StartSyncService(&root_task, &node_task); | 533 StartSyncService(&root_task, &node_task); |
| 526 | 534 |
| 527 std::vector<PasswordForm> new_sync_forms; | 535 std::vector<PasswordForm> new_sync_forms; |
| 528 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 536 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
| 529 | 537 |
| 530 EXPECT_EQ(1U, new_sync_forms.size()); | 538 EXPECT_EQ(1U, new_sync_forms.size()); |
| 531 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 539 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
| 532 } | 540 } |
| OLD | NEW |