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