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

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

Issue 7033018: Handler settings page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed errant /* */ Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/test/testing_browser_process_test.h" 11 #include "chrome/test/testing_browser_process_test.h"
12 #include "chrome/test/testing_browser_process_test.h" 12 #include "chrome/test/testing_browser_process_test.h"
13 #include "chrome/test/testing_pref_service.h" 13 #include "chrome/test/testing_pref_service.h"
14 #include "chrome/test/testing_profile.h" 14 #include "chrome/test/testing_profile.h"
15 #include "content/common/notification_observer.h" 15 #include "content/common/notification_observer.h"
16 #include "content/common/notification_registrar.h" 16 #include "content/common/notification_registrar.h"
17 #include "content/common/notification_service.h" 17 #include "content/common/notification_service.h"
18 18
19
19 class FakeDelegate : public ProtocolHandlerRegistry::Delegate { 20 class FakeDelegate : public ProtocolHandlerRegistry::Delegate {
20 public: 21 public:
21 virtual ~FakeDelegate() { } 22 virtual ~FakeDelegate() { }
22 virtual void RegisterExternalHandler(const std::string& protocol) { 23 virtual void RegisterExternalHandler(const std::string& protocol) {
23 ASSERT_TRUE( 24 ASSERT_TRUE(
24 registered_protocols_.find(protocol) == registered_protocols_.end()); 25 registered_protocols_.find(protocol) == registered_protocols_.end());
25 registered_protocols_.insert(protocol); 26 registered_protocols_.insert(protocol);
26 } 27 }
27 virtual void DeregisterExternalHandler(const std::string& protocol) { 28 virtual void DeregisterExternalHandler(const std::string& protocol) {
28 registered_protocols_.erase(protocol); 29 registered_protocols_.erase(protocol);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 registry()->Enable(); 135 registry()->Enable();
135 ASSERT_TRUE(registry()->enabled()); 136 ASSERT_TRUE(registry()->enabled());
136 } 137 }
137 138
138 TEST_F(ProtocolHandlerRegistryTest, 139 TEST_F(ProtocolHandlerRegistryTest,
139 DisallowRegisteringExternallyHandledProtocols) { 140 DisallowRegisteringExternallyHandledProtocols) {
140 delegate()->RegisterExternalHandler("test"); 141 delegate()->RegisterExternalHandler("test");
141 ASSERT_FALSE(registry()->CanSchemeBeOverridden("test")); 142 ASSERT_FALSE(registry()->CanSchemeBeOverridden("test"));
142 } 143 }
143 144
145 TEST_F(ProtocolHandlerRegistryTest, RemovingHandlerMeansItCanBeAddedAgain) {
146 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler());
147 ASSERT_TRUE(registry()->CanSchemeBeOverridden("test"));
148 registry()->RemoveHandler(test_protocol_handler());
149 ASSERT_TRUE(registry()->CanSchemeBeOverridden("test"));
150 }
151
144 TEST_F(ProtocolHandlerRegistryTest, TestStartsAsDefault) { 152 TEST_F(ProtocolHandlerRegistryTest, TestStartsAsDefault) {
145 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); 153 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler());
146 ASSERT_TRUE(registry()->IsDefault(test_protocol_handler())); 154 ASSERT_TRUE(registry()->IsDefault(test_protocol_handler()));
147 } 155 }
148 156
149 TEST_F(ProtocolHandlerRegistryTest, 157 TEST_F(ProtocolHandlerRegistryTest,
150 TestClearDefaultDoesntClearImplicitDefault) { 158 TestClearDefaultDoesntClearImplicitDefault) {
151 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler()); 159 registry()->OnAcceptRegisterProtocolHandler(test_protocol_handler());
152 registry()->ClearDefault("test"); 160 registry()->ClearDefault("test");
153 ASSERT_TRUE(registry()->IsDefault(test_protocol_handler())); 161 ASSERT_TRUE(registry()->IsDefault(test_protocol_handler()));
154 } 162 }
155 163
156 TEST_F(ProtocolHandlerRegistryTest, TestClearDefault) { 164 TEST_F(ProtocolHandlerRegistryTest, TestClearDefault) {
157 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); 165 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
158 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); 166 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2");
159 registry()->OnAcceptRegisterProtocolHandler(ph1); 167 registry()->OnAcceptRegisterProtocolHandler(ph1);
160 registry()->OnAcceptRegisterProtocolHandler(ph2); 168 registry()->OnAcceptRegisterProtocolHandler(ph2);
161 169
162 registry()->SetDefault(ph2); 170 registry()->SetDefault(ph1);
163 registry()->ClearDefault("test"); 171 registry()->ClearDefault("test");
164 ASSERT_FALSE(registry()->IsDefault(ph2)); 172 ASSERT_FALSE(registry()->IsDefault(ph1));
173 ASSERT_TRUE(registry()->IsDefault(ph2));
165 } 174 }
166 175
167 TEST_F(ProtocolHandlerRegistryTest, TestGetHandlerFor) { 176 TEST_F(ProtocolHandlerRegistryTest, TestGetHandlerFor) {
168 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); 177 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
169 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); 178 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2");
170 registry()->OnAcceptRegisterProtocolHandler(ph1); 179 registry()->OnAcceptRegisterProtocolHandler(ph1);
171 registry()->OnAcceptRegisterProtocolHandler(ph2); 180 registry()->OnAcceptRegisterProtocolHandler(ph2);
172 181
173 registry()->SetDefault(ph2); 182 registry()->SetDefault(ph2);
174 ASSERT_EQ(ph2, registry()->GetHandlerFor("test")); 183 ASSERT_EQ(ph2, registry()->GetHandlerFor("test"));
175 ASSERT_TRUE(registry()->HasDefault("test")); 184 ASSERT_TRUE(registry()->HasDefault("test"));
176 } 185 }
177 186
178 TEST_F(ProtocolHandlerRegistryTest, TestMultipleHandlersClearsDefault) { 187 TEST_F(ProtocolHandlerRegistryTest, TestMostRecentHandlerIsDefault) {
179 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); 188 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
180 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); 189 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2");
181 registry()->OnAcceptRegisterProtocolHandler(ph1); 190 registry()->OnAcceptRegisterProtocolHandler(ph1);
182 registry()->OnAcceptRegisterProtocolHandler(ph2); 191 registry()->OnAcceptRegisterProtocolHandler(ph2);
183 ASSERT_FALSE(registry()->IsDefault(ph1)); 192 ASSERT_FALSE(registry()->IsDefault(ph1));
184 ASSERT_FALSE(registry()->IsDefault(ph2)); 193 ASSERT_TRUE(registry()->IsDefault(ph2));
185 } 194 }
186 195
187 TEST_F(ProtocolHandlerRegistryTest, TestSetDefault) { 196 TEST_F(ProtocolHandlerRegistryTest, TestSetDefault) {
188 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); 197 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
189 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); 198 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2");
190 registry()->OnAcceptRegisterProtocolHandler(ph1); 199 registry()->OnAcceptRegisterProtocolHandler(ph1);
191 registry()->OnAcceptRegisterProtocolHandler(ph2); 200 registry()->OnAcceptRegisterProtocolHandler(ph2);
192 201
193 registry()->SetDefault(ph1); 202 registry()->SetDefault(ph1);
194 ASSERT_TRUE(registry()->IsDefault(ph1)); 203 ASSERT_TRUE(registry()->IsDefault(ph1));
(...skipping 18 matching lines...) Expand all
213 ASSERT_TRUE(registry()->IsDefault(ph2)); 222 ASSERT_TRUE(registry()->IsDefault(ph2));
214 } 223 }
215 224
216 TEST_F(ProtocolHandlerRegistryTest, TestRemoveHandler) { 225 TEST_F(ProtocolHandlerRegistryTest, TestRemoveHandler) {
217 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); 226 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
218 registry()->OnAcceptRegisterProtocolHandler(ph1); 227 registry()->OnAcceptRegisterProtocolHandler(ph1);
219 registry()->OnAcceptRegisterProtocolHandler(ph1); 228 registry()->OnAcceptRegisterProtocolHandler(ph1);
220 229
221 registry()->RemoveHandler(ph1); 230 registry()->RemoveHandler(ph1);
222 ASSERT_FALSE(registry()->IsRegistered(ph1)); 231 ASSERT_FALSE(registry()->IsRegistered(ph1));
223 ASSERT_FALSE(registry()->HasHandler("test")); 232 ASSERT_FALSE(registry()->IsHandledProtocol("test"));
224 } 233 }
225 234
226 TEST_F(ProtocolHandlerRegistryTest, TestIsRegistered) { 235 TEST_F(ProtocolHandlerRegistryTest, TestIsRegistered) {
227 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); 236 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
228 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); 237 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2");
229 registry()->OnAcceptRegisterProtocolHandler(ph1); 238 registry()->OnAcceptRegisterProtocolHandler(ph1);
230 registry()->OnAcceptRegisterProtocolHandler(ph2); 239 registry()->OnAcceptRegisterProtocolHandler(ph2);
231 240
232 ASSERT_TRUE(registry()->IsRegistered(ph1)); 241 ASSERT_TRUE(registry()->IsRegistered(ph1));
233 } 242 }
234 243
235 TEST_F(ProtocolHandlerRegistryTest, TestRemoveHandlerRemovesDefault) { 244 TEST_F(ProtocolHandlerRegistryTest, TestRemoveHandlerRemovesDefault) {
236 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1"); 245 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
237 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2"); 246 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2");
238 ProtocolHandler ph3 = CreateProtocolHandler("test", "test3"); 247 ProtocolHandler ph3 = CreateProtocolHandler("test", "test3");
248
239 registry()->OnAcceptRegisterProtocolHandler(ph1); 249 registry()->OnAcceptRegisterProtocolHandler(ph1);
240 registry()->OnAcceptRegisterProtocolHandler(ph2); 250 registry()->OnAcceptRegisterProtocolHandler(ph2);
241 registry()->OnAcceptRegisterProtocolHandler(ph3); 251 registry()->OnAcceptRegisterProtocolHandler(ph3);
242 252
243 registry()->SetDefault(ph1); 253 registry()->SetDefault(ph1);
244 registry()->RemoveHandler(ph1); 254 registry()->RemoveHandler(ph1);
245 ASSERT_FALSE(registry()->IsDefault(ph1)); 255 ASSERT_FALSE(registry()->IsDefault(ph1));
246 } 256 }
257
258 TEST_F(ProtocolHandlerRegistryTest, TestGetHandlersFor) {
259 ProtocolHandler ph1 = CreateProtocolHandler("test", "test1");
260 ProtocolHandler ph2 = CreateProtocolHandler("test", "test2");
261 ProtocolHandler ph3 = CreateProtocolHandler("test", "test3");
262 registry()->OnAcceptRegisterProtocolHandler(ph1);
263 registry()->OnAcceptRegisterProtocolHandler(ph2);
264 registry()->OnAcceptRegisterProtocolHandler(ph3);
265
266 const ProtocolHandlerList* handlers = registry()->GetHandlersFor("test");
267 ASSERT_TRUE(handlers != NULL);
268 ASSERT_EQ(ph1, (*handlers)[0]);
269 ASSERT_EQ(ph2, (*handlers)[1]);
270 ASSERT_EQ(ph3, (*handlers)[2]);
271 }
272
273 TEST_F(ProtocolHandlerRegistryTest, TestGetHandledProtocols) {
274 std::vector<std::string> protocols;
275 registry()->GetHandledProtocols(&protocols);
276 ASSERT_EQ((size_t) 0, protocols.size());
277
278 registry()->GetHandlersFor("test");
279
280 protocols.clear();
281 registry()->GetHandledProtocols(&protocols);
282 ASSERT_EQ((size_t) 0, protocols.size());
283 }
284
285 TEST_F(ProtocolHandlerRegistryTest, TestIsHandledProtocol) {
286 registry()->GetHandlersFor("test");
287 ASSERT_FALSE(registry()->IsHandledProtocol("test"));
288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698