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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 std::unique_ptr<net::URLRequestJob> job( | 47 std::unique_ptr<net::URLRequestJob> job( |
48 interceptor->MaybeCreateJobWithProtocolHandler( | 48 interceptor->MaybeCreateJobWithProtocolHandler( |
49 url.scheme(), request.get(), context.network_delegate())); | 49 url.scheme(), request.get(), context.network_delegate())); |
50 ASSERT_TRUE(job.get()); | 50 ASSERT_TRUE(job.get()); |
51 } | 51 } |
52 | 52 |
53 void AssertIntercepted( | 53 void AssertIntercepted( |
54 const GURL& url, | 54 const GURL& url, |
55 net::URLRequestJobFactory* interceptor) { | 55 net::URLRequestJobFactory* interceptor) { |
56 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
57 BrowserThread::PostTask(BrowserThread::IO, | 57 BrowserThread::PostTask( |
58 FROM_HERE, | 58 BrowserThread::IO, FROM_HERE, |
59 base::Bind(AssertInterceptedIO, | 59 base::BindOnce(AssertInterceptedIO, url, base::Unretained(interceptor))); |
60 url, | |
61 base::Unretained(interceptor))); | |
62 base::RunLoop().RunUntilIdle(); | 60 base::RunLoop().RunUntilIdle(); |
63 } | 61 } |
64 | 62 |
65 // FakeURLRequestJobFactory returns NULL for all job creation requests and false | 63 // FakeURLRequestJobFactory returns NULL for all job creation requests and false |
66 // for all IsHandledProtocol() requests. FakeURLRequestJobFactory can be chained | 64 // for all IsHandledProtocol() requests. FakeURLRequestJobFactory can be chained |
67 // to ProtocolHandlerRegistry::JobInterceptorFactory so the result of | 65 // to ProtocolHandlerRegistry::JobInterceptorFactory so the result of |
68 // MaybeCreateJobWithProtocolHandler() indicates whether the | 66 // MaybeCreateJobWithProtocolHandler() indicates whether the |
69 // ProtocolHandlerRegistry properly handled a job creation request. | 67 // ProtocolHandlerRegistry properly handled a job creation request. |
70 class FakeURLRequestJobFactory : public net::URLRequestJobFactory { | 68 class FakeURLRequestJobFactory : public net::URLRequestJobFactory { |
71 // net::URLRequestJobFactory implementation: | 69 // net::URLRequestJobFactory implementation: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 new FakeURLRequestJobFactory())); | 104 new FakeURLRequestJobFactory())); |
107 ASSERT_EQ(expected, interceptor->IsHandledProtocol(scheme)); | 105 ASSERT_EQ(expected, interceptor->IsHandledProtocol(scheme)); |
108 interceptor->Chain(std::unique_ptr<net::URLRequestJobFactory>()); | 106 interceptor->Chain(std::unique_ptr<net::URLRequestJobFactory>()); |
109 } | 107 } |
110 | 108 |
111 void AssertWillHandle( | 109 void AssertWillHandle( |
112 const std::string& scheme, | 110 const std::string& scheme, |
113 bool expected, | 111 bool expected, |
114 ProtocolHandlerRegistry::JobInterceptorFactory* interceptor) { | 112 ProtocolHandlerRegistry::JobInterceptorFactory* interceptor) { |
115 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 113 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
116 BrowserThread::PostTask(BrowserThread::IO, | 114 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
117 FROM_HERE, | 115 base::BindOnce(AssertWillHandleIO, scheme, expected, |
118 base::Bind(AssertWillHandleIO, | 116 base::Unretained(interceptor))); |
119 scheme, | |
120 expected, | |
121 base::Unretained(interceptor))); | |
122 base::RunLoop().RunUntilIdle(); | 117 base::RunLoop().RunUntilIdle(); |
123 } | 118 } |
124 | 119 |
125 std::unique_ptr<base::DictionaryValue> GetProtocolHandlerValue( | 120 std::unique_ptr<base::DictionaryValue> GetProtocolHandlerValue( |
126 const std::string& protocol, | 121 const std::string& protocol, |
127 const std::string& url) { | 122 const std::string& url) { |
128 auto value = base::MakeUnique<base::DictionaryValue>(); | 123 auto value = base::MakeUnique<base::DictionaryValue>(); |
129 value->SetString("protocol", protocol); | 124 value->SetString("protocol", protocol); |
130 value->SetString("url", url); | 125 value->SetString("url", url); |
131 return value; | 126 return value; |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 // added to pref. | 1079 // added to pref. |
1085 ASSERT_EQ(InPrefIgnoredHandlerCount(), 2); | 1080 ASSERT_EQ(InPrefIgnoredHandlerCount(), 2); |
1086 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); | 1081 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); |
1087 | 1082 |
1088 registry()->RemoveIgnoredHandler(p2u1); | 1083 registry()->RemoveIgnoredHandler(p2u1); |
1089 | 1084 |
1090 // p2u1 installed by user and policy, so it is removed from pref alone. | 1085 // p2u1 installed by user and policy, so it is removed from pref alone. |
1091 ASSERT_EQ(InPrefIgnoredHandlerCount(), 1); | 1086 ASSERT_EQ(InPrefIgnoredHandlerCount(), 1); |
1092 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); | 1087 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); |
1093 } | 1088 } |
OLD | NEW |