Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Unified Diff: chrome/browser/extensions/test_extension_prefs.cc

Issue 1695018: Adding ExtensionPrefs methods for storing update-when-idle data.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/test_extension_prefs.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/test_extension_prefs.cc
===================================================================
--- chrome/browser/extensions/test_extension_prefs.cc (revision 0)
+++ chrome/browser/extensions/test_extension_prefs.cc (revision 0)
@@ -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();
+}
Property changes on: chrome/browser/extensions/test_extension_prefs.cc
___________________________________________________________________
Name: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/extensions/test_extension_prefs.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698