Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 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 "chrome/browser/extensions/external_provider_impl.h" |
| 6 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
Henrique Ferreiro | 3777026 | 2021-02-06 01:20:53 | [diff] [blame] | 9 | #include "ash/constants/ash_pref_names.h" |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 10 | #include "base/command_line.h" |
Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 11 | #include "base/memory/ptr_util.h" |
Arthur Sonzogni | 3939693 | 2023-04-24 09:41:33 | [diff] [blame] | 12 | #include "base/memory/raw_ptr.h" |
Gabriel Charette | 078e366 | 2017-08-28 22:59:04 | [diff] [blame] | 13 | #include "base/run_loop.h" |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 14 | #include "base/test/scoped_path_override.h" |
Yeunjoo Choi | 9190764 | 2021-04-16 13:18:19 | [diff] [blame] | 15 | #include "chrome/browser/ash/customization/customization_document.h" |
Henrique Ferreiro | 1ab7f12f | 2021-03-04 19:54:40 | [diff] [blame] | 16 | #include "chrome/browser/ash/login/users/fake_chrome_user_manager.h" |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 17 | #include "chrome/browser/extensions/extension_service.h" |
| 18 | #include "chrome/browser/extensions/extension_service_test_base.h" |
sdefresne | ed27d86b | 2015-09-14 11:02:38 | [diff] [blame] | 19 | #include "chrome/browser/prefs/pref_service_syncable_util.h" |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 20 | #include "chrome/browser/profiles/profile_manager.h" |
Antonio Gomes | 3953a3f | 2018-11-26 19:31:32 | [diff] [blame] | 21 | #include "chrome/browser/signin/identity_test_environment_profile_adaptor.h" |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 22 | #include "chrome/common/chrome_paths.h" |
| 23 | #include "chrome/common/chrome_switches.h" |
[email protected] | 9436582 | 2014-04-23 14:17:57 | [diff] [blame] | 24 | #include "chrome/test/base/testing_browser_process.h" |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 25 | #include "chrome/test/base/testing_profile.h" |
Yeunjoo Choi | a10bd86e | 2022-12-15 02:34:51 | [diff] [blame] | 26 | #include "chromeos/ash/components/system/fake_statistics_provider.h" |
| 27 | #include "chromeos/ash/components/system/statistics_provider.h" |
Victor Hugo Vianna Silva | a48aa01c | 2022-02-09 20:38:23 | [diff] [blame] | 28 | #include "components/sync/base/command_line_switches.h" |
Roman Sorokin | 25277a7 | 2022-09-21 13:34:01 | [diff] [blame] | 29 | #include "components/sync/base/model_type.h" |
maxbogue | 2f960e5 | 2016-10-07 01:24:15 | [diff] [blame] | 30 | #include "components/sync/base/pref_names.h" |
skym | 7160384 | 2016-10-10 18:17:31 | [diff] [blame] | 31 | #include "components/sync/model/sync_change_processor.h" |
Victor Hugo Vianna Silva | c331eeb9 | 2022-08-15 20:13:37 | [diff] [blame] | 32 | #include "components/sync/test/fake_sync_change_processor.h" |
maxbogue | ea16ff41 | 2016-10-28 16:35:29 | [diff] [blame] | 33 | #include "components/sync_preferences/pref_service_syncable.h" |
Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 34 | #include "components/user_manager/scoped_user_manager.h" |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 35 | #include "content/public/test/test_utils.h" |
David Bertoni | 9f897c9 | 2019-09-20 17:46:35 | [diff] [blame] | 36 | #include "extensions/browser/extension_registry.h" |
Daniel d'Andrada | 36b41a7 | 2022-10-31 09:59:56 | [diff] [blame] | 37 | #include "extensions/browser/test_extension_registry_observer.h" |
Roman Sorokin | c2400cc | 2021-09-20 21:08:21 | [diff] [blame] | 38 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 39 | |
| 40 | namespace extensions { |
| 41 | |
| 42 | namespace { |
| 43 | |
| 44 | const char kExternalAppId[] = "kekdneafjmhmndejhmbcadfiiofngffo"; |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 45 | const char kStandaloneAppId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
khmel | cb892d5 | 2018-01-06 03:01:40 | [diff] [blame] | 46 | const char kStandaloneChildAppId[] = "hcglmfcclpfgljeaiahehebeoaiicbko"; |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 47 | |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 48 | const char kTestUserAccount[] = "user@test"; |
| 49 | |
[email protected] | e1d2ac7a | 2013-11-14 19:18:23 | [diff] [blame] | 50 | class ExternalProviderImplChromeOSTest : public ExtensionServiceTestBase { |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 51 | public: |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 52 | ExternalProviderImplChromeOSTest() |
Henrique Ferreiro | 4c2fc0a | 2021-03-26 10:42:47 | [diff] [blame] | 53 | : fake_user_manager_(new ash::FakeChromeUserManager()), |
Arthur Sonzogni | 3939693 | 2023-04-24 09:41:33 | [diff] [blame] | 54 | scoped_user_manager_(base::WrapUnique(fake_user_manager_.get())) {} |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 55 | |
Peter Boström | 53c6c595 | 2021-09-17 09:41:26 | [diff] [blame] | 56 | ExternalProviderImplChromeOSTest(const ExternalProviderImplChromeOSTest&) = |
| 57 | delete; |
| 58 | ExternalProviderImplChromeOSTest& operator=( |
| 59 | const ExternalProviderImplChromeOSTest&) = delete; |
| 60 | |
dcheng | 6d888df | 2015-01-16 18:12:48 | [diff] [blame] | 61 | ~ExternalProviderImplChromeOSTest() override {} |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 62 | |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 63 | void InitServiceWithExternalProviders(bool standalone) { |
khmel | cb892d5 | 2018-01-06 03:01:40 | [diff] [blame] | 64 | InitServiceWithExternalProvidersAndUserType(standalone, |
| 65 | false /* is_child */); |
| 66 | } |
| 67 | |
| 68 | void InitServiceWithExternalProvidersAndUserType(bool standalone, |
| 69 | bool is_child) { |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 70 | InitializeEmptyExtensionService(); |
khmel | cb892d5 | 2018-01-06 03:01:40 | [diff] [blame] | 71 | |
Edman Anjos | 0f2ad56 | 2023-11-08 10:40:49 | [diff] [blame] | 72 | if (is_child) { |
Aga Wronska | 9139e6cb | 2022-02-11 19:44:22 | [diff] [blame] | 73 | profile_->SetIsSupervisedProfile(); |
Edman Anjos | 0f2ad56 | 2023-11-08 10:40:49 | [diff] [blame] | 74 | } |
khmel | cb892d5 | 2018-01-06 03:01:40 | [diff] [blame] | 75 | |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 76 | service_->Init(); |
| 77 | |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 78 | if (standalone) { |
Peter Boström | 6b70182 | 2021-04-15 03:53:08 | [diff] [blame] | 79 | external_externsions_overrides_ = |
| 80 | std::make_unique<base::ScopedPathOverride>( |
| 81 | chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS, |
| 82 | data_dir().Append("external_standalone")); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 83 | } else { |
Peter Boström | 6b70182 | 2021-04-15 03:53:08 | [diff] [blame] | 84 | external_externsions_overrides_ = |
| 85 | std::make_unique<base::ScopedPathOverride>( |
| 86 | chrome::DIR_EXTERNAL_EXTENSIONS, data_dir().Append("external")); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 87 | } |
| 88 | |
Glen Robertson | afe91c7e | 2022-10-21 01:06:24 | [diff] [blame] | 89 | // This switch is set when creating a TestingProfile, but needs to be |
| 90 | // removed for some ExternalProviders to be created. |
| 91 | base::CommandLine::ForCurrentProcess()->RemoveSwitch( |
| 92 | switches::kDisableDefaultApps); |
| 93 | |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 94 | ProviderCollection providers; |
Emilia Paz | 2342695f | 2023-11-21 18:40:06 | [diff] [blame] | 95 | ExternalProviderImpl::CreateExternalProviders(service_, profile_.get(), |
| 96 | &providers); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 97 | |
Edman Anjos | 0f2ad56 | 2023-11-08 10:40:49 | [diff] [blame] | 98 | for (std::unique_ptr<ExternalProviderInterface>& provider : providers) { |
lazyboy | f33109d | 2016-08-31 00:37:08 | [diff] [blame] | 99 | service_->AddProviderForTesting(std::move(provider)); |
Edman Anjos | 0f2ad56 | 2023-11-08 10:40:49 | [diff] [blame] | 100 | } |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // ExtensionServiceTestBase overrides: |
Edman Anjos | 0f2ad56 | 2023-11-08 10:40:49 | [diff] [blame] | 104 | void SetUp() override { ExtensionServiceTestBase::SetUp(); } |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 105 | |
dcheng | 6d888df | 2015-01-16 18:12:48 | [diff] [blame] | 106 | void TearDown() override { |
Jay Civelli | e8323f73 | 2018-01-24 23:01:25 | [diff] [blame] | 107 | // If some extensions are being installed (on a background thread) and we |
| 108 | // stop before the intsallation is complete, some installation related |
| 109 | // objects might be leaked (as the background thread won't block on exit and |
| 110 | // finish cleanly). |
| 111 | // So ensure we let pending extension installations finish. |
| 112 | WaitForPendingStandaloneExtensionsInstalled(); |
Christian Dullweber | 64d38d08 | 2018-02-02 14:06:31 | [diff] [blame] | 113 | ExtensionServiceTestBase::TearDown(); |
[email protected] | f0aaf2c | 2014-03-07 01:12:23 | [diff] [blame] | 114 | } |
| 115 | |
khmel | cb892d5 | 2018-01-06 03:01:40 | [diff] [blame] | 116 | // Waits until all possible standalone extensions are installed. |
| 117 | void WaitForPendingStandaloneExtensionsInstalled() { |
| 118 | service_->CheckForExternalUpdates(); |
| 119 | base::RunLoop().RunUntilIdle(); |
Emilia Paz | 2342695f | 2023-11-21 18:40:06 | [diff] [blame] | 120 | PendingExtensionManager* const pending_extension_manager = |
khmel | cb892d5 | 2018-01-06 03:01:40 | [diff] [blame] | 121 | service_->pending_extension_manager(); |
| 122 | while (pending_extension_manager->IsIdPending(kStandaloneAppId) || |
| 123 | pending_extension_manager->IsIdPending(kStandaloneChildAppId)) { |
| 124 | base::RunLoop().RunUntilIdle(); |
| 125 | } |
| 126 | } |
| 127 | |
amraboelkher | 359f873 | 2022-03-01 15:31:37 | [diff] [blame] | 128 | void ValidateExternalProviderCountInAppMode(size_t expected_count) { |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 129 | base::CommandLine* command = base::CommandLine::ForCurrentProcess(); |
| 130 | command->AppendSwitchASCII(switches::kForceAppMode, std::string()); |
| 131 | command->AppendSwitchASCII(switches::kAppId, std::string("app_id")); |
| 132 | |
| 133 | InitializeEmptyExtensionService(); |
| 134 | |
| 135 | ProviderCollection providers; |
Emilia Paz | 2342695f | 2023-11-21 18:40:06 | [diff] [blame] | 136 | ExternalProviderImpl::CreateExternalProviders(service_, profile_.get(), |
| 137 | &providers); |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 138 | |
| 139 | EXPECT_EQ(providers.size(), expected_count); |
| 140 | } |
| 141 | |
Henrique Ferreiro | 4c2fc0a | 2021-03-26 10:42:47 | [diff] [blame] | 142 | ash::FakeChromeUserManager* fake_user_manager() const { |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 143 | return fake_user_manager_; |
| 144 | } |
| 145 | |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 146 | private: |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 147 | std::unique_ptr<base::ScopedPathOverride> external_externsions_overrides_; |
Yeunjoo Choi | 46289671 | 2022-12-20 01:15:40 | [diff] [blame] | 148 | ash::system::ScopedFakeStatisticsProvider fake_statistics_provider_; |
Arthur Sonzogni | ebfd4c1 | 2023-08-18 08:03:35 | [diff] [blame] | 149 | raw_ptr<ash::FakeChromeUserManager, DanglingUntriaged | ExperimentalAsh> |
| 150 | fake_user_manager_; |
Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 151 | user_manager::ScopedUserManager scoped_user_manager_; |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | } // namespace |
| 155 | |
| 156 | // Normal mode, external app should be installed. |
[email protected] | e1d2ac7a | 2013-11-14 19:18:23 | [diff] [blame] | 157 | TEST_F(ExternalProviderImplChromeOSTest, Normal) { |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 158 | InitServiceWithExternalProviders(false); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 159 | |
Elly Fong-Jones | bb330bc | 2023-07-20 23:44:18 | [diff] [blame] | 160 | TestExtensionRegistryObserver observer(registry(), kExternalAppId); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 161 | |
Daniel d'Andrada | 36b41a7 | 2022-10-31 09:59:56 | [diff] [blame] | 162 | service_->CheckForExternalUpdates(); |
| 163 | |
| 164 | scoped_refptr<const Extension> loaded_extension = |
| 165 | observer.WaitForExtensionLoaded(); |
| 166 | |
| 167 | EXPECT_EQ(loaded_extension->id(), kExternalAppId); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | // App mode, no external app should be installed. |
[email protected] | e1d2ac7a | 2013-11-14 19:18:23 | [diff] [blame] | 171 | TEST_F(ExternalProviderImplChromeOSTest, AppMode) { |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 172 | base::CommandLine* command = base::CommandLine::ForCurrentProcess(); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 173 | command->AppendSwitchASCII(switches::kForceAppMode, std::string()); |
| 174 | command->AppendSwitchASCII(switches::kAppId, std::string("app_id")); |
| 175 | |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 176 | InitServiceWithExternalProviders(false); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 177 | |
| 178 | service_->CheckForExternalUpdates(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 179 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 180 | |
David Bertoni | 9f897c9 | 2019-09-20 17:46:35 | [diff] [blame] | 181 | EXPECT_FALSE(registry()->GetInstalledExtension(kExternalAppId)); |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 182 | } |
| 183 | |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 184 | // Normal mode, standalone app should be installed, because sync is enabled but |
| 185 | // not running. |
Steven Holte | e104d49 | 2018-06-19 20:24:31 | [diff] [blame] | 186 | // flaky: crbug.com/854206 |
| 187 | TEST_F(ExternalProviderImplChromeOSTest, DISABLED_Standalone) { |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 188 | InitServiceWithExternalProviders(true); |
| 189 | |
khmel | cb892d5 | 2018-01-06 03:01:40 | [diff] [blame] | 190 | WaitForPendingStandaloneExtensionsInstalled(); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 191 | |
David Bertoni | 9f897c9 | 2019-09-20 17:46:35 | [diff] [blame] | 192 | EXPECT_TRUE(registry()->GetInstalledExtension(kStandaloneAppId)); |
khmel | cb892d5 | 2018-01-06 03:01:40 | [diff] [blame] | 193 | // Also include apps available for child. |
David Bertoni | 9f897c9 | 2019-09-20 17:46:35 | [diff] [blame] | 194 | EXPECT_TRUE(registry()->GetInstalledExtension(kStandaloneChildAppId)); |
khmel | cb892d5 | 2018-01-06 03:01:40 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | // Should include only subset of default apps |
Steven Holte | e104d49 | 2018-06-19 20:24:31 | [diff] [blame] | 198 | // flaky: crbug.com/854206 |
| 199 | TEST_F(ExternalProviderImplChromeOSTest, DISABLED_StandaloneChild) { |
khmel | cb892d5 | 2018-01-06 03:01:40 | [diff] [blame] | 200 | InitServiceWithExternalProvidersAndUserType(true /* standalone */, |
| 201 | true /* is_child */); |
| 202 | |
| 203 | WaitForPendingStandaloneExtensionsInstalled(); |
| 204 | |
| 205 | // kStandaloneAppId is not available for child. |
David Bertoni | 9f897c9 | 2019-09-20 17:46:35 | [diff] [blame] | 206 | EXPECT_FALSE(registry()->GetInstalledExtension(kStandaloneAppId)); |
| 207 | EXPECT_TRUE(registry()->GetInstalledExtension(kStandaloneChildAppId)); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | // Normal mode, standalone app should be installed, because sync is disabled. |
Daniel d'Andrada | 36b41a7 | 2022-10-31 09:59:56 | [diff] [blame] | 211 | TEST_F(ExternalProviderImplChromeOSTest, SyncDisabled) { |
Victor Hugo Vianna Silva | 3cd7ae9 | 2022-02-09 20:49:51 | [diff] [blame] | 212 | base::CommandLine::ForCurrentProcess()->AppendSwitch(syncer::kDisableSync); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 213 | |
| 214 | InitServiceWithExternalProviders(true); |
| 215 | |
Elly Fong-Jones | bb330bc | 2023-07-20 23:44:18 | [diff] [blame] | 216 | TestExtensionRegistryObserver observer(registry(), kStandaloneAppId); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 217 | |
Daniel d'Andrada | 36b41a7 | 2022-10-31 09:59:56 | [diff] [blame] | 218 | service_->CheckForExternalUpdates(); |
| 219 | |
| 220 | scoped_refptr<const Extension> loaded_extension = |
| 221 | observer.WaitForExtensionLoaded(); |
| 222 | EXPECT_EQ(loaded_extension->id(), kStandaloneAppId); |
David Bertoni | 9f897c9 | 2019-09-20 17:46:35 | [diff] [blame] | 223 | EXPECT_TRUE(registry()->GetInstalledExtension(kStandaloneAppId)); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | // User signed in, sync service started, install app when sync is disabled by |
| 227 | // policy. |
Daniel d'Andrada | 36b41a7 | 2022-10-31 09:59:56 | [diff] [blame] | 228 | TEST_F(ExternalProviderImplChromeOSTest, PolicyDisabled) { |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 229 | InitServiceWithExternalProviders(true); |
| 230 | |
| 231 | // Log user in, start sync. |
| 232 | TestingBrowserProcess::GetGlobal()->SetProfileManager( |
Alex Ilin | 036866e | 2021-04-22 18:40:49 | [diff] [blame] | 233 | std::make_unique<ProfileManagerWithoutInit>(temp_dir().GetPath())); |
Antonio Gomes | 3953a3f | 2018-11-26 19:31:32 | [diff] [blame] | 234 | |
| 235 | auto identity_test_env_profile_adaptor = |
| 236 | std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile()); |
| 237 | identity_test_env_profile_adaptor->identity_test_env() |
Tanmoy Mollik | aa34c12 | 2021-06-04 13:12:29 | [diff] [blame] | 238 | ->MakePrimaryAccountAvailable("[email protected]", |
| 239 | signin::ConsentLevel::kSync); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 240 | |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 241 | // Sync is dsabled by policy. |
Marc Treib | 3d2c9c6 | 2023-05-12 14:48:59 | [diff] [blame] | 242 | profile_->GetPrefs()->SetBoolean(syncer::prefs::internal::kSyncManaged, true); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 243 | |
Elly Fong-Jones | bb330bc | 2023-07-20 23:44:18 | [diff] [blame] | 244 | TestExtensionRegistryObserver observer(registry(), kStandaloneAppId); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 245 | |
Daniel d'Andrada | 36b41a7 | 2022-10-31 09:59:56 | [diff] [blame] | 246 | // App sync will wait for priority sync to complete. |
| 247 | service_->CheckForExternalUpdates(); |
| 248 | |
| 249 | scoped_refptr<const Extension> loaded_extension = |
| 250 | observer.WaitForExtensionLoaded(); |
| 251 | EXPECT_EQ(loaded_extension->id(), kStandaloneAppId); |
David Bertoni | 9f897c9 | 2019-09-20 17:46:35 | [diff] [blame] | 252 | EXPECT_TRUE(registry()->GetInstalledExtension(kStandaloneAppId)); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 253 | |
Alex Ilin | 036866e | 2021-04-22 18:40:49 | [diff] [blame] | 254 | TestingBrowserProcess::GetGlobal()->SetProfileManager(nullptr); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | // User signed in, sync service started, install app when priority sync is |
| 258 | // completed. |
Daniel d'Andrada | 36b41a7 | 2022-10-31 09:59:56 | [diff] [blame] | 259 | TEST_F(ExternalProviderImplChromeOSTest, PriorityCompleted) { |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 260 | InitServiceWithExternalProviders(true); |
| 261 | |
| 262 | // User is logged in. |
Antonio Gomes | 3953a3f | 2018-11-26 19:31:32 | [diff] [blame] | 263 | auto identity_test_env_profile_adaptor = |
| 264 | std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile()); |
| 265 | identity_test_env_profile_adaptor->identity_test_env()->SetPrimaryAccount( |
Tanmoy Mollik | ac233b04 | 2021-05-22 12:17:47 | [diff] [blame] | 266 | "[email protected]", signin::ConsentLevel::kSync); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 267 | |
James Cook | b322e08 | 2020-05-27 16:29:11 | [diff] [blame] | 268 | // OOBE screen completed with OS sync enabled. |
| 269 | PrefService* prefs = profile()->GetPrefs(); |
Yeunjoo Choi | 0c8273a | 2022-11-29 04:22:50 | [diff] [blame] | 270 | prefs->SetBoolean(ash::prefs::kSyncOobeCompleted, true); |
James Cook | b322e08 | 2020-05-27 16:29:11 | [diff] [blame] | 271 | |
Elly Fong-Jones | bb330bc | 2023-07-20 23:44:18 | [diff] [blame] | 272 | TestExtensionRegistryObserver observer(registry(), kStandaloneAppId); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 273 | |
| 274 | // Priority sync completed. |
James Cook | b322e08 | 2020-05-27 16:29:11 | [diff] [blame] | 275 | PrefServiceSyncableFromProfile(profile()) |
Roman Sorokin | 25277a7 | 2022-09-21 13:34:01 | [diff] [blame] | 276 | ->GetSyncableService(syncer::OS_PRIORITY_PREFERENCES) |
James Cook | b322e08 | 2020-05-27 16:29:11 | [diff] [blame] | 277 | ->MergeDataAndStartSyncing( |
Roman Sorokin | 25277a7 | 2022-09-21 13:34:01 | [diff] [blame] | 278 | syncer::OS_PRIORITY_PREFERENCES, syncer::SyncDataList(), |
Marc Treib | 7bf627d | 2023-01-18 18:17:56 | [diff] [blame] | 279 | std::make_unique<syncer::FakeSyncChangeProcessor>()); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 280 | |
Daniel d'Andrada | 36b41a7 | 2022-10-31 09:59:56 | [diff] [blame] | 281 | // App sync will wait for priority sync to complete. |
| 282 | service_->CheckForExternalUpdates(); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 283 | |
Daniel d'Andrada | 36b41a7 | 2022-10-31 09:59:56 | [diff] [blame] | 284 | scoped_refptr<const Extension> loaded_extension = |
| 285 | observer.WaitForExtensionLoaded(); |
| 286 | EXPECT_EQ(loaded_extension->id(), kStandaloneAppId); |
David Bertoni | 9f897c9 | 2019-09-20 17:46:35 | [diff] [blame] | 287 | EXPECT_TRUE(registry()->GetInstalledExtension(kStandaloneAppId)); |
ginkage | da30a3b | 2015-03-12 19:22:17 | [diff] [blame] | 288 | } |
| 289 | |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 290 | // Validate the external providers enabled in the Chrome App Kiosk session. The |
| 291 | // expected number should be 3. |
| 292 | // - |policy_provider|. |
| 293 | // - |kiosk_app_provider|. |
| 294 | // - |secondary_kiosk_app_provider|. |
| 295 | TEST_F(ExternalProviderImplChromeOSTest, ChromeAppKiosk) { |
| 296 | const AccountId kiosk_account_id(AccountId::FromUserEmail(kTestUserAccount)); |
| 297 | fake_user_manager()->AddKioskAppUser(kiosk_account_id); |
| 298 | fake_user_manager()->LoginUser(kiosk_account_id); |
| 299 | |
amraboelkher | 359f873 | 2022-03-01 15:31:37 | [diff] [blame] | 300 | ValidateExternalProviderCountInAppMode(3u); |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | // Validate the external providers enabled in the ARC++ App Kiosk session. The |
| 304 | // expected number should be only 1. |
| 305 | // - |policy_provider|. |
| 306 | TEST_F(ExternalProviderImplChromeOSTest, ArcAppKiosk) { |
| 307 | const AccountId kiosk_account_id(AccountId::FromUserEmail(kTestUserAccount)); |
| 308 | fake_user_manager()->AddArcKioskAppUser(kiosk_account_id); |
| 309 | fake_user_manager()->LoginUser(kiosk_account_id); |
| 310 | |
amraboelkher | 359f873 | 2022-03-01 15:31:37 | [diff] [blame] | 311 | ValidateExternalProviderCountInAppMode(1u); |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | // Validate the external providers enabled in the Web App Kiosk session. The |
| 315 | // expected number should be only 1. |
| 316 | // - |policy_provider|. |
| 317 | TEST_F(ExternalProviderImplChromeOSTest, WebAppKiosk) { |
| 318 | const AccountId kiosk_account_id(AccountId::FromUserEmail(kTestUserAccount)); |
| 319 | fake_user_manager()->AddWebKioskAppUser(kiosk_account_id); |
| 320 | fake_user_manager()->LoginUser(kiosk_account_id); |
| 321 | |
amraboelkher | 359f873 | 2022-03-01 15:31:37 | [diff] [blame] | 322 | ValidateExternalProviderCountInAppMode(1u); |
Anqing Zhao | f0e96fb4 | 2020-12-11 23:21:21 | [diff] [blame] | 323 | } |
| 324 | |
[email protected] | 8a839a0 | 2013-03-07 05:23:33 | [diff] [blame] | 325 | } // namespace extensions |