Upstream version 7.36.149.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/prefs/testing_pref_service.h"
10 #include "base/test/scoped_path_override.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/chromeos/customization_document.h"
13 #include "chrome/browser/extensions/extension_service_unittest.h"
14 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/testing_browser_process.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "chromeos/system/mock_statistics_provider.h"
19 #include "chromeos/system/statistics_provider.h"
20 #include "content/public/browser/notification_service.h"
21 #include "content/public/test/test_utils.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23
24 using ::testing::_;
25 using ::testing::NotNull;
26 using ::testing::Return;
27
28 namespace extensions {
29
30 namespace {
31
32 const char kExternalAppId[] = "kekdneafjmhmndejhmbcadfiiofngffo";
33
34 class ExternalProviderImplChromeOSTest : public ExtensionServiceTestBase {
35  public:
36   ExternalProviderImplChromeOSTest() {}
37   virtual ~ExternalProviderImplChromeOSTest() {}
38
39   void InitServiceWithExternalProviders() {
40     InitializeEmptyExtensionService();
41     service_->Init();
42
43     ProviderCollection providers;
44     extensions::ExternalProviderImpl::CreateExternalProviders(
45         service_, profile_.get(), &providers);
46
47     for (ProviderCollection::iterator i = providers.begin();
48          i != providers.end();
49          ++i) {
50       service_->AddProviderForTesting(i->release());
51     }
52   }
53
54   // ExtensionServiceTestBase overrides:
55   virtual void SetUp() OVERRIDE {
56     ExtensionServiceTestBase::SetUp();
57
58     TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
59     chromeos::ServicesCustomizationDocument::RegisterPrefs(
60         local_state_.registry());
61
62     external_externsions_overrides_.reset(
63         new base::ScopedPathOverride(chrome::DIR_EXTERNAL_EXTENSIONS,
64                                      data_dir_.Append("external")));
65
66     chromeos::system::StatisticsProvider::SetTestProvider(
67         &mock_statistics_provider_);
68     EXPECT_CALL(mock_statistics_provider_, GetMachineStatistic(_, NotNull()))
69         .WillRepeatedly(Return(false));
70   }
71
72   virtual void TearDown() OVERRIDE {
73     chromeos::system::StatisticsProvider::SetTestProvider(NULL);
74     TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
75   }
76
77  private:
78   TestingPrefServiceSimple local_state_;
79   scoped_ptr<base::ScopedPathOverride> external_externsions_overrides_;
80   chromeos::system::MockStatisticsProvider mock_statistics_provider_;
81
82   DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplChromeOSTest);
83 };
84
85 }  // namespace
86
87 // Normal mode, external app should be installed.
88 TEST_F(ExternalProviderImplChromeOSTest, Normal) {
89   InitServiceWithExternalProviders();
90
91   service_->CheckForExternalUpdates();
92   content::WindowedNotificationObserver(
93       chrome::NOTIFICATION_CRX_INSTALLER_DONE,
94       content::NotificationService::AllSources()).Wait();
95
96   EXPECT_TRUE(service_->GetInstalledExtension(kExternalAppId));
97 }
98
99 // App mode, no external app should be installed.
100 TEST_F(ExternalProviderImplChromeOSTest, AppMode) {
101   CommandLine* command = CommandLine::ForCurrentProcess();
102   command->AppendSwitchASCII(switches::kForceAppMode, std::string());
103   command->AppendSwitchASCII(switches::kAppId, std::string("app_id"));
104
105   InitServiceWithExternalProviders();
106
107   service_->CheckForExternalUpdates();
108   base::RunLoop().RunUntilIdle();
109
110   EXPECT_FALSE(service_->GetInstalledExtension(kExternalAppId));
111 }
112
113 }  // namespace extensions