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