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

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

Issue 8274012: Wait for URLBlacklist update tasks on automation tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added BrowserThread::WaitForPendingTasksOn, removed SignalingTask Created 9 years, 2 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/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "chrome/browser/extensions/extension_pref_store.h" 12 #include "chrome/browser/extensions/extension_pref_store.h"
14 #include "chrome/browser/extensions/extension_pref_value_map.h" 13 #include "chrome/browser/extensions/extension_pref_value_map.h"
15 #include "chrome/browser/extensions/extension_prefs.h" 14 #include "chrome/browser/extensions/extension_prefs.h"
16 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/prefs/pref_service_mock_builder.h" 16 #include "chrome/browser/prefs/pref_service_mock_builder.h"
18 #include "chrome/browser/prefs/pref_value_store.h" 17 #include "chrome/browser/prefs/pref_value_store.h"
19 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_constants.h" 19 #include "chrome/common/extensions/extension_constants.h"
21 #include "chrome/common/json_pref_store.h" 20 #include "chrome/common/json_pref_store.h"
22 #include "chrome/test/base/signaling_task.h"
23 #include "content/browser/browser_thread.h" 21 #include "content/browser/browser_thread.h"
24 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
25 23
26 namespace { 24 namespace {
27 25
28 // Mock ExtensionPrefs class with artificial clock to guarantee that no two 26 // Mock ExtensionPrefs class with artificial clock to guarantee that no two
29 // extensions get the same installation time stamp and we can reliably 27 // extensions get the same installation time stamp and we can reliably
30 // assert the installation order in the tests below. 28 // assert the installation order in the tests below.
31 class MockExtensionPrefs : public ExtensionPrefs { 29 class MockExtensionPrefs : public ExtensionPrefs {
32 public: 30 public:
(...skipping 29 matching lines...) Expand all
62 TestExtensionPrefs::~TestExtensionPrefs() {} 60 TestExtensionPrefs::~TestExtensionPrefs() {}
63 61
64 void TestExtensionPrefs::RecreateExtensionPrefs() { 62 void TestExtensionPrefs::RecreateExtensionPrefs() {
65 // We persist and reload the PrefService's PrefStores because this process 63 // We persist and reload the PrefService's PrefStores because this process
66 // deletes all empty dictionaries. The ExtensionPrefs implementation 64 // deletes all empty dictionaries. The ExtensionPrefs implementation
67 // needs to be able to handle this situation. 65 // needs to be able to handle this situation.
68 if (pref_service_.get()) { 66 if (pref_service_.get()) {
69 // 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
70 // 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
71 // PrefService. 69 // PrefService.
72 base::WaitableEvent io_finished(false, false);
73 pref_service_->SavePersistentPrefs(); 70 pref_service_->SavePersistentPrefs();
74 EXPECT_TRUE(BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 71 if (!BrowserThread::WaitForPendingTasksOn(BrowserThread::DB)) {
75 new SignalingTask(&io_finished))); 72 // If the FILE thread is in fact the current thread (possible in testing
76 73 // scenarios), we have to ensure the task is executed before proceeding.
77 // If the FILE thread is in fact the current thread (possible in testing 74 MessageLoop::current()->RunAllPending();
78 // scenarios), we have to ensure the task has a chance to run. If the FILE 75 }
79 // thread is a different thread, the test must ensure that thread is running
80 // (otherwise the Wait below will hang).
81 MessageLoop::current()->RunAllPending();
82
83 io_finished.Wait();
84 } 76 }
85 77
86 extension_pref_value_map_.reset(new ExtensionPrefValueMap); 78 extension_pref_value_map_.reset(new ExtensionPrefValueMap);
87 PrefServiceMockBuilder builder; 79 PrefServiceMockBuilder builder;
88 builder.WithUserFilePrefs(preferences_file_); 80 builder.WithUserFilePrefs(preferences_file_);
89 builder.WithExtensionPrefs( 81 builder.WithExtensionPrefs(
90 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); 82 new ExtensionPrefStore(extension_pref_value_map_.get(), false));
91 pref_service_.reset(builder.Create()); 83 pref_service_.reset(builder.Create());
92 ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); 84 ExtensionPrefs::RegisterUserPrefs(pref_service_.get());
93 85
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 139 }
148 140
149 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { 141 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const {
150 return pref_service_->CreateIncognitoPrefService( 142 return pref_service_->CreateIncognitoPrefService(
151 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); 143 new ExtensionPrefStore(extension_pref_value_map_.get(), true));
152 } 144 }
153 145
154 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { 146 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) {
155 extensions_disabled_ = extensions_disabled; 147 extensions_disabled_ = extensions_disabled;
156 } 148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698