OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/stringprintf.h" | 5 #include "base/stringprintf.h" |
6 #include "chrome/browser/profiles/profile.h" | 6 #include "chrome/browser/profiles/profile.h" |
7 #include "chrome/browser/sync/profile_sync_service_harness.h" | 7 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 8 #include "chrome/browser/sync/test/integration/apps_helper.h" |
8 #include "chrome/browser/sync/test/integration/extension_settings_helper.h" | 9 #include "chrome/browser/sync/test/integration/extension_settings_helper.h" |
9 #include "chrome/browser/sync/test/integration/extensions_helper.h" | 10 #include "chrome/browser/sync/test/integration/extensions_helper.h" |
10 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 11 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
11 #include "chrome/browser/sync/test/integration/sync_test.h" | 12 #include "chrome/browser/sync/test/integration/sync_test.h" |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
| 16 using apps_helper::InstallAppForAllProfiles; |
| 17 using extension_settings_helper::AllExtensionSettingsSameAsVerifier; |
15 using extension_settings_helper::SetExtensionSettings; | 18 using extension_settings_helper::SetExtensionSettings; |
16 using extension_settings_helper::SetExtensionSettingsForAllProfiles; | 19 using extension_settings_helper::SetExtensionSettingsForAllProfiles; |
17 using extension_settings_helper::AllExtensionSettingsSameAsVerifier; | 20 using extensions_helper::InstallExtensionForAllProfiles; |
18 using extensions_helper::InstallExtension; | |
19 using sync_datatype_helper::test; | 21 using sync_datatype_helper::test; |
20 | 22 |
21 std::string InstallExtensionForAllProfiles(int index) { | |
22 for (int i = 0; i < test()->num_clients(); ++i) | |
23 InstallExtension(test()->GetProfile(i), index); | |
24 return InstallExtension(test()->verifier(), index); | |
25 } | |
26 | |
27 // Generic mutations done after the initial setup of all tests. Note that | 23 // Generic mutations done after the initial setup of all tests. Note that |
28 // unfortuately we can't test existing configurations of the sync server since | 24 // unfortuately we can't test existing configurations of the sync server since |
29 // the tests don't support that. | 25 // the tests don't support that. |
30 void MutateSomeSettings( | 26 void MutateSomeSettings( |
31 int seed, // used to modify the mutation values, not keys. | 27 int seed, // used to modify the mutation values, not keys. |
32 const std::string& extension0, | 28 const std::string& extension0, |
33 const std::string& extension1, | 29 const std::string& extension1, |
34 const std::string& extension2) { | 30 const std::string& extension2) { |
35 { | 31 { |
36 // Write to extension0 from profile 0 but not profile 1. | 32 // Write to extension0 from profile 0 but not profile 1. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 64 |
69 private: | 65 private: |
70 DISALLOW_COPY_AND_ASSIGN(TwoClientExtensionSettingsSyncTest); | 66 DISALLOW_COPY_AND_ASSIGN(TwoClientExtensionSettingsSyncTest); |
71 }; | 67 }; |
72 | 68 |
73 // For three independent extensions: | 69 // For three independent extensions: |
74 // | 70 // |
75 // Set up each extension with the same (but not necessarily empty) settings for | 71 // Set up each extension with the same (but not necessarily empty) settings for |
76 // all profiles, start syncing, add some new settings, sync, mutate those | 72 // all profiles, start syncing, add some new settings, sync, mutate those |
77 // settings, sync. | 73 // settings, sync. |
78 IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsSyncTest, | 74 testing::AssertionResult StartWithSameSettingsTest( |
79 StartWithSameSettings) { | 75 const std::string& extension0, |
80 ASSERT_TRUE(SetupClients()); | 76 const std::string& extension1, |
81 | 77 const std::string& extension2) { |
82 const std::string& extension0 = InstallExtensionForAllProfiles(0); | |
83 const std::string& extension1 = InstallExtensionForAllProfiles(1); | |
84 const std::string& extension2 = InstallExtensionForAllProfiles(2); | |
85 | |
86 { | 78 { |
87 // Leave extension0 empty. | 79 // Leave extension0 empty. |
88 } | 80 } |
89 { | 81 { |
90 DictionaryValue settings; | 82 DictionaryValue settings; |
91 settings.SetString("foo", "bar"); | 83 settings.SetString("foo", "bar"); |
92 SetExtensionSettingsForAllProfiles(extension1, settings); | 84 SetExtensionSettingsForAllProfiles(extension1, settings); |
93 } | 85 } |
94 { | 86 { |
95 DictionaryValue settings; | 87 DictionaryValue settings; |
96 settings.SetString("foo", "bar"); | 88 settings.SetString("foo", "bar"); |
97 settings.SetString("baz", "qux"); | 89 settings.SetString("baz", "qux"); |
98 SetExtensionSettingsForAllProfiles(extension2, settings); | 90 SetExtensionSettingsForAllProfiles(extension2, settings); |
99 } | 91 } |
100 | 92 |
101 ASSERT_TRUE(SetupSync()); | 93 if (!test()->SetupSync()) |
102 ASSERT_TRUE(AwaitQuiescence()); | 94 return testing::AssertionFailure(); |
103 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | 95 if (!test()->AwaitQuiescence()) |
| 96 return testing::AssertionFailure(); |
| 97 if (!AllExtensionSettingsSameAsVerifier()) |
| 98 return testing::AssertionFailure(); |
104 | 99 |
105 MutateSomeSettings(0, extension0, extension1, extension2); | 100 MutateSomeSettings(0, extension0, extension1, extension2); |
106 ASSERT_TRUE(AwaitQuiescence()); | 101 if (!test()->AwaitQuiescence()) |
107 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | 102 return testing::AssertionFailure(); |
| 103 if (!AllExtensionSettingsSameAsVerifier()) |
| 104 return testing::AssertionFailure(); |
108 | 105 |
109 MutateSomeSettings(1, extension0, extension1, extension2); | 106 MutateSomeSettings(1, extension0, extension1, extension2); |
110 ASSERT_TRUE(AwaitQuiescence()); | 107 if (!test()->AwaitQuiescence()) |
111 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | 108 return testing::AssertionFailure(); |
| 109 if (!AllExtensionSettingsSameAsVerifier()) |
| 110 return testing::AssertionFailure(); |
| 111 |
| 112 return testing::AssertionSuccess(); |
112 } | 113 } |
113 | 114 |
114 // For three independent extensions: | 115 // For three independent extensions: |
115 // | 116 // |
116 // Set up each extension with different settings for each profile, start | 117 // Set up each extension with different settings for each profile, start |
117 // syncing, add some settings, sync, mutate those settings, sync, have a no-op | 118 // syncing, add some settings, sync, mutate those settings, sync, have a no-op |
118 // (non-)change to those settings, sync, mutate again, sync. | 119 // (non-)change to those settings, sync, mutate again, sync. |
119 IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsSyncTest, | 120 testing::AssertionResult StartWithDifferentSettingsTest( |
120 StartWithDifferentSettings) { | 121 const std::string& extension0, |
121 ASSERT_TRUE(SetupClients()); | 122 const std::string& extension1, |
122 | 123 const std::string& extension2) { |
123 const std::string& extension0 = InstallExtensionForAllProfiles(0); | |
124 const std::string& extension1 = InstallExtensionForAllProfiles(1); | |
125 const std::string& extension2 = InstallExtensionForAllProfiles(2); | |
126 | |
127 { | 124 { |
128 // Leave extension0 empty again for no particular reason other than it's | 125 // Leave extension0 empty again for no particular reason other than it's |
129 // the only remaining unique combination given the other 2 tests have | 126 // the only remaining unique combination given the other 2 tests have |
130 // (empty, nonempty) and (nonempty, nonempty) configurations. We can't test | 127 // (empty, nonempty) and (nonempty, nonempty) configurations. We can't test |
131 // (nonempty, nonempty) because the merging will provide unpredictable | 128 // (nonempty, nonempty) because the merging will provide unpredictable |
132 // results, so test (empty, empty). | 129 // results, so test (empty, empty). |
133 } | 130 } |
134 { | 131 { |
135 DictionaryValue settings; | 132 DictionaryValue settings; |
136 settings.SetString("foo", "bar"); | 133 settings.SetString("foo", "bar"); |
137 SetExtensionSettings(test()->verifier(), extension1, settings); | 134 SetExtensionSettings(test()->verifier(), extension1, settings); |
138 SetExtensionSettings(test()->GetProfile(0), extension1, settings); | 135 SetExtensionSettings(test()->GetProfile(0), extension1, settings); |
139 } | 136 } |
140 { | 137 { |
141 DictionaryValue settings; | 138 DictionaryValue settings; |
142 settings.SetString("foo", "bar"); | 139 settings.SetString("foo", "bar"); |
143 settings.SetString("baz", "qux"); | 140 settings.SetString("baz", "qux"); |
144 SetExtensionSettings(test()->verifier(), extension2, settings); | 141 SetExtensionSettings(test()->verifier(), extension2, settings); |
145 SetExtensionSettings(test()->GetProfile(1), extension2, settings); | 142 SetExtensionSettings(test()->GetProfile(1), extension2, settings); |
146 } | 143 } |
147 | 144 |
148 ASSERT_TRUE(SetupSync()); | 145 if (!test()->SetupSync()) |
149 ASSERT_TRUE(AwaitQuiescence()); | 146 return testing::AssertionFailure(); |
150 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | 147 if (!test()->AwaitQuiescence()) |
| 148 return testing::AssertionFailure(); |
| 149 if (!AllExtensionSettingsSameAsVerifier()) |
| 150 return testing::AssertionFailure(); |
151 | 151 |
152 MutateSomeSettings(2, extension0, extension1, extension2); | 152 MutateSomeSettings(2, extension0, extension1, extension2); |
153 ASSERT_TRUE(AwaitQuiescence()); | 153 if (!test()->AwaitQuiescence()) |
154 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | 154 return testing::AssertionFailure(); |
| 155 if (!AllExtensionSettingsSameAsVerifier()) |
| 156 return testing::AssertionFailure(); |
155 | 157 |
156 MutateSomeSettings(3, extension0, extension1, extension2); | 158 MutateSomeSettings(3, extension0, extension1, extension2); |
157 ASSERT_TRUE(AwaitQuiescence()); | 159 if (!test()->AwaitQuiescence()) |
158 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | 160 return testing::AssertionFailure(); |
| 161 if (!AllExtensionSettingsSameAsVerifier()) |
| 162 return testing::AssertionFailure(); |
159 | 163 |
160 // Test a round of no-ops once, for sanity. Ideally we'd want to assert that | 164 // Test a round of no-ops once, for sanity. Ideally we'd want to assert that |
161 // this causes no sync activity, but that sounds tricky. | 165 // this causes no sync activity, but that sounds tricky. |
162 MutateSomeSettings(3, extension0, extension1, extension2); | 166 MutateSomeSettings(3, extension0, extension1, extension2); |
163 ASSERT_TRUE(AwaitQuiescence()); | 167 if (!test()->AwaitQuiescence()) |
164 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | 168 return testing::AssertionFailure(); |
| 169 if (!AllExtensionSettingsSameAsVerifier()) |
| 170 return testing::AssertionFailure(); |
165 | 171 |
166 MutateSomeSettings(4, extension0, extension1, extension2); | 172 MutateSomeSettings(4, extension0, extension1, extension2); |
167 ASSERT_TRUE(AwaitQuiescence()); | 173 if (!test()->AwaitQuiescence()) |
168 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | 174 return testing::AssertionFailure(); |
| 175 if (!AllExtensionSettingsSameAsVerifier()) |
| 176 return testing::AssertionFailure(); |
| 177 |
| 178 return testing::AssertionSuccess(); |
| 179 } |
| 180 |
| 181 IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsSyncTest, |
| 182 ExtensionsStartWithSameSettings) { |
| 183 ASSERT_TRUE(SetupClients()); |
| 184 ASSERT_PRED3(StartWithSameSettingsTest, |
| 185 InstallExtensionForAllProfiles(0), |
| 186 InstallExtensionForAllProfiles(1), |
| 187 InstallExtensionForAllProfiles(2) |
| 188 ); |
| 189 } |
| 190 |
| 191 IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsSyncTest, |
| 192 AppsStartWithSameSettings) { |
| 193 ASSERT_TRUE(SetupClients()); |
| 194 ASSERT_PRED3(StartWithSameSettingsTest, |
| 195 InstallAppForAllProfiles(0), |
| 196 InstallAppForAllProfiles(1), |
| 197 InstallAppForAllProfiles(2) |
| 198 ); |
| 199 } |
| 200 |
| 201 IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsSyncTest, |
| 202 ExtensionsStartWithDifferentSettings) { |
| 203 ASSERT_TRUE(SetupClients()); |
| 204 ASSERT_PRED3(StartWithDifferentSettingsTest, |
| 205 InstallExtensionForAllProfiles(0), |
| 206 InstallExtensionForAllProfiles(1), |
| 207 InstallExtensionForAllProfiles(2) |
| 208 ); |
| 209 } |
| 210 |
| 211 IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsSyncTest, |
| 212 AppsStartWithDifferentSettings) { |
| 213 ASSERT_TRUE(SetupClients()); |
| 214 ASSERT_PRED3(StartWithDifferentSettingsTest, |
| 215 InstallAppForAllProfiles(0), |
| 216 InstallAppForAllProfiles(1), |
| 217 InstallAppForAllProfiles(2) |
| 218 ); |
169 } | 219 } |
170 | 220 |
171 } // namespace | 221 } // namespace |
OLD | NEW |