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

Side by Side Diff: components/policy/core/browser/url_blacklist_manager_unittest.cc

Issue 2211473003: Remove calls to deprecated MessageLoop methods on Windows and Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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
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 "components/policy/core/browser/url_blacklist_manager.h" 5 #include "components/policy/core/browser/url_blacklist_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <memory> 8 #include <memory>
9 #include <ostream> 9 #include <ostream>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h"
16 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/values.h" 18 #include "base/values.h"
18 #include "components/policy/core/common/policy_pref_names.h" 19 #include "components/policy/core/common/policy_pref_names.h"
19 #include "components/prefs/pref_registry_simple.h" 20 #include "components/prefs/pref_registry_simple.h"
20 #include "components/prefs/testing_pref_service.h" 21 #include "components/prefs/testing_pref_service.h"
21 #include "components/url_formatter/url_fixer.h" 22 #include "components/url_formatter/url_fixer.h"
22 #include "google_apis/gaia/gaia_urls.h" 23 #include "google_apis/gaia/gaia_urls.h"
23 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
24 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 }; 85 };
85 86
86 class URLBlacklistManagerTest : public testing::Test { 87 class URLBlacklistManagerTest : public testing::Test {
87 protected: 88 protected:
88 URLBlacklistManagerTest() {} 89 URLBlacklistManagerTest() {}
89 90
90 void SetUp() override { 91 void SetUp() override {
91 pref_service_.registry()->RegisterListPref(policy_prefs::kUrlBlacklist); 92 pref_service_.registry()->RegisterListPref(policy_prefs::kUrlBlacklist);
92 pref_service_.registry()->RegisterListPref(policy_prefs::kUrlWhitelist); 93 pref_service_.registry()->RegisterListPref(policy_prefs::kUrlWhitelist);
93 blacklist_manager_.reset(new TestingURLBlacklistManager(&pref_service_)); 94 blacklist_manager_.reset(new TestingURLBlacklistManager(&pref_service_));
94 loop_.RunUntilIdle(); 95 base::RunLoop().RunUntilIdle();
95 } 96 }
96 97
97 void TearDown() override { 98 void TearDown() override {
98 if (blacklist_manager_.get()) 99 if (blacklist_manager_.get())
99 blacklist_manager_->ShutdownOnUIThread(); 100 blacklist_manager_->ShutdownOnUIThread();
100 loop_.RunUntilIdle(); 101 base::RunLoop().RunUntilIdle();
101 // Delete |blacklist_manager_| while |io_thread_| is mapping IO to 102 // Delete |blacklist_manager_| while |io_thread_| is mapping IO to
102 // |loop_|. 103 // |loop_|.
103 blacklist_manager_.reset(); 104 blacklist_manager_.reset();
104 } 105 }
105 106
106 base::MessageLoopForIO loop_; 107 base::MessageLoopForIO loop_;
107 TestingPrefServiceSimple pref_service_; 108 TestingPrefServiceSimple pref_service_;
108 std::unique_ptr<TestingURLBlacklistManager> blacklist_manager_; 109 std::unique_ptr<TestingURLBlacklistManager> blacklist_manager_;
109 }; 110 };
110 111
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 EXPECT_EQ(GetParam().path(), path); 229 EXPECT_EQ(GetParam().path(), path);
229 } 230 }
230 231
231 TEST_F(URLBlacklistManagerTest, SingleUpdateForTwoPrefChanges) { 232 TEST_F(URLBlacklistManagerTest, SingleUpdateForTwoPrefChanges) {
232 base::ListValue* blacklist = new base::ListValue; 233 base::ListValue* blacklist = new base::ListValue;
233 blacklist->AppendString("*.google.com"); 234 blacklist->AppendString("*.google.com");
234 base::ListValue* whitelist = new base::ListValue; 235 base::ListValue* whitelist = new base::ListValue;
235 whitelist->AppendString("mail.google.com"); 236 whitelist->AppendString("mail.google.com");
236 pref_service_.SetManagedPref(policy_prefs::kUrlBlacklist, blacklist); 237 pref_service_.SetManagedPref(policy_prefs::kUrlBlacklist, blacklist);
237 pref_service_.SetManagedPref(policy_prefs::kUrlBlacklist, whitelist); 238 pref_service_.SetManagedPref(policy_prefs::kUrlBlacklist, whitelist);
238 loop_.RunUntilIdle(); 239 base::RunLoop().RunUntilIdle();
239 240
240 EXPECT_EQ(1, blacklist_manager_->update_called()); 241 EXPECT_EQ(1, blacklist_manager_->update_called());
241 } 242 }
242 243
243 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask0) { 244 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask0) {
244 // Post an update task to the UI thread. 245 // Post an update task to the UI thread.
245 blacklist_manager_->ScheduleUpdate(); 246 blacklist_manager_->ScheduleUpdate();
246 // Shutdown comes before the task is executed. 247 // Shutdown comes before the task is executed.
247 blacklist_manager_->ShutdownOnUIThread(); 248 blacklist_manager_->ShutdownOnUIThread();
248 blacklist_manager_.reset(); 249 blacklist_manager_.reset();
249 // Run the task after shutdown and deletion. 250 // Run the task after shutdown and deletion.
250 loop_.RunUntilIdle(); 251 base::RunLoop().RunUntilIdle();
251 } 252 }
252 253
253 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask1) { 254 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask1) {
254 // Post an update task. 255 // Post an update task.
255 blacklist_manager_->ScheduleUpdate(); 256 blacklist_manager_->ScheduleUpdate();
256 // Shutdown comes before the task is executed. 257 // Shutdown comes before the task is executed.
257 blacklist_manager_->ShutdownOnUIThread(); 258 blacklist_manager_->ShutdownOnUIThread();
258 // Run the task after shutdown, but before deletion. 259 // Run the task after shutdown, but before deletion.
259 loop_.RunUntilIdle(); 260 base::RunLoop().RunUntilIdle();
260 261
261 EXPECT_EQ(0, blacklist_manager_->update_called()); 262 EXPECT_EQ(0, blacklist_manager_->update_called());
262 blacklist_manager_.reset(); 263 blacklist_manager_.reset();
263 loop_.RunUntilIdle(); 264 base::RunLoop().RunUntilIdle();
264 } 265 }
265 266
266 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask2) { 267 TEST_F(URLBlacklistManagerTest, ShutdownWithPendingTask2) {
267 // This posts a task to the FILE thread. 268 // This posts a task to the FILE thread.
268 blacklist_manager_->UpdateOnIOForTesting(); 269 blacklist_manager_->UpdateOnIOForTesting();
269 // But shutdown happens before it is done. 270 // But shutdown happens before it is done.
270 blacklist_manager_->ShutdownOnUIThread(); 271 blacklist_manager_->ShutdownOnUIThread();
271 272
272 EXPECT_FALSE(blacklist_manager_->set_blacklist_called()); 273 EXPECT_FALSE(blacklist_manager_->set_blacklist_called());
273 blacklist_manager_.reset(); 274 blacklist_manager_.reset();
274 loop_.RunUntilIdle(); 275 base::RunLoop().RunUntilIdle();
275 } 276 }
276 277
277 INSTANTIATE_TEST_CASE_P( 278 INSTANTIATE_TEST_CASE_P(
278 URLBlacklistFilterToComponentsTestInstance, 279 URLBlacklistFilterToComponentsTestInstance,
279 URLBlacklistFilterToComponentsTest, 280 URLBlacklistFilterToComponentsTest,
280 testing::Values( 281 testing::Values(
281 FilterTestParams("google.com", 282 FilterTestParams("google.com",
282 std::string(), 283 std::string(),
283 ".google.com", 284 ".google.com",
284 true, 285 true,
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 EXPECT_EQ(in_whitelist, GetMatch("custom://*", "custom://app", true)); 830 EXPECT_EQ(in_whitelist, GetMatch("custom://*", "custom://app", true));
830 EXPECT_EQ(in_whitelist, GetMatch("custom:*", "custom://app/play", true)); 831 EXPECT_EQ(in_whitelist, GetMatch("custom:*", "custom://app/play", true));
831 EXPECT_EQ(in_whitelist, GetMatch("custom:*", "custom://app:8080", true)); 832 EXPECT_EQ(in_whitelist, GetMatch("custom:*", "custom://app:8080", true));
832 // Test blacklist states. 833 // Test blacklist states.
833 EXPECT_EQ(in_blacklist, GetMatch("ftp:*", "ftp://server", false)); 834 EXPECT_EQ(in_blacklist, GetMatch("ftp:*", "ftp://server", false));
834 // Test neutral states. 835 // Test neutral states.
835 EXPECT_EQ(neutral_state, GetMatch("file:*", "http://example.com", true)); 836 EXPECT_EQ(neutral_state, GetMatch("file:*", "http://example.com", true));
836 EXPECT_EQ(neutral_state, GetMatch("https://*", "http://example.com", false)); 837 EXPECT_EQ(neutral_state, GetMatch("https://*", "http://example.com", false));
837 } 838 }
838 } // namespace policy 839 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698