summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/test_extension_prefs.cc
diff options
context:
space:
mode:
authorbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-06 18:13:43 +0000
committerbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-06 18:13:43 +0000
commit73c479313b0abb39ab8ecf5fa8f3026449d6c04c (patch)
tree768bc2e495b798cfca857cee75ac882b4a261009 /chrome/browser/extensions/test_extension_prefs.cc
parent8f55e8087439851d78245881a8acd62b24251801 (diff)
downloadchromium_src-73c479313b0abb39ab8ecf5fa8f3026449d6c04c.zip
chromium_src-73c479313b0abb39ab8ecf5fa8f3026449d6c04c.tar.gz
chromium_src-73c479313b0abb39ab8ecf5fa8f3026449d6c04c.tar.bz2
Fix for Bug 50726 "Save extension list and "winning" prefs from extensions"
This is a redesign for http://codereview.chromium.org/4852002/ following discussions. The goal of this patch is to ensure that Chrome maintains the order in which extensions apply their preferences between restarts. This may be an issue if two extensions overwrite each others preferences. Furthermore, it ensures that preferences are persisted to disk between browser restarts. Therefore, previous settings are immediately available when the browser is restarted. A description of the design has been published https://docs.google.com/a/google.com/document/d/1E_HX_cUpET1gH2gDunGIU1EOywMM6FEOuVU6TlpnSwo/edit?hl=en for review and comments. - Sorry, accessible Google internally only. This CL requires http://codereview.chromium.org/5204006/ Contributed by battre@google.com BUG=50726 TEST=none Review URL: http://codereview.chromium.org/5213002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68355 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/test_extension_prefs.cc')
-rw-r--r--chrome/browser/extensions/test_extension_prefs.cc27
1 files changed, 25 insertions, 2 deletions
diff --git a/chrome/browser/extensions/test_extension_prefs.cc b/chrome/browser/extensions/test_extension_prefs.cc
index 2cbb2d1..d7f83fdb 100644
--- a/chrome/browser/extensions/test_extension_prefs.cc
+++ b/chrome/browser/extensions/test_extension_prefs.cc
@@ -17,7 +17,27 @@
#include "chrome/common/json_pref_store.h"
#include "testing/gtest/include/gtest/gtest.h"
-TestExtensionPrefs::TestExtensionPrefs() {
+// Mock ExtensionPrefs class with artificial clock to guarantee that no two
+// extensions get the same installation time stamp and we can reliably
+// assert the installation order in the tests below.
+class MockExtensionPrefs : public ExtensionPrefs {
+ public:
+ MockExtensionPrefs(PrefService* prefs, const FilePath& root_dir_)
+ : ExtensionPrefs(prefs, root_dir_),
+ currentTime(base::Time::Now())
+ {}
+ ~MockExtensionPrefs() {}
+
+ protected:
+ mutable base::Time currentTime;
+
+ virtual base::Time GetCurrentTime() const {
+ currentTime += base::TimeDelta::FromSeconds(10);
+ return currentTime;
+ }
+};
+
+TestExtensionPrefs::TestExtensionPrefs() : pref_service_(NULL) {
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
preferences_file_ = temp_dir_.path().AppendASCII("Preferences");
extensions_dir_ = temp_dir_.path().AppendASCII("Extensions");
@@ -29,6 +49,9 @@ TestExtensionPrefs::TestExtensionPrefs() {
TestExtensionPrefs::~TestExtensionPrefs() {}
void TestExtensionPrefs::RecreateExtensionPrefs() {
+ // We persist and reload the PrefService's PrefStores because this process
+ // deletes all empty dictionaries. The ExtensionPrefs implementation
+ // needs to be able to handle this situation.
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
@@ -42,7 +65,7 @@ void TestExtensionPrefs::RecreateExtensionPrefs() {
// Create a |PrefService| instance that contains only user defined values.
pref_service_.reset(PrefService::CreateUserPrefService(preferences_file_));
ExtensionPrefs::RegisterUserPrefs(pref_service_.get());
- prefs_.reset(new ExtensionPrefs(pref_service_.get(), temp_dir_.path()));
+ prefs_.reset(new MockExtensionPrefs(pref_service_.get(), temp_dir_.path()));
}
scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) {