- add sources.
[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 "content/public/browser/notification_service.h"
16 #include "content/public/test/test_utils.h"
17
18 namespace extensions {
19
20 namespace {
21
22 const char kExternalAppId[] = "kekdneafjmhmndejhmbcadfiiofngffo";
23
24 class ExternalProviderImplTest : public ExtensionServiceTestBase {
25  public:
26   ExternalProviderImplTest() {}
27   virtual ~ExternalProviderImplTest() {}
28
29   void InitServiceWithExternalProviders() {
30     InitializeEmptyExtensionService();
31     service_->Init();
32
33     ProviderCollection providers;
34     extensions::ExternalProviderImpl::CreateExternalProviders(
35         service_, profile_.get(), &providers);
36
37     for (ProviderCollection::iterator i = providers.begin();
38          i != providers.end();
39          ++i) {
40       service_->AddProviderForTesting(i->release());
41     }
42   }
43
44   // ExtensionServiceTestBase overrides:
45   virtual void SetUp() OVERRIDE {
46     ExtensionServiceTestBase::SetUp();
47
48     external_externsions_overrides_.reset(
49         new base::ScopedPathOverride(chrome::DIR_EXTERNAL_EXTENSIONS,
50                                      data_dir_.Append("external")));
51   }
52
53  private:
54   scoped_ptr<base::ScopedPathOverride> external_externsions_overrides_;
55
56   DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplTest);
57 };
58
59 }  // namespace
60
61 // Normal mode, external app should be installed.
62 TEST_F(ExternalProviderImplTest, Normal) {
63   InitServiceWithExternalProviders();
64
65   service_->CheckForExternalUpdates();
66   content::WindowedNotificationObserver(
67       chrome::NOTIFICATION_CRX_INSTALLER_DONE,
68       content::NotificationService::AllSources()).Wait();
69
70   EXPECT_TRUE(service_->GetInstalledExtension(kExternalAppId));
71 }
72
73 // App mode, no external app should be installed.
74 TEST_F(ExternalProviderImplTest, AppMode) {
75   CommandLine* command = CommandLine::ForCurrentProcess();
76   command->AppendSwitchASCII(switches::kForceAppMode, std::string());
77   command->AppendSwitchASCII(switches::kAppId, std::string("app_id"));
78
79   InitServiceWithExternalProviders();
80
81   service_->CheckForExternalUpdates();
82   base::RunLoop().RunUntilIdle();
83
84   EXPECT_FALSE(service_->GetInstalledExtension(kExternalAppId));
85 }
86
87 }  // namespace extensions