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

Side by Side 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, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/test_extension_prefs.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/test_extension_prefs.h"
6
7 #include "base/file_util.h"
8 #include "base/logging.h"
9 #include "base/message_loop.h"
10 #include "chrome/browser/chrome_thread.h"
11 #include "chrome/browser/extensions/extension_prefs.h"
12 #include "chrome/browser/json_pref_store.h"
13 #include "chrome/browser/pref_service.h"
14 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_constants.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 TestExtensionPrefs::TestExtensionPrefs() {
19 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
20 preferences_file_ = temp_dir_.path().AppendASCII("Preferences");
21 extensions_dir_ = temp_dir_.path().AppendASCII("Extensions");
22 EXPECT_TRUE(file_util::CreateDirectory(extensions_dir_));
23
24 RecreateExtensionPrefs();
25 }
26
27 TestExtensionPrefs::~TestExtensionPrefs() {}
28
29 void TestExtensionPrefs::RecreateExtensionPrefs() {
30 if (pref_service_.get()) {
31 // The PrefService writes its persistent file on the file thread, so we
32 // need to wait for any pending I/O to complete before creating a new
33 // PrefService.
34 MessageLoop file_loop;
35 ChromeThread file_thread(ChromeThread::FILE, &file_loop);
36 pref_service_->SavePersistentPrefs();
37 file_loop.RunAllPending();
38 }
39
40 pref_service_.reset(new PrefService(new JsonPrefStore(preferences_file_)));
41 ExtensionPrefs::RegisterUserPrefs(pref_service_.get());
42 prefs_.reset(new ExtensionPrefs(pref_service_.get(), temp_dir_.path()));
43 }
44
45 Extension* TestExtensionPrefs::AddExtension(std::string name) {
46 DictionaryValue dictionary;
47 dictionary.SetString(extension_manifest_keys::kName, name);
48 dictionary.SetString(extension_manifest_keys::kVersion, "0.1");
49 return AddExtensionWithManifest(dictionary);
50 }
51
52 Extension* TestExtensionPrefs::AddExtensionWithManifest(
53 const DictionaryValue& manifest) {
54 std::string name;
55 EXPECT_TRUE(manifest.GetString(extension_manifest_keys::kName, &name));
56 FilePath path = extensions_dir_.AppendASCII(name);
57 Extension* extension = new Extension(path);
58 std::string errors;
59 EXPECT_TRUE(extension->InitFromValue(manifest, false, &errors));
60 extension->set_location(Extension::INTERNAL);
61 EXPECT_TRUE(Extension::IdIsValid(extension->id()));
62 prefs_->OnExtensionInstalled(extension);
63 return extension;
64 }
65
66 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) {
67 scoped_ptr<Extension> extension(AddExtension(name));
68 return extension->id();
69 }
OLDNEW
« 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