summaryrefslogtreecommitdiff
path: root/chrome/browser/sync/test/integration/two_client_extension_settings_and_app_settings_sync_test.cc
blob: 8de4565c96d8e58d99f9d59294a9c58b88720140 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/strings/stringprintf.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/test/integration/apps_helper.h"
#include "chrome/browser/sync/test/integration/extension_settings_helper.h"
#include "chrome/browser/sync/test/integration/extensions_helper.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"

namespace {

using apps_helper::InstallAppForAllProfiles;
using extension_settings_helper::AllExtensionSettingsSameAsVerifier;
using extension_settings_helper::SetExtensionSettings;
using extension_settings_helper::SetExtensionSettingsForAllProfiles;
using extensions_helper::InstallExtensionForAllProfiles;
using sync_datatype_helper::test;

// Generic mutations done after the initial setup of all tests. Note that
// unfortuately we can't test existing configurations of the sync server since
// the tests don't support that.
void MutateSomeSettings(
    int seed, // used to modify the mutation values, not keys.
    const std::string& extension0,
    const std::string& extension1,
    const std::string& extension2) {
  {
    // Write to extension0 from profile 0 but not profile 1.
    base::DictionaryValue settings;
    settings.SetString("asdf", base::StringPrintf("asdfasdf-%d", seed));
    SetExtensionSettings(test()->verifier(),    extension0, settings);
    SetExtensionSettings(test()->GetProfile(0), extension0, settings);
  }
  {
    // Write the same data to extension1 from both profiles.
    base::DictionaryValue settings;
    settings.SetString("asdf", base::StringPrintf("asdfasdf-%d", seed));
    settings.SetString("qwer", base::StringPrintf("qwerqwer-%d", seed));
    SetExtensionSettingsForAllProfiles(extension1, settings);
  }
  {
    // Write different data to extension2 from each profile.
    base::DictionaryValue settings0;
    settings0.SetString("zxcv", base::StringPrintf("zxcvzxcv-%d", seed));
    SetExtensionSettings(test()->verifier(),    extension2, settings0);
    SetExtensionSettings(test()->GetProfile(0), extension2, settings0);

    base::DictionaryValue settings1;
    settings1.SetString("1324", base::StringPrintf("12341234-%d", seed));
    settings1.SetString("5687", base::StringPrintf("56785678-%d", seed));
    SetExtensionSettings(test()->verifier(),    extension2, settings1);
    SetExtensionSettings(test()->GetProfile(1), extension2, settings1);
  }
}

class TwoClientExtensionSettingsAndAppSettingsSyncTest : public SyncTest {
 public:
  TwoClientExtensionSettingsAndAppSettingsSyncTest() : SyncTest(TWO_CLIENT) {}
  virtual ~TwoClientExtensionSettingsAndAppSettingsSyncTest() {}

