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

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

Issue 10546083: Convert ProtocolHandlerRegistry to be a ProfileKeyedService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update ProtocolHandlerRegistry to be a ProfileKeyedService in lieu of a refcounted pointer. Created 8 years, 6 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"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } // namespace 195 } // namespace
196 196
197 class ProtocolHandlerRegistryTest : public testing::Test { 197 class ProtocolHandlerRegistryTest : public testing::Test {
198 protected: 198 protected:
199 ProtocolHandlerRegistryTest() 199 ProtocolHandlerRegistryTest()
200 : test_protocol_handler_(CreateProtocolHandler("test", "test")) {} 200 : test_protocol_handler_(CreateProtocolHandler("test", "test")) {}
201 201
202 FakeDelegate* delegate() const { return delegate_; } 202 FakeDelegate* delegate() const { return delegate_; }
203 TestingProfile* profile() const { return profile_.get(); } 203 TestingProfile* profile() const { return profile_.get(); }
204 PrefService* pref_service() const { return profile_->GetPrefs(); } 204 PrefService* pref_service() const { return profile_->GetPrefs(); }
205 ProtocolHandlerRegistry* registry() const { return registry_.get(); } 205 ProtocolHandlerRegistry* registry() const { return registry_; }
206 const ProtocolHandler& test_protocol_handler() const { 206 const ProtocolHandler& test_protocol_handler() const {
207 return test_protocol_handler_; 207 return test_protocol_handler_;
208 } 208 }
209 209
210 ProtocolHandler CreateProtocolHandler(const std::string& protocol, 210 ProtocolHandler CreateProtocolHandler(const std::string& protocol,
211 const GURL& url, 211 const GURL& url,
212 const std::string& title) { 212 const std::string& title) {
213 return ProtocolHandler::CreateProtocolHandler(protocol, url, 213 return ProtocolHandler::CreateProtocolHandler(protocol, url,
214 UTF8ToUTF16(title)); 214 UTF8ToUTF16(title));
215 } 215 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 delegate_ = new FakeDelegate(); 253 delegate_ = new FakeDelegate();
254 registry_ = new ProtocolHandlerRegistry(profile(), delegate()); 254 registry_ = new ProtocolHandlerRegistry(profile(), delegate());
255 registry_->Load(); 255 registry_->Load();
256 test_protocol_handler_ = 256 test_protocol_handler_ =
257 CreateProtocolHandler("test", GURL("http://test.com/%s"), "Test"); 257 CreateProtocolHandler("test", GURL("http://test.com/%s"), "Test");
258 258
259 ProtocolHandlerRegistry::RegisterPrefs(pref_service()); 259 ProtocolHandlerRegistry::RegisterPrefs(pref_service());
260 } 260 }
261 261
262 virtual void TearDown() { 262 virtual void TearDown() {
263 registry_->Finalize(); 263 registry_->Finalize();
Elliot Glaysher 2012/06/11 19:43:16 (And change the name here)
Steve McKay 2012/06/11 22:09:38 Done.
264 registry_ = NULL; 264 registry_ = NULL;
265 io_thread_->Stop(); 265 io_thread_->Stop();
266 io_thread_.reset(NULL); 266 io_thread_.reset(NULL);
267 file_thread_->Stop(); 267 file_thread_->Stop();
268 file_thread_.reset(NULL); 268 file_thread_.reset(NULL);
269 ui_thread_.reset(NULL); 269 ui_thread_.reset(NULL);
270 ui_message_loop_.reset(NULL); 270 ui_message_loop_.reset(NULL);
271 } 271 }
272 272
273 bool enabled_io() { 273 bool enabled_io() {
274 return registry()->enabled_io_; 274 return registry()->enabled_io_;
275 } 275 }
276 276
277 scoped_ptr<MessageLoopForUI> ui_message_loop_; 277 scoped_ptr<MessageLoopForUI> ui_message_loop_;
278 scoped_ptr<content::TestBrowserThread> ui_thread_; 278 scoped_ptr<content::TestBrowserThread> ui_thread_;
279 scoped_ptr<content::TestBrowserThread> io_thread_; 279 scoped_ptr<content::TestBrowserThread> io_thread_;
280 scoped_ptr<content::TestBrowserThread> file_thread_; 280 scoped_ptr<content::TestBrowserThread> file_thread_;
281 281
282 FakeDelegate* delegate_; 282 FakeDelegate* delegate_;
283 scoped_ptr<TestingProfile> profile_; 283 scoped_ptr<TestingProfile> profile_;
284 scoped_refptr<ProtocolHandlerRegistry> registry_; 284 ProtocolHandlerRegistry* registry_;
285 ProtocolHandler test_protocol_handler_; 285 ProtocolHandler test_protocol_handler_;
286 }; 286 };
287 287
288 TEST_F(ProtocolHandlerRegistryTest, AcceptProtocolHandlerHandlesProtocol) { 288 TEST_F(ProtocolHandlerRegistryTest, AcceptProtocolHandlerHandlesProtocol) {
289 ASSERT_FALSE(registry()->IsHandledProtocol("test")); 289 ASSERT_FALSE(registry()->IsHandledProtocol("test"));
290 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); 290 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler());
291 ASSERT_TRUE(registry()->IsHandledProtocol("test")); 291 ASSERT_TRUE(registry()->IsHandledProtocol("test"));
292 } 292 }
293 293
294 TEST_F(ProtocolHandlerRegistryTest, DeniedProtocolIsntHandledUntilAccepted) { 294 TEST_F(ProtocolHandlerRegistryTest, DeniedProtocolIsntHandledUntilAccepted) {
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 652 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
653 MessageLoop::QuitClosure()); 653 MessageLoop::QuitClosure());
654 scoped_refptr<net::URLRequestJob> job(registry->MaybeCreateJob(&request)); 654 scoped_refptr<net::URLRequestJob> job(registry->MaybeCreateJob(&request));
655 ASSERT_TRUE(job.get() != NULL); 655 ASSERT_TRUE(job.get() != NULL);
656 } 656 }
657 657
658 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) { 658 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) {
659 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); 659 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1");
660 registry()->OnAcceptRegisterProtocolHandler(ph1); 660 registry()->OnAcceptRegisterProtocolHandler(ph1);
661 GURL url("mailto:someone@something.com"); 661 GURL url("mailto:someone@something.com");
662 scoped_refptr<ProtocolHandlerRegistry> r(registry());
663 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 662 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
664 base::Bind(MakeRequest, url, r)); 663 base::Bind(MakeRequest,
664 url,
665 base::Unretained(registry_)));
665 MessageLoop::current()->Run(); 666 MessageLoop::current()->Run();
666 } 667 }
667 668
668 static void CheckIsHandled(const std::string& scheme, bool expected, 669 static void CheckIsHandled(const std::string& scheme, bool expected,
669 ProtocolHandlerRegistry* registry) { 670 ProtocolHandlerRegistry* registry) {
670 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 671 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
671 MessageLoop::QuitClosure()); 672 MessageLoop::QuitClosure());
672 ASSERT_EQ(expected, registry->IsHandledProtocolIO(scheme)); 673 ASSERT_EQ(expected, registry->IsHandledProtocolIO(scheme));
673 } 674 }
674 675
675 TEST_F(ProtocolHandlerRegistryTest, TestIsHandledProtocolWorksOnIOThread) { 676 TEST_F(ProtocolHandlerRegistryTest, TestIsHandledProtocolWorksOnIOThread) {
676 std::string scheme("mailto"); 677 std::string scheme("mailto");
677 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1"); 678 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1");
678 registry()->OnAcceptRegisterProtocolHandler(ph1); 679 registry()->OnAcceptRegisterProtocolHandler(ph1);
679 scoped_refptr<ProtocolHandlerRegistry> r(registry());
680 BrowserThread::PostTask( 680 BrowserThread::PostTask(
681 BrowserThread::IO, 681 BrowserThread::IO,
682 FROM_HERE, 682 FROM_HERE,
683 base::Bind(CheckIsHandled, scheme, true, r)); 683 base::Bind(CheckIsHandled, scheme, true, base::Unretained(registry_)));
684 } 684 }
685 685
686 TEST_F(ProtocolHandlerRegistryTest, TestRemovingDefaultFallsBackToOldDefault) { 686 TEST_F(ProtocolHandlerRegistryTest, TestRemovingDefaultFallsBackToOldDefault) {
687 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); 687 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1");
688 ProtocolHandler ph2 = CreateProtocolHandler("mailto", "test2"); 688 ProtocolHandler ph2 = CreateProtocolHandler("mailto", "test2");
689 ProtocolHandler ph3 = CreateProtocolHandler("mailto", "test3"); 689 ProtocolHandler ph3 = CreateProtocolHandler("mailto", "test3");
690 registry()->OnAcceptRegisterProtocolHandler(ph1); 690 registry()->OnAcceptRegisterProtocolHandler(ph1);
691 registry()->OnAcceptRegisterProtocolHandler(ph2); 691 registry()->OnAcceptRegisterProtocolHandler(ph2);
692 registry()->OnAcceptRegisterProtocolHandler(ph3); 692 registry()->OnAcceptRegisterProtocolHandler(ph3);
693 693
(...skipping 23 matching lines...) Expand all
717 717
718 ASSERT_EQ(ph2, handlers[0]); 718 ASSERT_EQ(ph2, handlers[0]);
719 ASSERT_EQ(ph1, handlers[1]); 719 ASSERT_EQ(ph1, handlers[1]);
720 } 720 }
721 721
722 TEST_F(ProtocolHandlerRegistryTest, TestClearDefaultGetsPropagatedToIO) { 722 TEST_F(ProtocolHandlerRegistryTest, TestClearDefaultGetsPropagatedToIO) {
723 std::string scheme("mailto"); 723 std::string scheme("mailto");
724 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1"); 724 ProtocolHandler ph1 = CreateProtocolHandler(scheme, "test1");
725 registry()->OnAcceptRegisterProtocolHandler(ph1); 725 registry()->OnAcceptRegisterProtocolHandler(ph1);
726 registry()->ClearDefault(scheme); 726 registry()->ClearDefault(scheme);
727 scoped_refptr<ProtocolHandlerRegistry> r(registry());
728 727
729 BrowserThread::PostTask( 728 BrowserThread::PostTask(
730 BrowserThread::IO, 729 BrowserThread::IO,
731 FROM_HERE, 730 FROM_HERE,
732 base::Bind(CheckIsHandled, scheme, false, r)); 731 base::Bind(CheckIsHandled, scheme, false, base::Unretained(registry_)));
733 } 732 }
734 733
735 static void QuitUILoop() { 734 static void QuitUILoop() {
736 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 735 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
737 MessageLoop::QuitClosure()); 736 MessageLoop::QuitClosure());
738 } 737 }
739 738
740 TEST_F(ProtocolHandlerRegistryTest, TestLoadEnabledGetsPropogatedToIO) { 739 TEST_F(ProtocolHandlerRegistryTest, TestLoadEnabledGetsPropogatedToIO) {
741 registry()->Disable(); 740 registry()->Disable();
742 ReloadProtocolHandlerRegistry(); 741 ReloadProtocolHandlerRegistry();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 ASSERT_EQ(ph3.url().GetOrigin() == ph2.url().GetOrigin(), 804 ASSERT_EQ(ph3.url().GetOrigin() == ph2.url().GetOrigin(),
806 ph3.IsSameOrigin(ph2)); 805 ph3.IsSameOrigin(ph2));
807 } 806 }
808 807
809 TEST_F(ProtocolHandlerRegistryTest, TestInstallDefaultHandler) { 808 TEST_F(ProtocolHandlerRegistryTest, TestInstallDefaultHandler) {
810 ReloadProtocolHandlerRegistryAndInstallDefaultHandler(); 809 ReloadProtocolHandlerRegistryAndInstallDefaultHandler();
811 std::vector<std::string> protocols; 810 std::vector<std::string> protocols;
812 registry()->GetRegisteredProtocols(&protocols); 811 registry()->GetRegisteredProtocols(&protocols);
813 ASSERT_EQ(static_cast<size_t>(1), protocols.size()); 812 ASSERT_EQ(static_cast<size_t>(1), protocols.size());
814 } 813 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698