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

Side by Side Diff: chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc

Issue 10139002: Preventing our default handlers for ChromeOS to show up or confuse the user (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed third review Created 8 years, 8 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 unified diff | Download patch
OLDNEW
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/test/test_browser_thread.h" 20 #include "content/test/test_browser_thread.h"
21 #include "content/test/test_browser_thread.h" 21 #include "content/test/test_browser_thread.h"
22 #include "content/test/test_renderer_host.h" 22 #include "content/test/test_renderer_host.h"
23 #include "grit/generated_resources.h"
23 #include "net/url_request/url_request.h" 24 #include "net/url_request/url_request.h"
25 #include "ui/base/l10n/l10n_util.h"
24 26
25 using content::BrowserThread; 27 using content::BrowserThread;
26 28
27 namespace { 29 namespace {
28 30
29 class FakeDelegate : public ProtocolHandlerRegistry::Delegate { 31 class FakeDelegate : public ProtocolHandlerRegistry::Delegate {
30 public: 32 public:
31 FakeDelegate() : force_os_failure_(false) {} 33 FakeDelegate() : force_os_failure_(false) {}
32 virtual ~FakeDelegate() { } 34 virtual ~FakeDelegate() { }
33 virtual void RegisterExternalHandler(const std::string& protocol) { 35 virtual void RegisterExternalHandler(const std::string& protocol) {
34 ASSERT_TRUE( 36 #if defined(OS_CHROMEOS)
35 registered_protocols_.find(protocol) == registered_protocols_.end()); 37 if (protocol != "mailto" && protocol != "webcal")
38 #endif
39 ASSERT_TRUE(
40 registered_protocols_.find(protocol) == registered_protocols_.end());
36 registered_protocols_.insert(protocol); 41 registered_protocols_.insert(protocol);
37 } 42 }
38 43
39 virtual void DeregisterExternalHandler(const std::string& protocol) { 44 virtual void DeregisterExternalHandler(const std::string& protocol) {
40 registered_protocols_.erase(protocol); 45 registered_protocols_.erase(protocol);
41 } 46 }
42 47
43 virtual ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( 48 virtual ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker(
44 ShellIntegration::DefaultWebClientObserver* observer, 49 ShellIntegration::DefaultWebClientObserver* observer,
45 const std::string& protocol); 50 const std::string& protocol);
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 ASSERT_EQ(static_cast<size_t>(3), handlers.size()); 528 ASSERT_EQ(static_cast<size_t>(3), handlers.size());
524 529
525 ASSERT_EQ(ph3, handlers[0]); 530 ASSERT_EQ(ph3, handlers[0]);
526 ASSERT_EQ(ph2, handlers[1]); 531 ASSERT_EQ(ph2, handlers[1]);
527 ASSERT_EQ(ph1, handlers[2]); 532 ASSERT_EQ(ph1, handlers[2]);
528 } 533 }
529 534
530 TEST_F(ProtocolHandlerRegistryTest, TestGetRegisteredProtocols) { 535 TEST_F(ProtocolHandlerRegistryTest, TestGetRegisteredProtocols) {
531 std::vector<std::string> protocols; 536 std::vector<std::string> protocols;
532 registry()->GetRegisteredProtocols(&protocols); 537 registry()->GetRegisteredProtocols(&protocols);
538 #if defined (OS_CHROMEOS)
koz (OOO until 15th September) 2012/04/24 00:52:29 The tests now require a lot of #ifdefs, which is u
Mr4D (OOO till 08-26) 2012/04/24 15:53:31 In my opinion the installation of the default prot
koz (OOO until 15th September) 2012/04/30 02:11:25 I disagree that the PHR is the class that should b
539 ASSERT_EQ(static_cast<size_t>(2), protocols.size());
540 #else
533 ASSERT_EQ(static_cast<size_t>(0), protocols.size()); 541 ASSERT_EQ(static_cast<size_t>(0), protocols.size());
542 #endif
534 543
535 registry()->GetHandlersFor("test"); 544 registry()->GetHandlersFor("test");
536 545
537 protocols.clear(); 546 protocols.clear();
538 registry()->GetRegisteredProtocols(&protocols); 547 registry()->GetRegisteredProtocols(&protocols);
548 #if defined (OS_CHROMEOS)
549 ASSERT_EQ(static_cast<size_t>(2), protocols.size());
550 #else
539 ASSERT_EQ(static_cast<size_t>(0), protocols.size()); 551 ASSERT_EQ(static_cast<size_t>(0), protocols.size());
552 #endif
540 } 553 }
541 554
542 TEST_F(ProtocolHandlerRegistryTest, TestIsHandledProtocol) { 555 TEST_F(ProtocolHandlerRegistryTest, TestIsHandledProtocol) {
543 registry()->GetHandlersFor("test"); 556 registry()->GetHandlersFor("test");
544 ASSERT_FALSE(registry()->IsHandledProtocol("test")); 557 ASSERT_FALSE(registry()->IsHandledProtocol("test"));
545 } 558 }
546 559
547 TEST_F(ProtocolHandlerRegistryTest, TestNotifications) { 560 TEST_F(ProtocolHandlerRegistryTest, TestNotifications) {
548 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); 561 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
549 NotificationCounter counter(profile()); 562 NotificationCounter counter(profile());
(...skipping 21 matching lines...) Expand all
571 registry()->OnAcceptRegisterProtocolHandler(ph1); 584 registry()->OnAcceptRegisterProtocolHandler(ph1);
572 ASSERT_TRUE(queryer.called_); 585 ASSERT_TRUE(queryer.called_);
573 } 586 }
574 587
575 TEST_F(ProtocolHandlerRegistryTest, TestProtocolsWithNoDefaultAreHandled) { 588 TEST_F(ProtocolHandlerRegistryTest, TestProtocolsWithNoDefaultAreHandled) {
576 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); 589 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
577 registry()->OnAcceptRegisterProtocolHandler(ph1); 590 registry()->OnAcceptRegisterProtocolHandler(ph1);
578 registry()->ClearDefault("test"); 591 registry()->ClearDefault("test");
579 std::vector<std::string> handled_protocols; 592 std::vector<std::string> handled_protocols;
580 registry()->GetRegisteredProtocols(&handled_protocols); 593 registry()->GetRegisteredProtocols(&handled_protocols);
594 #if defined (OS_CHROMEOS)
595 ASSERT_EQ(static_cast<size_t>(3), handled_protocols.size());
596 ASSERT_EQ("test", handled_protocols[1]);
597 #else
581 ASSERT_EQ(static_cast<size_t>(1), handled_protocols.size()); 598 ASSERT_EQ(static_cast<size_t>(1), handled_protocols.size());
582 ASSERT_EQ("test", handled_protocols[0]); 599 ASSERT_EQ("test", handled_protocols[0]);
600 #endif
583 } 601 }
584 602
585 TEST_F(ProtocolHandlerRegistryTest, TestDisablePreventsHandling) { 603 TEST_F(ProtocolHandlerRegistryTest, TestDisablePreventsHandling) {
586 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); 604 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
587 registry()->OnAcceptRegisterProtocolHandler(ph1); 605 registry()->OnAcceptRegisterProtocolHandler(ph1);
588 ASSERT_TRUE(registry()->IsHandledProtocol("test")); 606 ASSERT_TRUE(registry()->IsHandledProtocol("test"));
589 registry()->Disable(); 607 registry()->Disable();
590 ASSERT_FALSE(registry()->IsHandledProtocol("test")); 608 ASSERT_FALSE(registry()->IsHandledProtocol("test"));
591 } 609 }
592 610
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 656
639 static void MakeRequest(const GURL& url, ProtocolHandlerRegistry* registry) { 657 static void MakeRequest(const GURL& url, ProtocolHandlerRegistry* registry) {
640 net::URLRequest request(url, NULL); 658 net::URLRequest request(url, NULL);
641 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 659 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
642 MessageLoop::QuitClosure()); 660 MessageLoop::QuitClosure());
643 scoped_refptr<net::URLRequestJob> job(registry->MaybeCreateJob(&request)); 661 scoped_refptr<net::URLRequestJob> job(registry->MaybeCreateJob(&request));
644 ASSERT_TRUE(job.get() != NULL); 662 ASSERT_TRUE(job.get() != NULL);
645 } 663 }
646 664
647 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) { 665 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) {
648 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); 666 ProtocolHandler ph1 = CreateProtocolHandler("mailto-test", "test1");
649 registry()->OnAcceptRegisterProtocolHandler(ph1); 667 registry()->OnAcceptRegisterProtocolHandler(ph1);
650 GURL url("mailto:someone@something.com"); 668 GURL url("mailto-test:someone@something.com");
651 scoped_refptr<ProtocolHandlerRegistry> r(registry()); 669 scoped_refptr<ProtocolHandlerRegistry> r(registry());
652 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 670 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
653 base::Bind(MakeRequest, url, r)); 671 base::Bind(MakeRequest, url, r));
654 MessageLoop::current()->Run(); 672 MessageLoop::current()->Run();
655 } 673 }
656 674
657 static void CheckIsHandled(const std::string& scheme, bool expected, 675 static void CheckIsHandled(const std::string& scheme, bool expected,
658 ProtocolHandlerRegistry* registry) { 676 ProtocolHandlerRegistry* registry) {
659 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 677 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
660 MessageLoop::QuitClosure()); 678 MessageLoop::QuitClosure());
661 ASSERT_EQ(expected, registry->IsHandledProtocolIO(scheme)); 679 ASSERT_EQ(expected, registry->IsHandledProtocolIO(scheme));
662 } 680 }
663 681
664 TEST_F(ProtocolHandlerRegistryTest, TestIsHandledProtocolWorksOnIOThread) { 682 TEST_F(ProtocolHandlerRegistryTest, TestIsHandledProtocolWorksOnIOThread) {
665 std::string scheme("mailto"); 683 std::string scheme("mailto-test");
666 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1"); 684 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1");
667 registry()->OnAcceptRegisterProtocolHandler(ph1); 685 registry()->OnAcceptRegisterProtocolHandler(ph1);
668 scoped_refptr<ProtocolHandlerRegistry> r(registry()); 686 scoped_refptr<ProtocolHandlerRegistry> r(registry());
669 BrowserThread::PostTask( 687 BrowserThread::PostTask(
670 BrowserThread::IO, 688 BrowserThread::IO,
671 FROM_HERE, 689 FROM_HERE,
672 base::Bind(CheckIsHandled, scheme, true, r)); 690 base::Bind(CheckIsHandled, scheme, true, r));
673 } 691 }
674 692
675 TEST_F(ProtocolHandlerRegistryTest, TestRemovingDefaultFallsBackToOldDefault) { 693 TEST_F(ProtocolHandlerRegistryTest, TestRemovingDefaultFallsBackToOldDefault) {
676 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); 694 ProtocolHandler ph1 = CreateProtocolHandler("mailto-test", "test1");
677 ProtocolHandler ph2 = CreateProtocolHandler("mailto", "test2"); 695 ProtocolHandler ph2 = CreateProtocolHandler("mailto-test", "test2");
678 ProtocolHandler ph3 = CreateProtocolHandler("mailto", "test3"); 696 ProtocolHandler ph3 = CreateProtocolHandler("mailto-test", "test3");
679 registry()->OnAcceptRegisterProtocolHandler(ph1); 697 registry()->OnAcceptRegisterProtocolHandler(ph1);
680 registry()->OnAcceptRegisterProtocolHandler(ph2); 698 registry()->OnAcceptRegisterProtocolHandler(ph2);
681 registry()->OnAcceptRegisterProtocolHandler(ph3); 699 registry()->OnAcceptRegisterProtocolHandler(ph3);
682 700
683 ASSERT_TRUE(registry()->IsDefault(ph3)); 701 ASSERT_TRUE(registry()->IsDefault(ph3));
684 registry()->RemoveHandler(ph3); 702 registry()->RemoveHandler(ph3);
685 ASSERT_TRUE(registry()->IsDefault(ph2)); 703 ASSERT_TRUE(registry()->IsDefault(ph2));
686 registry()->OnAcceptRegisterProtocolHandler(ph3); 704 registry()->OnAcceptRegisterProtocolHandler(ph3);
687 ASSERT_TRUE(registry()->IsDefault(ph3)); 705 ASSERT_TRUE(registry()->IsDefault(ph3));
688 registry()->RemoveHandler(ph2); 706 registry()->RemoveHandler(ph2);
689 ASSERT_TRUE(registry()->IsDefault(ph3)); 707 ASSERT_TRUE(registry()->IsDefault(ph3));
690 registry()->RemoveHandler(ph3); 708 registry()->RemoveHandler(ph3);
691 ASSERT_TRUE(registry()->IsDefault(ph1)); 709 ASSERT_TRUE(registry()->IsDefault(ph1));
692 } 710 }
693 711
694 TEST_F(ProtocolHandlerRegistryTest, TestRemovingDefaultDoesntChangeHandlers) { 712 TEST_F(ProtocolHandlerRegistryTest, TestRemovingDefaultDoesntChangeHandlers) {
695 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); 713 ProtocolHandler ph1 = CreateProtocolHandler("mailto-test", "test1");
696 ProtocolHandler ph2 = CreateProtocolHandler("mailto", "test2"); 714 ProtocolHandler ph2 = CreateProtocolHandler("mailto-test", "test2");
697 ProtocolHandler ph3 = CreateProtocolHandler("mailto", "test3"); 715 ProtocolHandler ph3 = CreateProtocolHandler("mailto-test", "test3");
698 registry()->OnAcceptRegisterProtocolHandler(ph1); 716 registry()->OnAcceptRegisterProtocolHandler(ph1);
699 registry()->OnAcceptRegisterProtocolHandler(ph2); 717 registry()->OnAcceptRegisterProtocolHandler(ph2);
700 registry()->OnAcceptRegisterProtocolHandler(ph3); 718 registry()->OnAcceptRegisterProtocolHandler(ph3);
701 registry()->RemoveHandler(ph3); 719 registry()->RemoveHandler(ph3);
702 720
703 ProtocolHandlerRegistry::ProtocolHandlerList handlers = 721 ProtocolHandlerRegistry::ProtocolHandlerList handlers =
704 registry()->GetHandlersFor("mailto"); 722 registry()->GetHandlersFor("mailto-test");
705 ASSERT_EQ(static_cast<size_t>(2), handlers.size()); 723 ASSERT_EQ(static_cast<size_t>(2), handlers.size());
706
707 ASSERT_EQ(ph2, handlers[0]); 724 ASSERT_EQ(ph2, handlers[0]);
708 ASSERT_EQ(ph1, handlers[1]); 725 ASSERT_EQ(ph1, handlers[1]);
709 } 726 }
710 727
711 TEST_F(ProtocolHandlerRegistryTest, TestClearDefaultGetsPropagatedToIO) { 728 TEST_F(ProtocolHandlerRegistryTest, TestClearDefaultGetsPropagatedToIO) {
712 std::string scheme("mailto"); 729 std::string scheme("mailto-test");
713 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1"); 730 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1");
714 registry()->OnAcceptRegisterProtocolHandler(ph1); 731 registry()->OnAcceptRegisterProtocolHandler(ph1);
715 registry()->ClearDefault(scheme); 732 registry()->ClearDefault(scheme);
716 scoped_refptr<ProtocolHandlerRegistry> r(registry()); 733 scoped_refptr<ProtocolHandlerRegistry> r(registry());
717 734
718 BrowserThread::PostTask( 735 BrowserThread::PostTask(
719 BrowserThread::IO, 736 BrowserThread::IO,
720 FROM_HERE, 737 FROM_HERE,
721 base::Bind(CheckIsHandled, scheme, false, r)); 738 base::Bind(CheckIsHandled, scheme, false, r));
722 } 739 }
723 740
724 static void QuitUILoop() { 741 static void QuitUILoop() {
725 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 742 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
726 MessageLoop::QuitClosure()); 743 MessageLoop::QuitClosure());
727 } 744 }
728 745
729 TEST_F(ProtocolHandlerRegistryTest, TestLoadEnabledGetsPropogatedToIO) { 746 TEST_F(ProtocolHandlerRegistryTest, TestLoadEnabledGetsPropogatedToIO) {
730 registry()->Disable(); 747 registry()->Disable();
731 ReloadProtocolHandlerRegistry(); 748 ReloadProtocolHandlerRegistry();
732 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 749 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
733 base::Bind(QuitUILoop)); 750 base::Bind(QuitUILoop));
734 MessageLoop::current()->Run(); 751 MessageLoop::current()->Run();
735 ASSERT_FALSE(enabled_io()); 752 ASSERT_FALSE(enabled_io());
736 } 753 }
737 754
738 TEST_F(ProtocolHandlerRegistryTest, TestReplaceHandler) { 755 TEST_F(ProtocolHandlerRegistryTest, TestReplaceHandler) {
739 ProtocolHandler ph1 = CreateProtocolHandler("mailto", 756 ProtocolHandler ph1 = CreateProtocolHandler("mailto-test",
740 GURL("http://test.com/%s"), "test1"); 757 GURL("http://test.com/%s"), "test1");
741 ProtocolHandler ph2 = CreateProtocolHandler("mailto", 758 ProtocolHandler ph2 = CreateProtocolHandler("mailto-test",
742 GURL("http://test.com/updated-url/%s"), "test2"); 759 GURL("http://test.com/updated-url/%s"), "test2");
743 registry()->OnAcceptRegisterProtocolHandler(ph1); 760 registry()->OnAcceptRegisterProtocolHandler(ph1);
744 ASSERT_TRUE(registry()->AttemptReplace(ph2)); 761 ASSERT_TRUE(registry()->AttemptReplace(ph2));
745 const ProtocolHandler& handler(registry()->GetHandlerFor("mailto")); 762 const ProtocolHandler& handler(registry()->GetHandlerFor("mailto-test"));
746 ASSERT_EQ(handler.url(), ph2.url()); 763 ASSERT_EQ(handler.url(), ph2.url());
747 } 764 }
748 765
749 TEST_F(ProtocolHandlerRegistryTest, TestReplaceNonDefaultHandler) { 766 TEST_F(ProtocolHandlerRegistryTest, TestReplaceNonDefaultHandler) {
750 ProtocolHandler ph1 = CreateProtocolHandler("mailto", 767 ProtocolHandler ph1 = CreateProtocolHandler("mailto-test",
751 GURL("http://test.com/%s"), "test1"); 768 GURL("http://test.com/%s"), "test1");
752 ProtocolHandler ph2 = CreateProtocolHandler("mailto", 769 ProtocolHandler ph2 = CreateProtocolHandler("mailto-test",
753 GURL("http://test.com/updated-url/%s"), "test2"); 770 GURL("http://test.com/updated-url/%s"), "test2");
754 ProtocolHandler ph3 = CreateProtocolHandler("mailto", 771 ProtocolHandler ph3 = CreateProtocolHandler("mailto-test",
755 GURL("http://else.com/%s"), "test3"); 772 GURL("http://else.com/%s"), "test3");
756 registry()->OnAcceptRegisterProtocolHandler(ph1); 773 registry()->OnAcceptRegisterProtocolHandler(ph1);
757 registry()->OnAcceptRegisterProtocolHandler(ph3); 774 registry()->OnAcceptRegisterProtocolHandler(ph3);
758 ASSERT_TRUE(registry()->AttemptReplace(ph2)); 775 ASSERT_TRUE(registry()->AttemptReplace(ph2));
759 const ProtocolHandler& handler(registry()->GetHandlerFor("mailto")); 776 const ProtocolHandler& handler(registry()->GetHandlerFor("mailto-test"));
760 ASSERT_EQ(handler.url(), ph3.url()); 777 ASSERT_EQ(handler.url(), ph3.url());
761 } 778 }
762 779
763 TEST_F(ProtocolHandlerRegistryTest, TestReplaceRemovesStaleHandlers) { 780 TEST_F(ProtocolHandlerRegistryTest, TestReplaceRemovesStaleHandlers) {
764 ProtocolHandler ph1 = CreateProtocolHandler("mailto", 781 ProtocolHandler ph1 = CreateProtocolHandler("mailto-test",
765 GURL("http://test.com/%s"), "test1"); 782 GURL("http://test.com/%s"), "test1");
766 ProtocolHandler ph2 = CreateProtocolHandler("mailto", 783 ProtocolHandler ph2 = CreateProtocolHandler("mailto-test",
767 GURL("http://test.com/updated-url/%s"), "test2"); 784 GURL("http://test.com/updated-url/%s"), "test2");
768 ProtocolHandler ph3 = CreateProtocolHandler("mailto", 785 ProtocolHandler ph3 = CreateProtocolHandler("mailto-test",
769 GURL("http://test.com/third/%s"), "test"); 786 GURL("http://test.com/third/%s"), "test");
770 registry()->OnAcceptRegisterProtocolHandler(ph1); 787 registry()->OnAcceptRegisterProtocolHandler(ph1);
771 registry()->OnAcceptRegisterProtocolHandler(ph2); 788 registry()->OnAcceptRegisterProtocolHandler(ph2);
772 789
773 // This should replace the previous two handlers. 790 // This should replace the previous two handlers.
774 ASSERT_TRUE(registry()->AttemptReplace(ph3)); 791 ASSERT_TRUE(registry()->AttemptReplace(ph3));
775 const ProtocolHandler& handler(registry()->GetHandlerFor("mailto")); 792 const ProtocolHandler& handler(registry()->GetHandlerFor("mailto-test"));
776 ASSERT_EQ(handler.url(), ph3.url()); 793 ASSERT_EQ(handler.url(), ph3.url());
777 registry()->RemoveHandler(ph3); 794 registry()->RemoveHandler(ph3);
778 ASSERT_TRUE(registry()->GetHandlerFor("mailto").IsEmpty()); 795 ASSERT_TRUE(registry()->GetHandlerFor("mailto-test").IsEmpty());
779 } 796 }
780 797
781 TEST_F(ProtocolHandlerRegistryTest, TestIsSameOrigin) { 798 TEST_F(ProtocolHandlerRegistryTest, TestIsSameOrigin) {
782 ProtocolHandler ph1 = CreateProtocolHandler("mailto", 799 ProtocolHandler ph1 = CreateProtocolHandler("mailto-test",
783 GURL("http://test.com/%s"), "test1"); 800 GURL("http://test.com/%s"), "test1");
784 ProtocolHandler ph2 = CreateProtocolHandler("mailto", 801 ProtocolHandler ph2 = CreateProtocolHandler("mailto-test",
785 GURL("http://test.com/updated-url/%s"), "test2"); 802 GURL("http://test.com/updated-url/%s"), "test2");
786 ProtocolHandler ph3 = CreateProtocolHandler("mailto", 803 ProtocolHandler ph3 = CreateProtocolHandler("mailto-test",
787 GURL("http://other.com/%s"), "test"); 804 GURL("http://other.com/%s"), "test");
788 ASSERT_EQ(ph1.url().GetOrigin() == ph2.url().GetOrigin(), 805 ASSERT_EQ(ph1.url().GetOrigin() == ph2.url().GetOrigin(),
789 ph1.IsSameOrigin(ph2)); 806 ph1.IsSameOrigin(ph2));
790 ASSERT_EQ(ph1.url().GetOrigin() == ph2.url().GetOrigin(), 807 ASSERT_EQ(ph1.url().GetOrigin() == ph2.url().GetOrigin(),
791 ph2.IsSameOrigin(ph1)); 808 ph2.IsSameOrigin(ph1));
792 ASSERT_EQ(ph2.url().GetOrigin() == ph3.url().GetOrigin(), 809 ASSERT_EQ(ph2.url().GetOrigin() == ph3.url().GetOrigin(),
793 ph2.IsSameOrigin(ph3)); 810 ph2.IsSameOrigin(ph3));
794 ASSERT_EQ(ph3.url().GetOrigin() == ph2.url().GetOrigin(), 811 ASSERT_EQ(ph3.url().GetOrigin() == ph2.url().GetOrigin(),
795 ph3.IsSameOrigin(ph2)); 812 ph3.IsSameOrigin(ph2));
796 } 813 }
814
815 TEST_F(ProtocolHandlerRegistryTest, PredefinedHandlers) {
816 #if defined(OS_CHROMEOS)
817 // For ChromeOS we install default handlers for mailto and webcal.
818 ASSERT_FALSE(registry()->GetHandlerFor("mailto").IsEmpty());
819 ASSERT_FALSE(registry()->GetHandlerFor("webcal").IsEmpty());
820 #else
821 ASSERT_TRUE(registry()->GetHandlerFor("mailto").IsEmpty());
822 ASSERT_TRUE(registry()->GetHandlerFor("webcal").IsEmpty());
823 #endif
824 }
OLDNEW
« no previous file with comments | « chrome/browser/custom_handlers/protocol_handler_registry.cc ('k') | chrome/browser/platform_util_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698