 private:
  DISALLOW_COPY_AND_ASSIGN(TwoClientExtensionSettingsAndAppSettingsSyncTest);
};

// For three independent extensions:
//
// Set up each extension with the same (but not necessarily empty) settings for
// all profiles, start syncing, add some new settings, sync, mutate those
// settings, sync.
testing::AssertionResult StartWithSameSettingsTest(
    const std::string& extension0,
    const std::string& extension1,
    const std::string& extension2) {
  {
    // Leave extension0 empty.
  }
  {
    base::DictionaryValue settings;
    settings.SetString("foo", "bar");
    SetExtensionSettingsForAllProfiles(extension1, settings);
  }
  {
    base::DictionaryValue settings;
    settings.SetString("foo", "bar");
    settings.SetString("baz", "qux");
    SetExtensionSettingsForAllProfiles(extension2, settings);
  }

  if (!test()->SetupSync())
    return testing::AssertionFailure();
  if (!test()->AwaitQuiescence())
    return testing::AssertionFailure();
  if (!AllExtensionSettingsSameAsVerifier())
    return testing::AssertionFailure();

  MutateSomeSettings(0, extension0, extension1, extension2);
  if (!test()->AwaitQuiescence())
    return testing::AssertionFailure();
  if (!AllExtensionSettingsSameAsVerifier())
    return testing::AssertionFailure();

  MutateSomeSettings(1, extension0, extension1, extension2);
  if (!test()->AwaitQuiescence())
    return testing::AssertionFailure();
  if (!AllExtensionSettingsSameAsVerifier())
    return testing::AssertionFailure();

  return testing::AssertionSuccess();
}

// For three independent extensions:
//
// Set up each extension with different settings for each profile, start
// syncing, add some settings, sync, mutate those settings, sync, have a no-op
// (non-)change to those settings, sync, mutate again, sync.
testing::AssertionResult StartWithDifferentSettingsTest(
    const std::string& extension0,
    const std::string& extension1,
    const std::string& extension2) {
  {
    // Leave extension0 empty again for no particular reason other than it's
    // the only remaining unique combination given the other 2 tests have
    // (empty, nonempty) and (nonempty, nonempty) configurations. We can't test
    // (nonempty, nonempty) because the merging will provide unpredictable
    // results, so test (empty, empty).
  }
  {
    base::DictionaryValue settings;
    settings.SetString("foo", "bar");
    SetExtensionSettings(test()->verifier(), extension1, settings);
    SetExtensionSettings(test()->GetProfile(0), extension1, settings);
  }
  {
    base::DictionaryValue settings;
    settings.SetString("foo", "bar");
    settings.SetString("baz", "qux");
    SetExtensionSettings(test()->verifier(), extension2, settings);
    SetExtensionSettings(test()->GetProfile(1), extension2, settings);
  }

  if (!test()->SetupSync())
    return testing::AssertionFailure();
  if (!test()->AwaitQuiescence())
    return testing::AssertionFailure();
  if (!AllExtensionSettingsSameAsVerifier())
    return testing::AssertionFailure();

  MutateSomeSettings(2, extension0, extension1, extension2);
  if (!test()->AwaitQuiescence())
    return testing::AssertionFailure();
  if (!AllExtensionSettingsSameAsVerifier())
    return testing::AssertionFailure();

  MutateSomeSettings(3, extension0, extension1, extension2);
  if (!test()->AwaitQuiescence())
    return testing::AssertionFailure();
  if (!AllExtensionSettingsSameAsVerifier())
    return testing::AssertionFailure();

  // Test a round of no-ops once, for sanity. Ideally we'd want to assert that
  // this causes no sync activity, but that sounds tricky.
  MutateSomeSettings(3, extension0, extension1, extension2);
  if (!test()->AwaitQuiescence())
    return testing::AssertionFailure();
  if (!AllExtensionSettingsSameAsVerifier())
    return testing::AssertionFailure();

  MutateSomeSettings(4, extension0, extension1, extension2);
  if (!test()->AwaitQuiescence())
    return testing::AssertionFailure();
  if (!AllExtensionSettingsSameAsVerifier())
    return testing::AssertionFailure();

  return testing::AssertionSuccess();
}

IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsAndAppSettingsSyncTest,
                       ExtensionsStartWithSameSettings) {
  ASSERT_TRUE(SetupClients());
  ASSERT_PRED3(StartWithSameSettingsTest,
    InstallExtensionForAllProfiles(0),
    InstallExtensionForAllProfiles(1),
    InstallExtensionForAllProfiles(2)
  );
}

IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsAndAppSettingsSyncTest,
                       AppsStartWithSameSettings) {
  ASSERT_TRUE(SetupClients());
  ASSERT_PRED3(StartWithSameSettingsTest,
    InstallAppForAllProfiles(0),
    InstallAppForAllProfiles(1),
    InstallAppForAllProfiles(2)
  );
}

IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsAndAppSettingsSyncTest,
                       ExtensionsStartWithDifferentSettings) {
  ASSERT_TRUE(SetupClients());
  ASSERT_PRED3(StartWithDifferentSettingsTest,
    InstallExtensionForAllProfiles(0),
    InstallExtensionForAllProfiles(1),
    InstallExtensionForAllProfiles(2)
  );
}

IN_PROC_BROWSER_TEST_F(TwoClientExtensionSettingsAndAppSettingsSyncTest,
                       AppsStartWithDifferentSettings) {
  ASSERT_TRUE(SetupClients());
  ASSERT_PRED3(StartWithDifferentSettingsTest,
    InstallAppForAllProfiles(0),
    InstallAppForAllProfiles(1),
    InstallAppForAllProfiles(2)
  );
}

}  // namespace