Chromium Code Reviews| 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 #include "net/url_request/url_request_context.h" | 
| 24 | 24 | 
| 25 using content::BrowserThread; | 25 using content::BrowserThread; | 
| 26 | 26 | 
| 27 namespace { | 27 namespace { | 
| 28 | 28 | 
| 29 static scoped_refptr<net::URLRequestJob> MaybeInterceptIO( | |
| 30 const GURL& url, | |
| 31 net::URLRequestJobFactory::Interceptor* interceptor) { | |
| 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 33 net::URLRequestContext context; | |
| 34 net::URLRequest request(url, NULL, &context); | |
| 35 return interceptor->MaybeIntercept(&request); | |
| 36 } | |
| 37 | |
| 38 static void AssertInterceptedIO( | |
| 39 const GURL& url, | |
| 40 net::URLRequestJobFactory::Interceptor* interceptor) { | |
| 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 42 scoped_refptr<net::URLRequestJob> job = MaybeInterceptIO(url, interceptor); | |
| 43 ASSERT_TRUE(job.get() != NULL); | |
| 44 } | |
| 45 | |
| 46 static void AssertIntercepted( | |
| 47 const GURL& url, | |
| 48 net::URLRequestJobFactory::Interceptor* interceptor) { | |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 50 BrowserThread::PostTask(BrowserThread::IO, | |
| 51 FROM_HERE, | |
| 52 base::Bind(AssertInterceptedIO, | |
| 53 url, | |
| 54 base::Unretained(interceptor))); | |
| 55 MessageLoop::current()->RunAllPending(); | |
| 56 } | |
| 57 | |
| 58 static void WillHandleIO( | |
| 59 const std::string& scheme, | |
| 60 bool expected, | |
| 61 net::URLRequestJobFactory::Interceptor* interceptor) { | |
| 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 63 ASSERT_EQ(expected, interceptor->WillHandleProtocol(scheme)); | |
| 64 } | |
| 65 | |
| 66 static void WillHandle( | |
| 67 const std::string& scheme, | |
| 68 bool expected, | |
| 69 net::URLRequestJobFactory::Interceptor* interceptor) { | |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 71 BrowserThread::PostTask(BrowserThread::IO, | |
| 72 FROM_HERE, | |
| 73 base::Bind(WillHandleIO, | |
| 74 scheme, | |
| 75 expected, | |
| 76 base::Unretained(interceptor))); | |
| 77 MessageLoop::current()->RunAllPending(); | |
| 78 } | |
| 79 | |
| 29 class FakeDelegate : public ProtocolHandlerRegistry::Delegate { | 80 class FakeDelegate : public ProtocolHandlerRegistry::Delegate { | 
| 30 public: | 81 public: | 
| 31 FakeDelegate() : force_os_failure_(false) {} | 82 FakeDelegate() : force_os_failure_(false) {} | 
| 32 virtual ~FakeDelegate() { } | 83 virtual ~FakeDelegate() { } | 
| 33 virtual void RegisterExternalHandler(const std::string& protocol) { | 84 virtual void RegisterExternalHandler(const std::string& protocol) { | 
| 34 ASSERT_TRUE( | 85 ASSERT_TRUE( | 
| 35 registered_protocols_.find(protocol) == registered_protocols_.end()); | 86 registered_protocols_.find(protocol) == registered_protocols_.end()); | 
| 36 registered_protocols_.insert(protocol); | 87 registered_protocols_.insert(protocol); | 
| 37 } | 88 } | 
| 38 | 89 | 
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 } // namespace | 247 } // namespace | 
| 197 | 248 | 
| 198 class ProtocolHandlerRegistryTest : public testing::Test { | 249 class ProtocolHandlerRegistryTest : public testing::Test { | 
| 199 protected: | 250 protected: | 
| 200 ProtocolHandlerRegistryTest() | 251 ProtocolHandlerRegistryTest() | 
| 201 : test_protocol_handler_(CreateProtocolHandler("test", "test")) {} | 252 : test_protocol_handler_(CreateProtocolHandler("test", "test")) {} | 
| 202 | 253 | 
| 203 FakeDelegate* delegate() const { return delegate_; } | 254 FakeDelegate* delegate() const { return delegate_; } | 
| 204 TestingProfile* profile() const { return profile_.get(); } | 255 TestingProfile* profile() const { return profile_.get(); } | 
| 205 PrefService* pref_service() const { return profile_->GetPrefs(); } | 256 PrefService* pref_service() const { return profile_->GetPrefs(); } | 
| 206 ProtocolHandlerRegistry* registry() const { return registry_.get(); } | 257 ProtocolHandlerRegistry* registry() const { return registry_; } | 
| 207 const ProtocolHandler& test_protocol_handler() const { | 258 const ProtocolHandler& test_protocol_handler() const { | 
| 208 return test_protocol_handler_; | 259 return test_protocol_handler_; | 
| 209 } | 260 } | 
| 210 | 261 | 
| 211 ProtocolHandler CreateProtocolHandler(const std::string& protocol, | 262 ProtocolHandler CreateProtocolHandler(const std::string& protocol, | 
| 212 const GURL& url, | 263 const GURL& url, | 
| 213 const std::string& title) { | 264 const std::string& title) { | 
| 214 return ProtocolHandler::CreateProtocolHandler(protocol, url, | 265 return ProtocolHandler::CreateProtocolHandler(protocol, url, | 
| 215 UTF8ToUTF16(title)); | 266 UTF8ToUTF16(title)); | 
| 216 } | 267 } | 
| 217 | 268 | 
| 218 ProtocolHandler CreateProtocolHandler(const std::string& protocol, | 269 ProtocolHandler CreateProtocolHandler(const std::string& protocol, | 
| 219 const std::string& name) { | 270 const std::string& name) { | 
| 220 return CreateProtocolHandler(protocol, GURL("http://" + name + "/%s"), | 271 return CreateProtocolHandler(protocol, GURL("http://" + name + "/%s"), | 
| 221 name); | 272 name); | 
| 222 } | 273 } | 
| 223 | 274 | 
| 224 void ReloadProtocolHandlerRegistry() { | 275 void ReloadProtocolHandlerRegistry() { | 
| 225 delegate_ = new FakeDelegate(); | 276 delegate_ = new FakeDelegate(); | 
| 226 registry_->Finalize(); | 277 registry_->Shutdown(); | 
| 227 registry_ = NULL; | 278 registry_ = NULL; | 
| 228 registry_ = new ProtocolHandlerRegistry(profile(), delegate()); | 279 registry_ = new ProtocolHandlerRegistry(profile(), delegate()); | 
| 229 registry_->Load(); | 280 registry_->InitProtocolSettings(); | 
| 230 } | 281 } | 
| 231 | 282 | 
| 232 void ReloadProtocolHandlerRegistryAndInstallDefaultHandler() { | 283 void ReloadProtocolHandlerRegistryAndInstallDefaultHandler() { | 
| 233 delegate_ = new FakeDelegate(); | 284 delegate_ = new FakeDelegate(); | 
| 234 registry_->Finalize(); | 285 registry_->Shutdown(); | 
| 235 registry_ = NULL; | 286 registry_ = NULL; | 
| 236 registry_ = new ProtocolHandlerRegistry(profile(), delegate()); | 287 registry_ = new ProtocolHandlerRegistry(profile(), delegate()); | 
| 237 registry_->AddPredefinedHandler(CreateProtocolHandler( | 288 registry_->AddPredefinedHandler(CreateProtocolHandler( | 
| 238 "test", GURL("http://test.com/%s"), "Test")); | 289 "test", GURL("http://test.com/%s"), "Test")); | 
| 239 registry_->Load(); | 290 registry_->InitProtocolSettings(); | 
| 240 } | 291 } | 
| 241 | 292 | 
| 242 virtual void SetUp() { | 293 virtual void SetUp() { | 
| 243 ui_message_loop_.reset(new MessageLoopForUI()); | 294 ui_message_loop_.reset(new MessageLoopForUI()); | 
| 244 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, | 295 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, | 
| 245 MessageLoop::current())); | 296 MessageLoop::current())); | 
| 246 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); | 297 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); | 
| 247 io_thread_->StartIOThread(); | 298 io_thread_->StartIOThread(); | 
| 248 | 299 | 
| 249 file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE)); | 300 file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE)); | 
| 250 file_thread_->Start(); | 301 file_thread_->Start(); | 
| 251 | 302 | 
| 252 profile_.reset(new TestingProfile()); | 303 profile_.reset(new TestingProfile()); | 
| 253 profile_->SetPrefService(new TestingPrefService()); | 304 profile_->SetPrefService(new TestingPrefService()); | 
| 254 delegate_ = new FakeDelegate(); | 305 delegate_ = new FakeDelegate(); | 
| 255 registry_ = new ProtocolHandlerRegistry(profile(), delegate()); | 306 registry_ = new ProtocolHandlerRegistry(profile(), delegate()); | 
| 256 registry_->Load(); | 307 registry_->InitProtocolSettings(); | 
| 257 test_protocol_handler_ = | 308 test_protocol_handler_ = | 
| 258 CreateProtocolHandler("test", GURL("http://test.com/%s"), "Test"); | 309 CreateProtocolHandler("test", GURL("http://test.com/%s"), "Test"); | 
| 259 | 310 | 
| 260 ProtocolHandlerRegistry::RegisterPrefs(pref_service()); | 311 ProtocolHandlerRegistry::RegisterPrefs(pref_service()); | 
| 261 } | 312 } | 
| 262 | 313 | 
| 263 virtual void TearDown() { | 314 virtual void TearDown() { | 
| 264 registry_->Finalize(); | 315 registry_->Shutdown(); | 
| 265 registry_ = NULL; | 316 registry_ = NULL; | 
| 266 io_thread_->Stop(); | 317 io_thread_->Stop(); | 
| 267 io_thread_.reset(NULL); | 318 io_thread_.reset(NULL); | 
| 268 file_thread_->Stop(); | 319 file_thread_->Stop(); | 
| 269 file_thread_.reset(NULL); | 320 file_thread_.reset(NULL); | 
| 270 ui_thread_.reset(NULL); | 321 ui_thread_.reset(NULL); | 
| 271 ui_message_loop_.reset(NULL); | 322 ui_message_loop_.reset(NULL); | 
| 272 } | 323 } | 
| 273 | 324 | 
| 274 bool enabled_io() { | |
| 275 return registry()->enabled_io_; | |
| 276 } | |
| 277 | |
| 278 scoped_ptr<MessageLoopForUI> ui_message_loop_; | 325 scoped_ptr<MessageLoopForUI> ui_message_loop_; | 
| 279 scoped_ptr<content::TestBrowserThread> ui_thread_; | 326 scoped_ptr<content::TestBrowserThread> ui_thread_; | 
| 280 scoped_ptr<content::TestBrowserThread> io_thread_; | 327 scoped_ptr<content::TestBrowserThread> io_thread_; | 
| 281 scoped_ptr<content::TestBrowserThread> file_thread_; | 328 scoped_ptr<content::TestBrowserThread> file_thread_; | 
| 282 | 329 | 
| 283 FakeDelegate* delegate_; | 330 FakeDelegate* delegate_; | 
| 284 scoped_ptr<TestingProfile> profile_; | 331 scoped_ptr<TestingProfile> profile_; | 
| 285 scoped_refptr<ProtocolHandlerRegistry> registry_; | 332 ProtocolHandlerRegistry* registry_; | 
| 
 
