| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 CreateShellWorker( | 185 CreateShellWorker( |
| 186 const shell_integration::DefaultWebClientWorkerCallback& callback, | 186 const shell_integration::DefaultWebClientWorkerCallback& callback, |
| 187 const std::string& protocol) override { | 187 const std::string& protocol) override { |
| 188 return new FakeProtocolClientWorker(callback, protocol, force_os_failure_); | 188 return new FakeProtocolClientWorker(callback, protocol, force_os_failure_); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void RegisterWithOSAsDefaultClient( | 191 void RegisterWithOSAsDefaultClient( |
| 192 const std::string& protocol, | 192 const std::string& protocol, |
| 193 ProtocolHandlerRegistry* registry) override; | 193 ProtocolHandlerRegistry* registry) override; |
| 194 | 194 |
| 195 bool IsExternalHandlerRegistered(const std::string& protocol) override { | |
| 196 return registered_protocols_.find(protocol) != registered_protocols_.end(); | |
| 197 } | |
| 198 | |
| 199 bool IsFakeRegisteredWithOS(const std::string& protocol) { | 195 bool IsFakeRegisteredWithOS(const std::string& protocol) { |
| 200 return os_registered_protocols_.find(protocol) != | 196 return os_registered_protocols_.find(protocol) != |
| 201 os_registered_protocols_.end(); | 197 os_registered_protocols_.end(); |
| 202 } | 198 } |
| 203 | 199 |
| 204 void FakeRegisterWithOS(const std::string& protocol) { | 200 void FakeRegisterWithOS(const std::string& protocol) { |
| 205 os_registered_protocols_.insert(protocol); | 201 os_registered_protocols_.insert(protocol); |
| 206 } | 202 } |
| 207 | 203 |
| 208 void Reset() { | 204 void Reset() { |
| 209 registered_protocols_.clear(); | 205 registered_protocols_.clear(); |
| 210 os_registered_protocols_.clear(); | 206 os_registered_protocols_.clear(); |
| 211 force_os_failure_ = false; | 207 force_os_failure_ = false; |
| 212 } | 208 } |
| 213 | 209 |
| 214 void set_force_os_failure(bool force) { force_os_failure_ = force; } | 210 void set_force_os_failure(bool force) { force_os_failure_ = force; } |
| 215 | 211 |
| 216 bool force_os_failure() { return force_os_failure_; } | 212 bool force_os_failure() { return force_os_failure_; } |
| 217 | 213 |
| 214 bool IsExternalHandlerRegistered(const std::string& protocol) { |
| 215 return registered_protocols_.find(protocol) != registered_protocols_.end(); |
| 216 } |
| 217 |
| 218 private: | 218 private: |
| 219 std::set<std::string> registered_protocols_; | 219 std::set<std::string> registered_protocols_; |
| 220 std::set<std::string> os_registered_protocols_; | 220 std::set<std::string> os_registered_protocols_; |
| 221 bool force_os_failure_; | 221 bool force_os_failure_; |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 void OnShellWorkerFinished(ProtocolHandlerRegistry* registry, | 224 void OnShellWorkerFinished(ProtocolHandlerRegistry* registry, |
| 225 FakeDelegate* delegate, | 225 FakeDelegate* delegate, |
| 226 const std::string& protocol, | 226 const std::string& protocol, |
| 227 shell_integration::DefaultWebClientState state) { | 227 shell_integration::DefaultWebClientState state) { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 | 436 |
| 437 TEST_F(ProtocolHandlerRegistryTest, ClearDefaultMakesProtocolNotHandled) { | 437 TEST_F(ProtocolHandlerRegistryTest, ClearDefaultMakesProtocolNotHandled) { |
| 438 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); | 438 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); |
| 439 registry()->ClearDefault("test"); | 439 registry()->ClearDefault("test"); |
| 440 ASSERT_FALSE(registry()->IsHandledProtocol("test")); | 440 ASSERT_FALSE(registry()->IsHandledProtocol("test")); |
| 441 ASSERT_TRUE(registry()->GetHandlerFor("test").IsEmpty()); | 441 ASSERT_TRUE(registry()->GetHandlerFor("test").IsEmpty()); |
| 442 } | 442 } |
| 443 | 443 |
| 444 TEST_F(ProtocolHandlerRegistryTest, DisableDeregistersProtocolHandlers) { | 444 TEST_F(ProtocolHandlerRegistryTest, DisableDeregistersProtocolHandlers) { |
| 445 ASSERT_FALSE(delegate()->IsExternalHandlerRegistered("test")); | 445 ASSERT_FALSE(delegate()->IsExternalHandlerRegistered("test")); |
| 446 ASSERT_TRUE(delegate()->CanSchemeBeOverridden("test")); |
| 446 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); | 447 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); |
| 447 ASSERT_TRUE(delegate()->IsExternalHandlerRegistered("test")); | 448 ASSERT_TRUE(delegate()->IsExternalHandlerRegistered("test")); |
| 449 ASSERT_FALSE(delegate()->CanSchemeBeOverridden("test")); |
| 448 | 450 |
| 449 registry()->Disable(); | 451 registry()->Disable(); |
| 450 ASSERT_FALSE(delegate()->IsExternalHandlerRegistered("test")); | 452 ASSERT_FALSE(delegate()->IsExternalHandlerRegistered("test")); |
| 453 ASSERT_TRUE(delegate()->CanSchemeBeOverridden("test")); |
| 451 registry()->Enable(); | 454 registry()->Enable(); |
| 452 ASSERT_TRUE(delegate()->IsExternalHandlerRegistered("test")); | 455 ASSERT_TRUE(delegate()->IsExternalHandlerRegistered("test")); |
| 456 ASSERT_FALSE(delegate()->CanSchemeBeOverridden("test")); |
| 453 } | 457 } |
| 454 | 458 |
| 455 TEST_F(ProtocolHandlerRegistryTest, IgnoreProtocolHandler) { | 459 TEST_F(ProtocolHandlerRegistryTest, IgnoreProtocolHandler) { |
| 456 registry()->OnIgnoreRegisterProtocolHandler(test_protocol_handler()); | 460 registry()->OnIgnoreRegisterProtocolHandler(test_protocol_handler()); |
| 457 ASSERT_TRUE(registry()->IsIgnored(test_protocol_handler())); | 461 ASSERT_TRUE(registry()->IsIgnored(test_protocol_handler())); |
| 458 | 462 |
| 459 registry()->RemoveIgnoredHandler(test_protocol_handler()); | 463 registry()->RemoveIgnoredHandler(test_protocol_handler()); |
| 460 ASSERT_FALSE(registry()->IsIgnored(test_protocol_handler())); | 464 ASSERT_FALSE(registry()->IsIgnored(test_protocol_handler())); |
| 461 } | 465 } |
| 462 | 466 |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 // added to pref. | 1088 // added to pref. |
| 1085 ASSERT_EQ(InPrefIgnoredHandlerCount(), 2); | 1089 ASSERT_EQ(InPrefIgnoredHandlerCount(), 2); |
| 1086 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); | 1090 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); |
| 1087 | 1091 |
| 1088 registry()->RemoveIgnoredHandler(p2u1); | 1092 registry()->RemoveIgnoredHandler(p2u1); |
| 1089 | 1093 |
| 1090 // p2u1 installed by user and policy, so it is removed from pref alone. | 1094 // p2u1 installed by user and policy, so it is removed from pref alone. |
| 1091 ASSERT_EQ(InPrefIgnoredHandlerCount(), 1); | 1095 ASSERT_EQ(InPrefIgnoredHandlerCount(), 1); |
| 1092 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); | 1096 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); |
| 1093 } | 1097 } |
| OLD | NEW |