| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | |
| 9 #include <ostream> | 8 #include <ostream> |
| 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/prefs/pref_registry_simple.h" | 15 #include "base/prefs/pref_registry_simple.h" |
| 16 #include "base/prefs/testing_pref_service.h" | 16 #include "base/prefs/testing_pref_service.h" |
| 17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 18 #include "components/policy/core/common/policy_pref_names.h" | 18 #include "components/policy/core/common/policy_pref_names.h" |
| 19 #include "components/url_formatter/url_fixer.h" | 19 #include "components/url_formatter/url_fixer.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 50 ~TestingURLBlacklistManager() override {} | 50 ~TestingURLBlacklistManager() override {} |
| 51 | 51 |
| 52 // Make this method public for testing. | 52 // Make this method public for testing. |
| 53 using URLBlacklistManager::ScheduleUpdate; | 53 using URLBlacklistManager::ScheduleUpdate; |
| 54 | 54 |
| 55 // Makes a direct call to UpdateOnIO during tests. | 55 // Makes a direct call to UpdateOnIO during tests. |
| 56 void UpdateOnIOForTesting() { | 56 void UpdateOnIOForTesting() { |
| 57 scoped_ptr<base::ListValue> block(new base::ListValue); | 57 scoped_ptr<base::ListValue> block(new base::ListValue); |
| 58 block->Append(new base::StringValue("example.com")); | 58 block->Append(new base::StringValue("example.com")); |
| 59 scoped_ptr<base::ListValue> allow(new base::ListValue); | 59 scoped_ptr<base::ListValue> allow(new base::ListValue); |
| 60 URLBlacklistManager::UpdateOnIO(block.Pass(), allow.Pass()); | 60 URLBlacklistManager::UpdateOnIO(std::move(block), std::move(allow)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // URLBlacklistManager overrides: | 63 // URLBlacklistManager overrides: |
| 64 void SetBlacklist(scoped_ptr<URLBlacklist> blacklist) override { | 64 void SetBlacklist(scoped_ptr<URLBlacklist> blacklist) override { |
| 65 set_blacklist_called_ = true; | 65 set_blacklist_called_ = true; |
| 66 URLBlacklistManager::SetBlacklist(blacklist.Pass()); | 66 URLBlacklistManager::SetBlacklist(std::move(blacklist)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void Update() override { | 69 void Update() override { |
| 70 update_called_++; | 70 update_called_++; |
| 71 URLBlacklistManager::Update(); | 71 URLBlacklistManager::Update(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 int update_called() const { return update_called_; } | 74 int update_called() const { return update_called_; } |
| 75 bool set_blacklist_called() const { return set_blacklist_called_; } | 75 bool set_blacklist_called() const { return set_blacklist_called_; } |
| 76 | 76 |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("https://very.safe/"))); | 635 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("https://very.safe/"))); |
| 636 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://very.safe/path"))); | 636 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://very.safe/path"))); |
| 637 EXPECT_FALSE(blacklist.IsURLBlocked(GURL("https://very.safe/path"))); | 637 EXPECT_FALSE(blacklist.IsURLBlocked(GURL("https://very.safe/path"))); |
| 638 } | 638 } |
| 639 | 639 |
| 640 TEST_F(URLBlacklistManagerTest, DontBlockResources) { | 640 TEST_F(URLBlacklistManagerTest, DontBlockResources) { |
| 641 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist(GetSegmentURLCallback())); | 641 scoped_ptr<URLBlacklist> blacklist(new URLBlacklist(GetSegmentURLCallback())); |
| 642 scoped_ptr<base::ListValue> blocked(new base::ListValue); | 642 scoped_ptr<base::ListValue> blocked(new base::ListValue); |
| 643 blocked->Append(new base::StringValue("google.com")); | 643 blocked->Append(new base::StringValue("google.com")); |
| 644 blacklist->Block(blocked.get()); | 644 blacklist->Block(blocked.get()); |
| 645 blacklist_manager_->SetBlacklist(blacklist.Pass()); | 645 blacklist_manager_->SetBlacklist(std::move(blacklist)); |
| 646 EXPECT_TRUE(blacklist_manager_->IsURLBlocked(GURL("http://google.com"))); | 646 EXPECT_TRUE(blacklist_manager_->IsURLBlocked(GURL("http://google.com"))); |
| 647 | 647 |
| 648 int reason = net::ERR_UNEXPECTED; | 648 int reason = net::ERR_UNEXPECTED; |
| 649 EXPECT_TRUE(blacklist_manager_->ShouldBlockRequestForFrame( | 649 EXPECT_TRUE(blacklist_manager_->ShouldBlockRequestForFrame( |
| 650 GURL("http://google.com"), &reason)); | 650 GURL("http://google.com"), &reason)); |
| 651 EXPECT_EQ(net::ERR_BLOCKED_BY_ADMINISTRATOR, reason); | 651 EXPECT_EQ(net::ERR_BLOCKED_BY_ADMINISTRATOR, reason); |
| 652 } | 652 } |
| 653 | 653 |
| 654 TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) { | 654 TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) { |
| 655 URLBlacklist blacklist(GetSegmentURLCallback()); | 655 URLBlacklist blacklist(GetSegmentURLCallback()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 673 blacklist.Allow(allowed.get()); | 673 blacklist.Allow(allowed.get()); |
| 674 | 674 |
| 675 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://www.google.com"))); | 675 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://www.google.com"))); |
| 676 EXPECT_TRUE((blacklist.IsURLBlocked(GURL("chrome-extension://xyz")))); | 676 EXPECT_TRUE((blacklist.IsURLBlocked(GURL("chrome-extension://xyz")))); |
| 677 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-extension://abc")))); | 677 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-extension://abc")))); |
| 678 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-search://local-ntp")))); | 678 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-search://local-ntp")))); |
| 679 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-native://ntp")))); | 679 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-native://ntp")))); |
| 680 } | 680 } |
| 681 | 681 |
| 682 } // namespace policy | 682 } // namespace policy |
| OLD | NEW |