diff options
author | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-27 21:21:34 +0000 |
---|---|---|
committer | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-27 21:21:34 +0000 |
commit | 63c64d193c42c0c5dd819395994031a16c9a3d71 (patch) | |
tree | a772e9b87c869649ada5f5a47215b77c92b8dfdd /chrome/browser/extensions/test_extension_prefs.cc | |
parent | 2b39687f1feb296be488a75ef5286a908be81e3a (diff) | |
download | chromium_src-63c64d193c42c0c5dd819395994031a16c9a3d71.zip chromium_src-63c64d193c42c0c5dd819395994031a16c9a3d71.tar.gz chromium_src-63c64d193c42c0c5dd819395994031a16c9a3d71.tar.bz2 |
Adding ExtensionPrefs methods for storing update-when-idle data.
This includes adding a few methods to ExtensionPrefs that I'm going to need to
use inside ExtensionUpdater for implementing the "do updates at idle" feature.
Instead of adding more call-through stubs to the interface that
ExtensionsService providers to the ExtensionUpdater, I instead decided it was
time to do some refactoring to expose a ExtensionPrefs getter in the interface.
TEST=(Should be covered by unit/browser tests)
BUG=37971
Review URL: http://codereview.chromium.org/1695018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45738 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/test_extension_prefs.cc')
-rw-r--r-- | chrome/browser/extensions/test_extension_prefs.cc | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/chrome/browser/extensions/test_extension_prefs.cc b/chrome/browser/extensions/test_extension_prefs.cc new file mode 100644 index 0000000..e9a1472 --- /dev/null +++ b/chrome/browser/extensions/test_extension_prefs.cc @@ -0,0 +1,69 @@ +// Copyright (c) 2010 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/test_extension_prefs.h" + +#include "base/file_util.h" +#include "base/logging.h" +#include "base/message_loop.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/extensions/extension_prefs.h" +#include "chrome/browser/json_pref_store.h" +#include "chrome/browser/pref_service.h" +#include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_constants.h" +#include "testing/gtest/include/gtest/gtest.h" + +TestExtensionPrefs::TestExtensionPrefs() { + EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); + preferences_file_ = temp_dir_.path().AppendASCII("Preferences"); + extensions_dir_ = temp_dir_.path().AppendASCII("Extensions"); + EXPECT_TRUE(file_util::CreateDirectory(extensions_dir_)); + + RecreateExtensionPrefs(); +} + +TestExtensionPrefs::~TestExtensionPrefs() {} + +void TestExtensionPrefs::RecreateExtensionPrefs() { + if (pref_service_.get()) { + // The PrefService writes its persistent file on the file thread, so we + // need to wait for any pending I/O to complete before creating a new + // PrefService. + MessageLoop file_loop; + ChromeThread file_thread(ChromeThread::FILE, &file_loop); + pref_service_->SavePersistentPrefs(); + file_loop.RunAllPending(); + } + + pref_service_.reset(new PrefService(new JsonPrefStore(preferences_file_))); + ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); + prefs_.reset(new ExtensionPrefs(pref_service_.get(), temp_dir_.path())); +} + +Extension* TestExtensionPrefs::AddExtension(std::string name) { + DictionaryValue dictionary; + dictionary.SetString(extension_manifest_keys::kName, name); + dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); + return AddExtensionWithManifest(dictionary); +} + +Extension* TestExtensionPrefs::AddExtensionWithManifest( + const DictionaryValue& manifest) { + std::string name; + EXPECT_TRUE(manifest.GetString(extension_manifest_keys::kName, &name)); + FilePath path = extensions_dir_.AppendASCII(name); + Extension* extension = new Extension(path); + std::string errors; + EXPECT_TRUE(extension->InitFromValue(manifest, false, &errors)); + extension->set_location(Extension::INTERNAL); + EXPECT_TRUE(Extension::IdIsValid(extension->id())); + prefs_->OnExtensionInstalled(extension); + return extension; +} + +std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { + scoped_ptr<Extension> extension(AddExtension(name)); + return extension->id(); +} |