1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/gtest/include/gtest/gtest.h"
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/message_loop.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/data_type_controller.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_factory_impl.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/net/fake_network_change_notifier_thread.h"
#include "chrome/test/testing_profile.h"
using browser_sync::DataTypeController;
class ProfileSyncFactoryImplTest : public testing::Test {
protected:
ProfileSyncFactoryImplTest()
: ui_thread_(ChromeThread::UI, &message_loop_) {}
virtual void SetUp() {
profile_.reset(new TestingProfile());
FilePath program_path(FILE_PATH_LITERAL("chrome.exe"));
command_line_.reset(new CommandLine(program_path));
profile_sync_service_factory_.reset(
new ProfileSyncFactoryImpl(profile_.get(),
&fake_network_change_notifier_thread_,
command_line_.get()));
}
MessageLoop message_loop_;
ChromeThread ui_thread_;
scoped_ptr<Profile> profile_;
scoped_ptr<CommandLine> command_line_;
chrome_common_net::FakeNetworkChangeNotifierThread
fake_network_change_notifier_thread_;
scoped_ptr<ProfileSyncFactoryImpl> profile_sync_service_factory_;
};
TEST_F(ProfileSyncFactoryImplTest, CreatePSSDefault) {
scoped_ptr<ProfileSyncService> pss;
pss.reset(profile_sync_service_factory_->CreateProfileSyncService());
DataTypeController::StateMap controller_states;
DataTypeController::StateMap* controller_states_ptr = &controller_states;
pss->GetDataTypeControllerStates(controller_states_ptr);
EXPECT_EQ(3U, controller_states_ptr->size());
EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS));
EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES));
EXPECT_EQ(0U, controller_states_ptr->count(syncable::AUTOFILL));
EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES));
}
TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableAutofill) {
command_line_->AppendSwitch(switches::kDisableSyncAutofill);
scoped_ptr<ProfileSyncService> pss;
pss.reset(profile_sync_service_factory_->CreateProfileSyncService());
DataTypeController::StateMap controller_states;
DataTypeController::StateMap* controller_states_ptr = &controller_states;
pss->GetDataTypeControllerStates(controller_states_ptr);
EXPECT_EQ(3U, controller_states_ptr->size());
EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS));
EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES));
EXPECT_EQ(0U, controller_states_ptr->count(syncable::AUTOFILL));
EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES));
}
TEST_F(ProfileSyncFactoryImplTest, CreatePSSEnableAutofill) {
command_line_->AppendSwitch(switches::kEnableSyncAutofill);
scoped_ptr<ProfileSyncService> pss;
pss.reset(profile_sync_service_factory_->CreateProfileSyncService());
DataTypeController::StateMap controller_states;
DataTypeController::StateMap* controller_states_ptr = &controller_states;
pss->GetDataTypeControllerStates(controller_states_ptr);
EXPECT_EQ(4U, controller_states_ptr->size());
EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS));
EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES));
EXPECT_EQ(1U, controller_states_ptr->count(syncable::AUTOFILL));
EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES));
}
TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableBookmarks) {
command_line_->AppendSwitch(switches::kDisableSyncBookmarks);
scoped_ptr<ProfileSyncService> pss;
pss.reset(profile_sync_service_factory_->CreateProfileSyncService());
DataTypeController::StateMap controller_states;
DataTypeController::StateMap* controller_states_ptr = &controller_states;
pss->GetDataTypeControllerStates(controller_states_ptr);
EXPECT_EQ(2U, controller_states_ptr->size());
EXPECT_EQ(0U, controller_states_ptr->count(syncable::BOOKMARKS));
EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES));
EXPECT_EQ(0U, controller_states_ptr->count(syncable::AUTOFILL));
EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES));
}
TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisablePreferences) {
command_line_->AppendSwitch(switches::kDisableSyncPreferences);
scoped_ptr<ProfileSyncService> pss;
pss.reset(profile_sync_service_factory_->CreateProfileSyncService());
DataTypeController::StateMap controller_states;
DataTypeController::StateMap* controller_states_ptr = &controller_states;
pss->GetDataTypeControllerStates(controller_states_ptr);
EXPECT_EQ(2U, controller_states_ptr->size());
EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS));
EXPECT_EQ(0U, controller_states_ptr->count(syncable::PREFERENCES));
EXPECT_EQ(0U, controller_states_ptr->count(syncable::AUTOFILL));
EXPECT_EQ(1U, controller_states_ptr->count(syncable::THEMES));
}
TEST_F(ProfileSyncFactoryImplTest, CreatePSSDisableThemes) {
command_line_->AppendSwitch(switches::kDisableSyncThemes);
scoped_ptr<ProfileSyncService> pss;
pss.reset(profile_sync_service_factory_->CreateProfileSyncService());
DataTypeController::StateMap controller_states;
DataTypeController::StateMap* controller_states_ptr = &controller_states;
pss->GetDataTypeControllerStates(controller_states_ptr);
EXPECT_EQ(2U, controller_states_ptr->size());
EXPECT_EQ(1U, controller_states_ptr->count(syncable::BOOKMARKS));
EXPECT_EQ(1U, controller_states_ptr->count(syncable::PREFERENCES));
EXPECT_EQ(0U, controller_states_ptr->count(syncable::AUTOFILL));
EXPECT_EQ(0U, controller_states_ptr->count(syncable::THEMES));
}
|