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

Side by Side Diff: chrome/browser/policy/url_blacklist_manager_unittest.cc

Issue 1134733004: Remove LOAD_SUB_FRAME load flag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to atwilson's comments Created 5 years, 7 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
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
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));
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); 645 EXPECT_EQ(net::ERR_BLOCKED_BY_ADMINISTRATOR, reason);
657 } 646 }
658 647
659 TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) { 648 TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) {
660 URLBlacklist blacklist(GetSegmentURLCallback()); 649 URLBlacklist blacklist(GetSegmentURLCallback());
661 scoped_ptr<base::ListValue> blocked(new base::ListValue); 650 scoped_ptr<base::ListValue> blocked(new base::ListValue);
662 651
663 // Blacklist everything: 652 // Blacklist everything:
664 blocked->Append(new base::StringValue("*")); 653 blocked->Append(new base::StringValue("*"));
665 blacklist.Block(blocked.get()); 654 blacklist.Block(blocked.get());
(...skipping 12 matching lines...) Expand all
678 blacklist.Allow(allowed.get()); 667 blacklist.Allow(allowed.get());
679 668
680 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://www.google.com"))); 669 EXPECT_TRUE(blacklist.IsURLBlocked(GURL("http://www.google.com")));
681 EXPECT_TRUE((blacklist.IsURLBlocked(GURL("chrome-extension://xyz")))); 670 EXPECT_TRUE((blacklist.IsURLBlocked(GURL("chrome-extension://xyz"))));
682 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-extension://abc")))); 671 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-extension://abc"))));
683 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-search://local-ntp")))); 672 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-search://local-ntp"))));
684 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-native://ntp")))); 673 EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-native://ntp"))));
685 } 674 }
686 675
687 } // namespace policy 676 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/net/connect_interceptor.cc ('k') | components/policy/core/browser/url_blacklist_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698