Chromium Code Reviews| 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/browser/prefs/pref_registry_syncable.h" | |
| 14 #include "chrome/browser/prefs/pref_service_syncable.h" | |
| 13 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "chrome/common/custom_handlers/protocol_handler.h" | 16 #include "chrome/common/custom_handlers/protocol_handler.h" |
| 15 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "chrome/test/base/testing_pref_service.h" | 18 #include "chrome/test/base/testing_pref_service.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 18 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
| 21 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
| 22 #include "content/public/test/test_renderer_host.h" | 24 #include "content/public/test/test_renderer_host.h" |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 : ui_thread_(BrowserThread::UI, &loop_), | 323 : ui_thread_(BrowserThread::UI, &loop_), |
| 322 file_thread_(BrowserThread::FILE, &loop_), | 324 file_thread_(BrowserThread::FILE, &loop_), |
| 323 io_thread_(BrowserThread::IO, &loop_), | 325 io_thread_(BrowserThread::IO, &loop_), |
| 324 test_protocol_handler_(CreateProtocolHandler("test", "test")) {} | 326 test_protocol_handler_(CreateProtocolHandler("test", "test")) {} |
| 325 | 327 |
| 326 FakeDelegate* delegate() const { return delegate_; } | 328 FakeDelegate* delegate() const { return delegate_; } |
| 327 ProtocolHandlerRegistry* registry() { return registry_.get(); } | 329 ProtocolHandlerRegistry* registry() { return registry_.get(); } |
| 328 TestingProfile* profile() const { return profile_.get(); } | 330 TestingProfile* profile() const { return profile_.get(); } |
| 329 // TODO(joi): Check if this can be removed, as well as the call to | 331 // TODO(joi): Check if this can be removed, as well as the call to |
| 330 // SetPrefService in SetUp. | 332 // SetPrefService in SetUp. |
| 331 PrefServiceSyncable* pref_service() const { return profile_->GetPrefs(); } | 333 PrefServiceSyncable* pref_service() const { |
| 334 return PrefServiceSyncable::FromProfile(profile_.get()); | |
| 335 } | |
| 332 const ProtocolHandler& test_protocol_handler() const { | 336 const ProtocolHandler& test_protocol_handler() const { |
| 333 return test_protocol_handler_; | 337 return test_protocol_handler_; |
| 334 } | 338 } |
| 335 | 339 |
| 336 ProtocolHandler CreateProtocolHandler(const std::string& protocol, | 340 ProtocolHandler CreateProtocolHandler(const std::string& protocol, |
| 337 const GURL& url, | 341 const GURL& url, |
| 338 const std::string& title) { | 342 const std::string& title) { |
| 339 return ProtocolHandler::CreateProtocolHandler(protocol, url, | 343 return ProtocolHandler::CreateProtocolHandler(protocol, url, |
| 340 UTF8ToUTF16(title)); | 344 UTF8ToUTF16(title)); |
| 341 } | 345 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 367 | 371 |
| 368 virtual void SetUp() { | 372 virtual void SetUp() { |
| 369 profile_.reset(new TestingProfile()); | 373 profile_.reset(new TestingProfile()); |
| 370 profile_->SetPrefService(new TestingPrefServiceSyncable()); | 374 profile_->SetPrefService(new TestingPrefServiceSyncable()); |
| 371 SetUpRegistry(true); | 375 SetUpRegistry(true); |
| 372 test_protocol_handler_ = | 376 test_protocol_handler_ = |
| 373 CreateProtocolHandler("test", GURL("http://test.com/%s"), "Test"); | 377 CreateProtocolHandler("test", GURL("http://test.com/%s"), "Test"); |
| 374 | 378 |
| 375 // TODO(joi): If pref_service() and the SetPrefService above go, | 379 // TODO(joi): If pref_service() and the SetPrefService above go, |
| 376 // then this could go. | 380 // then this could go. |
| 377 ProtocolHandlerRegistry::RegisterUserPrefs(pref_service()); | 381 ProtocolHandlerRegistry::RegisterUserPrefs( |
| 382 static_cast<PrefRegistrySyncable*>( | |
| 383 pref_service()->DeprecatedGetPrefRegistry())); | |
|
Mattias Nissler (ping if slow)
2013/02/06 17:53:33
I guess you can just drop this and line 374 and re
Jói
2013/02/07 14:52:32
I did the same as Joe Thomas contributed in https:
Mattias Nissler (ping if slow)
2013/02/08 11:26:56
Good solution, thanks!
| |
| 378 } | 384 } |
| 379 | 385 |
| 380 virtual void TearDown() { | 386 virtual void TearDown() { |
| 381 TeadDownRegistry(); | 387 TeadDownRegistry(); |
| 382 } | 388 } |
| 383 | 389 |
| 384 TestMessageLoop loop_; | 390 TestMessageLoop loop_; |
| 385 | 391 |
| 386 private: | 392 private: |
| 387 content::TestBrowserThread ui_thread_; | 393 content::TestBrowserThread ui_thread_; |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 | 944 |
| 939 TEST_F(ProtocolHandlerRegistryTest, MAYBE_TestInstallDefaultHandler) { | 945 TEST_F(ProtocolHandlerRegistryTest, MAYBE_TestInstallDefaultHandler) { |
| 940 RecreateRegistry(false); | 946 RecreateRegistry(false); |
| 941 registry()->AddPredefinedHandler(CreateProtocolHandler( | 947 registry()->AddPredefinedHandler(CreateProtocolHandler( |
| 942 "test", GURL("http://test.com/%s"), "Test")); | 948 "test", GURL("http://test.com/%s"), "Test")); |
| 943 registry()->InitProtocolSettings(); | 949 registry()->InitProtocolSettings(); |
| 944 std::vector<std::string> protocols; | 950 std::vector<std::string> protocols; |
| 945 registry()->GetRegisteredProtocols(&protocols); | 951 registry()->GetRegisteredProtocols(&protocols); |
| 946 ASSERT_EQ(static_cast<size_t>(1), protocols.size()); | 952 ASSERT_EQ(static_cast<size_t>(1), protocols.size()); |
| 947 } | 953 } |
| OLD | NEW |