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

Side by Side Diff: chrome/browser/privacy_blacklist/blacklist_interceptor_unittest.cc

Issue 501082: Implement delaying resource requests until privacy blacklists are ready. (Closed)
Patch Set: don't get stuck on errors Created 10 years, 11 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
(Empty)
1 // Copyright (c) 2009 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 "app/l10n_util.h"
6 #include "base/message_loop.h"
7 #include "base/path_service.h"
8 #include "chrome/browser/chrome_thread.h"
9 #include "chrome/browser/privacy_blacklist/blacklist_interceptor.h"
10 #include "chrome/browser/privacy_blacklist/blacklist_manager.h"
11 #include "chrome/browser/privacy_blacklist/blacklist_request_info.h"
12 #include "chrome/browser/privacy_blacklist/blacklist_test_util.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "grit/browser_resources.h"
15 #include "grit/generated_resources.h"
16 #include "net/base/io_buffer.h"
17 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_status.h"
19 #include "net/url_request/url_request_unittest.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace {
23
24 const char kDataUrl[] = "data:text/plain,Hello World!";
25 const char kBlockedUrl[] = "http://example.com/annoying_ads/ad.jpg";
26
27 class BlacklistInterceptorTest : public testing::Test {
28 public:
29 BlacklistInterceptorTest()
30 : loop_(MessageLoop::TYPE_IO),
31 ui_thread_(ChromeThread::UI, &loop_),
32 file_thread_(ChromeThread::FILE, &loop_),
33 io_thread_(ChromeThread::IO, &loop_) {
34 }
35
36 virtual void SetUp() {
37 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_));
38 test_data_dir_ = test_data_dir_.AppendASCII("blacklist_samples");
39 }
40
41 protected:
42 bool InterceptedTestRequest(const std::string& url,
43 BlacklistRequestInfo* request_info) {
44 TestDelegate delegate;
45 TestURLRequest request(GURL(url), &delegate);
46 request.SetUserData(&BlacklistRequestInfo::kURLRequestDataKey,
47 request_info);
48 request.Start();
49 MessageLoop::current()->Run();
50
51 std::string response(delegate.data_received());
52 return (ContainsResourceString(response, IDS_BLACKLIST_TITLE) &&
53 ContainsResourceString(response, IDS_BLACKLIST_MESSAGE));
54 }
55
56 BlacklistInterceptor interceptor_;
57
58 FilePath test_data_dir_;
59
60 private:
61 bool ContainsResourceString(const std::string& text, int string_id) {
62 return text.find(l10n_util::GetStringUTF8(string_id)) != std::string::npos;
63 }
64
65 MessageLoop loop_;
66
67 ChromeThread ui_thread_;
68 ChromeThread file_thread_;
69 ChromeThread io_thread_;
70 };
71
72 TEST_F(BlacklistInterceptorTest, Basic) {
73 EXPECT_FALSE(InterceptedTestRequest(kDataUrl, NULL));
74 }
75
76 TEST_F(BlacklistInterceptorTest, Intercepted) {
77 BlacklistTestingProfile profile;
78 TestBlacklistPathProvider path_provider(&profile);
79 path_provider.AddTransientPath(
80 test_data_dir_.AppendASCII("annoying_ads.pbl"));
81 scoped_refptr<BlacklistManager> blacklist_manager(
82 new BlacklistManager(&profile, &path_provider));
83 blacklist_manager->Initialize();
84 MessageLoop::current()->RunAllPending();
85
86 EXPECT_FALSE(InterceptedTestRequest(kDataUrl, NULL));
87
88 BlacklistRequestInfo* request_info =
89 new BlacklistRequestInfo(GURL(kBlockedUrl), ResourceType::MAIN_FRAME,
90 blacklist_manager.get());
91 EXPECT_TRUE(InterceptedTestRequest(kBlockedUrl, request_info));
92 }
93
94 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/privacy_blacklist/blacklist_interceptor.cc ('k') | chrome/browser/privacy_blacklist/blacklist_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698