OLD | NEW |
| (Empty) |
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/stringprintf.h" | |
6 #include "chrome/browser/profiles/profile.h" | |
7 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
8 #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/sync_datatype_helper.h" | |
11 #include "chrome/browser/sync/test/integration/sync_test.h" | |
12 | |
13 namespace { | |
14 | |
15 using extension_settings_helper::SetExtensionSettings; | |
16 using extension_settings_helper::SetExtensionSettingsForAllProfiles; | |
17 using extension_settings_helper::AllExtensionSettingsSameAsVerifier; | |
18 using extensions_helper::InstallExtension; | |
19 using sync_datatype_helper::test; | |
20 | |
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 | |
28 // unfortuately we can't test existing configurations of the sync server since | |
29 // the tests don't support that. | |
30 void MutateSomeSettings( | |
31 int seed, // used to modify the mutation values, not keys. | |
32 const std::string& extension0, | |
33 const std::string& extension1, | |
34 const std::string& extension2) { | |
35 { | |
36 // Write to extension0 from profile 0 but not profile 1. | |
37 DictionaryValue settings; | |
38 settings.SetString("asdf", StringPrintf("asdfasdf-%d", seed)); | |
39 SetExtensionSettings(test()->verifier(), extension0, settings); | |
40 SetExtensionSettings(test()->GetProfile(0), extension0, settings); | |
41 } | |
42 { | |
43 // Write the same data to extension1 from both profiles. | |
44 DictionaryValue settings; | |
45 settings.SetString("asdf", StringPrintf("asdfasdf-%d", seed)); | |
46 settings.SetString("qwer", StringPrintf("qwerqwer-%d", seed)); | |
47 SetExtensionSettingsForAllProfiles(extension1, settings); | |
48 } | |
49 { | |
50 // Write different data to extension2 from each profile. | |
51 DictionaryValue settings0; | |
52 settings0.SetString("zxcv", StringPrintf("zxcvzxcv-%d", seed)); | |
53 SetExtensionSettings(test()->verifier(), extension2, settings0); | |
54 SetExtensionSettings(test()->GetProfile(0), extension2, settings0); | |
55 | |
56 DictionaryValue settings1; | |
57 settings1.SetString("1324", StringPrintf("12341234-%d", seed)); | |
58 settings1.SetString("5687", StringPrintf("56785678-%d", seed)); | |
59 SetExtensionSettings(test()->verifier(), extension2, settings1); | |
60 SetExtensionSettings(test()->GetProfile(1), extension2, settings1); | |
61 } | |
62 } | |
63 | |
64 class TwoClientExtensionSettingsSyncTest : public SyncTest { | |
65 public: | |
66 TwoClientExtensionSettingsSyncTest() : SyncTest(TWO_CLIENT) {} | |
67 virtual ~TwoClientExtensionSettingsSyncTest() {} | |
68 | |
69 private: | |
70 DISALLOW_COPY_AND_ASSIGN(TwoClientExtensionSettingsSyncTest); | |
71 }; | |
72 | |
73 // For three independent extensions: | |
74 // | |
75 // 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 | |
77 // settings, sync. | |
78 IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsSyncTest, | |
79 StartWithSameSettings) { | |
80 ASSERT_TRUE(SetupClients()); | |
81 | |
82 const std::string& extension0 = InstallExtensionForAllProfiles(0); | |
83 const std::string& extension1 = InstallExtensionForAllProfiles(1); | |
84 const std::string& extension2 = InstallExtensionForAllProfiles(2); | |
85 | |
86 { | |
87 // Leave extension0 empty. | |
88 } | |
89 { | |
90 DictionaryValue settings; | |
91 settings.SetString("foo", "bar"); | |
92 SetExtensionSettingsForAllProfiles(extension1, settings); | |
93 } | |
94 { | |
95 DictionaryValue settings; | |
96 settings.SetString("foo", "bar"); | |
97 settings.SetString("baz", "qux"); | |
98 SetExtensionSettingsForAllProfiles(extension2, settings); | |
99 } | |
100 | |
101 ASSERT_TRUE(SetupSync()); | |
102 ASSERT_TRUE(AwaitQuiescence()); | |
103 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | |
104 | |
105 MutateSomeSettings(0, extension0, extension1, extension2); | |
106 ASSERT_TRUE(AwaitQuiescence()); | |
107 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | |
108 | |
109 MutateSomeSettings(1, extension0, extension1, extension2); | |
110 ASSERT_TRUE(AwaitQuiescence()); | |
111 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | |
112 } | |
113 | |
114 // For three independent extensions: | |
115 // | |
116 // 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 // (non-)change to those settings, sync, mutate again, sync. | |
119 IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsSyncTest, | |
120 StartWithDifferentSettings) { | |
121 ASSERT_TRUE(SetupClients()); | |
122 | |
123 const std::string& extension0 = InstallExtensionForAllProfiles(0); | |
124 const std::string& extension1 = InstallExtensionForAllProfiles(1); | |
125 const std::string& extension2 = InstallExtensionForAllProfiles(2); | |
126 | |
127 { | |
128 // Leave extension0 empty again for no particular reason other than it's | |
129 // the only remaining unique combination given the other 2 tests have | |
130 // (empty, nonempty) and (nonempty, nonempty) configurations. We can't test | |
131 // (nonempty, nonempty) because the merging will provide unpredictable | |
132 // results, so test (empty, empty). | |
133 } | |
134 { | |
135 DictionaryValue settings; | |
136 settings.SetString("foo", "bar"); | |
137 SetExtensionSettings(test()->verifier(), extension1, settings); | |
138 SetExtensionSettings(test()->GetProfile(0), extension1, settings); | |
139 } | |
140 { | |
141 DictionaryValue settings; | |
142 settings.SetString("foo", "bar"); | |
143 settings.SetString("baz", "qux"); | |
144 SetExtensionSettings(test()->verifier(), extension2, settings); | |
145 SetExtensionSettings(test()->GetProfile(1), extension2, settings); | |
146 } | |
147 | |
148 ASSERT_TRUE(SetupSync()); | |
149 ASSERT_TRUE(AwaitQuiescence()); | |
150 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | |
151 | |
152 MutateSomeSettings(2, extension0, extension1, extension2); | |
153 ASSERT_TRUE(AwaitQuiescence()); | |
154 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | |
155 | |
156 MutateSomeSettings(3, extension0, extension1, extension2); | |
157 ASSERT_TRUE(AwaitQuiescence()); | |
158 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | |
159 | |
160 // 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. | |
162 MutateSomeSettings(3, extension0, extension1, extension2); | |
163 ASSERT_TRUE(AwaitQuiescence()); | |
164 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | |
165 | |
166 MutateSomeSettings(4, extension0, extension1, extension2); | |
167 ASSERT_TRUE(AwaitQuiescence()); | |
168 ASSERT_TRUE(AllExtensionSettingsSameAsVerifier()); | |
169 } | |
170 | |
171 } // namespace | |
OLD | NEW |