OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 MessageLoop::current()->Run(); | 633 MessageLoop::current()->Run(); |
634 ASSERT_TRUE(registry()->IsHandledProtocol("do")); | 634 ASSERT_TRUE(registry()->IsHandledProtocol("do")); |
635 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("do").size()); | 635 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("do").size()); |
636 ASSERT_FALSE(registry()->IsHandledProtocol("dont")); | 636 ASSERT_FALSE(registry()->IsHandledProtocol("dont")); |
637 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("dont").size()); | 637 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("dont").size()); |
638 } | 638 } |
639 | 639 |
640 static void MakeRequest(const GURL& url, ProtocolHandlerRegistry* registry) { | 640 static void MakeRequest(const GURL& url, ProtocolHandlerRegistry* registry) { |
641 net::URLRequest request(url, NULL); | 641 net::URLRequest request(url, NULL); |
642 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 642 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
643 new MessageLoop::QuitTask()); | 643 MessageLoop::QuitClosure()); |
644 scoped_refptr<net::URLRequestJob> job(registry->MaybeCreateJob(&request)); | 644 scoped_refptr<net::URLRequestJob> job(registry->MaybeCreateJob(&request)); |
645 ASSERT_TRUE(job.get() != NULL); | 645 ASSERT_TRUE(job.get() != NULL); |
646 } | 646 } |
647 | 647 |
648 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) { | 648 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) { |
649 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); | 649 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); |
650 registry()->OnAcceptRegisterProtocolHandler(ph1); | 650 registry()->OnAcceptRegisterProtocolHandler(ph1); |
651 GURL url("mailto:someone@something.com"); | 651 GURL url("mailto:someone@something.com"); |
652 scoped_refptr<ProtocolHandlerRegistry> r(registry()); | 652 scoped_refptr<ProtocolHandlerRegistry> r(registry()); |
653 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 653 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
654 base::Bind(MakeRequest, url, r)); | 654 base::Bind(MakeRequest, url, r)); |
655 MessageLoop::current()->Run(); | 655 MessageLoop::current()->Run(); |
656 } | 656 } |
657 | 657 |
658 static void CheckIsHandled(const std::string& scheme, bool expected, | 658 static void CheckIsHandled(const std::string& scheme, bool expected, |
659 ProtocolHandlerRegistry* registry) { | 659 ProtocolHandlerRegistry* registry) { |
660 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 660 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
661 new MessageLoop::QuitTask()); | 661 MessageLoop::QuitClosure()); |
662 ASSERT_EQ(expected, registry->IsHandledProtocolIO(scheme)); | 662 ASSERT_EQ(expected, registry->IsHandledProtocolIO(scheme)); |
663 } | 663 } |
664 | 664 |
665 TEST_F(ProtocolHandlerRegistryTest, TestIsHandledProtocolWorksOnIOThread) { | 665 TEST_F(ProtocolHandlerRegistryTest, TestIsHandledProtocolWorksOnIOThread) { |
666 std::string scheme("mailto"); | 666 std::string scheme("mailto"); |
667 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1"); | 667 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1"); |
668 registry()->OnAcceptRegisterProtocolHandler(ph1); | 668 registry()->OnAcceptRegisterProtocolHandler(ph1); |
669 scoped_refptr<ProtocolHandlerRegistry> r(registry()); | 669 scoped_refptr<ProtocolHandlerRegistry> r(registry()); |
670 BrowserThread::PostTask( | 670 BrowserThread::PostTask( |
671 BrowserThread::IO, | 671 BrowserThread::IO, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 scoped_refptr<ProtocolHandlerRegistry> r(registry()); | 717 scoped_refptr<ProtocolHandlerRegistry> r(registry()); |
718 | 718 |
719 BrowserThread::PostTask( | 719 BrowserThread::PostTask( |
720 BrowserThread::IO, | 720 BrowserThread::IO, |
721 FROM_HERE, | 721 FROM_HERE, |
722 base::Bind(CheckIsHandled, scheme, false, r)); | 722 base::Bind(CheckIsHandled, scheme, false, r)); |
723 } | 723 } |
724 | 724 |
725 static void QuitUILoop() { | 725 static void QuitUILoop() { |
726 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 726 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
727 new MessageLoop::QuitTask()); | 727 MessageLoop::QuitClosure()); |
728 } | 728 } |
729 | 729 |
730 TEST_F(ProtocolHandlerRegistryTest, TestLoadEnabledGetsPropogatedToIO) { | 730 TEST_F(ProtocolHandlerRegistryTest, TestLoadEnabledGetsPropogatedToIO) { |
731 registry()->Disable(); | 731 registry()->Disable(); |
732 ReloadProtocolHandlerRegistry(); | 732 ReloadProtocolHandlerRegistry(); |
733 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 733 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
734 base::Bind(QuitUILoop)); | 734 base::Bind(QuitUILoop)); |
735 MessageLoop::current()->Run(); | 735 MessageLoop::current()->Run(); |
736 ASSERT_FALSE(enabled_io()); | 736 ASSERT_FALSE(enabled_io()); |
737 } | 737 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 GURL("http://other.com/%s"), "test"); | 788 GURL("http://other.com/%s"), "test"); |
789 ASSERT_EQ(ph1.url().GetOrigin() == ph2.url().GetOrigin(), | 789 ASSERT_EQ(ph1.url().GetOrigin() == ph2.url().GetOrigin(), |
790 ph1.IsSameOrigin(ph2)); | 790 ph1.IsSameOrigin(ph2)); |
791 ASSERT_EQ(ph1.url().GetOrigin() == ph2.url().GetOrigin(), | 791 ASSERT_EQ(ph1.url().GetOrigin() == ph2.url().GetOrigin(), |
792 ph2.IsSameOrigin(ph1)); | 792 ph2.IsSameOrigin(ph1)); |
793 ASSERT_EQ(ph2.url().GetOrigin() == ph3.url().GetOrigin(), | 793 ASSERT_EQ(ph2.url().GetOrigin() == ph3.url().GetOrigin(), |
794 ph2.IsSameOrigin(ph3)); | 794 ph2.IsSameOrigin(ph3)); |
795 ASSERT_EQ(ph3.url().GetOrigin() == ph2.url().GetOrigin(), | 795 ASSERT_EQ(ph3.url().GetOrigin() == ph2.url().GetOrigin(), |
796 ph3.IsSameOrigin(ph2)); | 796 ph3.IsSameOrigin(ph2)); |
797 } | 797 } |
OLD | NEW |