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

Side by Side Diff: chrome/browser/policy/url_blacklist_manager_unittest.cc

Issue 11413050: chrome/browser: Update calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/policy/url_blacklist_manager.h" 5 #include "chrome/browser/policy/url_blacklist_manager.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 : ui_thread_(BrowserThread::UI, &loop_), 69 : ui_thread_(BrowserThread::UI, &loop_),
70 file_thread_(BrowserThread::FILE, &loop_), 70 file_thread_(BrowserThread::FILE, &loop_),
71 io_thread_(BrowserThread::IO, &loop_) { 71 io_thread_(BrowserThread::IO, &loop_) {
72 } 72 }
73 73
74 virtual void SetUp() OVERRIDE { 74 virtual void SetUp() OVERRIDE {
75 pref_service_.RegisterListPref(prefs::kUrlBlacklist); 75 pref_service_.RegisterListPref(prefs::kUrlBlacklist);
76 pref_service_.RegisterListPref(prefs::kUrlWhitelist); 76 pref_service_.RegisterListPref(prefs::kUrlWhitelist);
77 blacklist_manager_.reset( 77 blacklist_manager_.reset(
78 new TestingURLBlacklistManager(&pref_service_)); 78 new TestingURLBlacklistManager(&pref_service_));
79 loop_.RunAllPending(); 79 loop_.RunUntilIdle();
80 } 80 }
81 81
82 virtual void TearDown() OVERRIDE { 82 virtual void TearDown() OVERRIDE {
83 if (blacklist_manager_.get()) 83 if (blacklist_manager_.get())
84 blacklist_manager_->ShutdownOnUIThread(); 84 blacklist_manager_->ShutdownOnUIThread();
85 loop_.RunAllPending(); 85 loop_.RunUntilIdle();
86 // Delete |blacklist_manager_| while |io_thread_| is mapping IO to 86 // Delete |blacklist_manager_| while |io_thread_| is mapping IO to
87 // |loop_|. 87 // |loop_|.
88 blacklist_manager_.reset(); 88 blacklist_manager_.reset();
89 } 89 }
90 90
91 MessageLoop loop_; 91 MessageLoop loop_;
92 TestingPrefService pref_service_; 92 TestingPrefService pref_service_;
93 scoped_ptr<TestingURLBlacklistManager> blacklist_manager_; 93 scoped_ptr<TestingURLBlacklistManager> blacklist_manager_;
94 94
95 private: 95 private:
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 EXPECT_EQ(GetParam().path(), path); 174 EXPECT_EQ(GetParam().path(), path);
175 } 175 }
176 176
177 TEST_F(URLBlacklistManagerTest, SingleUpdateForTwoPrefChanges) { 177 TEST_F(URLBlacklistManagerTest, SingleUpdateForTwoPrefChanges) {
178 ListValue* blacklist = new ListValue; 178 ListValue* blacklist = new ListValue;
179 blacklist->Append(new StringValue("*.google.com")); 179 blacklist->Append(new StringValue("*.google.com"));
180 ListValue* whitelist = new ListValue; 180 ListValue* whitelist = new ListValue;
181 whitelist->Append(new StringValue("mail.google.com")); 181 whitelist->Append(new StringValue("mail.google.com"));
182 pref_service_.SetManagedPref(prefs::kUrlBlacklist, blacklist); 182 pref_service_.SetManagedPref(prefs::kUrlBlacklist, blacklist);
183 pref_service_.SetManagedPref(prefs::kUrlBlacklist, whitelist); 183 pref_service_.SetManagedPref(prefs::kUrlBlacklist, whitelist);
184 loop_.RunAllPending(); 184 loop_.RunUntilIdle();
185 185
186 EXPECT_EQ(1, blacklist_manager_->update_called()); 186 EXPECT_EQ(1, blacklist_manager_->update_called());
187 } 187 }
188 188
189 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask0) { 189 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask0) {
190 // Post an update task to the UI thread. 190 // Post an update task to the UI thread.
191 blacklist_manager_->ScheduleUpdate(); 191 blacklist_manager_->ScheduleUpdate();
192 // Shutdown comes before the task is executed. 192 // Shutdown comes before the task is executed.
193 blacklist_manager_->ShutdownOnUIThread(); 193 blacklist_manager_->ShutdownOnUIThread();
194 blacklist_manager_.reset(); 194 blacklist_manager_.reset();
195 // Run the task after shutdown and deletion. 195 // Run the task after shutdown and deletion.
196 loop_.RunAllPending(); 196 loop_.RunUntilIdle();
197 } 197 }
198 198
199 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask1) { 199 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask1) {
200 // Post an update task. 200 // Post an update task.
201 blacklist_manager_->ScheduleUpdate(); 201 blacklist_manager_->ScheduleUpdate();
202 // Shutdown comes before the task is executed. 202 // Shutdown comes before the task is executed.
203 blacklist_manager_->ShutdownOnUIThread(); 203 blacklist_manager_->ShutdownOnUIThread();
204 // Run the task after shutdown, but before deletion. 204 // Run the task after shutdown, but before deletion.
205 loop_.RunAllPending(); 205 loop_.RunUntilIdle();
206 206
207 EXPECT_EQ(0, blacklist_manager_->update_called()); 207 EXPECT_EQ(0, blacklist_manager_->update_called());
208 blacklist_manager_.reset(); 208 blacklist_manager_.reset();
209 loop_.RunAllPending(); 209 loop_.RunUntilIdle();
210 } 210 }
211 211
212 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask2) { 212 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask2) {
213 // This posts a task to the FILE thread. 213 // This posts a task to the FILE thread.
214 blacklist_manager_->UpdateOnIOForTesting(); 214 blacklist_manager_->UpdateOnIOForTesting();
215 // But shutdown happens before it is done. 215 // But shutdown happens before it is done.
216 blacklist_manager_->ShutdownOnUIThread(); 216 blacklist_manager_->ShutdownOnUIThread();
217 217
218 EXPECT_FALSE(blacklist_manager_->set_blacklist_called()); 218 EXPECT_FALSE(blacklist_manager_->set_blacklist_called());
219 blacklist_manager_.reset(); 219 blacklist_manager_.reset();
220 loop_.RunAllPending(); 220 loop_.RunUntilIdle();
221 } 221 }
222 222
223 TEST_F(URLBlacklistManagerTest, HasStandardScheme) { 223 TEST_F(URLBlacklistManagerTest, HasStandardScheme) {
224 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("http://example.com"))); 224 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("http://example.com")));
225 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("https://example.com"))); 225 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("https://example.com")));
226 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("ftp://example.com"))); 226 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("ftp://example.com")));
227 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("gopher://example.com"))); 227 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("gopher://example.com")));
228 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("ws://example.com"))); 228 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("ws://example.com")));
229 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("wss://example.com"))); 229 EXPECT_TRUE(URLBlacklist::HasStandardScheme(GURL("wss://example.com")));
230 EXPECT_FALSE(URLBlacklist::HasStandardScheme(GURL("wtf://example.com"))); 230 EXPECT_FALSE(URLBlacklist::HasStandardScheme(GURL("wtf://example.com")));
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 EXPECT_FALSE(blacklist.IsURLBlocked(GURL("http://s.plus.google.com"))); 434 EXPECT_FALSE(blacklist.IsURLBlocked(GURL("http://s.plus.google.com")));
435 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://mail.google.com"))); 435 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://mail.google.com")));
436 EXPECT_FALSE(blacklist.IsURLBlocked(GURL("https://mail.google.com"))); 436 EXPECT_FALSE(blacklist.IsURLBlocked(GURL("https://mail.google.com")));
437 EXPECT_FALSE(blacklist.IsURLBlocked(GURL("https://s.mail.google.com"))); 437 EXPECT_FALSE(blacklist.IsURLBlocked(GURL("https://s.mail.google.com")));
438 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("https://very.safe/"))); 438 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("https://very.safe/")));
439 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://very.safe/path"))); 439 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://very.safe/path")));
440 EXPECT_FALSE(blacklist.IsURLBlocked(GURL("https://very.safe/path"))); 440 EXPECT_FALSE(blacklist.IsURLBlocked(GURL("https://very.safe/path")));
441 } 441 }
442 442
443 } // namespace policy 443 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698