Commit 404d6107 authored by anthonyvd's avatar anthonyvd Committed by Commit bot

Fix unit tests on official bots.

Some of the tests weren't properly instantiating a PrefService. It's now being
done in the ExtensionServiceTestBase class and its subclasses were modified
where needed.

BUG=461484

Review URL: https://codereview.chromium.org/965803003

Cr-Commit-Position: refs/heads/master@{#318552}
parent e6eb185c
......@@ -42,13 +42,9 @@ namespace extensions {
class ExtensionGarbageCollectorChromeOSUnitTest
: public ExtensionServiceTestBase {
protected:
PrefService& local_state() { return local_state_; }
const base::FilePath& cache_dir() { return cache_dir_.path(); }
void SetUp() override {
TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
chrome::RegisterLocalState(local_state_.registry());
#if defined(ENABLE_PLUGINS)
content::PluginService::GetInstance()->Init();
#endif
......@@ -77,10 +73,6 @@ class ExtensionGarbageCollectorChromeOSUnitTest
GetFakeUserManager()->GetActiveUser(), profile_.get());
}
void TearDown() override {
TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
}
void GarbageCollectExtensions() {
ExtensionGarbageCollector::Get(profile_.get())
->GarbageCollectExtensionsForTest();
......@@ -100,7 +92,7 @@ class ExtensionGarbageCollectorChromeOSUnitTest
const std::string& version,
const std::string& users_string,
const base::FilePath& path) {
DictionaryPrefUpdate shared_extensions(&local_state_,
DictionaryPrefUpdate shared_extensions(testing_local_state_.Get(),
ExtensionAssetsManagerChromeOS::kSharedExtensions);
base::DictionaryValue* extension_info = NULL;
......@@ -152,7 +144,6 @@ class ExtensionGarbageCollectorChromeOSUnitTest
private:
scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
TestingPrefServiceSimple local_state_;
base::ScopedTempDir cache_dir_;
};
......@@ -195,8 +186,8 @@ TEST_F(ExtensionGarbageCollectorChromeOSUnitTest, SharedExtensions) {
EXPECT_TRUE(base::PathExists(path_id2_1));
const base::DictionaryValue* shared_extensions = local_state().GetDictionary(
ExtensionAssetsManagerChromeOS::kSharedExtensions);
const base::DictionaryValue* shared_extensions = testing_local_state_.Get()->
GetDictionary(ExtensionAssetsManagerChromeOS::kSharedExtensions);
ASSERT_TRUE(shared_extensions);
EXPECT_FALSE(shared_extensions->HasKey(kExtensionId1));
......
......@@ -19,6 +19,7 @@
#include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/browser/browser_context.h"
......@@ -73,6 +74,7 @@ ExtensionServiceTestBase::ExtensionServiceInitParams::
ExtensionServiceTestBase::ExtensionServiceTestBase()
: service_(NULL),
testing_local_state_(TestingBrowserProcess::GetGlobal()),
thread_bundle_(new content::TestBrowserThreadBundle(kThreadOptions)),
did_reset_thread_bundle_(false),
registry_(NULL) {
......
......@@ -9,6 +9,7 @@
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -112,6 +113,7 @@ class ExtensionServiceTestBase : public testing::Test {
// The ExtensionService, whose lifetime is managed by |profile|'s
// ExtensionSystem.
ExtensionService* service_;
ScopedTestingLocalState testing_local_state_;
private:
void CreateExtensionService(const ExtensionServiceInitParams& params);
......
......@@ -6,7 +6,6 @@
#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"
......@@ -57,21 +56,15 @@ class ExternalProviderImplChromeOSTest : public ExtensionServiceTestBase {
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")));
}
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_;
user_manager::FakeUserManager* fake_user_manager_;
......
......@@ -9,7 +9,6 @@
#include "base/files/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/prefs/testing_pref_service.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_path_override.h"
#include "chrome/browser/chrome_notification_types.h"
......@@ -99,12 +98,6 @@ class ExternalProviderImplTest : public ExtensionServiceTestBase {
ExtensionServiceTestBase::SetUp();
test_server_.reset(new EmbeddedTestServer());
#if defined(OS_CHROMEOS)
TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
chromeos::ServicesCustomizationDocument::RegisterPrefs(
local_state_.registry());
#endif
ASSERT_TRUE(test_server_->InitializeAndWaitUntilReady());
test_server_->RegisterRequestHandler(
base::Bind(&ExternalProviderImplTest::HandleRequest,
......@@ -117,10 +110,6 @@ class ExternalProviderImplTest : public ExtensionServiceTestBase {
test_server_->GetURL(kManifestPath).spec());
}
void TearDown() override {
TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
}
private:
scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
GURL url = test_server_->GetURL(request.relative_url);
......@@ -163,7 +152,6 @@ class ExternalProviderImplTest : public ExtensionServiceTestBase {
// chromeos::ServicesCustomizationExternalLoader is hooked up as an
// extensions::ExternalLoader and depends on a functioning StatisticsProvider.
chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_;
TestingPrefServiceSimple local_state_;
#endif
DISALLOW_COPY_AND_ASSIGN(ExternalProviderImplTest);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment