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.h" | 10 #include "base/message_loop.h" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/custom_handlers/protocol_handler.h" | 14 #include "chrome/common/custom_handlers/protocol_handler.h" |
15 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
16 #include "chrome/test/base/testing_pref_service.h" | |
17 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
18 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
20 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
21 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
22 #include "content/public/test/test_renderer_host.h" | 21 #include "content/public/test/test_renderer_host.h" |
23 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
24 #include "net/url_request/url_request_context.h" | 23 #include "net/url_request/url_request_context.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
26 | 25 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 protected: | 318 protected: |
320 ProtocolHandlerRegistryTest() | 319 ProtocolHandlerRegistryTest() |
321 : ui_thread_(BrowserThread::UI, &loop_), | 320 : ui_thread_(BrowserThread::UI, &loop_), |
322 file_thread_(BrowserThread::FILE, &loop_), | 321 file_thread_(BrowserThread::FILE, &loop_), |
323 io_thread_(BrowserThread::IO, &loop_), | 322 io_thread_(BrowserThread::IO, &loop_), |
324 test_protocol_handler_(CreateProtocolHandler("test", "test")) {} | 323 test_protocol_handler_(CreateProtocolHandler("test", "test")) {} |
325 | 324 |
326 FakeDelegate* delegate() const { return delegate_; } | 325 FakeDelegate* delegate() const { return delegate_; } |
327 ProtocolHandlerRegistry* registry() { return registry_.get(); } | 326 ProtocolHandlerRegistry* registry() { return registry_.get(); } |
328 TestingProfile* profile() const { return profile_.get(); } | 327 TestingProfile* profile() const { return profile_.get(); } |
329 // TODO(joi): Check if this can be removed, as well as the call to | |
330 // SetPrefService in SetUp. | |
331 PrefServiceSyncable* pref_service() const { return profile_->GetPrefs(); } | |
332 const ProtocolHandler& test_protocol_handler() const { | 328 const ProtocolHandler& test_protocol_handler() const { |
333 return test_protocol_handler_; | 329 return test_protocol_handler_; |
334 } | 330 } |
335 | 331 |
336 ProtocolHandler CreateProtocolHandler(const std::string& protocol, | 332 ProtocolHandler CreateProtocolHandler(const std::string& protocol, |
337 const GURL& url, | 333 const GURL& url, |
338 const std::string& title) { | 334 const std::string& title) { |
339 return ProtocolHandler::CreateProtocolHandler(protocol, url, | 335 return ProtocolHandler::CreateProtocolHandler(protocol, url, |
340 UTF8ToUTF16(title)); | 336 UTF8ToUTF16(title)); |
341 } | 337 } |
(...skipping 18 matching lines...) Expand all Loading... |
360 } | 356 } |
361 | 357 |
362 void TeadDownRegistry() { | 358 void TeadDownRegistry() { |
363 registry_->Shutdown(); | 359 registry_->Shutdown(); |
364 registry_.reset(); | 360 registry_.reset(); |
365 // Registry owns the delegate_ it handles deletion of that object. | 361 // Registry owns the delegate_ it handles deletion of that object. |
366 } | 362 } |
367 | 363 |
368 virtual void SetUp() { | 364 virtual void SetUp() { |
369 profile_.reset(new TestingProfile()); | 365 profile_.reset(new TestingProfile()); |
370 profile_->SetPrefService(new TestingPrefServiceSyncable()); | 366 CHECK(profile_->GetPrefs()); |
371 SetUpRegistry(true); | 367 SetUpRegistry(true); |
372 test_protocol_handler_ = | 368 test_protocol_handler_ = |
373 CreateProtocolHandler("test", GURL("http://test.com/%s"), "Test"); | 369 CreateProtocolHandler("test", GURL("http://test.com/%s"), "Test"); |
374 | |
375 // TODO(joi): If pref_service() and the SetPrefService above go, | |
376 // then this could go. | |
377 ProtocolHandlerRegistry::RegisterUserPrefs(pref_service()); | |
378 } | 370 } |
379 | 371 |
380 virtual void TearDown() { | 372 virtual void TearDown() { |
381 TeadDownRegistry(); | 373 TeadDownRegistry(); |
382 } | 374 } |
383 | 375 |
384 TestMessageLoop loop_; | 376 TestMessageLoop loop_; |
385 | 377 |
386 private: | 378 private: |
387 content::TestBrowserThread ui_thread_; | 379 content::TestBrowserThread ui_thread_; |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 | 930 |
939 TEST_F(ProtocolHandlerRegistryTest, MAYBE_TestInstallDefaultHandler) { | 931 TEST_F(ProtocolHandlerRegistryTest, MAYBE_TestInstallDefaultHandler) { |
940 RecreateRegistry(false); | 932 RecreateRegistry(false); |
941 registry()->AddPredefinedHandler(CreateProtocolHandler( | 933 registry()->AddPredefinedHandler(CreateProtocolHandler( |
942 "test", GURL("http://test.com/%s"), "Test")); | 934 "test", GURL("http://test.com/%s"), "Test")); |
943 registry()->InitProtocolSettings(); | 935 registry()->InitProtocolSettings(); |
944 std::vector<std::string> protocols; | 936 std::vector<std::string> protocols; |
945 registry()->GetRegisteredProtocols(&protocols); | 937 registry()->GetRegisteredProtocols(&protocols); |
946 ASSERT_EQ(static_cast<size_t>(1), protocols.size()); | 938 ASSERT_EQ(static_cast<size_t>(1), protocols.size()); |
947 } | 939 } |
OLD | NEW |