Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / external_provider_impl_chromeos_unittest.cc
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.
4
5 #include "chrome/browser/extensions/external_provider_impl.h"
6
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"
20
21 using ::testing::_;
22 using ::testing::NotNull;
23 using ::testing::Return;
24
25 namespace extensions {
26
27 namespace {
28
29 const char kExternalAppId[] = "kekdneafjmhmndejhmbcadfiiofngffo";
30
31 class ExternalProviderImplChromeOSTest : public ExtensionServiceTestBase {
32  public:
33   ExternalProviderImplChromeOSTest() {}
34   virtual ~ExternalProviderImplChromeOSTest() {}
35
36   void InitServiceWithExternalProviders() {
37     InitializeEmptyExtensionService();
38     service_->Init();
39
40     ProviderCollection providers;
41     extensions::ExternalProviderImpl::CreateExternalProviders(
42         service_, profile_.get(), &providers);
43
44     for (ProviderCollection::iterator i = providers.begin();
45          i != providers.end();
46          ++i) {
47       service_->AddProviderForTesting(i->release());
48     }
49   }
50
51   // ExtensionServiceTestBase overrides:
52   virtual void SetUp() OVERRIDE {
53     ExtensionServiceTestBase::SetUp();
54
55     external_externsions_overrides_.reset(
56         new base::ScopedPathOverride(chrome::DIR_EXTERNAL_EXTENSIONS,
57                                      data_dir_.Append("external")));
58
59     chromeos::system::StatisticsProvider::SetTestProvider(
60         &mock_statistics_provider_);
61     EXPECT_CALL(mock_statistics_provider_, GetMachineStatistic(_, NotNull()))
62         .WillRepeatedly(Return(false));
63   }
64
65   virtual void TearDown() OVERRIDE {
66     chromeos::system::StatisticsProvider::SetTestProvider(NULL);
67   }
68
69  private:
70   scoped_ptr<base::ScopedPathOverride> external_externsions_overrides_;
71   chromeos::system::MockStatisticsProvider mock_statistics_provider_;
72
73   DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplChromeOSTest);
74 };
75
76 }  // namespace
77
78 // Normal mode, external app should be installed.
79 TEST_F(ExternalProviderImplChromeOSTest, Normal) {
80   InitServiceWithExternalProviders();
81
82   service_->CheckForExternalUpdates();
83   content::WindowedNotificationObserver(
84       chrome::NOTIFICATION_CRX_INSTALLER_DONE,
85       content::NotificationService::AllSources()).Wait();
86
87   EXPECT_TRUE(service_->GetInstalledExtension(kExternalAppId));
88 }
89
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"));
95
96   InitServiceWithExternalProviders();
97
98   service_->CheckForExternalUpdates();
99   base::RunLoop().RunUntilIdle();
100
101   EXPECT_FALSE(service_->GetInstalledExtension(kExternalAppId));
102 }
103
104 }  // namespace extensions