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 222 223
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "build/build_config.h"
#include "chrome/browser/extensions/scoped_test_mv2_enabler.h"
#include "chrome/browser/sync/test/integration/extensions_helper.h"
#include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "content/public/test/browser_test.h"
namespace {
using extensions_helper::AllProfilesHaveSameExtensions;
using extensions_helper::DisableExtension;
using extensions_helper::EnableExtension;
using extensions_helper::GetInstalledExtensions;
using extensions_helper::HasSameExtensions;
using extensions_helper::IncognitoDisableExtension;
using extensions_helper::IncognitoEnableExtension;
using extensions_helper::InstallExtension;
using extensions_helper::UninstallExtension;
class TwoClientExtensionsSyncTest : public SyncTest {
public:
TwoClientExtensionsSyncTest() : SyncTest(TWO_CLIENT) {}
~TwoClientExtensionsSyncTest() override = default;
bool TestUsesSelfNotifications() override { return false; }
private:
// TODO(https://crbug.com/40804030): Remove when these tests use only MV3
// extensions.
extensions::ScopedTestMV2Enabler mv2_enabler_;
};
IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
E2E_ENABLED(StartWithNoExtensions)) {
ASSERT_TRUE(ResetSyncForPrimaryAccount());
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
}
// Flaky on Mac: http://crbug.com/535996
#if BUILDFLAG(IS_MAC)
#define MAYBE_StartWithSameExtensions DISABLED_StartWithSameExtensions
#else
#define MAYBE_StartWithSameExtensions StartWithSameExtensions
#endif
IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
E2E_ENABLED(MAYBE_StartWithSameExtensions)) {
ASSERT_TRUE(ResetSyncForPrimaryAccount());
ASSERT_TRUE(SetupClients());
const int kNumExtensions = 5;
for (int i = 0; i < kNumExtensions; ++i) {
InstallExtension(GetProfile(0), i);
InstallExtension(GetProfile(1), i);
}
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
EXPECT_EQ(kNumExtensions,
static_cast<int>(GetInstalledExtensions(GetProfile(0)).size()));
}
// Flaky on Mac: http://crbug.com/535996
#if BUILDFLAG(IS_MAC)
#define MAYBE_StartWithDifferentExtensions DISABLED_StartWithDifferentExtensions
#else
#define MAYBE_StartWithDifferentExtensions StartWithDifferentExtensions
#endif
IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
E2E_ENABLED(MAYBE_StartWithDifferentExtensions)) {
ASSERT_TRUE(ResetSyncForPrimaryAccount());
ASSERT_TRUE(SetupClients());
int extension_index = 0;
const int kNumCommonExtensions = 5;
for (int i = 0; i < kNumCommonExtensions; ++extension_index, ++i) {
InstallExtension(GetProfile(0), extension_index);
InstallExtension(GetProfile(1), extension_index);
}
const int kNumProfile0Extensions = 10;
for (int i = 0; i < kNumProfile0Extensions; ++extension_index, ++i) {
InstallExtension(GetProfile(0), extension_index);
}
const int kNumProfile1Extensions = 10;
for (int i = 0; i < kNumProfile1Extensions; ++extension_index, ++i) {
InstallExtension(GetProfile(1), extension_index);
}
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
EXPECT_EQ(
kNumCommonExtensions + kNumProfile0Extensions + kNumProfile1Extensions,
static_cast<int>(GetInstalledExtensions(GetProfile(0)).size()));
}
IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
E2E_ENABLED(InstallDifferentExtensions)) {
ASSERT_TRUE(ResetSyncForPrimaryAccount());
ASSERT_TRUE(SetupClients());
int extension_index = 0;
const int kNumCommonExtensions = 5;
for (int i = 0; i < kNumCommonExtensions; ++extension_index, ++i) {
InstallExtension(GetProfile(0), extension_index);
InstallExtension(GetProfile(1), extension_index);
}
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
const int kNumProfile0Extensions = 10;
for (int i = 0; i < kNumProfile0Extensions; ++extension_index, ++i) {
InstallExtension(GetProfile(0), extension_index);
}
const int kNumProfile1Extensions = 10;
for (int i = 0; i < kNumProfile1Extensions; ++extension_index, ++i) {
InstallExtension(GetProfile(1), extension_index);
}
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
EXPECT_EQ(
kNumCommonExtensions + kNumProfile0Extensions + kNumProfile1Extensions,
static_cast<int>(GetInstalledExtensions(GetProfile(0)).size()));
}
IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest, E2E_ENABLED(Add)) {
ASSERT_TRUE(ResetSyncForPrimaryAccount());
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameExtensions());
InstallExtension(GetProfile(0), 0);
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
EXPECT_EQ(1u, GetInstalledExtensions(GetProfile(0)).size());
}
IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest, E2E_ENABLED(Uninstall)) {
ASSERT_TRUE(ResetSyncForPrimaryAccount());
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameExtensions());
InstallExtension(GetProfile(0), 0);
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
UninstallExtension(GetProfile(0), 0);
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
EXPECT_TRUE(GetInstalledExtensions(GetProfile(0)).empty());
}
IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
E2E_ENABLED(UpdateEnableDisableExtension)) {
ASSERT_TRUE(ResetSyncForPrimaryAccount());
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameExtensions());
InstallExtension(GetProfile(0), 0);
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
DisableExtension(GetProfile(0), 0);
ASSERT_FALSE(HasSameExtensions(0, 1));
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
EnableExtension(GetProfile(1), 0);
ASSERT_FALSE(HasSameExtensions(0, 1));
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
}
IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
E2E_ENABLED(UpdateIncognitoEnableDisable)) {
ASSERT_TRUE(ResetSyncForPrimaryAccount());
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AllProfilesHaveSameExtensions());
InstallExtension(GetProfile(0), 0);
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
IncognitoEnableExtension(GetProfile(0), 0);
ASSERT_FALSE(HasSameExtensions(0, 1));
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
IncognitoDisableExtension(GetProfile(1), 0);
ASSERT_FALSE(HasSameExtensions(0, 1));
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
}
// Regression test for bug 104399: ensure that an extension installed prior to
// setting up sync, when uninstalled, is also uninstalled from sync.
IN_PROC_BROWSER_TEST_F(TwoClientExtensionsSyncTest,
E2E_ENABLED(UninstallPreinstalledExtensions)) {
ASSERT_TRUE(ResetSyncForPrimaryAccount());
ASSERT_TRUE(SetupClients());
ASSERT_TRUE(AllProfilesHaveSameExtensions());
InstallExtension(GetProfile(0), 0);
ASSERT_TRUE(SetupSync());
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
ASSERT_EQ(1u, GetInstalledExtensions(GetProfile(0)).size());
UninstallExtension(GetProfile(0), 0);
ASSERT_TRUE(ExtensionsMatchChecker().Wait());
EXPECT_TRUE(GetInstalledExtensions(GetProfile(0)).empty());
}
// TODO(akalin): Add tests exercising:
// - Offline installation/uninstallation behavior
} // namespace
|