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

Side by Side Diff: chrome/browser/extensions/test_extension_prefs.cc

Issue 5213002: Fix for Bug 50726 "Save extension list and "winning" prefs from extensions" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: reuse old DefaultPrefStore as InMemoryPrefStore Created 10 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/test_extension_prefs.h" 5 #include "chrome/browser/extensions/test_extension_prefs.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/browser_thread.h" 11 #include "chrome/browser/browser_thread.h"
12 #include "chrome/browser/extensions/extension_prefs.h" 12 #include "chrome/browser/extensions/extension_prefs.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/prefs/pref_value_store.h" 14 #include "chrome/browser/prefs/pref_value_store.h"
15 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/extensions/extension_constants.h" 16 #include "chrome/common/extensions/extension_constants.h"
17 #include "chrome/common/json_pref_store.h" 17 #include "chrome/common/json_pref_store.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 // Mock ExtensionPrefs class with artificial clock.
21 class ExtensionPrefsFake : public ExtensionPrefs {
22 public:
23 explicit ExtensionPrefsFake(PrefService* prefs, const FilePath& root_dir_)
24 : ExtensionPrefs(prefs, root_dir_), currentTime(base::Time::Now()) {}
25 ~ExtensionPrefsFake() {}
26
27 protected:
28 mutable base::Time currentTime;
29 // For unit testing
30 base::Time GetCurrentTime() const {
Mattias Nissler (ping if slow) 2010/11/19 10:47:40 note my other comment about GetCurrentTime() not b
battre (please use the other) 2010/11/19 16:03:18 Done.
31 currentTime += base::TimeDelta::FromSeconds(10);
32 return currentTime;
33 }
34 };
35
20 TestExtensionPrefs::TestExtensionPrefs() { 36 TestExtensionPrefs::TestExtensionPrefs() {
21 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 37 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
22 preferences_file_ = temp_dir_.path().AppendASCII("Preferences"); 38 preferences_file_ = temp_dir_.path().AppendASCII("Preferences");
23 extensions_dir_ = temp_dir_.path().AppendASCII("Extensions"); 39 extensions_dir_ = temp_dir_.path().AppendASCII("Extensions");
24 EXPECT_TRUE(file_util::CreateDirectory(extensions_dir_)); 40 EXPECT_TRUE(file_util::CreateDirectory(extensions_dir_));
25 41
26 RecreateExtensionPrefs(); 42 RecreateExtensionPrefs();
27 } 43 }
28 44
29 TestExtensionPrefs::~TestExtensionPrefs() {} 45 TestExtensionPrefs::~TestExtensionPrefs() {}
30 46
31 void TestExtensionPrefs::RecreateExtensionPrefs() { 47 void TestExtensionPrefs::RecreateExtensionPrefs() {
32 if (pref_service_.get()) { 48 if (pref_service_.get()) {
33 // The PrefService writes its persistent file on the file thread, so we 49 // The PrefService writes its persistent file on the file thread, so we
34 // need to wait for any pending I/O to complete before creating a new 50 // need to wait for any pending I/O to complete before creating a new
35 // PrefService. 51 // PrefService.
36 MessageLoop file_loop; 52 MessageLoop file_loop;
37 BrowserThread file_thread(BrowserThread::FILE, &file_loop); 53 BrowserThread file_thread(BrowserThread::FILE, &file_loop);
38 pref_service_->SavePersistentPrefs(); 54 pref_service_->SavePersistentPrefs();
39 file_loop.RunAllPending(); 55 file_loop.RunAllPending();
40 } 56 }
41 57
42 // Create a |PrefService| instance that contains only user defined values. 58 // Create a |PrefService| instance that contains only user defined values.
43 pref_service_.reset(PrefService::CreateUserPrefService(preferences_file_)); 59 pref_service_.reset(PrefService::CreateUserPrefService(preferences_file_));
44 ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); 60 ExtensionPrefs::RegisterUserPrefs(pref_service_.get());
45 prefs_.reset(new ExtensionPrefs(pref_service_.get(), temp_dir_.path())); 61 prefs_.reset(new ExtensionPrefsFake(pref_service_.get(), temp_dir_.path()));
46 } 62 }
47 63
48 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) { 64 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) {
49 DictionaryValue dictionary; 65 DictionaryValue dictionary;
50 dictionary.SetString(extension_manifest_keys::kName, name); 66 dictionary.SetString(extension_manifest_keys::kName, name);
51 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); 67 dictionary.SetString(extension_manifest_keys::kVersion, "0.1");
52 return AddExtensionWithManifest(dictionary, Extension::INTERNAL); 68 return AddExtensionWithManifest(dictionary, Extension::INTERNAL);
53 } 69 }
54 70
55 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifest( 71 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifest(
(...skipping 12 matching lines...) Expand all
68 const bool kInitialIncognitoEnabled = false; 84 const bool kInitialIncognitoEnabled = false;
69 prefs_->OnExtensionInstalled(extension, Extension::ENABLED, 85 prefs_->OnExtensionInstalled(extension, Extension::ENABLED,
70 kInitialIncognitoEnabled); 86 kInitialIncognitoEnabled);
71 return extension; 87 return extension;
72 } 88 }
73 89
74 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { 90 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) {
75 scoped_refptr<Extension> extension(AddExtension(name)); 91 scoped_refptr<Extension> extension(AddExtension(name));
76 return extension->id(); 92 return extension->id();
77 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698