OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "chrome/browser/profiles/profile.h" | |
7 #include "chrome/browser/sync/profile_sync_service_harness.h" | 6 #include "chrome/browser/sync/profile_sync_service_harness.h" |
8 #include "chrome/common/extensions/extension.h" | |
9 #include "chrome/test/live_sync/live_themes_sync_test.h" | 7 #include "chrome/test/live_sync/live_themes_sync_test.h" |
10 | 8 |
11 class TwoClientLiveThemesSyncTest : public LiveThemesSyncTest { | 9 class TwoClientLiveThemesSyncTest : public LiveThemesSyncTest { |
12 public: | 10 public: |
13 TwoClientLiveThemesSyncTest() : LiveThemesSyncTest(TWO_CLIENT) {} | 11 TwoClientLiveThemesSyncTest() : LiveThemesSyncTest(TWO_CLIENT) {} |
14 virtual ~TwoClientLiveThemesSyncTest() {} | 12 virtual ~TwoClientLiveThemesSyncTest() {} |
15 | 13 |
16 private: | 14 private: |
17 DISALLOW_COPY_AND_ASSIGN(TwoClientLiveThemesSyncTest); | 15 DISALLOW_COPY_AND_ASSIGN(TwoClientLiveThemesSyncTest); |
18 }; | 16 }; |
19 | 17 |
20 // TODO(akalin): Add tests for model association (i.e., tests that | 18 // TODO(akalin): Add tests for model association (i.e., tests that |
21 // start with SetupClients(), change the theme state, then call | 19 // start with SetupClients(), change the theme state, then call |
22 // SetupSync()). | 20 // SetupSync()). |
23 | 21 |
24 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomTheme) { | 22 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomTheme) { |
25 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 23 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
26 | 24 |
27 ASSERT_EQ(NULL, GetCustomTheme(GetProfile(0))); | 25 ASSERT_FALSE(UsingCustomTheme(GetProfile(0))); |
28 ASSERT_EQ(NULL, GetCustomTheme(GetProfile(1))); | 26 ASSERT_FALSE(UsingCustomTheme(GetProfile(1))); |
29 ASSERT_EQ(NULL, GetCustomTheme(verifier())); | 27 ASSERT_FALSE(UsingCustomTheme(verifier())); |
30 | 28 |
31 SetTheme(GetProfile(0), GetTheme(0)); | 29 UseCustomTheme(GetProfile(0), 0); |
32 SetTheme(verifier(), GetTheme(0)); | 30 UseCustomTheme(verifier(), 0); |
33 ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); | 31 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0))); |
34 ASSERT_EQ(NULL, GetCustomTheme(GetProfile(1))); | 32 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier())); |
35 ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); | |
36 | 33 |
37 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 34 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
38 | 35 |
39 ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); | 36 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0))); |
| 37 ASSERT_FALSE(UsingCustomTheme(GetProfile(1))); |
40 // TODO(akalin): Add functions to simulate when a pending extension | 38 // TODO(akalin): Add functions to simulate when a pending extension |
41 // is installed as well as when a pending extension fails to | 39 // is installed as well as when a pending extension fails to |
42 // install. | 40 // install. |
43 ASSERT_TRUE(ExtensionIsPendingInstall(GetProfile(1), GetTheme(0))); | 41 ASSERT_TRUE(ThemeIsPendingInstall(GetProfile(1), GetCustomTheme(0))); |
44 ASSERT_EQ(GetTheme(0), GetCustomTheme(verifier())); | 42 ASSERT_EQ(GetCustomTheme(0), GetThemeID(verifier())); |
45 } | 43 } |
46 | 44 |
47 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeTheme) { | 45 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeTheme) { |
48 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 46 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
49 | 47 |
50 SetTheme(GetProfile(0), GetTheme(0)); | 48 UseCustomTheme(GetProfile(0), 0); |
51 SetTheme(GetProfile(1), GetTheme(0)); | 49 UseCustomTheme(GetProfile(1), 0); |
52 SetTheme(verifier(), GetTheme(0)); | 50 UseCustomTheme(verifier(), 0); |
53 | 51 |
54 ASSERT_TRUE(AwaitQuiescence()); | 52 ASSERT_TRUE(AwaitQuiescence()); |
55 | 53 |
56 SetNativeTheme(GetProfile(0)); | 54 UseNativeTheme(GetProfile(0)); |
57 SetNativeTheme(verifier()); | 55 UseNativeTheme(verifier()); |
58 ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); | 56 ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); |
59 ASSERT_FALSE(UsingNativeTheme(GetProfile(1))); | |
60 ASSERT_TRUE(UsingNativeTheme(verifier())); | 57 ASSERT_TRUE(UsingNativeTheme(verifier())); |
61 | 58 |
62 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 59 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
63 | 60 |
64 ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); | 61 ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); |
65 ASSERT_TRUE(UsingNativeTheme(GetProfile(1))); | 62 ASSERT_TRUE(UsingNativeTheme(GetProfile(1))); |
66 ASSERT_TRUE(UsingNativeTheme(verifier())); | 63 ASSERT_TRUE(UsingNativeTheme(verifier())); |
67 } | 64 } |
68 | 65 |
69 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, DefaultTheme) { | 66 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, DefaultTheme) { |
70 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 67 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
71 | 68 |
72 SetTheme(GetProfile(0), GetTheme(0)); | 69 UseCustomTheme(GetProfile(0), 0); |
73 SetTheme(GetProfile(1), GetTheme(0)); | 70 UseCustomTheme(GetProfile(1), 0); |
74 SetTheme(verifier(), GetTheme(0)); | 71 UseCustomTheme(verifier(), 0); |
75 | 72 |
76 ASSERT_TRUE(AwaitQuiescence()); | 73 ASSERT_TRUE(AwaitQuiescence()); |
77 | 74 |
78 UseDefaultTheme(GetProfile(0)); | 75 UseDefaultTheme(GetProfile(0)); |
79 UseDefaultTheme(verifier()); | 76 UseDefaultTheme(verifier()); |
80 ASSERT_TRUE(UsingDefaultTheme(GetProfile(0))); | 77 ASSERT_TRUE(UsingDefaultTheme(GetProfile(0))); |
81 ASSERT_FALSE(UsingDefaultTheme(GetProfile(1))); | |
82 ASSERT_TRUE(UsingDefaultTheme(verifier())); | 78 ASSERT_TRUE(UsingDefaultTheme(verifier())); |
83 | 79 |
84 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | 80 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); |
85 | 81 |
86 ASSERT_TRUE(UsingDefaultTheme(GetProfile(0))); | 82 ASSERT_TRUE(UsingDefaultTheme(GetProfile(0))); |
87 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1))); | 83 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1))); |
88 ASSERT_TRUE(UsingDefaultTheme(verifier())); | 84 ASSERT_TRUE(UsingDefaultTheme(verifier())); |
89 } | 85 } |
90 | 86 |
91 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeDefaultRace) { | 87 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, NativeDefaultRace) { |
92 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 88 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
93 | 89 |
94 SetNativeTheme(GetProfile(0)); | 90 UseNativeTheme(GetProfile(0)); |
95 UseDefaultTheme(GetProfile(1)); | 91 UseDefaultTheme(GetProfile(1)); |
96 ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); | 92 ASSERT_TRUE(UsingNativeTheme(GetProfile(0))); |
97 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1))); | 93 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1))); |
98 | 94 |
99 ASSERT_TRUE(AwaitQuiescence()); | 95 ASSERT_TRUE(AwaitQuiescence()); |
100 | 96 |
101 // TODO(akalin): Add function that compares two profiles to see if | 97 // TODO(akalin): Add function that compares two profiles to see if |
102 // they're at the same state. | 98 // they're at the same state. |
103 | 99 |
104 ASSERT_EQ(UsingNativeTheme(GetProfile(0)), | 100 ASSERT_EQ(UsingNativeTheme(GetProfile(0)), |
105 UsingNativeTheme(GetProfile(1))); | 101 UsingNativeTheme(GetProfile(1))); |
106 ASSERT_EQ(UsingDefaultTheme(GetProfile(0)), | 102 ASSERT_EQ(UsingDefaultTheme(GetProfile(0)), |
107 UsingDefaultTheme(GetProfile(1))); | 103 UsingDefaultTheme(GetProfile(1))); |
108 } | 104 } |
109 | 105 |
110 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomNativeRace) { | 106 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomNativeRace) { |
111 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 107 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
112 | 108 |
113 SetTheme(GetProfile(0), GetTheme(0)); | 109 UseCustomTheme(GetProfile(0), 0); |
114 SetNativeTheme(GetProfile(1)); | 110 UseNativeTheme(GetProfile(1)); |
115 ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); | 111 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0))); |
116 ASSERT_TRUE(UsingNativeTheme(GetProfile(1))); | 112 ASSERT_TRUE(UsingNativeTheme(GetProfile(1))); |
117 | 113 |
118 ASSERT_TRUE(AwaitQuiescence()); | 114 ASSERT_TRUE(AwaitQuiescence()); |
119 | 115 |
120 // TODO(akalin): Add function to wait for pending extensions to be | 116 // TODO(akalin): Add function to wait for pending extensions to be |
121 // installed. | 117 // installed. |
122 | 118 |
123 ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetTheme(0)), | 119 ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)), |
124 HasOrWillHaveCustomTheme(GetProfile(1), GetTheme(0))); | 120 HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0))); |
125 } | 121 } |
126 | 122 |
127 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomDefaultRace) { | 123 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomDefaultRace) { |
128 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 124 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
129 | 125 |
130 SetTheme(GetProfile(0), GetTheme(0)); | 126 UseCustomTheme(GetProfile(0), 0); |
131 UseDefaultTheme(GetProfile(1)); | 127 UseDefaultTheme(GetProfile(1)); |
132 ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); | 128 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0))); |
133 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1))); | 129 ASSERT_TRUE(UsingDefaultTheme(GetProfile(1))); |
134 | 130 |
135 ASSERT_TRUE(AwaitQuiescence()); | 131 ASSERT_TRUE(AwaitQuiescence()); |
136 | 132 |
137 ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetTheme(0)), | 133 ASSERT_EQ(HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(0)), |
138 HasOrWillHaveCustomTheme(GetProfile(1), GetTheme(0))); | 134 HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0))); |
139 } | 135 } |
140 | 136 |
141 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomCustomRace) { | 137 IN_PROC_BROWSER_TEST_F(TwoClientLiveThemesSyncTest, CustomCustomRace) { |
142 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 138 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
143 | 139 |
144 // TODO(akalin): Generalize this to n clients. | 140 // TODO(akalin): Generalize this to n clients. |
145 | 141 |
146 SetTheme(GetProfile(0), GetTheme(0)); | 142 UseCustomTheme(GetProfile(0), 0); |
147 SetTheme(GetProfile(1), GetTheme(1)); | 143 UseCustomTheme(GetProfile(1), 1); |
148 ASSERT_EQ(GetTheme(0), GetCustomTheme(GetProfile(0))); | 144 ASSERT_EQ(GetCustomTheme(0), GetThemeID(GetProfile(0))); |
149 ASSERT_EQ(GetTheme(1), GetCustomTheme(GetProfile(1))); | 145 ASSERT_EQ(GetCustomTheme(1), GetThemeID(GetProfile(1))); |
150 | 146 |
151 ASSERT_TRUE(AwaitQuiescence()); | 147 ASSERT_TRUE(AwaitQuiescence()); |
152 | 148 |
153 bool using_theme_0 = | 149 bool using_theme_0 = |
154 (GetCustomTheme(GetProfile(0)) == GetTheme(0)) && | 150 (GetThemeID(GetProfile(0)) == GetCustomTheme(0)) && |
155 HasOrWillHaveCustomTheme(GetProfile(1), GetTheme(0)); | 151 HasOrWillHaveCustomTheme(GetProfile(1), GetCustomTheme(0)); |
156 bool using_theme_1 = | 152 bool using_theme_1 = |
157 HasOrWillHaveCustomTheme(GetProfile(0), GetTheme(1)) && | 153 HasOrWillHaveCustomTheme(GetProfile(0), GetCustomTheme(1)) && |
158 (GetCustomTheme(GetProfile(1)) == GetTheme(1)); | 154 (GetThemeID(GetProfile(1)) == GetCustomTheme(1)); |
159 | 155 |
160 // Equivalent to using_theme_0 xor using_theme_1. | 156 // Equivalent to using_theme_0 xor using_theme_1. |
161 ASSERT_NE(using_theme_0, using_theme_1); | 157 ASSERT_NE(using_theme_0, using_theme_1); |
162 } | 158 } |
OLD | NEW |