| 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> |
| 6 |
| 5 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 7 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 8 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 9 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 10 #include "chrome/browser/browser_thread.h" | 12 #include "chrome/browser/browser_thread.h" |
| 11 #include "chrome/browser/sync/engine/syncapi.h" | 13 #include "chrome/browser/sync/engine/syncapi.h" |
| 12 #include "chrome/browser/sync/glue/data_type_controller.h" | 14 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | 15 #include "chrome/browser/sync/profile_sync_service.h" |
| 14 #include "chrome/browser/sync/profile_sync_factory_impl.h" | 16 #include "chrome/browser/sync/profile_sync_factory_impl.h" |
| 15 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/test/testing_profile.h" | 18 #include "chrome/test/testing_profile.h" |
| 17 | 19 |
| 18 using browser_sync::DataTypeController; | 20 using browser_sync::DataTypeController; |
| 19 | 21 |
| 20 class ProfileSyncFactoryImplTest : public testing::Test { | 22 class ProfileSyncFactoryImplTest : public testing::Test { |
| 21 protected: | 23 protected: |
| 22 ProfileSyncFactoryImplTest() | 24 ProfileSyncFactoryImplTest() |
| 23 : ui_thread_(BrowserThread::UI, &message_loop_) {} | 25 : ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 24 | 26 |
| 25 virtual void SetUp() { | 27 virtual void SetUp() { |
| 26 profile_.reset(new TestingProfile()); | 28 profile_.reset(new TestingProfile()); |
| 27 FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); | 29 FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); |
| 28 command_line_.reset(new CommandLine(program_path)); | 30 command_line_.reset(new CommandLine(program_path)); |
| 29 profile_sync_service_factory_.reset( | 31 profile_sync_service_factory_.reset( |
| 30 new ProfileSyncFactoryImpl(profile_.get(), command_line_.get())); | 32 new ProfileSyncFactoryImpl(profile_.get(), command_line_.get())); |
| 31 } | 33 } |
| 32 | 34 |
| 35 // Returns the collection of default datatypes. |
| 36 static std::vector<syncable::ModelType> DefaultDatatypes() { |
| 37 std::vector<syncable::ModelType> datatypes; |
| 38 datatypes.push_back(syncable::BOOKMARKS); |
| 39 datatypes.push_back(syncable::PREFERENCES); |
| 40 datatypes.push_back(syncable::AUTOFILL); |
| 41 datatypes.push_back(syncable::THEMES); |
| 42 datatypes.push_back(syncable::EXTENSIONS); |
| 43 datatypes.push_back(syncable::APPS); |
| 44 datatypes.push_back(syncable::AUTOFILL_PROFILE); |
| 45 datatypes.push_back(syncable::PASSWORDS); |
| 46 return datatypes; |
| 47 } |
| 48 |
| 49 // Returns the number of default datatypes. |
| 50 static size_t DefaultDatatypesCount() { |
| 51 return DefaultDatatypes().size(); |
| 52 } |
| 53 |
| 54 // Asserts that all the default datatypes are in |map|, except |
| 55 // for |exception_type|, which unless it is UNDEFINED, is asserted to |
| 56 // not be in |map|. |
| 57 static void CheckDefaultDatatypesInMapExcept( |
| 58 DataTypeController::StateMap* map, |
| 59 syncable::ModelType exception_type) { |
| 60 std::vector<syncable::ModelType> defaults = DefaultDatatypes(); |
| 61 std::vector<syncable::ModelType>::iterator iter; |
| 62 for (iter = defaults.begin(); iter != defaults.end(); ++iter) { |
| 63 if (exception_type != syncable::UNSPECIFIED && exception_type == *iter) |
| 64 EXPECT_EQ(0U, map->count(*iter)) |
| 65 << *iter << " found in dataypes map, shouldn't be there."; |
| 66 else |
| 67 EXPECT_EQ(1U, map->count(*iter)) |
| 68 << *iter << " not found in datatypes map"; |
| 69 } |
| 70 } |
| 71 |
| 72 // Asserts that if you apply the command line switch |cmd_switch|, |
| 73 // all types are enabled except for |type|, which is disabled. |
| 74 void TestSwitchDisablesType(const char* cmd_switch, |
| 75 syncable::ModelType type) { |
| 76 command_line_->AppendSwitch(cmd_switch); |
| 77 scoped_ptr<ProfileSyncService> pss( |
| 78 profile_sync_service_factory_->CreateProfileSyncService("")); |
| 79 DataTypeController::StateMap controller_states; |
| 80 pss->GetDataTypeControllerStates(&controller_states); |
| 81 EXPECT_EQ(DefaultDatatypesCount() - 1, controller_states.size()); |
| 82 CheckDefaultDatatypesInMapExcept(&controller_states, type); |
| 83 } |
| 84 |
| 33 MessageLoop message_loop_; | 85 MessageLoop message_loop_; |
| 34 BrowserThread ui_thread_; | 86 BrowserThread ui_thread_; |
| 35 scoped_ptr<Profile> profile_; | 87 scoped_ptr<Profile> profile_; |
| 36 scoped_ptr<CommandLine> command_line_; | 88 scoped_ptr<CommandLine> command_line_; |
| 37 scoped_ptr<ProfileSyncFactoryImpl> profile_sync_service_factory_; | 89 scoped_ptr<ProfileSyncFactoryImpl> profile_sync_service_factory_; |
| 38 }; | 90 }; |
| 39 | 91 |
| 40 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDefault) { | 92 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDefault) { |
| 41 scoped_ptr<ProfileSyncService> pss; | 93 scoped_ptr<ProfileSyncService> pss( |
| 42 pss.reset(profile_sync_service_factory_->CreateProfileSyncService("")); | 94 profile_sync_service_factory_->CreateProfileSyncService("")); |
| 43 DataTypeController::StateMap controller_states; | 95 DataTypeController::StateMap controller_states; |
| 44 DataTypeController::StateMap* controller_states_ptr = &controller_states; | 96 pss->GetDataTypeControllerStates(&controller_states); |
| 45 pss->GetDataTypeControllerStates(controller_states_ptr); | 97 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); |
| 46 EXPECT_EQ(7U, controller_states_ptr->size()); | 98 CheckDefaultDatatypesInMapExcept(&controller_states, syncable::UNSPECIFIED); |
| 47 EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); | |
| 48 EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); | |
| 49 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); | |
| 50 EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); | |
| 51 EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); | |
| 52 EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); | |
| 53 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL_PROFILE)); | |
| 54 } | 99 } |
| 55 | 100 |
| 56 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofill) { | 101 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofill) { |
| 57 command_line_->AppendSwitch(switches::kDisableSyncAutofill); | 102 TestSwitchDisablesType(switches::kDisableSyncAutofill, |
| 58 scoped_ptr<ProfileSyncService> pss; | 103 syncable::AUTOFILL); |
| 59 pss.reset(profile_sync_service_factory_->CreateProfileSyncService("")); | |
| 60 DataTypeController::StateMap controller_states; | |
| 61 DataTypeController::StateMap* controller_states_ptr = &controller_states; | |
| 62 pss->GetDataTypeControllerStates(controller_states_ptr); | |
| 63 EXPECT_EQ(6U, controller_states_ptr->size()); | |
| 64 EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); | |
| 65 EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); | |
| 66 EXPECT_EQ(0U, controller_states_ptr->count(syncable::AUTOFILL)); | |
| 67 EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); | |
| 68 EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); | |
| 69 EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); | |
| 70 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL_PROFILE)); | |
| 71 } | 104 } |
| 72 | 105 |
| 73 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableBookmarks) { | 106 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableBookmarks) { |
| 74 command_line_->AppendSwitch(switches::kDisableSyncBookmarks); | 107 TestSwitchDisablesType(switches::kDisableSyncBookmarks, |
| 75 scoped_ptr<ProfileSyncService> pss; | 108 syncable::BOOKMARKS); |
| 76 pss.reset(profile_sync_service_factory_->CreateProfileSyncService("")); | |
| 77 DataTypeController::StateMap controller_states; | |
| 78 DataTypeController::StateMap* controller_states_ptr = &controller_states; | |
| 79 pss->GetDataTypeControllerStates(controller_states_ptr); | |
| 80 EXPECT_EQ(6U, controller_states_ptr->size()); | |
| 81 EXPECT_EQ(0U, controller_states_ptr->count(syncable::BOOKMARKS)); | |
| 82 EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); | |
| 83 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); | |
| 84 EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); | |
| 85 EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); | |
| 86 EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); | |
| 87 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL_PROFILE)); | |
| 88 } | 109 } |
| 89 | 110 |
| 90 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePreferences) { | 111 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePreferences) { |
| 91 command_line_->AppendSwitch(switches::kDisableSyncPreferences); | 112 TestSwitchDisablesType(switches::kDisableSyncPreferences, |
| 92 scoped_ptr<ProfileSyncService> pss; | 113 syncable::PREFERENCES); |
| 93 pss.reset(profile_sync_service_factory_->CreateProfileSyncService("")); | |
| 94 DataTypeController::StateMap controller_states; | |
| 95 DataTypeController::StateMap* controller_states_ptr = &controller_states; | |
| 96 pss->GetDataTypeControllerStates(controller_states_ptr); | |
| 97 EXPECT_EQ(6U, controller_states_ptr->size()); | |
| 98 EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); | |
| 99 EXPECT_EQ(0U, controller_states_ptr->count(syncable::PREFERENCES)); | |
| 100 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); | |
| 101 EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); | |
| 102 EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); | |
| 103 EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); | |
| 104 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL_PROFILE)); | |
| 105 } | 114 } |
| 106 | 115 |
| 107 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableThemes) { | 116 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableThemes) { |
| 108 command_line_->AppendSwitch(switches::kDisableSyncThemes); | 117 TestSwitchDisablesType(switches::kDisableSyncThemes, |
| 109 scoped_ptr<ProfileSyncService> pss; | 118 syncable::THEMES); |
| 110 pss.reset(profile_sync_service_factory_->CreateProfileSyncService("")); | |
| 111 DataTypeController::StateMap controller_states; | |
| 112 DataTypeController::StateMap* controller_states_ptr = &controller_states; | |
| 113 pss->GetDataTypeControllerStates(controller_states_ptr); | |
| 114 EXPECT_EQ(6U, controller_states_ptr->size()); | |
| 115 EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); | |
| 116 EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); | |
| 117 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); | |
| 118 EXPECT_EQ(0U, controller_states_ptr->count(syncable::THEMES)); | |
| 119 EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); | |
| 120 EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); | |
| 121 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL_PROFILE)); | |
| 122 } | 119 } |
| 123 | 120 |
| 124 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableExtensions) { | 121 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableExtensions) { |
| 125 command_line_->AppendSwitch(switches::kDisableSyncExtensions); | 122 TestSwitchDisablesType(switches::kDisableSyncExtensions, |
| 126 scoped_ptr<ProfileSyncService> pss; | 123 syncable::EXTENSIONS); |
| 127 pss.reset(profile_sync_service_factory_->CreateProfileSyncService("")); | |
| 128 DataTypeController::StateMap controller_states; | |
| 129 DataTypeController::StateMap* controller_states_ptr = &controller_states; | |
| 130 pss->GetDataTypeControllerStates(controller_states_ptr); | |
| 131 EXPECT_EQ(6U, controller_states_ptr->size()); | |
| 132 EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); | |
| 133 EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); | |
| 134 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); | |
| 135 EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); | |
| 136 EXPECT_EQ(0U, controller_states_ptr->count(syncable::EXTENSIONS)); | |
| 137 EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); | |
| 138 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL_PROFILE)); | |
| 139 } | 124 } |
| 140 | 125 |
| 141 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableApps) { | 126 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableApps) { |
| 142 command_line_->AppendSwitch(switches::kDisableSyncApps); | 127 TestSwitchDisablesType(switches::kDisableSyncApps, |
| 143 scoped_ptr<ProfileSyncService> pss; | 128 syncable::APPS); |
| 144 pss.reset(profile_sync_service_factory_->CreateProfileSyncService("")); | |
| 145 DataTypeController::StateMap controller_states; | |
| 146 DataTypeController::StateMap* controller_states_ptr = &controller_states; | |
| 147 pss->GetDataTypeControllerStates(controller_states_ptr); | |
| 148 EXPECT_EQ(6U, controller_states_ptr->size()); | |
| 149 EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); | |
| 150 EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); | |
| 151 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); | |
| 152 EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); | |
| 153 EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); | |
| 154 EXPECT_EQ(0U, controller_states_ptr->count(syncable::APPS)); | |
| 155 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL_PROFILE)); | |
| 156 } | 129 } |
| 157 | 130 |
| 158 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofillProfile) { | 131 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofillProfile) { |
| 159 command_line_->AppendSwitch(switches::kDisableSyncAutofillProfile); | 132 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile, |
| 160 scoped_ptr<ProfileSyncService> pss; | 133 syncable::AUTOFILL_PROFILE); |
| 161 pss.reset(profile_sync_service_factory_->CreateProfileSyncService("")); | |
| 162 DataTypeController::StateMap controller_states; | |
| 163 DataTypeController::StateMap* controller_states_ptr = &controller_states; | |
| 164 pss->GetDataTypeControllerStates(controller_states_ptr); | |
| 165 EXPECT_EQ(6U, controller_states_ptr->size()); | |
| 166 EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS)); | |
| 167 EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES)); | |
| 168 EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL)); | |
| 169 EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES)); | |
| 170 EXPECT_EQ(1U, controller_states_ptr->count(syncable::EXTENSIONS)); | |
| 171 EXPECT_EQ(1U, controller_states_ptr->count(syncable::APPS)); | |
| 172 EXPECT_EQ(0U, controller_states_ptr->count(syncable::AUTOFILL_PROFILE)); | |
| 173 } | 134 } |
| 135 |
| 136 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePasswords) { |
| 137 TestSwitchDisablesType(switches::kDisableSyncPasswords, |
| 138 syncable::PASSWORDS); |
| 139 } |
| OLD | NEW |