Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / test / integration / two_client_preferences_sync_test.cc
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.
4
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"
11
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;
22
23 class TwoClientPreferencesSyncTest : public SyncTest {
24  public:
25   TwoClientPreferencesSyncTest() : SyncTest(TWO_CLIENT) {}
26   ~TwoClientPreferencesSyncTest() override {}
27
28   bool TestUsesSelfNotifications() override { return false; }
29
30  private:
31   DISALLOW_COPY_AND_ASSIGN(TwoClientPreferencesSyncTest);
32 };
33
34 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest, BooleanPref) {
35   ASSERT_TRUE(SetupSync());
36   ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kHomePageIsNewTabPage));
37
38   ChangeBooleanPref(0, prefs::kHomePageIsNewTabPage);
39   ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kHomePageIsNewTabPage));
40 }
41
42 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest, Bidirectional) {
43   ASSERT_TRUE(SetupSync());
44
45   ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage));
46
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));
50
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));
54 }
55
56 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest, UnsyncableBooleanPref) {
57   ASSERT_TRUE(SetupSync());
58   DisableVerifier();
59   ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage));
60   ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kCheckDefaultBrowser));
61
62   // This pref is not syncable.
63   ChangeBooleanPref(0, prefs::kCheckDefaultBrowser);
64
65   // This pref is syncable.
66   ChangeStringPref(0, prefs::kHomePage, "http://news.google.com");
67
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));
72 }
73
74 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest, StringPref) {
75   ASSERT_TRUE(SetupSync());
76   ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage));
77
78   ChangeStringPref(0, prefs::kHomePage, "http://news.google.com");
79   ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage));
80 }
81
82 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest, ComplexPrefs) {
83   ASSERT_TRUE(SetupSync());
84   ASSERT_TRUE(AwaitIntegerPrefMatches(prefs::kRestoreOnStartup));
85   ASSERT_TRUE(AwaitListPrefMatches(prefs::kURLsToRestoreOnStartup));
86
87   ChangeIntegerPref(0, prefs::kRestoreOnStartup, 0);
88   ASSERT_TRUE(AwaitIntegerPrefMatches(prefs::kRestoreOnStartup));
89
90   base::ListValue urls;
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));
97 }
98
99 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest,
100                        kAutofillAuxiliaryProfilesEnabled) {
101   ASSERT_TRUE(SetupSync());
102   DisableVerifier();
103
104   ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage));
105   ASSERT_TRUE(AwaitBooleanPrefMatches(
106       autofill::prefs::kAutofillAuxiliaryProfilesEnabled));
107
108   // This pref may be syncable.
109   ChangeBooleanPref(0, autofill::prefs::kAutofillAuxiliaryProfilesEnabled);
110
111   // This pref is always syncable.
112   ChangeStringPref(0, prefs::kHomePage, "http://news.google.com");
113
114   // Wait for the syncable pref to propagate.
115   ASSERT_TRUE(AwaitStringPrefMatches(prefs::kHomePage));
116
117   // kAutofillAuxiliaryProfilesEnabled is only synced on Mac and Android.
118 #if defined(OS_MACOSX) || defined(OS_ANDROID)
119   ASSERT_TRUE(
120       BooleanPrefMatches(autofill::prefs::kAutofillAuxiliaryProfilesEnabled));
121 #else
122   ASSERT_FALSE(
123       BooleanPrefMatches(autofill::prefs::kAutofillAuxiliaryProfilesEnabled));
124 #endif  // defined(OS_MACOSX) || defined(OS_ANDROID)
125 }
126
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));
132
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));
140 }
141
142 IN_PROC_BROWSER_TEST_F(TwoClientPreferencesSyncTest,
143                        BothClientsEnabledEncryptionAndChangedMultipleTimes) {
144   ASSERT_TRUE(SetupSync());
145   ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kHomePageIsNewTabPage));
146
147   ChangeBooleanPref(0, prefs::kHomePageIsNewTabPage);
148   ASSERT_TRUE(EnableEncryption(0));
149   ASSERT_TRUE(EnableEncryption(1));
150   ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kHomePageIsNewTabPage));
151
152   ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kShowHomeButton));
153   ChangeBooleanPref(0, prefs::kShowHomeButton);
154   ASSERT_TRUE(AwaitBooleanPrefMatches(prefs::kShowHomeButton));
155 }