Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / extensions / external_provider_impl_chromeos_unittest.cc
blob809e2e9f65939c968a4fa7cf3223293e0a0ebfce
1 // Copyright 2013 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.
5 #include "chrome/browser/extensions/external_provider_impl.h"
7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/test/scoped_path_override.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
12 #include "chrome/browser/chromeos/customization/customization_document.h"
13 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_service_test_base.h"
16 #include "chrome/browser/prefs/pref_service_syncable.h"
17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
19 #include "chrome/browser/signin/signin_manager_factory.h"
20 #include "chrome/browser/sync/profile_sync_service.h"
21 #include "chrome/browser/sync/profile_sync_service_factory.h"
22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_profile.h"
26 #include "chromeos/system/fake_statistics_provider.h"
27 #include "chromeos/system/statistics_provider.h"
28 #include "components/signin/core/browser/profile_oauth2_token_service.h"
29 #include "components/signin/core/browser/signin_manager_base.h"
30 #include "components/sync_driver/pref_names.h"
31 #include "components/user_manager/fake_user_manager.h"
32 #include "content/public/browser/notification_service.h"
33 #include "content/public/test/test_utils.h"
34 #include "sync/api/fake_sync_change_processor.h"
35 #include "sync/api/sync_change_processor.h"
36 #include "sync/api/sync_error_factory_mock.h"
38 namespace extensions {
40 namespace {
42 const char kExternalAppId[] = "kekdneafjmhmndejhmbcadfiiofngffo";
43 const char kStandaloneAppId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
45 class ExternalProviderImplChromeOSTest : public ExtensionServiceTestBase {
46 public:
47 ExternalProviderImplChromeOSTest()
48 : fake_user_manager_(new user_manager::FakeUserManager()),
49 scoped_user_manager_(fake_user_manager_) {}
51 ~ExternalProviderImplChromeOSTest() override {}
53 void InitServiceWithExternalProviders(bool standalone) {
54 InitializeEmptyExtensionService();
55 service_->Init();
57 if (standalone) {
58 external_externsions_overrides_.reset(new base::ScopedPathOverride(
59 chrome::DIR_STANDALONE_EXTERNAL_EXTENSIONS,
60 data_dir().Append("external_standalone")));
61 } else {
62 external_externsions_overrides_.reset(new base::ScopedPathOverride(
63 chrome::DIR_EXTERNAL_EXTENSIONS, data_dir().Append("external")));
66 ProviderCollection providers;
67 extensions::ExternalProviderImpl::CreateExternalProviders(
68 service_, profile_.get(), &providers);
70 for (ProviderCollection::iterator i = providers.begin();
71 i != providers.end();
72 ++i) {
73 service_->AddProviderForTesting(i->release());
77 // ExtensionServiceTestBase overrides:
78 void SetUp() override {
79 ExtensionServiceTestBase::SetUp();
82 void TearDown() override {
83 chromeos::KioskAppManager::Shutdown();
86 private:
87 scoped_ptr<base::ScopedPathOverride> external_externsions_overrides_;
88 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_;
89 user_manager::FakeUserManager* fake_user_manager_;
90 chromeos::ScopedUserManagerEnabler scoped_user_manager_;
92 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplChromeOSTest);
95 } // namespace
97 // Normal mode, external app should be installed.
98 TEST_F(ExternalProviderImplChromeOSTest, Normal) {
99 InitServiceWithExternalProviders(false);
101 service_->CheckForExternalUpdates();
102 content::WindowedNotificationObserver(
103 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
104 content::NotificationService::AllSources()).Wait();
106 EXPECT_TRUE(service_->GetInstalledExtension(kExternalAppId));
109 // App mode, no external app should be installed.
110 TEST_F(ExternalProviderImplChromeOSTest, AppMode) {
111 base::CommandLine* command = base::CommandLine::ForCurrentProcess();
112 command->AppendSwitchASCII(switches::kForceAppMode, std::string());
113 command->AppendSwitchASCII(switches::kAppId, std::string("app_id"));
115 InitServiceWithExternalProviders(false);
117 service_->CheckForExternalUpdates();
118 base::RunLoop().RunUntilIdle();
120 EXPECT_FALSE(service_->GetInstalledExtension(kExternalAppId));
123 // Normal mode, standalone app should be installed, because sync is enabled but
124 // not running.
125 TEST_F(ExternalProviderImplChromeOSTest, Standalone) {
126 InitServiceWithExternalProviders(true);
128 service_->CheckForExternalUpdates();
129 content::WindowedNotificationObserver(
130 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
131 content::NotificationService::AllSources()).Wait();
133 EXPECT_TRUE(service_->GetInstalledExtension(kStandaloneAppId));
136 // Normal mode, standalone app should be installed, because sync is disabled.
137 TEST_F(ExternalProviderImplChromeOSTest, SyncDisabled) {
138 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync);
140 InitServiceWithExternalProviders(true);
142 service_->CheckForExternalUpdates();
143 content::WindowedNotificationObserver(
144 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
145 content::NotificationService::AllSources()).Wait();
147 EXPECT_TRUE(service_->GetInstalledExtension(kStandaloneAppId));
150 // User signed in, sync service started, install app when sync is disabled by
151 // policy.
152 TEST_F(ExternalProviderImplChromeOSTest, PolicyDisabled) {
153 InitServiceWithExternalProviders(true);
155 // Log user in, start sync.
156 TestingBrowserProcess::GetGlobal()->SetProfileManager(
157 new ProfileManagerWithoutInit(temp_dir().path()));
158 SigninManagerBase* signin =
159 SigninManagerFactory::GetForProfile(profile_.get());
160 signin->SetAuthenticatedAccountInfo("gaia-id-test_user@gmail.com",
161 "test_user@gmail.com");
162 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get())
163 ->UpdateCredentials("test_user@gmail.com", "oauth2_login_token");
165 // App sync will wait for priority sync to complete.
166 service_->CheckForExternalUpdates();
168 // Sync is dsabled by policy.
169 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true);
171 content::WindowedNotificationObserver(
172 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
173 content::NotificationService::AllSources()).Wait();
175 EXPECT_TRUE(service_->GetInstalledExtension(kStandaloneAppId));
177 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
180 // User signed in, sync service started, install app when priority sync is
181 // completed.
182 TEST_F(ExternalProviderImplChromeOSTest, PriorityCompleted) {
183 InitServiceWithExternalProviders(true);
185 // User is logged in.
186 SigninManagerBase* signin =
187 SigninManagerFactory::GetForProfile(profile_.get());
188 signin->SetAuthenticatedAccountInfo("gaia-id-test_user@gmail.com",
189 "test_user@gmail.com");
191 // App sync will wait for priority sync to complete.
192 service_->CheckForExternalUpdates();
194 // Priority sync completed.
195 PrefServiceSyncable::FromProfile(profile_.get())
196 ->GetSyncableService(syncer::PRIORITY_PREFERENCES)
197 ->MergeDataAndStartSyncing(syncer::PRIORITY_PREFERENCES,
198 syncer::SyncDataList(),
199 scoped_ptr<syncer::SyncChangeProcessor>(
200 new syncer::FakeSyncChangeProcessor),
201 scoped_ptr<syncer::SyncErrorFactory>(
202 new syncer::SyncErrorFactoryMock()));
204 content::WindowedNotificationObserver(
205 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
206 content::NotificationService::AllSources()).Wait();
208 EXPECT_TRUE(service_->GetInstalledExtension(kStandaloneAppId));
211 } // namespace extensions