| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <vector> | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/file_path.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/message_loop.h" | |
| 11 #include "chrome/browser/sync/glue/data_type_controller.h" | |
| 12 #include "chrome/browser/sync/profile_sync_factory_impl.h" | |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | |
| 14 #include "chrome/common/chrome_switches.h" | |
| 15 #include "chrome/test/base/testing_profile.h" | |
| 16 #include "content/test/test_browser_thread.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 | |
| 19 using browser_sync::DataTypeController; | |
| 20 using content::BrowserThread; | |
| 21 | |
| 22 class ProfileSyncFactoryImplTest : public testing::Test { | |
| 23 protected: | |
| 24 ProfileSyncFactoryImplTest() | |
| 25 : ui_thread_(BrowserThread::UI, &message_loop_) {} | |
| 26 | |
| 27 virtual void SetUp() { | |
| 28 profile_.reset(new TestingProfile()); | |
| 29 FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); | |
| 30 command_line_.reset(new CommandLine(program_path)); | |
| 31 profile_sync_service_factory_.reset( | |
| 32 new ProfileSyncFactoryImpl(profile_.get(), command_line_.get())); | |
| 33 } | |
| 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::APP_NOTIFICATIONS); | |
| 45 datatypes.push_back(syncable::AUTOFILL_PROFILE); | |
| 46 datatypes.push_back(syncable::PASSWORDS); | |
| 47 datatypes.push_back(syncable::TYPED_URLS); | |
| 48 datatypes.push_back(syncable::SEARCH_ENGINES); | |
| 49 return datatypes; | |
| 50 } | |
| 51 | |
| 52 // Returns the number of default datatypes. | |
| 53 static size_t DefaultDatatypesCount() { | |
| 54 return DefaultDatatypes().size(); | |
| 55 } | |
| 56 | |
| 57 // Asserts that all the default datatypes are in |map|, except | |
| 58 // for |exception_type|, which unless it is UNDEFINED, is asserted to | |
| 59 // not be in |map|. | |
| 60 static void CheckDefaultDatatypesInMapExcept( | |
| 61 DataTypeController::StateMap* map, | |
| 62 syncable::ModelType exception_type) { | |
| 63 std::vector<syncable::ModelType> defaults = DefaultDatatypes(); | |
| 64 std::vector<syncable::ModelType>::iterator iter; | |
| 65 for (iter = defaults.begin(); iter != defaults.end(); ++iter) { | |
| 66 if (exception_type != syncable::UNSPECIFIED && exception_type == *iter) | |
| 67 EXPECT_EQ(0U, map->count(*iter)) | |
| 68 << *iter << " found in dataypes map, shouldn't be there."; | |
| 69 else | |
| 70 EXPECT_EQ(1U, map->count(*iter)) | |
| 71 << *iter << " not found in datatypes map"; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 // Asserts that if you apply the command line switch |cmd_switch|, | |
| 76 // all types are enabled except for |type|, which is disabled. | |
| 77 void TestSwitchDisablesType(const char* cmd_switch, | |
| 78 syncable::ModelType type) { | |
| 79 command_line_->AppendSwitch(cmd_switch); | |
| 80 scoped_ptr<ProfileSyncService> pss( | |
| 81 profile_sync_service_factory_->CreateProfileSyncService("")); | |
| 82 profile_sync_service_factory_->RegisterDataTypes(pss.get()); | |
| 83 DataTypeController::StateMap controller_states; | |
| 84 pss->GetDataTypeControllerStates(&controller_states); | |
| 85 EXPECT_EQ(DefaultDatatypesCount() - 1, controller_states.size()); | |
| 86 CheckDefaultDatatypesInMapExcept(&controller_states, type); | |
| 87 } | |
| 88 | |
| 89 MessageLoop message_loop_; | |
| 90 content::TestBrowserThread ui_thread_; | |
| 91 scoped_ptr<Profile> profile_; | |
| 92 scoped_ptr<CommandLine> command_line_; | |
| 93 scoped_ptr<ProfileSyncFactoryImpl> profile_sync_service_factory_; | |
| 94 }; | |
| 95 | |
| 96 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDefault) { | |
| 97 scoped_ptr<ProfileSyncService> pss( | |
| 98 profile_sync_service_factory_->CreateProfileSyncService("")); | |
| 99 profile_sync_service_factory_->RegisterDataTypes(pss.get()); | |
| 100 DataTypeController::StateMap controller_states; | |
| 101 pss->GetDataTypeControllerStates(&controller_states); | |
| 102 EXPECT_EQ(DefaultDatatypesCount(), controller_states.size()); | |
| 103 CheckDefaultDatatypesInMapExcept(&controller_states, syncable::UNSPECIFIED); | |
| 104 } | |
| 105 | |
| 106 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofill) { | |
| 107 TestSwitchDisablesType(switches::kDisableSyncAutofill, | |
| 108 syncable::AUTOFILL); | |
| 109 } | |
| 110 | |
| 111 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableBookmarks) { | |
| 112 TestSwitchDisablesType(switches::kDisableSyncBookmarks, | |
| 113 syncable::BOOKMARKS); | |
| 114 } | |
| 115 | |
| 116 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePreferences) { | |
| 117 TestSwitchDisablesType(switches::kDisableSyncPreferences, | |
| 118 syncable::PREFERENCES); | |
| 119 } | |
| 120 | |
| 121 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableThemes) { | |
| 122 TestSwitchDisablesType(switches::kDisableSyncThemes, | |
| 123 syncable::THEMES); | |
| 124 } | |
| 125 | |
| 126 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableExtensions) { | |
| 127 TestSwitchDisablesType(switches::kDisableSyncExtensions, | |
| 128 syncable::EXTENSIONS); | |
| 129 } | |
| 130 | |
| 131 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableApps) { | |
| 132 TestSwitchDisablesType(switches::kDisableSyncApps, | |
| 133 syncable::APPS); | |
| 134 } | |
| 135 | |
| 136 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofillProfile) { | |
| 137 TestSwitchDisablesType(switches::kDisableSyncAutofillProfile, | |
| 138 syncable::AUTOFILL_PROFILE); | |
| 139 } | |
| 140 | |
| 141 TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePasswords) { | |
| 142 TestSwitchDisablesType(switches::kDisableSyncPasswords, | |
| 143 syncable::PASSWORDS); | |
| 144 } | |
| OLD | NEW |