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

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

Issue 12079097: Introduce PrefRegistrySyncable, simplifying PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more merge to head. Created 7 years, 10 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) 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
321 protected: 323 protected:
322 ProtocolHandlerRegistryTest() 324 ProtocolHandlerRegistryTest()
323 : ui_thread_(BrowserThread::UI, &loop_), 325 : ui_thread_(BrowserThread::UI, &loop_),
324 file_thread_(BrowserThread::FILE, &loop_), 326 file_thread_(BrowserThread::FILE, &loop_),
325 io_thread_(BrowserThread::IO, &loop_), 327 io_thread_(BrowserThread::IO, &loop_),
326 test_protocol_handler_(CreateProtocolHandler("test", "test")) {} 328 test_protocol_handler_(CreateProtocolHandler("test", "test")) {}
327 329
328 FakeDelegate* delegate() const { return delegate_; } 330 FakeDelegate* delegate() const { return delegate_; }
329 ProtocolHandlerRegistry* registry() { return registry_.get(); } 331 ProtocolHandlerRegistry* registry() { return registry_.get(); }
330 TestingProfile* profile() const { return profile_.get(); } 332 TestingProfile* profile() const { return profile_.get(); }
331 // TODO(joi): Check if this can be removed, as well as the call to
332 // SetPrefService in SetUp.
333 PrefServiceSyncable* pref_service() const { return profile_->GetPrefs(); }
334 const ProtocolHandler& test_protocol_handler() const { 333 const ProtocolHandler& test_protocol_handler() const {
335 return test_protocol_handler_; 334 return test_protocol_handler_;
336 } 335 }
337 336
338 ProtocolHandler CreateProtocolHandler(const std::string& protocol, 337 ProtocolHandler CreateProtocolHandler(const std::string& protocol,
339 const GURL& url, 338 const GURL& url,
340 const std::string& title) { 339 const std::string& title) {
341 return ProtocolHandler::CreateProtocolHandler(protocol, url, 340 return ProtocolHandler::CreateProtocolHandler(protocol, url,
342 UTF8ToUTF16(title)); 341 UTF8ToUTF16(title));
343 } 342 }
(...skipping 18 matching lines...) Expand all
362 } 361 }
363 362
364 void TeadDownRegistry() { 363 void TeadDownRegistry() {
365 registry_->Shutdown(); 364 registry_->Shutdown();
366 registry_.reset(); 365 registry_.reset();
367 // Registry owns the delegate_ it handles deletion of that object. 366 // Registry owns the delegate_ it handles deletion of that object.
368 } 367 }
369 368
370 virtual void SetUp() { 369 virtual void SetUp() {
371 profile_.reset(new TestingProfile()); 370 profile_.reset(new TestingProfile());
372 profile_->SetPrefService(new TestingPrefServiceSyncable()); 371 CHECK(profile_->GetPrefs());
373 SetUpRegistry(true); 372 SetUpRegistry(true);
374 test_protocol_handler_ = 373 test_protocol_handler_ =
375 CreateProtocolHandler("test", GURL("http://test.com/%s"), "Test"); 374 CreateProtocolHandler("test", GURL("http://test.com/%s"), "Test");
376
377 // TODO(joi): If pref_service() and the SetPrefService above go,
378 // then this could go.
379 ProtocolHandlerRegistry::RegisterUserPrefs(pref_service());
380 } 375 }
381 376
382 virtual void TearDown() { 377 virtual void TearDown() {
383 TeadDownRegistry(); 378 TeadDownRegistry();
384 } 379 }
385 380
386 TestMessageLoop loop_; 381 TestMessageLoop loop_;
387 382
388 private: 383 private:
389 content::TestBrowserThread ui_thread_; 384 content::TestBrowserThread ui_thread_;
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 935
941 TEST_F(ProtocolHandlerRegistryTest, MAYBE_TestInstallDefaultHandler) { 936 TEST_F(ProtocolHandlerRegistryTest, MAYBE_TestInstallDefaultHandler) {
942 RecreateRegistry(false); 937 RecreateRegistry(false);
943 registry()->AddPredefinedHandler(CreateProtocolHandler( 938 registry()->AddPredefinedHandler(CreateProtocolHandler(
944 "test", GURL("http://test.com/%s"), "Test")); 939 "test", GURL("http://test.com/%s"), "Test"));
945 registry()->InitProtocolSettings(); 940 registry()->InitProtocolSettings();
946 std::vector<std::string> protocols; 941 std::vector<std::string> protocols;
947 registry()->GetRegisteredProtocols(&protocols); 942 registry()->GetRegisteredProtocols(&protocols);
948 ASSERT_EQ(static_cast<size_t>(1), protocols.size()); 943 ASSERT_EQ(static_cast<size_t>(1), protocols.size());
949 } 944 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698