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

Unified Diff: components/policy/core/browser/url_blacklist_manager_unittest.cc

Issue 1692503002: Functionality to allow blacklist and whitelist of custom schemes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another variable set as const Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: components/policy/core/browser/url_blacklist_manager_unittest.cc
diff --git a/components/policy/core/browser/url_blacklist_manager_unittest.cc b/components/policy/core/browser/url_blacklist_manager_unittest.cc
index 5e6e7f5fdad3f6ce7daf54fda7709e91b0263732..bf90091561c9ec4318749f4e637253f520e228e8 100644
--- a/components/policy/core/browser/url_blacklist_manager_unittest.cc
+++ b/components/policy/core/browser/url_blacklist_manager_unittest.cc
@@ -391,6 +391,16 @@ TEST_F(URLBlacklistManagerTest, Filtering) {
EXPECT_FALSE(blacklist.IsURLBlocked(GURL("https://ws.aaa.com")));
EXPECT_FALSE(blacklist.IsURLBlocked(GURL("ftp://ws.aaa.com")));
+ // Filter custom schemes.
+ blocked.reset(new base::ListValue);
bartfab (slow) 2016/03/10 13:49:41 Nit: #include "base/values.h"
+ blocked->Append(new base::StringValue("custom://*"));
+ blacklist.Block(blocked.get());
+ EXPECT_TRUE(blacklist.IsURLBlocked(GURL("custom://example_app")));
+ EXPECT_TRUE(blacklist.IsURLBlocked(GURL("custom:example2_app")));
+ EXPECT_FALSE(blacklist.IsURLBlocked(GURL("customs://example_apps")));
+ EXPECT_FALSE(blacklist.IsURLBlocked(GURL("cust*://example_ap")));
+ EXPECT_FALSE(blacklist.IsURLBlocked(GURL("ecustom:example_app")));
+
// Test exceptions to path prefixes, and most specific matches.
blocked.reset(new base::ListValue);
scoped_ptr<base::ListValue> allowed(new base::ListValue);
@@ -679,4 +689,53 @@ TEST_F(URLBlacklistManagerTest, DefaultBlacklistExceptions) {
EXPECT_FALSE((blacklist.IsURLBlocked(GURL("chrome-native://ntp"))));
}
+TEST_F(URLBlacklistManagerTest, UseBlacklistState) {
+ URLBlacklist blacklist(GetSegmentURLCallback());
+ scoped_ptr<base::ListValue> blocked(new base::ListValue);
+ scoped_ptr<base::ListValue> allowed(new base::ListValue);
+
+ // Check some types of custom schemes.
+ blocked->AppendString("youtube.com");
+ blocked->AppendString("custom://*");
+ allowed->AppendString("ggl://*");
+ allowed->AppendString("AbC://*");
+ // This is bad format, we support only custom_scheme://*.
+ allowed->AppendString("wrong://app");
+ allowed->AppendString(" wrong://*");
+ allowed->AppendString("wrong ://*");
+ blacklist.Block(blocked.get());
+ blacklist.Allow(allowed.get());
+
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("http://www.youtube.com")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_IN_BLACKLIST);
bartfab (slow) 2016/03/10 13:49:41 Nit: Here and below: Indent.
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("custom://my_app1")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_IN_BLACKLIST);
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("custom://my_app1/play")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_IN_BLACKLIST);
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("custom://my_app2:8080")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_IN_BLACKLIST);
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("custom:my_app3/path")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_IN_BLACKLIST);
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("custom:my_app4_game")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_IN_BLACKLIST);
+
+ // Shouldn't match with anything, since the format defined in allowed is not
Thiemo Nagel 2016/03/10 14:37:26 s/with// s/,//
igorcov1 2016/04/12 07:01:46 Done.
+ // supported.
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("wrong://app")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_NEUTRAL_STATE);
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL(" wrong://app")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_NEUTRAL_STATE);
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("wrong ://*")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_NEUTRAL_STATE);
+
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("ggl:super_app")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_IN_WHITELIST);
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("ggl://app/path:8182")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_IN_WHITELIST);
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("AbC://app/path:8182")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_IN_WHITELIST);
+ EXPECT_TRUE(blacklist.GetURLBlacklistState(GURL("abc://app")) ==
+ net::NetworkDelegate::URLBlacklistState::URL_IN_WHITELIST);
+}
+
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698