| 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" |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 TEST_F(URLBlacklistManagerTest, DontBlockResources) { | 637 TEST_F(URLBlacklistManagerTest, DontBlockResources) { |
| 638 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist(GetSegmentURLCallback())); | 638 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist(GetSegmentURLCallback())); |
| 639 scoped_ptr<base::ListValue> blocked(new base::ListValue); | 639 scoped_ptr<base::ListValue> blocked(new base::ListValue); |
| 640 blocked->Append(new base::StringValue("google.com")); | 640 blocked->Append(new base::StringValue("google.com")); |
| 641 blacklist->Block(blocked.get()); | 641 blacklist->Block(blocked.get()); |
| 642 blacklist_manager_->SetBlacklist(blacklist.Pass()); | 642 blacklist_manager_->SetBlacklist(blacklist.Pass()); |
| 643 EXPECT_TRUE(blacklist_manager_->IsURLBlocked(GURL("http://google.com"))); | 643 EXPECT_TRUE(blacklist_manager_->IsURLBlocked(GURL("http://google.com"))); |
| 644 | 644 |
| 645 net::TestURLRequestContext context; | 645 net::TestURLRequestContext context; |
| 646 scoped_ptr<net::URLRequest> request(context.CreateRequest( | 646 scoped_ptr<net::URLRequest> request(context.CreateRequest( |
| 647 GURL("http://google.com"), net::DEFAULT_PRIORITY, NULL, NULL)); | 647 GURL("http://google.com"), net::DEFAULT_PRIORITY, NULL)); |
| 648 | 648 |
| 649 int reason = net::ERR_UNEXPECTED; | 649 int reason = net::ERR_UNEXPECTED; |
| 650 // Background requests aren't filtered. | 650 // Background requests aren't filtered. |
| 651 EXPECT_FALSE(blacklist_manager_->IsRequestBlocked(*request.get(), &reason)); | 651 EXPECT_FALSE(blacklist_manager_->IsRequestBlocked(*request.get(), &reason)); |
| 652 | 652 |
| 653 // Main frames are filtered. | 653 // Main frames are filtered. |
| 654 request->SetLoadFlags(net::LOAD_MAIN_FRAME); | 654 request->SetLoadFlags(net::LOAD_MAIN_FRAME); |
| 655 EXPECT_TRUE(blacklist_manager_->IsRequestBlocked(*request.get(), &reason)); | 655 EXPECT_TRUE(blacklist_manager_->IsRequestBlocked(*request.get(), &reason)); |
| 656 EXPECT_EQ(net::ERR_BLOCKED_BY_ADMINISTRATOR, reason); | 656 EXPECT_EQ(net::ERR_BLOCKED_BY_ADMINISTRATOR, reason); |
| 657 | 657 |
| 658 // On most platforms, sync gets a free pass due to signin flows. | 658 // On most platforms, sync gets a free pass due to signin flows. |
| 659 bool block_signin_urls = false; | 659 bool block_signin_urls = false; |
| 660 #if defined(OS_CHROMEOS) | 660 #if defined(OS_CHROMEOS) |
| 661 // There are no sync specific signin flows on Chrome OS, so no special | 661 // There are no sync specific signin flows on Chrome OS, so no special |
| 662 // treatment. | 662 // treatment. |
| 663 block_signin_urls = true; | 663 block_signin_urls = true; |
| 664 #endif | 664 #endif |
| 665 | 665 |
| 666 GURL sync_url(GaiaUrls::GetInstance()->service_login_url().Resolve( | 666 GURL sync_url(GaiaUrls::GetInstance()->service_login_url().Resolve( |
| 667 "?service=chromiumsync")); | 667 "?service=chromiumsync")); |
| 668 scoped_ptr<net::URLRequest> sync_request(context.CreateRequest( | 668 scoped_ptr<net::URLRequest> sync_request(context.CreateRequest( |
| 669 sync_url, net::DEFAULT_PRIORITY, NULL, NULL)); | 669 sync_url, net::DEFAULT_PRIORITY, NULL)); |
| 670 sync_request->SetLoadFlags(net::LOAD_MAIN_FRAME); | 670 sync_request->SetLoadFlags(net::LOAD_MAIN_FRAME); |
| 671 EXPECT_EQ(block_signin_urls, | 671 EXPECT_EQ(block_signin_urls, |
| 672 blacklist_manager_->IsRequestBlocked(*sync_request.get(), &reason)); | 672 blacklist_manager_->IsRequestBlocked(*sync_request.get(), &reason)); |
| 673 } | 673 } |
| 674 | 674 |
| 675 TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) { | 675 TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) { |
| 676 URLBlacklist blacklist(GetSegmentURLCallback()); | 676 URLBlacklist blacklist(GetSegmentURLCallback()); |
| 677 scoped_ptr<base::ListValue> blocked(new base::ListValue); | 677 scoped_ptr<base::ListValue> blocked(new base::ListValue); |
| 678 | 678 |
| 679 // Blacklist everything: | 679 // Blacklist everything: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 694 blacklist.Allow(allowed.get()); | 694 blacklist.Allow(allowed.get()); |
| 695 | 695 |
| 696 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://www.google.com"))); | 696 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://www.google.com"))); |
| 697 EXPECT_TRUE((blacklist.IsURLBlocked(GURL("chrome-extension://xyz")))); | 697 EXPECT_TRUE((blacklist.IsURLBlocked(GURL("chrome-extension://xyz")))); |
| 698 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-extension://abc")))); | 698 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-extension://abc")))); |
| 699 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-search://local-ntp")))); | 699 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-search://local-ntp")))); |
| 700 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-native://ntp")))); | 700 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-native://ntp")))); |
| 701 } | 701 } |
| 702 | 702 |
| 703 } // namespace policy | 703 } // namespace policy |
| OLD | NEW |