| 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.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "chrome/common/custom_handlers/protocol_handler.h" | 13 #include "chrome/common/custom_handlers/protocol_handler.h" |
| 14 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
| 15 #include "chrome/test/base/testing_pref_service.h" | 15 #include "chrome/test/base/testing_pref_service.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
| 21 #include "content/public/test/test_renderer_host.h" | 21 #include "content/public/test/test_renderer_host.h" |
| 22 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 23 #include "net/url_request/url_request_context.h" |
| 23 | 24 |
| 24 using content::BrowserThread; | 25 using content::BrowserThread; |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 class FakeDelegate : public ProtocolHandlerRegistry::Delegate { | 29 class FakeDelegate : public ProtocolHandlerRegistry::Delegate { |
| 29 public: | 30 public: |
| 30 FakeDelegate() : force_os_failure_(false) {} | 31 FakeDelegate() : force_os_failure_(false) {} |
| 31 virtual ~FakeDelegate() { } | 32 virtual ~FakeDelegate() { } |
| 32 virtual void RegisterExternalHandler(const std::string& protocol) { | 33 virtual void RegisterExternalHandler(const std::string& protocol) { |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 delegate()->set_force_os_failure(true); | 669 delegate()->set_force_os_failure(true); |
| 669 registry()->OnAcceptRegisterProtocolHandler(ph_dont); | 670 registry()->OnAcceptRegisterProtocolHandler(ph_dont); |
| 670 MessageLoop::current()->Run(); | 671 MessageLoop::current()->Run(); |
| 671 ASSERT_TRUE(registry()->IsHandledProtocol("do")); | 672 ASSERT_TRUE(registry()->IsHandledProtocol("do")); |
| 672 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("do").size()); | 673 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("do").size()); |
| 673 ASSERT_FALSE(registry()->IsHandledProtocol("dont")); | 674 ASSERT_FALSE(registry()->IsHandledProtocol("dont")); |
| 674 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("dont").size()); | 675 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("dont").size()); |
| 675 } | 676 } |
| 676 | 677 |
| 677 static void MakeRequest(const GURL& url, ProtocolHandlerRegistry* registry) { | 678 static void MakeRequest(const GURL& url, ProtocolHandlerRegistry* registry) { |
| 678 net::URLRequest request(url, NULL); | 679 net::URLRequestContext context; |
| 680 net::URLRequest request(url, NULL, &context); |
| 679 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 681 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 680 MessageLoop::QuitClosure()); | 682 MessageLoop::QuitClosure()); |
| 681 scoped_refptr<net::URLRequestJob> job(registry->MaybeCreateJob(&request)); | 683 scoped_refptr<net::URLRequestJob> job(registry->MaybeCreateJob(&request)); |
| 682 ASSERT_TRUE(job.get() != NULL); | 684 ASSERT_TRUE(job.get() != NULL); |
| 683 } | 685 } |
| 684 | 686 |
| 685 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) { | 687 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) { |
| 686 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); | 688 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); |
| 687 registry()->OnAcceptRegisterProtocolHandler(ph1); | 689 registry()->OnAcceptRegisterProtocolHandler(ph1); |
| 688 GURL url("mailto:someone@something.com"); | 690 GURL url("mailto:someone@something.com"); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 ASSERT_EQ(ph3.url().GetOrigin() == ph2.url().GetOrigin(), | 835 ASSERT_EQ(ph3.url().GetOrigin() == ph2.url().GetOrigin(), |
| 834 ph3.IsSameOrigin(ph2)); | 836 ph3.IsSameOrigin(ph2)); |
| 835 } | 837 } |
| 836 | 838 |
| 837 TEST_F(ProtocolHandlerRegistryTest, TestInstallDefaultHandler) { | 839 TEST_F(ProtocolHandlerRegistryTest, TestInstallDefaultHandler) { |
| 838 ReloadProtocolHandlerRegistryAndInstallDefaultHandler(); | 840 ReloadProtocolHandlerRegistryAndInstallDefaultHandler(); |
| 839 std::vector<std::string> protocols; | 841 std::vector<std::string> protocols; |
| 840 registry()->GetRegisteredProtocols(&protocols); | 842 registry()->GetRegisteredProtocols(&protocols); |
| 841 ASSERT_EQ(static_cast<size_t>(1), protocols.size()); | 843 ASSERT_EQ(static_cast<size_t>(1), protocols.size()); |
| 842 } | 844 } |
| OLD | NEW |