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

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

Issue 2862041: Remove abonded privacy blacklist implementation. (Closed)
Patch Set: fix unit tests Created 10 years, 5 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 "chrome/browser/privacy_blacklist/blacklist_interceptor.h"
8 #include "chrome/browser/privacy_blacklist/blacklist_request_info.h"
9 #include "grit/browser_resources.h"
10 #include "grit/generated_resources.h"
11 #include "net/base/io_buffer.h"
12 #include "net/url_request/url_request.h"
13 #include "net/url_request/url_request_status.h"
14 #include "net/url_request/url_request_unittest.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace {
18
19 const char kDataUrl[] = "data:text/plain,Hello World!";
20 const char kBlockedUrl[] = "http://example.com/annoying_ads/ad.jpg";
21
22 class BlacklistInterceptorTest : public testing::Test {
23 public:
24 BlacklistInterceptorTest() : loop_(MessageLoop::TYPE_IO) {
25 }
26
27 protected:
28 bool InterceptedTestRequest(const std::string& url,
29 BlacklistRequestInfo* request_info) {
30 TestDelegate delegate;
31 TestURLRequest request(GURL(url), &delegate);
32 request.SetUserData(&BlacklistRequestInfo::kURLRequestDataKey,
33 request_info);
34 request.Start();
35 MessageLoop::current()->Run();
36
37 std::string response(delegate.data_received());
38 return (ContainsResourceString(response, IDS_BLACKLIST_TITLE) &&
39 ContainsResourceString(response, IDS_BLACKLIST_MESSAGE));
40 }
41
42 BlacklistInterceptor interceptor_;
43
44 private:
45 bool ContainsResourceString(const std::string& text, int string_id) {
46 return text.find(l10n_util::GetStringUTF8(string_id)) != std::string::npos;
47 }
48
49 MessageLoop loop_;
50 };
51
52 TEST_F(BlacklistInterceptorTest, Basic) {
53 EXPECT_FALSE(InterceptedTestRequest(kDataUrl, NULL));
54 }
55
56 TEST_F(BlacklistInterceptorTest, Intercepted) {
57 EXPECT_FALSE(InterceptedTestRequest(kDataUrl, NULL));
58
59 scoped_refptr<Blacklist> blacklist = new Blacklist();
60 Blacklist::Provider* provider = new Blacklist::Provider();
61 blacklist->AddProvider(provider);
62 Blacklist::Entry* entry =
63 new Blacklist::Entry("@/annoying_ads/@", provider, false);
64 entry->AddAttributes(Blacklist::kBlockAll);
65 blacklist->AddEntry(entry);
66
67 BlacklistRequestInfo* request_info =
68 new BlacklistRequestInfo(GURL(kBlockedUrl), ResourceType::MAIN_FRAME,
69 blacklist.get());
70 EXPECT_TRUE(InterceptedTestRequest(kBlockedUrl, request_info));
71 }
72
73 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/privacy_blacklist/blacklist_interceptor.cc ('k') | chrome/browser/privacy_blacklist/blacklist_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698