Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / extensions / external_provider_impl_chromeos_unittest.cc
blob51a7489a689f7bf7e5648a71ccb22f8a45e5b0b4
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/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"
27 namespace extensions {
29 namespace {
31 const char kExternalAppId[] = "kekdneafjmhmndejhmbcadfiiofngffo";
33 class ExternalProviderImplChromeOSTest : public ExtensionServiceTestBase {
34 public:
35 ExternalProviderImplChromeOSTest()
36 : fake_user_manager_(new chromeos::FakeUserManager()),
37 scoped_user_manager_(fake_user_manager_) {
40 virtual ~ExternalProviderImplChromeOSTest() {}
42 void InitServiceWithExternalProviders() {
43 InitializeEmptyExtensionService();
44 service_->Init();
46 ProviderCollection providers;
47 extensions::ExternalProviderImpl::CreateExternalProviders(
48 service_, profile_.get(), &providers);
50 for (ProviderCollection::iterator i = providers.begin();
51 i != providers.end();
52 ++i) {
53 service_->AddProviderForTesting(i->release());
57 // ExtensionServiceTestBase overrides:
58 virtual void SetUp() override {
59 ExtensionServiceTestBase::SetUp();
61 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
62 chromeos::ServicesCustomizationDocument::RegisterPrefs(
63 local_state_.registry());
65 external_externsions_overrides_.reset(new base::ScopedPathOverride(
66 chrome::DIR_EXTERNAL_EXTENSIONS, data_dir().Append("external")));
69 virtual void TearDown() override {
70 chromeos::KioskAppManager::Shutdown();
71 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
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_;
81 DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplChromeOSTest);
84 } // namespace
86 // Normal mode, external app should be installed.
87 TEST_F(ExternalProviderImplChromeOSTest, Normal) {
88 InitServiceWithExternalProviders();
90 service_->CheckForExternalUpdates();
91 content::WindowedNotificationObserver(
92 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
93 content::NotificationService::AllSources()).Wait();
95 EXPECT_TRUE(service_->GetInstalledExtension(kExternalAppId));
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"));
104 InitServiceWithExternalProviders();
106 service_->CheckForExternalUpdates();
107 base::RunLoop().RunUntilIdle();
109 EXPECT_FALSE(service_->GetInstalledExtension(kExternalAppId));
112 } // namespace extensions