OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/custom_handlers/protocol_handler.h" | 9 #include "chrome/browser/custom_handlers/protocol_handler.h" |
10 #include "chrome/test/testing_browser_process.h" | 10 #include "chrome/test/testing_browser_process.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 registry()->Enable(); | 134 registry()->Enable(); |
135 ASSERT_TRUE(registry()->enabled()); | 135 ASSERT_TRUE(registry()->enabled()); |
136 } | 136 } |
137 | 137 |
138 TEST_F(ProtocolHandlerRegistryTest, | 138 TEST_F(ProtocolHandlerRegistryTest, |
139 DisallowRegisteringExternallyHandledProtocols) { | 139 DisallowRegisteringExternallyHandledProtocols) { |
140 delegate()->RegisterExternalHandler("test"); | 140 delegate()->RegisterExternalHandler("test"); |
141 ASSERT_FALSE(registry()->CanSchemeBeOverridden("test")); | 141 ASSERT_FALSE(registry()->CanSchemeBeOverridden("test")); |
142 } | 142 } |
143 | 143 |
144 TEST_F(ProtocolHandlerRegistryTest, RemovingHandlerMeansItCanBeAddedAgain) { | |
145 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); | |
146 ASSERT_TRUE(registry()->CanSchemeBeOverridden("test")); | |
147 registry()->RemoveHandler(test_protocol_handler()); | |
148 ASSERT_TRUE(registry()->CanSchemeBeOverridden("test")); | |
149 } | |
150 | |
144 TEST_F(ProtocolHandlerRegistryTest, TestStartsAsDefault) { | 151 TEST_F(ProtocolHandlerRegistryTest, TestStartsAsDefault) { |
145 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); | 152 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); |
146 ASSERT_TRUE(registry()->IsDefault(test_protocol_handler())); | 153 ASSERT_TRUE(registry()->IsDefault(test_protocol_handler())); |
147 } | 154 } |
148 | 155 |
149 TEST_F(ProtocolHandlerRegistryTest, | 156 TEST_F(ProtocolHandlerRegistryTest, |
150 TestClearDefaultDoesntClearImplicitDefault) { | 157 TestClearDefaultDoesntClearImplicitDefault) { |
151 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); | 158 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); |
152 registry()->ClearDefault("test"); | 159 registry()->ClearDefault("test"); |
153 ASSERT_TRUE(registry()->IsDefault(test_protocol_handler())); | 160 ASSERT_TRUE(registry()->IsDefault(test_protocol_handler())); |
154 } | 161 } |
155 | 162 |
156 TEST_F(ProtocolHandlerRegistryTest, TestClearDefault) { | 163 TEST_F(ProtocolHandlerRegistryTest, TestClearDefault) { |
157 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); | 164 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); |
158 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); | 165 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); |
159 registry()->OnAcceptRegisterProtocolHandler(ph1); | 166 registry()->OnAcceptRegisterProtocolHandler(ph1); |
160 registry()->OnAcceptRegisterProtocolHandler(ph2); | 167 registry()->OnAcceptRegisterProtocolHandler(ph2); |
161 | 168 |
162 registry()->SetDefault(ph2); | 169 registry()->SetDefault(ph1); |
163 registry()->ClearDefault("test"); | 170 registry()->ClearDefault("test"); |
164 ASSERT_FALSE(registry()->IsDefault(ph2)); | 171 ASSERT_FALSE(registry()->IsDefault(ph1)); |
172 ASSERT_TRUE(registry()->IsDefault(ph2)); | |
165 } | 173 } |
166 | 174 |
167 TEST_F(ProtocolHandlerRegistryTest, TestGetHandlerFor) { | 175 TEST_F(ProtocolHandlerRegistryTest, TestGetHandlerFor) { |
168 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); | 176 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); |
169 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); | 177 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); |
170 registry()->OnAcceptRegisterProtocolHandler(ph1); | 178 registry()->OnAcceptRegisterProtocolHandler(ph1); |
171 registry()->OnAcceptRegisterProtocolHandler(ph2); | 179 registry()->OnAcceptRegisterProtocolHandler(ph2); |
172 | 180 |
173 registry()->SetDefault(ph2); | 181 registry()->SetDefault(ph2); |
174 ASSERT_EQ(ph2, registry()->GetHandlerFor("test")); | 182 ASSERT_EQ(ph2, registry()->GetHandlerFor("test")); |
175 ASSERT_TRUE(registry()->HasDefault("test")); | 183 ASSERT_TRUE(registry()->HasDefault("test")); |
176 } | 184 } |
177 | 185 |
178 TEST_F(ProtocolHandlerRegistryTest, TestMultipleHandlersClearsDefault) { | 186 TEST_F(ProtocolHandlerRegistryTest, TestMostRecentHandlerIsDefault) { |
179 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); | 187 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); |
180 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); | 188 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); |
181 registry()->OnAcceptRegisterProtocolHandler(ph1); | 189 registry()->OnAcceptRegisterProtocolHandler(ph1); |
182 registry()->OnAcceptRegisterProtocolHandler(ph2); | 190 registry()->OnAcceptRegisterProtocolHandler(ph2); |
183 ASSERT_FALSE(registry()->IsDefault(ph1)); | 191 ASSERT_FALSE(registry()->IsDefault(ph1)); |
184 ASSERT_FALSE(registry()->IsDefault(ph2)); | 192 ASSERT_TRUE(registry()->IsDefault(ph2)); |
185 } | 193 } |
186 | 194 |
187 TEST_F(ProtocolHandlerRegistryTest, TestSetDefault) { | 195 TEST_F(ProtocolHandlerRegistryTest, TestSetDefault) { |
188 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); | 196 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); |
189 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); | 197 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); |
190 registry()->OnAcceptRegisterProtocolHandler(ph1); | 198 registry()->OnAcceptRegisterProtocolHandler(ph1); |
191 registry()->OnAcceptRegisterProtocolHandler(ph2); | 199 registry()->OnAcceptRegisterProtocolHandler(ph2); |
192 | 200 |
193 registry()->SetDefault(ph1); | 201 registry()->SetDefault(ph1); |
194 ASSERT_TRUE(registry()->IsDefault(ph1)); | 202 ASSERT_TRUE(registry()->IsDefault(ph1)); |
(...skipping 18 matching lines...) Expand all Loading... | |
213 ASSERT_TRUE(registry()->IsDefault(ph2)); | 221 ASSERT_TRUE(registry()->IsDefault(ph2)); |
214 } | 222 } |
215 | 223 |
216 TEST_F(ProtocolHandlerRegistryTest, TestRemoveHandler) { | 224 TEST_F(ProtocolHandlerRegistryTest, TestRemoveHandler) { |
217 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); | 225 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); |
218 registry()->OnAcceptRegisterProtocolHandler(ph1); | 226 registry()->OnAcceptRegisterProtocolHandler(ph1); |
219 registry()->OnAcceptRegisterProtocolHandler(ph1); | 227 registry()->OnAcceptRegisterProtocolHandler(ph1); |
220 | 228 |
221 registry()->RemoveHandler(ph1); | 229 registry()->RemoveHandler(ph1); |
222 ASSERT_FALSE(registry()->IsRegistered(ph1)); | 230 ASSERT_FALSE(registry()->IsRegistered(ph1)); |
223 ASSERT_FALSE(registry()->HasHandler("test")); | 231 ASSERT_FALSE(registry()->IsHandledProtocol("test")); |
224 } | 232 } |
225 | 233 |
226 TEST_F(ProtocolHandlerRegistryTest, TestIsRegistered) { | 234 TEST_F(ProtocolHandlerRegistryTest, TestIsRegistered) { |
227 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); | 235 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); |
228 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); | 236 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); |
229 registry()->OnAcceptRegisterProtocolHandler(ph1); | 237 registry()->OnAcceptRegisterProtocolHandler(ph1); |
230 registry()->OnAcceptRegisterProtocolHandler(ph2); | 238 registry()->OnAcceptRegisterProtocolHandler(ph2); |
231 | 239 |
232 ASSERT_TRUE(registry()->IsRegistered(ph1)); | 240 ASSERT_TRUE(registry()->IsRegistered(ph1)); |
233 } | 241 } |
234 | 242 |
235 TEST_F(ProtocolHandlerRegistryTest, TestRemoveHandlerRemovesDefault) { | 243 TEST_F(ProtocolHandlerRegistryTest, TestRemoveHandlerRemovesDefault) { |
236 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); | 244 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); |
237 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); | 245 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); |
238 ProtocolHandler ph3 = CreateProtocolHandler("test", "test3"); | 246 ProtocolHandler ph3 = CreateProtocolHandler("test", "test3"); |
247 | |
239 registry()->OnAcceptRegisterProtocolHandler(ph1); | 248 registry()->OnAcceptRegisterProtocolHandler(ph1); |
240 registry()->OnAcceptRegisterProtocolHandler(ph2); | 249 registry()->OnAcceptRegisterProtocolHandler(ph2); |
241 registry()->OnAcceptRegisterProtocolHandler(ph3); | 250 registry()->OnAcceptRegisterProtocolHandler(ph3); |
242 | 251 |
243 registry()->SetDefault(ph1); | 252 registry()->SetDefault(ph1); |
244 registry()->RemoveHandler(ph1); | 253 registry()->RemoveHandler(ph1); |
245 ASSERT_FALSE(registry()->IsDefault(ph1)); | 254 ASSERT_FALSE(registry()->IsDefault(ph1)); |
246 } | 255 } |
256 | |
257 TEST_F(ProtocolHandlerRegistryTest, TestGetHandlersFor) { | |
258 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); | |
259 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); | |
260 ProtocolHandler ph3 = CreateProtocolHandler("test", "test3"); | |
261 registry()->OnAcceptRegisterProtocolHandler(ph1); | |
262 registry()->OnAcceptRegisterProtocolHandler(ph2); | |
263 registry()->OnAcceptRegisterProtocolHandler(ph3); | |
264 | |
265 const ProtocolHandlerList* handlers = registry()->GetHandlersFor("test"); | |
266 ASSERT_TRUE(handlers != NULL); | |
267 ASSERT_EQ(ph1, (*handlers)[0]); | |
268 ASSERT_EQ(ph2, (*handlers)[1]); | |
269 ASSERT_EQ(ph3, (*handlers)[2]); | |
270 } | |
271 | |
272 TEST_F(ProtocolHandlerRegistryTest, TestGetHandledProtocols) { | |
273 std::vector<std::string> protocols; | |
274 registry()->GetHandledProtocols(&protocols); | |
275 ASSERT_EQ((size_t) 0, protocols.size()); | |
276 | |
277 registry()->GetHandlersFor("test"); | |
278 | |
279 protocols.clear(); | |
280 registry()->GetHandledProtocols(&protocols); | |
281 ASSERT_EQ((size_t) 0, protocols.size()); | |
282 } | |
283 | |
284 TEST_F(ProtocolHandlerRegistryTest, TestIsHandledProtocol) { | |
285 registry()->GetHandlersFor("test"); | |
286 ASSERT_FALSE(registry()->IsHandledProtocol("test")); | |
287 } | |
tony
2011/05/23 21:42:00
Can we add some notification tests?
koz (OOO until 15th September)
2011/05/24 08:47:49
Done.
| |
OLD | NEW |