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