| 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 "chrome/browser/custom_handlers/protocol_handler_registry.h" | 5 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 } | 965 } |
| 966 | 966 |
| 967 #define URL_p1u1 "http://p1u1.com/%s" | 967 #define URL_p1u1 "http://p1u1.com/%s" |
| 968 #define URL_p1u2 "http://p1u2.com/%s" | 968 #define URL_p1u2 "http://p1u2.com/%s" |
| 969 #define URL_p1u3 "http://p1u3.com/%s" | 969 #define URL_p1u3 "http://p1u3.com/%s" |
| 970 #define URL_p2u1 "http://p2u1.com/%s" | 970 #define URL_p2u1 "http://p2u1.com/%s" |
| 971 #define URL_p2u2 "http://p2u2.com/%s" | 971 #define URL_p2u2 "http://p2u2.com/%s" |
| 972 #define URL_p3u1 "http://p3u1.com/%s" | 972 #define URL_p3u1 "http://p3u1.com/%s" |
| 973 | 973 |
| 974 TEST_F(ProtocolHandlerRegistryTest, TestPrefPolicyOverlapRegister) { | 974 TEST_F(ProtocolHandlerRegistryTest, TestPrefPolicyOverlapRegister) { |
| 975 base::ListValue* handlers_registered_by_pref = new base::ListValue(); | 975 base::ListValue handlers_registered_by_pref; |
| 976 base::ListValue* handlers_registered_by_policy = new base::ListValue(); | 976 base::ListValue handlers_registered_by_policy; |
| 977 | 977 |
| 978 handlers_registered_by_pref->Append( | 978 handlers_registered_by_pref.Append( |
| 979 GetProtocolHandlerValueWithDefault("p1", URL_p1u2, true)); | 979 GetProtocolHandlerValueWithDefault("p1", URL_p1u2, true)); |
| 980 handlers_registered_by_pref->Append( | 980 handlers_registered_by_pref.Append( |
| 981 GetProtocolHandlerValueWithDefault("p1", URL_p1u1, true)); | 981 GetProtocolHandlerValueWithDefault("p1", URL_p1u1, true)); |
| 982 handlers_registered_by_pref->Append( | 982 handlers_registered_by_pref.Append( |
| 983 GetProtocolHandlerValueWithDefault("p1", URL_p1u2, false)); | 983 GetProtocolHandlerValueWithDefault("p1", URL_p1u2, false)); |
| 984 | 984 |
| 985 handlers_registered_by_policy->Append( | 985 handlers_registered_by_policy.Append( |
| 986 GetProtocolHandlerValueWithDefault("p1", URL_p1u1, false)); | 986 GetProtocolHandlerValueWithDefault("p1", URL_p1u1, false)); |
| 987 handlers_registered_by_policy->Append( | 987 handlers_registered_by_policy.Append( |
| 988 GetProtocolHandlerValueWithDefault("p3", URL_p3u1, true)); | 988 GetProtocolHandlerValueWithDefault("p3", URL_p3u1, true)); |
| 989 | 989 |
| 990 profile()->GetPrefs()->Set( | 990 profile()->GetPrefs()->Set(prefs::kRegisteredProtocolHandlers, |
| 991 prefs::kRegisteredProtocolHandlers, | 991 handlers_registered_by_pref); |
| 992 *static_cast<base::Value*>(handlers_registered_by_pref)); | 992 profile()->GetPrefs()->Set(prefs::kPolicyRegisteredProtocolHandlers, |
| 993 profile()->GetPrefs()->Set( | 993 handlers_registered_by_policy); |
| 994 prefs::kPolicyRegisteredProtocolHandlers, | |
| 995 *static_cast<base::Value*>(handlers_registered_by_policy)); | |
| 996 registry()->InitProtocolSettings(); | 994 registry()->InitProtocolSettings(); |
| 997 | 995 |
| 998 // Duplicate p1u2 eliminated in memory but not yet saved in pref | 996 // Duplicate p1u2 eliminated in memory but not yet saved in pref |
| 999 ProtocolHandler p1u1 = CreateProtocolHandler("p1", GURL(URL_p1u1)); | 997 ProtocolHandler p1u1 = CreateProtocolHandler("p1", GURL(URL_p1u1)); |
| 1000 ProtocolHandler p1u2 = CreateProtocolHandler("p1", GURL(URL_p1u2)); | 998 ProtocolHandler p1u2 = CreateProtocolHandler("p1", GURL(URL_p1u2)); |
| 1001 ASSERT_EQ(InPrefHandlerCount(), 3); | 999 ASSERT_EQ(InPrefHandlerCount(), 3); |
| 1002 ASSERT_EQ(InMemoryHandlerCount(), 3); | 1000 ASSERT_EQ(InMemoryHandlerCount(), 3); |
| 1003 ASSERT_TRUE(registry()->IsDefault(p1u1)); | 1001 ASSERT_TRUE(registry()->IsDefault(p1u1)); |
| 1004 ASSERT_FALSE(registry()->IsDefault(p1u2)); | 1002 ASSERT_FALSE(registry()->IsDefault(p1u2)); |
| 1005 | 1003 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 // p1u3 the default handler for p1 removed from user pref and memory. | 1045 // p1u3 the default handler for p1 removed from user pref and memory. |
| 1048 ASSERT_EQ(InPrefHandlerCount(), 1); | 1046 ASSERT_EQ(InPrefHandlerCount(), 1); |
| 1049 ASSERT_EQ(InMemoryHandlerCount(), 3); | 1047 ASSERT_EQ(InMemoryHandlerCount(), 3); |
| 1050 ASSERT_FALSE(registry()->IsDefault(p1u3)); | 1048 ASSERT_FALSE(registry()->IsDefault(p1u3)); |
| 1051 ASSERT_TRUE(registry()->IsDefault(p1u1)); | 1049 ASSERT_TRUE(registry()->IsDefault(p1u1)); |
| 1052 ASSERT_TRUE(registry()->IsDefault(p3u1)); | 1050 ASSERT_TRUE(registry()->IsDefault(p3u1)); |
| 1053 ASSERT_FALSE(registry()->IsDefault(p2u1)); | 1051 ASSERT_FALSE(registry()->IsDefault(p2u1)); |
| 1054 } | 1052 } |
| 1055 | 1053 |
| 1056 TEST_F(ProtocolHandlerRegistryTest, TestPrefPolicyOverlapIgnore) { | 1054 TEST_F(ProtocolHandlerRegistryTest, TestPrefPolicyOverlapIgnore) { |
| 1057 base::ListValue* handlers_ignored_by_pref = new base::ListValue(); | 1055 base::ListValue handlers_ignored_by_pref; |
| 1058 base::ListValue* handlers_ignored_by_policy = new base::ListValue(); | 1056 base::ListValue handlers_ignored_by_policy; |
| 1059 | 1057 |
| 1060 handlers_ignored_by_pref->Append(GetProtocolHandlerValue("p1", URL_p1u1)); | 1058 handlers_ignored_by_pref.Append(GetProtocolHandlerValue("p1", URL_p1u1)); |
| 1061 handlers_ignored_by_pref->Append(GetProtocolHandlerValue("p1", URL_p1u2)); | 1059 handlers_ignored_by_pref.Append(GetProtocolHandlerValue("p1", URL_p1u2)); |
| 1062 handlers_ignored_by_pref->Append(GetProtocolHandlerValue("p1", URL_p1u2)); | 1060 handlers_ignored_by_pref.Append(GetProtocolHandlerValue("p1", URL_p1u2)); |
| 1063 handlers_ignored_by_pref->Append(GetProtocolHandlerValue("p3", URL_p3u1)); | 1061 handlers_ignored_by_pref.Append(GetProtocolHandlerValue("p3", URL_p3u1)); |
| 1064 | 1062 |
| 1065 handlers_ignored_by_policy->Append(GetProtocolHandlerValue("p1", URL_p1u2)); | 1063 handlers_ignored_by_policy.Append(GetProtocolHandlerValue("p1", URL_p1u2)); |
| 1066 handlers_ignored_by_policy->Append(GetProtocolHandlerValue("p1", URL_p1u3)); | 1064 handlers_ignored_by_policy.Append(GetProtocolHandlerValue("p1", URL_p1u3)); |
| 1067 handlers_ignored_by_policy->Append(GetProtocolHandlerValue("p2", URL_p2u1)); | 1065 handlers_ignored_by_policy.Append(GetProtocolHandlerValue("p2", URL_p2u1)); |
| 1068 | 1066 |
| 1069 profile()->GetPrefs()->Set( | 1067 profile()->GetPrefs()->Set(prefs::kIgnoredProtocolHandlers, |
| 1070 prefs::kIgnoredProtocolHandlers, | 1068 handlers_ignored_by_pref); |
| 1071 *static_cast<base::Value*>(handlers_ignored_by_pref)); | 1069 profile()->GetPrefs()->Set(prefs::kPolicyIgnoredProtocolHandlers, |
| 1072 profile()->GetPrefs()->Set( | 1070 handlers_ignored_by_policy); |
| 1073 prefs::kPolicyIgnoredProtocolHandlers, | |
| 1074 *static_cast<base::Value*>(handlers_ignored_by_policy)); | |
| 1075 registry()->InitProtocolSettings(); | 1071 registry()->InitProtocolSettings(); |
| 1076 | 1072 |
| 1077 // Duplicate p1u2 eliminated in memory but not yet saved in pref | 1073 // Duplicate p1u2 eliminated in memory but not yet saved in pref |
| 1078 ASSERT_EQ(InPrefIgnoredHandlerCount(), 4); | 1074 ASSERT_EQ(InPrefIgnoredHandlerCount(), 4); |
| 1079 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 5); | 1075 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 5); |
| 1080 | 1076 |
| 1081 ProtocolHandler p2u2 = CreateProtocolHandler("p2", GURL(URL_p2u2)); | 1077 ProtocolHandler p2u2 = CreateProtocolHandler("p2", GURL(URL_p2u2)); |
| 1082 registry()->OnIgnoreRegisterProtocolHandler(p2u2); | 1078 registry()->OnIgnoreRegisterProtocolHandler(p2u2); |
| 1083 | 1079 |
| 1084 // Duplicate p1u2 eliminated in pref, p2u2 added to pref and memory. | 1080 // Duplicate p1u2 eliminated in pref, p2u2 added to pref and memory. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 // added to pref. | 1115 // added to pref. |
| 1120 ASSERT_EQ(InPrefIgnoredHandlerCount(), 2); | 1116 ASSERT_EQ(InPrefIgnoredHandlerCount(), 2); |
| 1121 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); | 1117 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); |
| 1122 | 1118 |
| 1123 registry()->RemoveIgnoredHandler(p2u1); | 1119 registry()->RemoveIgnoredHandler(p2u1); |
| 1124 | 1120 |
| 1125 // p2u1 installed by user and policy, so it is removed from pref alone. | 1121 // p2u1 installed by user and policy, so it is removed from pref alone. |
| 1126 ASSERT_EQ(InPrefIgnoredHandlerCount(), 1); | 1122 ASSERT_EQ(InPrefIgnoredHandlerCount(), 1); |
| 1127 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); | 1123 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); |
| 1128 } | 1124 } |
| OLD | NEW |