1 // Copyright (c) 2012 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.
5 #include "base/prefs/pref_service.h"
6 #include "chrome/browser/sync/test/integration/preferences_helper.h"
7 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
8 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
9 #include "chrome/browser/sync/test/integration/sync_test.h"
10 #include "chrome/common/pref_names.h"
12 using preferences_helper::AwaitBooleanPrefMatches
;
13 using preferences_helper::AwaitIntegerPrefMatches
;
14 using preferences_helper::AwaitListPrefMatches
;
15 using preferences_helper::AwaitStringPrefMatches
;
16 using preferences_helper::BooleanPrefMatches
;
17 using preferences_helper::ChangeBooleanPref
;
18 using preferences_helper::ChangeIntegerPref
;
19 using preferences_helper::ChangeListPref
;
20 using preferences_helper::ChangeStringPref
;
21 using preferences_helper::GetPrefs
;
23 class TwoClientPreferencesSyncTest
: public SyncTest
{
25 TwoClientPreferencesSyncTest() : SyncTest(TWO_CLIENT
) {}
26 ~TwoClientPreferencesSyncTest() override
{}
28 bool TestUsesSelfNotifications() override
{ return false; }
31 DISALLOW_COPY_AND_ASSIGN(TwoClientPreferencesSyncTest
);
34 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest
, BooleanPref
) {
35 ASSERT_TRUE(SetupSync());
36 ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kHomePageIsNewTabPage
));
38 ChangeBooleanPref(0, prefs::kHomePageIsNewTabPage
);
39 ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kHomePageIsNewTabPage
));
42 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest
, Bidirectional
) {
43 ASSERT_TRUE(SetupSync());
45 ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage
));
47 ChangeStringPref(0, prefs::kHomePage
, "http://www.google.com/0");
48 ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage
));
49 EXPECT_EQ("http://www.google.com/0", GetPrefs(0)->GetString(prefs::kHomePage
));
51 ChangeStringPref(1, prefs::kHomePage
, "http://www.google.com/1");
52 ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage
));
53 EXPECT_EQ("http://www.google.com/1", GetPrefs(0)->GetString(prefs::kHomePage
));
56 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest
, UnsyncableBooleanPref
) {
57 ASSERT_TRUE(SetupSync());
59 ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage
));
60 ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kCheckDefaultBrowser
));
62 // This pref is not syncable.
63 ChangeBooleanPref(0, prefs::kCheckDefaultBrowser
);
65 // This pref is syncable.
66 ChangeStringPref(0, prefs::kHomePage
, "http://news.google.com");
68 // Wait until the syncable pref is synced, then expect that the non-syncable
69 // one is still out of sync.
70 ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage
));
71 ASSERT_FALSE(BooleanPrefMatches(prefs::kCheckDefaultBrowser
));
74 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest
, StringPref
) {
75 ASSERT_TRUE(SetupSync());
76 ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage
));
78 ChangeStringPref(0, prefs::kHomePage
, "http://news.google.com");
79 ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage
));
82 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest
, ComplexPrefs
) {
83 ASSERT_TRUE(SetupSync());
84 ASSERT_TRUE(AwaitIntegerPrefMatches(prefs::kRestoreOnStartup
));
85 ASSERT_TRUE(AwaitListPrefMatches(prefs::kURLsToRestoreOnStartup
));
87 ChangeIntegerPref(0, prefs::kRestoreOnStartup
, 0);
88 ASSERT_TRUE(AwaitIntegerPrefMatches(prefs::kRestoreOnStartup
));
91 urls
.Append(new base::StringValue("http://www.google.com/"));
92 urls
.Append(new base::StringValue("http://www.flickr.com/"));
93 ChangeIntegerPref(0, prefs::kRestoreOnStartup
, 4);
94 ChangeListPref(0, prefs::kURLsToRestoreOnStartup
, urls
);
95 ASSERT_TRUE(AwaitIntegerPrefMatches(prefs::kRestoreOnStartup
));
96 ASSERT_TRUE(AwaitListPrefMatches(prefs::kURLsToRestoreOnStartup
));
99 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest
,
100 kAutofillAuxiliaryProfilesEnabled
) {
101 ASSERT_TRUE(SetupSync());
104 ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage
));
105 ASSERT_TRUE(AwaitBooleanPrefMatches(
106 autofill::prefs::kAutofillAuxiliaryProfilesEnabled
));
108 // This pref may be syncable.
109 ChangeBooleanPref(0, autofill::prefs::kAutofillAuxiliaryProfilesEnabled
);
111 // This pref is always syncable.
112 ChangeStringPref(0, prefs::kHomePage
, "http://news.google.com");
114 // Wait for the syncable pref to propagate.
115 ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage
));
117 // kAutofillAuxiliaryProfilesEnabled is only synced on Mac and Android.
118 #if defined(OS_MACOSX) || defined(OS_ANDROID)
120 BooleanPrefMatches(autofill::prefs::kAutofillAuxiliaryProfilesEnabled
));
123 BooleanPrefMatches(autofill::prefs::kAutofillAuxiliaryProfilesEnabled
));
124 #endif // defined(OS_MACOSX) || defined(OS_ANDROID)
127 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest
,
128 SingleClientEnabledEncryptionBothChanged
) {
129 ASSERT_TRUE(SetupSync());
130 ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kHomePageIsNewTabPage
));
131 ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage
));
133 ASSERT_TRUE(EnableEncryption(0));
134 ChangeBooleanPref(0, prefs::kHomePageIsNewTabPage
);
135 ChangeStringPref(1, prefs::kHomePage
, "http://www.google.com/1");
136 ASSERT_TRUE(AwaitEncryptionComplete(0));
137 ASSERT_TRUE(AwaitEncryptionComplete(1));
138 ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage
));
139 ASSERT_TRUE(BooleanPrefMatches(prefs::kHomePageIsNewTabPage
));
142 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest
,
143 BothClientsEnabledEncryptionAndChangedMultipleTimes
) {
144 ASSERT_TRUE(SetupSync());
145 ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kHomePageIsNewTabPage
));
147 ChangeBooleanPref(0, prefs::kHomePageIsNewTabPage
);
148 ASSERT_TRUE(EnableEncryption(0));
149 ASSERT_TRUE(EnableEncryption(1));
150 ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kHomePageIsNewTabPage
));
152 ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kShowHomeButton
));
153 ChangeBooleanPref(0, prefs::kShowHomeButton
);
154 ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kShowHomeButton
));