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 "chromeos/system/mock_statistics_provider.h"
16 #include "chromeos/system/statistics_provider.h"
17 #include "content/public/browser/notification_service.h"
18 #include "content/public/test/test_utils.h"
19 #include "testing/gmock/include/gmock/gmock.h"
22 using ::testing::NotNull;
23 using ::testing::Return;
25 namespace extensions {
29 const char kExternalAppId[] = "kekdneafjmhmndejhmbcadfiiofngffo";
31 class ExternalProviderImplChromeOSTest : public ExtensionServiceTestBase {
33 ExternalProviderImplChromeOSTest() {}
34 virtual ~ExternalProviderImplChromeOSTest() {}
36 void InitServiceWithExternalProviders() {
37 InitializeEmptyExtensionService();
40 ProviderCollection providers;
41 extensions::ExternalProviderImpl::CreateExternalProviders(
42 service_, profile_.get(), &providers);
44 for (ProviderCollection::iterator i = providers.begin();
47 service_->AddProviderForTesting(i->release());
51 // ExtensionServiceTestBase overrides:
52 virtual void SetUp() OVERRIDE {
53 ExtensionServiceTestBase::SetUp();
55 external_externsions_overrides_.reset(
56 new base::ScopedPathOverride(chrome::DIR_EXTERNAL_EXTENSIONS,
57 data_dir_.Append("external")));
59 chromeos::system::StatisticsProvider::SetTestProvider(
60 &mock_statistics_provider_);
61 EXPECT_CALL(mock_statistics_provider_, GetMachineStatistic(_, NotNull()))
62 .WillRepeatedly(Return(false));
65 virtual void TearDown() OVERRIDE {
66 chromeos::system::StatisticsProvider::SetTestProvider(NULL);
70 scoped_ptr<base::ScopedPathOverride> external_externsions_overrides_;
71 chromeos::system::MockStatisticsProvider mock_statistics_provider_;
73 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplChromeOSTest);
78 // Normal mode, external app should be installed.
79 TEST_F(ExternalProviderImplChromeOSTest, Normal) {
80 InitServiceWithExternalProviders();
82 service_->CheckForExternalUpdates();
83 content::WindowedNotificationObserver(
84 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
85 content::NotificationService::AllSources()).Wait();
87 EXPECT_TRUE(service_->GetInstalledExtension(kExternalAppId));
90 // App mode, no external app should be installed.
91 TEST_F(ExternalProviderImplChromeOSTest, AppMode) {
92 CommandLine* command = CommandLine::ForCurrentProcess();
93 command->AppendSwitchASCII(switches::kForceAppMode, std::string());
94 command->AppendSwitchASCII(switches::kAppId, std::string("app_id"));
96 InitServiceWithExternalProviders();
98 service_->CheckForExternalUpdates();
99 base::RunLoop().RunUntilIdle();
101 EXPECT_FALSE(service_->GetInstalledExtension(kExternalAppId));
104 } // namespace extensions