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

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

Issue 2083363002: Remove calls to deprecated MessageLoop methods in chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 11
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
15 #include "build/build_config.h" 16 #include "build/build_config.h"
16 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/common/custom_handlers/protocol_handler.h" 18 #include "chrome/common/custom_handlers/protocol_handler.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/testing_browser_process.h" 20 #include "chrome/test/base/testing_browser_process.h"
20 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
21 #include "components/pref_registry/pref_registry_syncable.h" 22 #include "components/pref_registry/pref_registry_syncable.h"
22 #include "components/syncable_prefs/pref_service_syncable.h" 23 #include "components/syncable_prefs/pref_service_syncable.h"
(...skipping 26 matching lines...) Expand all
49 50
50 void AssertIntercepted( 51 void AssertIntercepted(
51 const GURL& url, 52 const GURL& url,
52 net::URLRequestJobFactory* interceptor) { 53 net::URLRequestJobFactory* interceptor) {
53 DCHECK_CURRENTLY_ON(BrowserThread::UI); 54 DCHECK_CURRENTLY_ON(BrowserThread::UI);
54 BrowserThread::PostTask(BrowserThread::IO, 55 BrowserThread::PostTask(BrowserThread::IO,
55 FROM_HERE, 56 FROM_HERE,
56 base::Bind(AssertInterceptedIO, 57 base::Bind(AssertInterceptedIO,
57 url, 58 url,
58 base::Unretained(interceptor))); 59 base::Unretained(interceptor)));
59 base::MessageLoop::current()->RunUntilIdle(); 60 base::RunLoop().RunUntilIdle();
60 } 61 }
61 62
62 // FakeURLRequestJobFactory returns NULL for all job creation requests and false 63 // FakeURLRequestJobFactory returns NULL for all job creation requests and false
63 // for all IsHandled*() requests. FakeURLRequestJobFactory can be chained to 64 // for all IsHandled*() requests. FakeURLRequestJobFactory can be chained to
64 // ProtocolHandlerRegistry::JobInterceptorFactory so the result of 65 // ProtocolHandlerRegistry::JobInterceptorFactory so the result of
65 // MaybeCreateJobWithProtocolHandler() indicates whether the 66 // MaybeCreateJobWithProtocolHandler() indicates whether the
66 // ProtocolHandlerRegistry properly handled a job creation request. 67 // ProtocolHandlerRegistry properly handled a job creation request.
67 class FakeURLRequestJobFactory : public net::URLRequestJobFactory { 68 class FakeURLRequestJobFactory : public net::URLRequestJobFactory {
68 // net::URLRequestJobFactory implementation: 69 // net::URLRequestJobFactory implementation:
69 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( 70 net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const std::string& scheme, 111 const std::string& scheme,
111 bool expected, 112 bool expected,
112 ProtocolHandlerRegistry::JobInterceptorFactory* interceptor) { 113 ProtocolHandlerRegistry::JobInterceptorFactory* interceptor) {
113 DCHECK_CURRENTLY_ON(BrowserThread::UI); 114 DCHECK_CURRENTLY_ON(BrowserThread::UI);
114 BrowserThread::PostTask(BrowserThread::IO, 115 BrowserThread::PostTask(BrowserThread::IO,
115 FROM_HERE, 116 FROM_HERE,
116 base::Bind(AssertWillHandleIO, 117 base::Bind(AssertWillHandleIO,
117 scheme, 118 scheme,
118 expected, 119 expected,
119 base::Unretained(interceptor))); 120 base::Unretained(interceptor)));
120 base::MessageLoop::current()->RunUntilIdle(); 121 base::RunLoop().RunUntilIdle();
121 } 122 }
122 123
123 base::DictionaryValue* GetProtocolHandlerValue(std::string protocol, 124 base::DictionaryValue* GetProtocolHandlerValue(std::string protocol,
124 std::string url) { 125 std::string url) {
125 base::DictionaryValue* value = new base::DictionaryValue(); 126 base::DictionaryValue* value = new base::DictionaryValue();
126 value->SetString("protocol", protocol); 127 value->SetString("protocol", protocol);
127 value->SetString("url", url); 128 value->SetString("url", url);
128 return value; 129 return value;
129 } 130 }
130 131
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 TEST_F(ProtocolHandlerRegistryTest, TestOSRegistration) { 732 TEST_F(ProtocolHandlerRegistryTest, TestOSRegistration) {
732 ProtocolHandler ph_do1 = CreateProtocolHandler("do", "test1"); 733 ProtocolHandler ph_do1 = CreateProtocolHandler("do", "test1");
733 ProtocolHandler ph_do2 = CreateProtocolHandler("do", "test2"); 734 ProtocolHandler ph_do2 = CreateProtocolHandler("do", "test2");
734 ProtocolHandler ph_dont = CreateProtocolHandler("dont", "test"); 735 ProtocolHandler ph_dont = CreateProtocolHandler("dont", "test");
735 736
736 ASSERT_FALSE(delegate()->IsFakeRegisteredWithOS("do")); 737 ASSERT_FALSE(delegate()->IsFakeRegisteredWithOS("do"));
737 ASSERT_FALSE(delegate()->IsFakeRegisteredWithOS("dont")); 738 ASSERT_FALSE(delegate()->IsFakeRegisteredWithOS("dont"));
738 739
739 registry()->OnAcceptRegisterProtocolHandler(ph_do1); 740 registry()->OnAcceptRegisterProtocolHandler(ph_do1);
740 registry()->OnDenyRegisterProtocolHandler(ph_dont); 741 registry()->OnDenyRegisterProtocolHandler(ph_dont);
741 base::MessageLoop::current()->Run(); // FILE thread needs to run. 742 base::RunLoop().Run(); // FILE thread needs to run.
742 ASSERT_TRUE(delegate()->IsFakeRegisteredWithOS("do")); 743 ASSERT_TRUE(delegate()->IsFakeRegisteredWithOS("do"));
743 ASSERT_FALSE(delegate()->IsFakeRegisteredWithOS("dont")); 744 ASSERT_FALSE(delegate()->IsFakeRegisteredWithOS("dont"));
744 745
745 // This should not register with the OS, if it does the delegate 746 // This should not register with the OS, if it does the delegate
746 // will assert for us. We don't need to wait for the message loop 747 // will assert for us. We don't need to wait for the message loop
747 // as it should not go through to the shell worker. 748 // as it should not go through to the shell worker.
748 registry()->OnAcceptRegisterProtocolHandler(ph_do2); 749 registry()->OnAcceptRegisterProtocolHandler(ph_do2);
749 } 750 }
750 751
751 #if defined(OS_LINUX) 752 #if defined(OS_LINUX)
752 // TODO(benwells): When Linux support is more reliable and 753 // TODO(benwells): When Linux support is more reliable and
753 // http://crbug.com/88255 is fixed this test will pass. 754 // http://crbug.com/88255 is fixed this test will pass.
754 #define MAYBE_TestOSRegistrationFailure DISABLED_TestOSRegistrationFailure 755 #define MAYBE_TestOSRegistrationFailure DISABLED_TestOSRegistrationFailure
755 #else 756 #else
756 #define MAYBE_TestOSRegistrationFailure TestOSRegistrationFailure 757 #define MAYBE_TestOSRegistrationFailure TestOSRegistrationFailure
757 #endif 758 #endif
758 759
759 // TODO(smckay): This is much more appropriately an integration 760 // TODO(smckay): This is much more appropriately an integration
760 // test. Make that so, then update the 761 // test. Make that so, then update the
761 // ShellIntegretion{Delegate,Callback,Worker} test classes we use to fully 762 // ShellIntegretion{Delegate,Callback,Worker} test classes we use to fully
762 // isolate this test from the FILE thread. 763 // isolate this test from the FILE thread.
763 TEST_F(ProtocolHandlerRegistryTest, MAYBE_TestOSRegistrationFailure) { 764 TEST_F(ProtocolHandlerRegistryTest, MAYBE_TestOSRegistrationFailure) {
764 ProtocolHandler ph_do = CreateProtocolHandler("do", "test1"); 765 ProtocolHandler ph_do = CreateProtocolHandler("do", "test1");
765 ProtocolHandler ph_dont = CreateProtocolHandler("dont", "test"); 766 ProtocolHandler ph_dont = CreateProtocolHandler("dont", "test");
766 767
767 ASSERT_FALSE(registry()->IsHandledProtocol("do")); 768 ASSERT_FALSE(registry()->IsHandledProtocol("do"));
768 ASSERT_FALSE(registry()->IsHandledProtocol("dont")); 769 ASSERT_FALSE(registry()->IsHandledProtocol("dont"));
769 770
770 registry()->OnAcceptRegisterProtocolHandler(ph_do); 771 registry()->OnAcceptRegisterProtocolHandler(ph_do);
771 base::MessageLoop::current()->Run(); // FILE thread needs to run. 772 base::RunLoop().Run(); // FILE thread needs to run.
772 delegate()->set_force_os_failure(true); 773 delegate()->set_force_os_failure(true);
773 registry()->OnAcceptRegisterProtocolHandler(ph_dont); 774 registry()->OnAcceptRegisterProtocolHandler(ph_dont);
774 base::MessageLoop::current()->Run(); // FILE thread needs to run. 775 base::RunLoop().Run(); // FILE thread needs to run.
775 ASSERT_TRUE(registry()->IsHandledProtocol("do")); 776 ASSERT_TRUE(registry()->IsHandledProtocol("do"));
776 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("do").size()); 777 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("do").size());
777 ASSERT_FALSE(registry()->IsHandledProtocol("dont")); 778 ASSERT_FALSE(registry()->IsHandledProtocol("dont"));
778 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("dont").size()); 779 ASSERT_EQ(static_cast<size_t>(1), registry()->GetHandlersFor("dont").size());
779 } 780 }
780 781
781 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) { 782 TEST_F(ProtocolHandlerRegistryTest, TestMaybeCreateTaskWorksFromIOThread) {
782 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1"); 783 ProtocolHandler ph1 = CreateProtocolHandler("mailto", "test1");
783 registry()->OnAcceptRegisterProtocolHandler(ph1); 784 registry()->OnAcceptRegisterProtocolHandler(ph1);
784 GURL url("mailto:someone@something.com"); 785 GURL url("mailto:someone@something.com");
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 // added to pref. 1080 // added to pref.
1080 ASSERT_EQ(InPrefIgnoredHandlerCount(), 2); 1081 ASSERT_EQ(InPrefIgnoredHandlerCount(), 2);
1081 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); 1082 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4);
1082 1083
1083 registry()->RemoveIgnoredHandler(p2u1); 1084 registry()->RemoveIgnoredHandler(p2u1);
1084 1085
1085 // p2u1 installed by user and policy, so it is removed from pref alone. 1086 // p2u1 installed by user and policy, so it is removed from pref alone.
1086 ASSERT_EQ(InPrefIgnoredHandlerCount(), 1); 1087 ASSERT_EQ(InPrefIgnoredHandlerCount(), 1);
1087 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); 1088 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4);
1088 } 1089 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698