Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / test / integration / two_client_themes_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/basictypes.h"
6 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
7 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
8 #include "chrome/browser/sync/test/integration/sync_test.h"
9 #include "chrome/browser/sync/test/integration/themes_helper.h"
10
11 using themes_helper::AwaitThemeIsPendingInstall;
12 using themes_helper::AwaitUsingSystemTheme;
13 using themes_helper::AwaitUsingDefaultTheme;
14 using themes_helper::GetCustomTheme;
15 using themes_helper::GetThemeID;
16 using themes_helper::UseCustomTheme;
17 using themes_helper::UseDefaultTheme;
18 using themes_helper::UseSystemTheme;
19 using themes_helper::UsingCustomTheme;
20 using themes_helper::UsingDefaultTheme;
21 using themes_helper::UsingSystemTheme;
22
23 class TwoClientThemesSyncTest : public SyncTest {
24  public:
25   TwoClientThemesSyncTest() : SyncTest(TWO_CLIENT) {}
26   ~TwoClientThemesSyncTest() override {}
27
28   bool TestUsesSelfNotifications() override { return false; }
29
30  private:
31   DISALLOW_COPY_AND_ASSIGN(TwoClientThemesSyncTest);
32 };
33
34 // Starts with default themes, then sets up sync and uses it to set all
35 // profiles to use a custom theme.  Does not actually install any themes, but
36 // instead verifies the custom theme is pending for install.
37 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, DefaultThenSyncCustom) {
38   ASSERT_TRUE(SetupSync());
39
40   ASSERT_FALSE(UsingCustomTheme(GetProfile(0)));
41   ASSERT_FALSE(UsingCustomTheme(GetProfile(1)));
42   ASSERT_FALSE(UsingCustomTheme(verifier()));
43
44   UseCustomTheme(GetProfile(0), 0);
45   UseCustomTheme(verifier(), 0);
46   ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
47   ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
48
49   // TODO(sync): Add functions to simulate when a pending extension
50   // is installed as well as when a pending extension fails to
51   // install.
52   ASSERT_TRUE(AwaitThemeIsPendingInstall(GetProfile(1), GetCustomTheme(0)));
53
54   EXPECT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
55   EXPECT_FALSE(UsingCustomTheme(GetProfile(1)));
56   EXPECT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
57 }
58
59 // Starts with custom themes, then sets up sync and uses it to set all profiles
60 // to the system theme.
61 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomThenSyncNative) {
62   ASSERT_TRUE(SetupClients());
63
64   UseCustomTheme(GetProfile(0), 0);
65   UseCustomTheme(GetProfile(1), 0);
66   UseCustomTheme(verifier(), 0);
67
68   ASSERT_TRUE(SetupSync());
69
70   UseSystemTheme(GetProfile(0));
71   UseSystemTheme(verifier());
72   ASSERT_TRUE(UsingSystemTheme(GetProfile(0)));
73   ASSERT_TRUE(UsingSystemTheme(verifier()));
74
75   ASSERT_TRUE(AwaitUsingSystemTheme(GetProfile(1)));
76
77   EXPECT_TRUE(UsingSystemTheme(GetProfile(0)));
78   EXPECT_TRUE(UsingSystemTheme(GetProfile(1)));
79   EXPECT_TRUE(UsingSystemTheme(verifier()));
80 }
81
82 // Starts with custom themes, then sets up sync and uses it to set all profiles
83 // to the default theme.
84 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CustomThenSyncDefault) {
85   ASSERT_TRUE(SetupClients());
86
87   UseCustomTheme(GetProfile(0), 0);
88   UseCustomTheme(GetProfile(1), 0);
89   UseCustomTheme(verifier(), 0);
90
91   ASSERT_TRUE(SetupSync());
92
93   UseDefaultTheme(GetProfile(0));
94   UseDefaultTheme(verifier());
95   EXPECT_TRUE(UsingDefaultTheme(GetProfile(0)));
96   EXPECT_TRUE(UsingDefaultTheme(verifier()));
97
98   ASSERT_TRUE(AwaitUsingDefaultTheme(GetProfile(1)));
99   EXPECT_TRUE(UsingDefaultTheme(GetProfile(0)));
100   EXPECT_TRUE(UsingDefaultTheme(GetProfile(1)));
101   EXPECT_TRUE(UsingDefaultTheme(verifier()));
102 }
103
104 // Cycles through a set of options.
105 //
106 // Most other tests have significant coverage of model association.  This test
107 // is intended to test steady-state scenarios.
108 IN_PROC_BROWSER_TEST_F(TwoClientThemesSyncTest, CycleOptions) {
109   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
110
111   UseCustomTheme(GetProfile(0), 0);
112   UseCustomTheme(verifier(), 0);
113
114   ASSERT_TRUE(AwaitThemeIsPendingInstall(GetProfile(1), GetCustomTheme(0)));
115   EXPECT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0)));
116   EXPECT_EQ(GetCustomTheme(0), GetThemeID(verifier()));
117
118   UseSystemTheme(GetProfile(0));
119   UseSystemTheme(verifier());
120
121   ASSERT_TRUE(AwaitUsingSystemTheme(GetProfile(1)));
122   EXPECT_TRUE(UsingSystemTheme(GetProfile(0)));
123   EXPECT_TRUE(UsingSystemTheme(GetProfile(1)));
124   EXPECT_TRUE(UsingSystemTheme(verifier()));
125
126   UseDefaultTheme(GetProfile(0));
127   UseDefaultTheme(verifier());
128
129   ASSERT_TRUE(AwaitUsingDefaultTheme(GetProfile(1)));
130   EXPECT_TRUE(UsingDefaultTheme(GetProfile(0)));
131   EXPECT_TRUE(UsingDefaultTheme(GetProfile(1)));
132   EXPECT_TRUE(UsingDefaultTheme(verifier()));
133
134   UseCustomTheme(GetProfile(0), 1);
135   UseCustomTheme(verifier(), 1);
136   ASSERT_TRUE(AwaitThemeIsPendingInstall(GetProfile(1), GetCustomTheme(1)));
137   EXPECT_EQ(GetCustomTheme(1), GetThemeID(GetProfile(0)));
138   EXPECT_EQ(GetCustomTheme(1), GetThemeID(verifier()));
139 }