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

Unified Diff: chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc

Issue 7967024: Profile shouldn't own PersonalDataManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
diff --git a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
index 1dd4943f9419c14e22deb640f1d61d0c3826072e..953c24e4155de3faa93a92dded3262f69649fb7d 100644
--- a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
+++ b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc
@@ -10,6 +10,7 @@
#include "base/message_loop.h"
#include "base/synchronization/waitable_event.h"
#include "chrome/browser/autofill/personal_data_manager.h"
+#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/sync/glue/autofill_data_type_controller.h"
#include "chrome/browser/sync/glue/change_processor_mock.h"
#include "chrome/browser/sync/glue/model_associator_mock.h"
@@ -50,9 +51,22 @@ class StartCallback {
const tracked_objects::Location& location));
};
+// This class mocks PersonalDataManager and provides a factory method to
+// serve back the mocked object to callers of
+// |PersonalDataManagerFactory::GetForProfile()|.
class PersonalDataManagerMock : public PersonalDataManager {
public:
+ PersonalDataManagerMock() : PersonalDataManager() {}
+ virtual ~PersonalDataManagerMock() {}
+
+ static ProfileKeyedService* Build(Profile* profile) {
+ return new PersonalDataManagerMock;
+ }
+
MOCK_CONST_METHOD0(IsDataLoaded, bool());
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerMock);
};
class WebDataServiceFake : public WebDataService {
@@ -91,10 +105,11 @@ class AutofillDataTypeControllerTest : public testing::Test {
Return(&service_));
db_thread_.Start();
web_data_service_ = new WebDataServiceFake(true);
- personal_data_manager_ = new PersonalDataManagerMock();
+ personal_data_manager_ = static_cast<PersonalDataManagerMock*>(
+ PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse(
+ &profile_, PersonalDataManagerMock::Build));
autofill_dtc_ =
- new AutofillDataTypeController(&profile_sync_factory_,
- &profile_);
+ new AutofillDataTypeController(&profile_sync_factory_, &profile_);
}
virtual void TearDown() {
@@ -104,9 +119,7 @@ class AutofillDataTypeControllerTest : public testing::Test {
protected:
void SetStartExpectations() {
- EXPECT_CALL(profile_, GetPersonalDataManager()).
- WillRepeatedly(Return(personal_data_manager_.get()));
- EXPECT_CALL(*(personal_data_manager_.get()), IsDataLoaded()).
+ EXPECT_CALL(*personal_data_manager_, IsDataLoaded()).
WillRepeatedly(Return(true));
EXPECT_CALL(profile_, GetWebDataService(_)).
WillOnce(Return(web_data_service_.get()));
@@ -116,7 +129,7 @@ class AutofillDataTypeControllerTest : public testing::Test {
model_associator_ = new ModelAssociatorMock();
change_processor_ = new ChangeProcessorMock();
EXPECT_CALL(profile_sync_factory_,
- CreateAutofillSyncComponents(_, _, _, _)).
+ CreateAutofillSyncComponents(_, _, _)).
WillOnce(Return(
ProfileSyncFactory::SyncComponents(model_associator_,
change_processor_)));
@@ -151,7 +164,7 @@ class AutofillDataTypeControllerTest : public testing::Test {
scoped_refptr<AutofillDataTypeController> autofill_dtc_;
ProfileSyncFactoryMock profile_sync_factory_;
ProfileMock profile_;
- scoped_refptr<PersonalDataManagerMock> personal_data_manager_;
+ PersonalDataManagerMock* personal_data_manager_;
scoped_refptr<WebDataService> web_data_service_;
ProfileSyncServiceMock service_;
ModelAssociatorMock* model_associator_;
@@ -162,6 +175,7 @@ class AutofillDataTypeControllerTest : public testing::Test {
TEST_F(AutofillDataTypeControllerTest, StartPDMAndWDSReady) {
SetStartExpectations();
SetAssociateExpectations();
+
EXPECT_EQ(DataTypeController::NOT_RUNNING, autofill_dtc_->state());
EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _)).
WillOnce(QuitUIMessageLoop());
@@ -174,9 +188,7 @@ TEST_F(AutofillDataTypeControllerTest, StartPDMAndWDSReady) {
}
TEST_F(AutofillDataTypeControllerTest, AbortWhilePDMStarting) {
- EXPECT_CALL(profile_, GetPersonalDataManager()).
- WillRepeatedly(Return(personal_data_manager_.get()));
- EXPECT_CALL(*(personal_data_manager_.get()), IsDataLoaded()).
+ EXPECT_CALL(*personal_data_manager_, IsDataLoaded()).
WillRepeatedly(Return(false));
autofill_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run));
EXPECT_EQ(DataTypeController::MODEL_STARTING, autofill_dtc_->state());
@@ -188,9 +200,7 @@ TEST_F(AutofillDataTypeControllerTest, AbortWhilePDMStarting) {
}
TEST_F(AutofillDataTypeControllerTest, AbortWhileWDSStarting) {
- EXPECT_CALL(profile_, GetPersonalDataManager()).
- WillRepeatedly(Return(personal_data_manager_.get()));
- EXPECT_CALL(*(personal_data_manager_.get()), IsDataLoaded()).
+ EXPECT_CALL(*personal_data_manager_, IsDataLoaded()).
WillRepeatedly(Return(true));
scoped_refptr<WebDataServiceFake> web_data_service_not_loaded(
new WebDataServiceFake(false));
@@ -211,7 +221,7 @@ TEST_F(AutofillDataTypeControllerTest, AbortWhileAssociatingNotActivated) {
model_associator_ = new ModelAssociatorMock();
change_processor_ = new ChangeProcessorMock();
EXPECT_CALL(profile_sync_factory_,
- CreateAutofillSyncComponents(_, _, _, _)).
+ CreateAutofillSyncComponents(_, _, _)).
WillOnce(Return(
ProfileSyncFactory::SyncComponents(model_associator_,
change_processor_)));
@@ -251,7 +261,7 @@ TEST_F(AutofillDataTypeControllerTest, AbortWhileAssociatingActivated) {
model_associator_ = new ModelAssociatorMock();
change_processor_ = new ChangeProcessorMock();
EXPECT_CALL(profile_sync_factory_,
- CreateAutofillSyncComponents(_, _, _, _)).
+ CreateAutofillSyncComponents(_, _, _)).
WillOnce(Return(
ProfileSyncFactory::SyncComponents(model_associator_,
change_processor_)));

Powered by Google App Engine
This is Rietveld 408576698