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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
29 | 29 |
30 using content::BrowserThread; | 30 using content::BrowserThread; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 void AssertInterceptedIO( | 34 void AssertInterceptedIO( |
35 const GURL& url, | 35 const GURL& url, |
36 net::URLRequestJobFactory* interceptor) { | 36 net::URLRequestJobFactory* interceptor) { |
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 37 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
38 net::URLRequestContext context; | 38 net::URLRequestContext context; |
39 scoped_ptr<net::URLRequest> request(context.CreateRequest( | 39 scoped_ptr<net::URLRequest> request(context.CreateRequest( |
40 url, net::DEFAULT_PRIORITY, NULL)); | 40 url, net::DEFAULT_PRIORITY, NULL)); |
41 scoped_refptr<net::URLRequestJob> job = | 41 scoped_refptr<net::URLRequestJob> job = |
42 interceptor->MaybeCreateJobWithProtocolHandler( | 42 interceptor->MaybeCreateJobWithProtocolHandler( |
43 url.scheme(), request.get(), context.network_delegate()); | 43 url.scheme(), request.get(), context.network_delegate()); |
44 ASSERT_TRUE(job.get() != NULL); | 44 ASSERT_TRUE(job.get() != NULL); |
45 } | 45 } |
46 | 46 |
47 void AssertIntercepted( | 47 void AssertIntercepted( |
48 const GURL& url, | 48 const GURL& url, |
49 net::URLRequestJobFactory* interceptor) { | 49 net::URLRequestJobFactory* interceptor) { |
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 50 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
51 BrowserThread::PostTask(BrowserThread::IO, | 51 BrowserThread::PostTask(BrowserThread::IO, |
52 FROM_HERE, | 52 FROM_HERE, |
53 base::Bind(AssertInterceptedIO, | 53 base::Bind(AssertInterceptedIO, |
54 url, | 54 url, |
55 base::Unretained(interceptor))); | 55 base::Unretained(interceptor))); |
56 base::MessageLoop::current()->RunUntilIdle(); | 56 base::MessageLoop::current()->RunUntilIdle(); |
57 } | 57 } |
58 | 58 |
59 // FakeURLRequestJobFactory returns NULL for all job creation requests and false | 59 // FakeURLRequestJobFactory returns NULL for all job creation requests and false |
60 // for all IsHandled*() requests. FakeURLRequestJobFactory can be chained to | 60 // for all IsHandled*() requests. FakeURLRequestJobFactory can be chained to |
(...skipping 28 matching lines...) Expand all Loading... |
89 bool IsHandledURL(const GURL& url) const override { return false; } | 89 bool IsHandledURL(const GURL& url) const override { return false; } |
90 bool IsSafeRedirectTarget(const GURL& location) const override { | 90 bool IsSafeRedirectTarget(const GURL& location) const override { |
91 return true; | 91 return true; |
92 } | 92 } |
93 }; | 93 }; |
94 | 94 |
95 void AssertWillHandleIO( | 95 void AssertWillHandleIO( |
96 const std::string& scheme, | 96 const std::string& scheme, |
97 bool expected, | 97 bool expected, |
98 ProtocolHandlerRegistry::JobInterceptorFactory* interceptor) { | 98 ProtocolHandlerRegistry::JobInterceptorFactory* interceptor) { |
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 99 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
100 interceptor->Chain(scoped_ptr<net::URLRequestJobFactory>( | 100 interceptor->Chain(scoped_ptr<net::URLRequestJobFactory>( |
101 new FakeURLRequestJobFactory())); | 101 new FakeURLRequestJobFactory())); |
102 ASSERT_EQ(expected, interceptor->IsHandledProtocol(scheme)); | 102 ASSERT_EQ(expected, interceptor->IsHandledProtocol(scheme)); |
103 interceptor->Chain(scoped_ptr<net::URLRequestJobFactory>()); | 103 interceptor->Chain(scoped_ptr<net::URLRequestJobFactory>()); |
104 } | 104 } |
105 | 105 |
106 void AssertWillHandle( | 106 void AssertWillHandle( |
107 const std::string& scheme, | 107 const std::string& scheme, |
108 bool expected, | 108 bool expected, |
109 ProtocolHandlerRegistry::JobInterceptorFactory* interceptor) { | 109 ProtocolHandlerRegistry::JobInterceptorFactory* interceptor) { |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 110 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
111 BrowserThread::PostTask(BrowserThread::IO, | 111 BrowserThread::PostTask(BrowserThread::IO, |
112 FROM_HERE, | 112 FROM_HERE, |
113 base::Bind(AssertWillHandleIO, | 113 base::Bind(AssertWillHandleIO, |
114 scheme, | 114 scheme, |
115 expected, | 115 expected, |
116 base::Unretained(interceptor))); | 116 base::Unretained(interceptor))); |
117 base::MessageLoop::current()->RunUntilIdle(); | 117 base::MessageLoop::current()->RunUntilIdle(); |
118 } | 118 } |
119 | 119 |
120 base::DictionaryValue* GetProtocolHandlerValue(std::string protocol, | 120 base::DictionaryValue* GetProtocolHandlerValue(std::string protocol, |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 // added to pref. | 1122 // added to pref. |
1123 ASSERT_EQ(InPrefIgnoredHandlerCount(), 2); | 1123 ASSERT_EQ(InPrefIgnoredHandlerCount(), 2); |
1124 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); | 1124 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); |
1125 | 1125 |
1126 registry()->RemoveIgnoredHandler(p2u1); | 1126 registry()->RemoveIgnoredHandler(p2u1); |
1127 | 1127 |
1128 // p2u1 installed by user and policy, so it is removed from pref alone. | 1128 // p2u1 installed by user and policy, so it is removed from pref alone. |
1129 ASSERT_EQ(InPrefIgnoredHandlerCount(), 1); | 1129 ASSERT_EQ(InPrefIgnoredHandlerCount(), 1); |
1130 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); | 1130 ASSERT_EQ(InMemoryIgnoredHandlerCount(), 4); |
1131 } | 1131 } |
OLD | NEW |