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/callback.h" | 10 #include "base/callback.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
13 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/testing_pref_service.h" | 14 #include "base/prefs/testing_pref_service.h" |
15 #include "chrome/browser/policy/policy_helpers.h" | 15 #include "chrome/browser/policy/policy_helpers.h" |
16 #include "components/policy/core/common/policy_pref_names.h" | 16 #include "components/policy/core/common/policy_pref_names.h" |
17 #include "components/url_fixer/url_fixer.h" | 17 #include "components/url_fixer/url_fixer.h" |
18 #include "google_apis/gaia/gaia_urls.h" | 18 #include "google_apis/gaia/gaia_urls.h" |
19 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "net/base/request_priority.h" | 21 #include "net/base/request_priority.h" |
22 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 23 #include "net/url_request/url_request_context.h" |
23 #include "net/url_request/url_request_test_util.h" | 24 #include "net/url_request/url_request_test_util.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
26 | 27 |
27 // TODO(joaodasilva): this file should be moved next to | 28 // TODO(joaodasilva): this file should be moved next to |
28 // components/policy/core/browser/url_blacklist_manager.(cc|h). | 29 // components/policy/core/browser/url_blacklist_manager.(cc|h). |
29 // However, url_fixer_upper.h can't be included from the component. Rather | 30 // However, url_fixer_upper.h can't be included from the component. Rather |
30 // than having it mocked out, the actual url_fixer::SegmentURL call is used | 31 // than having it mocked out, the actual url_fixer::SegmentURL call is used |
31 // to make sure that the parsing of URL filters is correct. | 32 // to make sure that the parsing of URL filters is correct. |
32 | 33 |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 | 637 |
637 TEST_F(URLBlacklistManagerTest, DontBlockResources) { | 638 TEST_F(URLBlacklistManagerTest, DontBlockResources) { |
638 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist(GetSegmentURLCallback())); | 639 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist(GetSegmentURLCallback())); |
639 scoped_ptr<base::ListValue> blocked(new base::ListValue); | 640 scoped_ptr<base::ListValue> blocked(new base::ListValue); |
640 blocked->Append(new base::StringValue("google.com")); | 641 blocked->Append(new base::StringValue("google.com")); |
641 blacklist->Block(blocked.get()); | 642 blacklist->Block(blocked.get()); |
642 blacklist_manager_->SetBlacklist(blacklist.Pass()); | 643 blacklist_manager_->SetBlacklist(blacklist.Pass()); |
643 EXPECT_TRUE(blacklist_manager_->IsURLBlocked(GURL("http://google.com"))); | 644 EXPECT_TRUE(blacklist_manager_->IsURLBlocked(GURL("http://google.com"))); |
644 | 645 |
645 net::TestURLRequestContext context; | 646 net::TestURLRequestContext context; |
646 net::URLRequest request( | 647 scoped_ptr<net::URLRequest> request(context.CreateRequest( |
647 GURL("http://google.com"), net::DEFAULT_PRIORITY, NULL, &context); | 648 GURL("http://google.com"), net::DEFAULT_PRIORITY, NULL, NULL)); |
648 | 649 |
649 int reason = net::ERR_UNEXPECTED; | 650 int reason = net::ERR_UNEXPECTED; |
650 // Background requests aren't filtered. | 651 // Background requests aren't filtered. |
651 EXPECT_FALSE(blacklist_manager_->IsRequestBlocked(request, &reason)); | 652 EXPECT_FALSE(blacklist_manager_->IsRequestBlocked(*request.get(), &reason)); |
652 | 653 |
653 // Main frames are filtered. | 654 // Main frames are filtered. |
654 request.SetLoadFlags(net::LOAD_MAIN_FRAME); | 655 request->SetLoadFlags(net::LOAD_MAIN_FRAME); |
655 EXPECT_TRUE(blacklist_manager_->IsRequestBlocked(request, &reason)); | 656 EXPECT_TRUE(blacklist_manager_->IsRequestBlocked(*request.get(), &reason)); |
656 EXPECT_EQ(net::ERR_BLOCKED_BY_ADMINISTRATOR, reason); | 657 EXPECT_EQ(net::ERR_BLOCKED_BY_ADMINISTRATOR, reason); |
657 | 658 |
658 // On most platforms, sync gets a free pass due to signin flows. | 659 // On most platforms, sync gets a free pass due to signin flows. |
659 bool block_signin_urls = false; | 660 bool block_signin_urls = false; |
660 #if defined(OS_CHROMEOS) | 661 #if defined(OS_CHROMEOS) |
661 // There are no sync specific signin flows on Chrome OS, so no special | 662 // There are no sync specific signin flows on Chrome OS, so no special |
662 // treatment. | 663 // treatment. |
663 block_signin_urls = true; | 664 block_signin_urls = true; |
664 #endif | 665 #endif |
665 | 666 |
666 GURL sync_url(GaiaUrls::GetInstance()->service_login_url().Resolve( | 667 GURL sync_url(GaiaUrls::GetInstance()->service_login_url().Resolve( |
667 "?service=chromiumsync")); | 668 "?service=chromiumsync")); |
668 net::URLRequest sync_request(sync_url, net::DEFAULT_PRIORITY, NULL, &context); | 669 scoped_ptr<net::URLRequest> sync_request(context.CreateRequest( |
669 sync_request.SetLoadFlags(net::LOAD_MAIN_FRAME); | 670 sync_url, net::DEFAULT_PRIORITY, NULL, NULL)); |
| 671 sync_request->SetLoadFlags(net::LOAD_MAIN_FRAME); |
670 EXPECT_EQ(block_signin_urls, | 672 EXPECT_EQ(block_signin_urls, |
671 blacklist_manager_->IsRequestBlocked(sync_request, &reason)); | 673 blacklist_manager_->IsRequestBlocked(*sync_request.get(), &reason)); |
672 } | 674 } |
673 | 675 |
674 TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) { | 676 TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) { |
675 URLBlacklist blacklist(GetSegmentURLCallback()); | 677 URLBlacklist blacklist(GetSegmentURLCallback()); |
676 scoped_ptr<base::ListValue> blocked(new base::ListValue); | 678 scoped_ptr<base::ListValue> blocked(new base::ListValue); |
677 | 679 |
678 // Blacklist everything: | 680 // Blacklist everything: |
679 blocked->Append(new base::StringValue("*")); | 681 blocked->Append(new base::StringValue("*")); |
680 blacklist.Block(blocked.get()); | 682 blacklist.Block(blocked.get()); |
681 | 683 |
(...skipping 11 matching lines...) Expand all Loading... |
693 blacklist.Allow(allowed.get()); | 695 blacklist.Allow(allowed.get()); |
694 | 696 |
695 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://www.google.com"))); | 697 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://www.google.com"))); |
696 EXPECT_TRUE((blacklist.IsURLBlocked(GURL("chrome-extension://xyz")))); | 698 EXPECT_TRUE((blacklist.IsURLBlocked(GURL("chrome-extension://xyz")))); |
697 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-extension://abc")))); | 699 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-extension://abc")))); |
698 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-search://local-ntp")))); | 700 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-search://local-ntp")))); |
699 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-native://ntp")))); | 701 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-native://ntp")))); |
700 } | 702 } |
701 | 703 |
702 } // namespace policy | 704 } // namespace policy |
OLD | NEW |