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

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

Issue 6627060: ImportantFileWriter: check return value of PostTask... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "base/synchronization/waitable_event.h"
12 #include "chrome/browser/extensions/extension_pref_store.h" 13 #include "chrome/browser/extensions/extension_pref_store.h"
13 #include "chrome/browser/extensions/extension_pref_value_map.h" 14 #include "chrome/browser/extensions/extension_pref_value_map.h"
14 #include "chrome/browser/extensions/extension_prefs.h" 15 #include "chrome/browser/extensions/extension_prefs.h"
15 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/prefs/pref_service_mock_builder.h" 17 #include "chrome/browser/prefs/pref_service_mock_builder.h"
17 #include "chrome/browser/prefs/pref_value_store.h" 18 #include "chrome/browser/prefs/pref_value_store.h"
18 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/extension_constants.h" 20 #include "chrome/common/extensions/extension_constants.h"
20 #include "chrome/common/json_pref_store.h" 21 #include "chrome/common/json_pref_store.h"
22 #include "chrome/test/signaling_task.h"
21 #include "content/browser/browser_thread.h" 23 #include "content/browser/browser_thread.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 25
24 namespace { 26 namespace {
25 27
26 // Mock ExtensionPrefs class with artificial clock to guarantee that no two 28 // Mock ExtensionPrefs class with artificial clock to guarantee that no two
27 // extensions get the same installation time stamp and we can reliably 29 // extensions get the same installation time stamp and we can reliably
28 // assert the installation order in the tests below. 30 // assert the installation order in the tests below.
29 class MockExtensionPrefs : public ExtensionPrefs { 31 class MockExtensionPrefs : public ExtensionPrefs {
30 public: 32 public:
(...skipping 27 matching lines...) Expand all
58 TestExtensionPrefs::~TestExtensionPrefs() {} 60 TestExtensionPrefs::~TestExtensionPrefs() {}
59 61
60 void TestExtensionPrefs::RecreateExtensionPrefs() { 62 void TestExtensionPrefs::RecreateExtensionPrefs() {
61 // We persist and reload the PrefService's PrefStores because this process 63 // We persist and reload the PrefService's PrefStores because this process
62 // deletes all empty dictionaries. The ExtensionPrefs implementation 64 // deletes all empty dictionaries. The ExtensionPrefs implementation
63 // needs to be able to handle this situation. 65 // needs to be able to handle this situation.
64 if (pref_service_.get()) { 66 if (pref_service_.get()) {
65 // 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
66 // 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
67 // PrefService. 69 // PrefService.
68 MessageLoop file_loop; 70 base::WaitableEvent io_finished(false, false);
69 BrowserThread file_thread(BrowserThread::FILE, &file_loop);
70 pref_service_->SavePersistentPrefs(); 71 pref_service_->SavePersistentPrefs();
71 file_loop.RunAllPending(); 72 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
73 new SignalingTask(&io_finished));
74 EXPECT_TRUE(io_finished.Wait());
asargent_no_longer_on_chrome 2011/03/09 20:53:17 Nice, this looks much better.
72 } 75 }
73 76
74 extension_pref_value_map_.reset(new ExtensionPrefValueMap); 77 extension_pref_value_map_.reset(new ExtensionPrefValueMap);
75 PrefServiceMockBuilder builder; 78 PrefServiceMockBuilder builder;
76 builder.WithUserFilePrefs(preferences_file_); 79 builder.WithUserFilePrefs(preferences_file_);
77 builder.WithExtensionPrefs( 80 builder.WithExtensionPrefs(
78 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); 81 new ExtensionPrefStore(extension_pref_value_map_.get(), false));
79 pref_service_.reset(builder.Create()); 82 pref_service_.reset(builder.Create());
80 ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); 83 ExtensionPrefs::RegisterUserPrefs(pref_service_.get());
81 84
(...skipping 30 matching lines...) Expand all
112 115
113 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) { 116 std::string TestExtensionPrefs::AddExtensionAndReturnId(std::string name) {
114 scoped_refptr<Extension> extension(AddExtension(name)); 117 scoped_refptr<Extension> extension(AddExtension(name));
115 return extension->id(); 118 return extension->id();
116 } 119 }
117 120
118 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { 121 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const {
119 return pref_service_->CreateIncognitoPrefService( 122 return pref_service_->CreateIncognitoPrefService(
120 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); 123 new ExtensionPrefStore(extension_pref_value_map_.get(), true));
121 } 124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698