benwells
2012/06/22 23:31:27
I think you've got a leak now. You need to delete
 
Steve McKay
2012/06/27 21:56:45
Test is updated to explicitly manage the lifecycle
 
 | |
| 286 ProtocolHandler test_protocol_handler_; | 333 ProtocolHandler test_protocol_handler_; | 
| 287 }; | 334 }; | 
| 288 | 335 | 
| 289 // ProtocolHandlerRegistryTest tests are flaky on Linux & ChromeOS. | 336 // ProtocolHandlerRegistryTest tests are flaky on Linux & ChromeOS. | 
| 290 // http://crbug.com/133023 | 337 // http://crbug.com/133023 | 
| 291 #if defined(OS_LINUX) || defined(OS_CHROMEOS) | 338 #if defined(OS_LINUX) || defined(OS_CHROMEOS) | 
| 292 #define MAYBE_AcceptProtocolHandlerHandlesProtocol \ | 339 #define MAYBE_AcceptProtocolHandlerHandlesProtocol \ | 
| 293 DISABLED_AcceptProtocolHandlerHandlesProtocol | 340 DISABLED_AcceptProtocolHandlerHandlesProtocol | 
| 294 #define MAYBE_DeniedProtocolIsntHandledUntilAccepted \ | 341 #define MAYBE_DeniedProtocolIsntHandledUntilAccepted \ | 
| 295 DISABLED_DeniedProtocolIsntHandledUntilAccepted | 342 DISABLED_DeniedProtocolIsntHandledUntilAccepted | 
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 668 MessageLoop::current()->Run(); | 715 MessageLoop::current()->Run(); | 
| 669 delegate()->set_force_os_failure(true); | 716 delegate()->set_force_os_failure(true); | 
| 670 registry()->OnAcceptRegisterProtocolHandler(ph_dont); | 717 registry()->OnAcceptRegisterProtocolHandler(ph_dont); | 
| 671 MessageLoop::current()->Run(); | 718 MessageLoop::current()->Run(); | 
| 672 ASSERT_TRUE(registry()->IsHandledProtocol("do")); | 719 ASSERT_TRUE(registry()->IsHandledProtocol("do")); | 
| 673 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("do").size()); | 720 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("do").size()); | 
| 674 ASSERT_FALSE(registry()->IsHandledProtocol("dont")); | 721 ASSERT_FALSE(registry()->IsHandledProtocol("dont")); | 
| 675 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("dont").size()); | 722 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("dont").size()); | 
| 676 } | 723 } | 
| 677 | 724 | 
| 678 static void MakeRequest(const GURL& url, ProtocolHandlerRegistry* registry) { | |
| 679 net::URLRequestContext context; | |
| 680 net::URLRequest request(url, NULL, &context); | |
| 681 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 682 MessageLoop::QuitClosure()); | |
| 683 scoped_refptr<net::URLRequestJob> job(registry->MaybeCreateJob(&request)); | |
| 684 ASSERT_TRUE(job.get() != NULL); | |
| 685 } | |
| 686 | |
| 687 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) { | 725 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) { | 
| 688 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); | 726 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); | 
| 689 registry()->OnAcceptRegisterProtocolHandler(ph1); | 727 registry()->OnAcceptRegisterProtocolHandler(ph1); | 
| 690 GURL url("mailto:someone@something.com"); | 728 GURL url("mailto:someone@something.com"); | 
| 691 scoped_refptr<ProtocolHandlerRegistry> r(registry()); | |
| 692 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 693 base::Bind(MakeRequest, url, r)); | |
| 694 MessageLoop::current()->Run(); | |
| 695 } | |
| 696 | 729 | 
| 697 static void CheckIsHandled(const std::string& scheme, bool expected, | 730 net::URLRequestJobFactory::Interceptor* interceptor = | 
| 698 ProtocolHandlerRegistry* registry) { | 731 registry()->CreateIOURLInterceptor(); | 
| 732 | |
| 733 // tell the UI thread it can quit after we're done | |
| 699 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 734 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 
| 700 MessageLoop::QuitClosure()); | 735 MessageLoop::QuitClosure()); | 
| 701 ASSERT_EQ(expected, registry->IsHandledProtocolIO(scheme)); | 736 | 
| 737 AssertIntercepted(url, interceptor); | |
| 702 } | 738 } | 
| 703 | 739 | 
| 704 TEST_F(ProtocolHandlerRegistryTest, | 740 TEST_F(ProtocolHandlerRegistryTest, | 
| 705 MAYBE_TestIsHandledProtocolWorksOnIOThread) { | 741 MAYBE_TestIsHandledProtocolWorksOnIOThread) { | 
| 706 std::string scheme("mailto"); | 742 std::string scheme("mailto"); | 
| 707 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1"); | 743 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1"); | 
| 708 registry()->OnAcceptRegisterProtocolHandler(ph1); | 744 registry()->OnAcceptRegisterProtocolHandler(ph1); | 
| 709 scoped_refptr<ProtocolHandlerRegistry> r(registry()); | 745 | 
| 710 BrowserThread::PostTask( | 746 net::URLRequestJobFactory::Interceptor* interceptor = | 
| 711 BrowserThread::IO, | 747 registry()->CreateIOURLInterceptor(); | 
| 712 FROM_HERE, | 748 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 
| 713 base::Bind(CheckIsHandled, scheme, true, r)); | 749 MessageLoop::QuitClosure()); | 
| 750 WillHandle(scheme, true, interceptor); | |
| 714 } | 751 } | 
| 715 | 752 | 
| 716 TEST_F(ProtocolHandlerRegistryTest, TestRemovingDefaultFallsBackToOldDefault) { | 753 TEST_F(ProtocolHandlerRegistryTest, TestRemovingDefaultFallsBackToOldDefault) { | 
| 717 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); | 754 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); | 
| 718 ProtocolHandler ph2 = CreateProtocolHandler("mailto", "test2"); | 755 ProtocolHandler ph2 = CreateProtocolHandler("mailto", "test2"); | 
| 719 ProtocolHandler ph3 = CreateProtocolHandler("mailto", "test3"); | 756 ProtocolHandler ph3 = CreateProtocolHandler("mailto", "test3"); | 
| 720 registry()->OnAcceptRegisterProtocolHandler(ph1); | 757 registry()->OnAcceptRegisterProtocolHandler(ph1); | 
| 721 registry()->OnAcceptRegisterProtocolHandler(ph2); | 758 registry()->OnAcceptRegisterProtocolHandler(ph2); | 
| 722 registry()->OnAcceptRegisterProtocolHandler(ph3); | 759 registry()->OnAcceptRegisterProtocolHandler(ph3); | 
| 723 | 760 | 
| (...skipping 23 matching lines...) Expand all Loading... | |
| 747 | 784 | 
| 748 ASSERT_EQ(ph2, handlers[0]); | 785 ASSERT_EQ(ph2, handlers[0]); | 
| 749 ASSERT_EQ(ph1, handlers[1]); | 786 ASSERT_EQ(ph1, handlers[1]); | 
| 750 } | 787 } | 
| 751 | 788 | 
| 752 TEST_F(ProtocolHandlerRegistryTest, MAYBE_TestClearDefaultGetsPropagatedToIO) { | 789 TEST_F(ProtocolHandlerRegistryTest, MAYBE_TestClearDefaultGetsPropagatedToIO) { | 
| 753 std::string scheme("mailto"); | 790 std::string scheme("mailto"); | 
| 754 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1"); | 791 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1"); | 
| 755 registry()->OnAcceptRegisterProtocolHandler(ph1); | 792 registry()->OnAcceptRegisterProtocolHandler(ph1); | 
| 756 registry()->ClearDefault(scheme); | 793 registry()->ClearDefault(scheme); | 
| 757 scoped_refptr<ProtocolHandlerRegistry> r(registry()); | 794 net::URLRequestJobFactory::Interceptor* interceptor = | 
| 758 | 795 registry()->CreateIOURLInterceptor(); | 
| 759 BrowserThread::PostTask( | |
| 760 BrowserThread::IO, | |
| 761 FROM_HERE, | |
| 762 base::Bind(CheckIsHandled, scheme, false, r)); | |
| 763 } | |
| 764 | |
| 765 static void QuitUILoop() { | |
| 766 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 796 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 
| 767 MessageLoop::QuitClosure()); | 797 MessageLoop::QuitClosure()); | 
| 798 WillHandle(scheme, false, interceptor); | |
| 768 } | 799 } | 
| 769 | 800 | 
| 770 TEST_F(ProtocolHandlerRegistryTest, TestLoadEnabledGetsPropogatedToIO) { | 801 TEST_F(ProtocolHandlerRegistryTest, TestLoadEnabledGetsPropogatedToIO) { | 
| 802 std::string mailto("mailto"); | |
| 803 ProtocolHandler ph1 = CreateProtocolHandler(mailto, "MailtoHandler"); | |
| 804 registry()->OnAcceptRegisterProtocolHandler(ph1); | |
| 805 WillHandle(mailto, true, registry()->CreateIOURLInterceptor()); | |
| 771 registry()->Disable(); | 806 registry()->Disable(); | 
| 772 ReloadProtocolHandlerRegistry(); | 807 WillHandle(mailto, false, registry()->CreateIOURLInterceptor()); | 
| 773 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 774 base::Bind(QuitUILoop)); | |
| 775 MessageLoop::current()->Run(); | |
| 776 ASSERT_FALSE(enabled_io()); | |
| 777 } | 808 } | 
| 778 | 809 | 
| 779 TEST_F(ProtocolHandlerRegistryTest, TestReplaceHandler) { | 810 TEST_F(ProtocolHandlerRegistryTest, TestReplaceHandler) { | 
| 780 ProtocolHandler ph1 = CreateProtocolHandler("mailto", | 811 ProtocolHandler ph1 = CreateProtocolHandler("mailto", | 
| 781 GURL("http://test.com/%s"), "test1"); | 812 GURL("http://test.com/%s"), "test1"); | 
| 782 ProtocolHandler ph2 = CreateProtocolHandler("mailto", | 813 ProtocolHandler ph2 = CreateProtocolHandler("mailto", | 
| 783 GURL("http://test.com/updated-url/%s"), "test2"); | 814 GURL("http://test.com/updated-url/%s"), "test2"); | 
| 784 registry()->OnAcceptRegisterProtocolHandler(ph1); | 815 registry()->OnAcceptRegisterProtocolHandler(ph1); | 
| 785 ASSERT_TRUE(registry()->AttemptReplace(ph2)); | 816 ASSERT_TRUE(registry()->AttemptReplace(ph2)); | 
| 786 const ProtocolHandler& handler(registry()->GetHandlerFor("mailto")); | 817 const ProtocolHandler& handler(registry()->GetHandlerFor("mailto")); | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 ASSERT_EQ(ph3.url().GetOrigin() == ph2.url().GetOrigin(), | 866 ASSERT_EQ(ph3.url().GetOrigin() == ph2.url().GetOrigin(), | 
| 836 ph3.IsSameOrigin(ph2)); | 867 ph3.IsSameOrigin(ph2)); | 
| 837 } | 868 } | 
| 838 | 869 | 
| 839 TEST_F(ProtocolHandlerRegistryTest, TestInstallDefaultHandler) { | 870 TEST_F(ProtocolHandlerRegistryTest, TestInstallDefaultHandler) { | 
| 840 ReloadProtocolHandlerRegistryAndInstallDefaultHandler(); | 871 ReloadProtocolHandlerRegistryAndInstallDefaultHandler(); | 
| 841 std::vector<std::string> protocols; | 872 std::vector<std::string> protocols; | 
| 842 registry()->GetRegisteredProtocols(&protocols); | 873 registry()->GetRegisteredProtocols(&protocols); | 
| 843 ASSERT_EQ(static_cast<size_t>(1), protocols.size()); | 874 ASSERT_EQ(static_cast<size_t>(1), protocols.size()); | 
| 844 } | 875 } | 
| OLD | NEW |