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

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

Issue 5915004: Introduce incognito preference settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitespaces + fixes for trybot Created 10 years 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/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
(...skipping 10 matching lines...) Expand all
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace { 23 namespace {
24 24
25 // Mock ExtensionPrefs class with artificial clock to guarantee that no two 25 // Mock ExtensionPrefs class with artificial clock to guarantee that no two
26 // extensions get the same installation time stamp and we can reliably 26 // extensions get the same installation time stamp and we can reliably
27 // assert the installation order in the tests below. 27 // assert the installation order in the tests below.
28 class MockExtensionPrefs : public ExtensionPrefs { 28 class MockExtensionPrefs : public ExtensionPrefs {
29 public: 29 public:
30 MockExtensionPrefs(PrefService* prefs, 30 MockExtensionPrefs(PrefService* prefs,
31 PrefService* incognito_prefs,
31 const FilePath& root_dir_, 32 const FilePath& root_dir_,
32 ExtensionPrefStore* pref_store) 33 scoped_refptr<ExtensionPrefStore> pref_store,
33 : ExtensionPrefs(prefs, root_dir_, pref_store), 34 scoped_refptr<ExtensionPrefStore> incognito_pref_store)
35 : ExtensionPrefs(prefs, incognito_prefs, root_dir_, pref_store,
36 incognito_pref_store),
34 currentTime(base::Time::Now()) {} 37 currentTime(base::Time::Now()) {}
35 ~MockExtensionPrefs() {} 38 ~MockExtensionPrefs() {}
36 39
37 protected: 40 protected:
38 mutable base::Time currentTime; 41 mutable base::Time currentTime;
39 42
40 virtual base::Time GetCurrentTime() const { 43 virtual base::Time GetCurrentTime() const {
41 currentTime += base::TimeDelta::FromSeconds(10); 44 currentTime += base::TimeDelta::FromSeconds(10);
42 return currentTime; 45 return currentTime;
43 } 46 }
(...skipping 19 matching lines...) Expand all
63 if (pref_service_.get()) { 66 if (pref_service_.get()) {
64 // The PrefService writes its persistent file on the file thread, so we 67 // The PrefService writes its persistent file on the file thread, so we
65 // need to wait for any pending I/O to complete before creating a new 68 // need to wait for any pending I/O to complete before creating a new
66 // PrefService. 69 // PrefService.
67 MessageLoop file_loop; 70 MessageLoop file_loop;
68 BrowserThread file_thread(BrowserThread::FILE, &file_loop); 71 BrowserThread file_thread(BrowserThread::FILE, &file_loop);
69 pref_service_->SavePersistentPrefs(); 72 pref_service_->SavePersistentPrefs();
70 file_loop.RunAllPending(); 73 file_loop.RunAllPending();
71 } 74 }
72 75
73 ExtensionPrefStore* pref_store = new ExtensionPrefStore; 76 scoped_refptr<ExtensionPrefStore> pref_store = new ExtensionPrefStore;
74 PrefServiceMockBuilder builder; 77 PrefServiceMockBuilder builder;
75 builder.WithUserFilePrefs(preferences_file_); 78 builder.WithUserFilePrefs(preferences_file_);
76 builder.WithExtensionPrefs(pref_store); 79 builder.WithExtensionPrefs(pref_store);
77 pref_service_.reset(builder.Create()); 80 pref_service_.reset(builder.Create());
78 ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); 81 ExtensionPrefs::RegisterUserPrefs(pref_service_.get());
79 prefs_.reset(new MockExtensionPrefs(pref_service_.get(), temp_dir_.path(), 82
80 pref_store)); 83 scoped_refptr<ExtensionPrefStore> incognito_pref_store =
84 new ExtensionPrefStore;
85 incognito_pref_service_.reset(
86 pref_service_->CreateIncognitoPrefService(incognito_pref_store));
87
88 prefs_.reset(new MockExtensionPrefs(pref_service_.get(),
89 incognito_pref_service_.get(),
90 temp_dir_.path(),
91 pref_store,
92 incognito_pref_store));
81 } 93 }
82 94
83 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) { 95 scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) {
84 DictionaryValue dictionary; 96 DictionaryValue dictionary;
85 dictionary.SetString(extension_manifest_keys::kName, name); 97 dictionary.SetString(extension_manifest_keys::kName, name);
86 dictionary.SetString(extension_manifest_keys::kVersion, "0.1"); 98 dictionary.SetString(extension_manifest_keys::kVersion, "0.1");
87 return AddExtensionWithManifest(dictionary, Extension::INTERNAL); 99 return AddExtensionWithManifest(dictionary, Extension::INTERNAL);
88 } 100 }
89 101
90 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifest( 102 scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifest(
(...skipping 12 matching lines...) Expand all
103 const bool kInitialIncognitoEnabled = false; 115 const bool kInitialIncognitoEnabled = false;
104 prefs_->OnExtensionInstalled(extension, Extension::ENABLED, 116 prefs_->OnExtensionInstalled(extension, Extension::ENABLED,
105 kInitialIncognitoEnabled); 117 kInitialIncognitoEnabled);
106 return extension; 118 return extension;
107 } 119 }
108 120
109 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { 121 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) {
110 scoped_refptr<Extension> extension(AddExtension(name)); 122 scoped_refptr<Extension> extension(AddExtension(name));
111 return extension->id(); 123 return extension->id();
112 } 124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698