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/extensions/extension_service_unittest.h"
12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/browser/notification_service.h"
16 #include "content/public/test/test_utils.h"
18 namespace extensions
{
22 const char kExternalAppId
[] = "kekdneafjmhmndejhmbcadfiiofngffo";
24 class ExternalProviderImplChromeOSTest
: public ExtensionServiceTestBase
{
26 ExternalProviderImplChromeOSTest() {}
27 virtual ~ExternalProviderImplChromeOSTest() {}
29 void InitServiceWithExternalProviders() {
30 InitializeEmptyExtensionService();
33 ProviderCollection providers
;
34 extensions::ExternalProviderImpl::CreateExternalProviders(
35 service_
, profile_
.get(), &providers
);
37 for (ProviderCollection::iterator i
= providers
.begin();
40 service_
->AddProviderForTesting(i
->release());
44 // ExtensionServiceTestBase overrides:
45 virtual void SetUp() OVERRIDE
{
46 ExtensionServiceTestBase::SetUp();
48 external_externsions_overrides_
.reset(
49 new base::ScopedPathOverride(chrome::DIR_EXTERNAL_EXTENSIONS
,
50 data_dir_
.Append("external")));
54 scoped_ptr
<base::ScopedPathOverride
> external_externsions_overrides_
;
56 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplChromeOSTest
);
61 // Normal mode, external app should be installed.
62 TEST_F(ExternalProviderImplChromeOSTest
, Normal
) {
63 InitServiceWithExternalProviders();
65 service_
->CheckForExternalUpdates();
66 content::WindowedNotificationObserver(
67 chrome::NOTIFICATION_CRX_INSTALLER_DONE
,
68 content::NotificationService::AllSources()).Wait();
70 EXPECT_TRUE(service_
->GetInstalledExtension(kExternalAppId
));
73 // App mode, no external app should be installed.
74 TEST_F(ExternalProviderImplChromeOSTest
, AppMode
) {
75 CommandLine
* command
= CommandLine::ForCurrentProcess();
76 command
->AppendSwitchASCII(switches::kForceAppMode
, std::string());
77 command
->AppendSwitchASCII(switches::kAppId
, std::string("app_id"));
79 InitServiceWithExternalProviders();
81 service_
->CheckForExternalUpdates();
82 base::RunLoop().RunUntilIdle();
84 EXPECT_FALSE(service_
->GetInstalledExtension(kExternalAppId
));
87 } // namespace extensions