OLD | NEW |
---|---|
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 <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | |
10 #include "base/callback.h" | 11 #include "base/callback.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
13 #include "base/prefs/testing_pref_service.h" | 14 #include "base/prefs/testing_pref_service.h" |
14 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
15 #include "chrome/browser/policy/policy_helpers.h" | 16 #include "chrome/browser/policy/policy_helpers.h" |
16 #include "components/policy/core/common/policy_pref_names.h" | 17 #include "components/policy/core/common/policy_pref_names.h" |
17 #include "components/url_fixer/url_fixer.h" | 18 #include "components/url_fixer/url_fixer.h" |
18 #include "google_apis/gaia/gaia_urls.h" | 19 #include "google_apis/gaia/gaia_urls.h" |
19 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
20 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
21 #include "net/base/request_priority.h" | |
22 #include "net/url_request/url_request.h" | |
23 #include "net/url_request/url_request_context.h" | |
24 #include "net/url_request/url_request_test_util.h" | |
25 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "url/gurl.h" | 23 #include "url/gurl.h" |
27 | 24 |
28 // TODO(joaodasilva): this file should be moved next to | 25 // TODO(joaodasilva): this file should be moved next to |
29 // components/policy/core/browser/url_blacklist_manager.(cc|h). | 26 // components/policy/core/browser/url_blacklist_manager.(cc|h). |
30 // However, url_fixer_upper.h can't be included from the component. Rather | 27 // However, url_fixer_upper.h can't be included from the component. Rather |
31 // than having it mocked out, the actual url_fixer::SegmentURL call is used | 28 // than having it mocked out, the actual url_fixer::SegmentURL call is used |
32 // to make sure that the parsing of URL filters is correct. | 29 // to make sure that the parsing of URL filters is correct. |
33 | 30 |
34 namespace policy { | 31 namespace policy { |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 } | 632 } |
636 | 633 |
637 TEST_F(URLBlacklistManagerTest, DontBlockResources) { | 634 TEST_F(URLBlacklistManagerTest, DontBlockResources) { |
638 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist(GetSegmentURLCallback())); | 635 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist(GetSegmentURLCallback())); |
639 scoped_ptr<base::ListValue> blocked(new base::ListValue); | 636 scoped_ptr<base::ListValue> blocked(new base::ListValue); |
640 blocked->Append(new base::StringValue("google.com")); | 637 blocked->Append(new base::StringValue("google.com")); |
641 blacklist->Block(blocked.get()); | 638 blacklist->Block(blocked.get()); |
642 blacklist_manager_->SetBlacklist(blacklist.Pass()); | 639 blacklist_manager_->SetBlacklist(blacklist.Pass()); |
643 EXPECT_TRUE(blacklist_manager_->IsURLBlocked(GURL("http://google.com"))); | 640 EXPECT_TRUE(blacklist_manager_->IsURLBlocked(GURL("http://google.com"))); |
644 | 641 |
645 net::TestURLRequestContext context; | |
646 scoped_ptr<net::URLRequest> request(context.CreateRequest( | |
647 GURL("http://google.com"), net::DEFAULT_PRIORITY, NULL)); | |
648 | |
649 int reason = net::ERR_UNEXPECTED; | 642 int reason = net::ERR_UNEXPECTED; |
650 // Background requests aren't filtered. | 643 EXPECT_TRUE(blacklist_manager_->ShouldBlockRequestForFrame( |
651 EXPECT_FALSE(blacklist_manager_->IsRequestBlocked(*request.get(), &reason)); | 644 GURL("http://google.com"), &reason)); |
Andrew T Wilson (Slow)
2015/05/12 16:44:30
This is no longer checking the reason for the requ
mmenke
2015/05/12 16:59:13
Yea, it should still check that (Added back).
mmenke
2015/05/12 17:04:07
I'm happy to add an integration test in a followup
| |
652 | |
653 // Main frames are filtered. | |
654 request->SetLoadFlags(net::LOAD_MAIN_FRAME); | |
655 EXPECT_TRUE(blacklist_manager_->IsRequestBlocked(*request.get(), &reason)); | |
656 EXPECT_EQ(net::ERR_BLOCKED_BY_ADMINISTRATOR, reason); | |
657 } | 645 } |
658 | 646 |
659 TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) { | 647 TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) { |
660 URLBlacklist blacklist(GetSegmentURLCallback()); | 648 URLBlacklist blacklist(GetSegmentURLCallback()); |
661 scoped_ptr<base::ListValue> blocked(new base::ListValue); | 649 scoped_ptr<base::ListValue> blocked(new base::ListValue); |
662 | 650 |
663 // Blacklist everything: | 651 // Blacklist everything: |
664 blocked->Append(new base::StringValue("*")); | 652 blocked->Append(new base::StringValue("*")); |
665 blacklist.Block(blocked.get()); | 653 blacklist.Block(blocked.get()); |
666 | 654 |
(...skipping 11 matching lines...) Expand all Loading... | |
678 blacklist.Allow(allowed.get()); | 666 blacklist.Allow(allowed.get()); |
679 | 667 |
680 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://www.google.com"))); | 668 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://www.google.com"))); |
681 EXPECT_TRUE((blacklist.IsURLBlocked(GURL("chrome-extension://xyz")))); | 669 EXPECT_TRUE((blacklist.IsURLBlocked(GURL("chrome-extension://xyz")))); |
682 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-extension://abc")))); | 670 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-extension://abc")))); |
683 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-search://local-ntp")))); | 671 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-search://local-ntp")))); |
684 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-native://ntp")))); | 672 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-native://ntp")))); |
685 } | 673 } |
686 | 674 |
687 } // namespace policy | 675 } // namespace policy |
OLD | NEW |