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

Side by Side Diff: chrome/test/base/testing_profile.cc

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix silly compile error Created 7 years, 4 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/test/base/testing_profile.h" 5 #include "chrome/test/base/testing_profile.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 19 matching lines...) Expand all
30 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" 30 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
31 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto ry.h" 31 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto ry.h"
32 #include "chrome/browser/history/history_backend.h" 32 #include "chrome/browser/history/history_backend.h"
33 #include "chrome/browser/history/history_db_task.h" 33 #include "chrome/browser/history/history_db_task.h"
34 #include "chrome/browser/history/history_service.h" 34 #include "chrome/browser/history/history_service.h"
35 #include "chrome/browser/history/history_service_factory.h" 35 #include "chrome/browser/history/history_service_factory.h"
36 #include "chrome/browser/history/shortcuts_backend.h" 36 #include "chrome/browser/history/shortcuts_backend.h"
37 #include "chrome/browser/history/shortcuts_backend_factory.h" 37 #include "chrome/browser/history/shortcuts_backend_factory.h"
38 #include "chrome/browser/history/top_sites.h" 38 #include "chrome/browser/history/top_sites.h"
39 #include "chrome/browser/history/web_history_service_factory.h" 39 #include "chrome/browser/history/web_history_service_factory.h"
40 #include "chrome/browser/net/cookie_store_util.h"
40 #include "chrome/browser/net/pref_proxy_config_tracker.h" 41 #include "chrome/browser/net/pref_proxy_config_tracker.h"
41 #include "chrome/browser/net/proxy_service_factory.h" 42 #include "chrome/browser/net/proxy_service_factory.h"
42 #include "chrome/browser/notifications/desktop_notification_service.h" 43 #include "chrome/browser/notifications/desktop_notification_service.h"
43 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 44 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
44 #include "chrome/browser/policy/profile_policy_connector.h" 45 #include "chrome/browser/policy/profile_policy_connector.h"
45 #include "chrome/browser/policy/profile_policy_connector_factory.h" 46 #include "chrome/browser/policy/profile_policy_connector_factory.h"
46 #include "chrome/browser/prefs/browser_prefs.h" 47 #include "chrome/browser/prefs/browser_prefs.h"
47 #include "chrome/browser/prefs/pref_service_syncable.h" 48 #include "chrome/browser/prefs/pref_service_syncable.h"
48 #include "chrome/browser/prerender/prerender_manager.h" 49 #include "chrome/browser/prerender/prerender_manager.h"
49 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" 50 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
50 #include "chrome/browser/profiles/storage_partition_descriptor.h" 51 #include "chrome/browser/profiles/storage_partition_descriptor.h"
51 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" 52 #include "chrome/browser/search_engines/template_url_fetcher_factory.h"
52 #include "chrome/browser/webdata/web_data_service.h" 53 #include "chrome/browser/webdata/web_data_service.h"
53 #include "chrome/browser/webdata/web_data_service_factory.h" 54 #include "chrome/browser/webdata/web_data_service_factory.h"
54 #include "chrome/common/chrome_constants.h" 55 #include "chrome/common/chrome_constants.h"
55 #include "chrome/common/chrome_switches.h" 56 #include "chrome/common/chrome_switches.h"
56 #include "chrome/common/pref_names.h" 57 #include "chrome/common/pref_names.h"
57 #include "chrome/common/url_constants.h" 58 #include "chrome/common/url_constants.h"
58 #include "chrome/test/base/bookmark_load_observer.h" 59 #include "chrome/test/base/bookmark_load_observer.h"
59 #include "chrome/test/base/history_index_restore_observer.h" 60 #include "chrome/test/base/history_index_restore_observer.h"
60 #include "chrome/test/base/testing_pref_service_syncable.h" 61 #include "chrome/test/base/testing_pref_service_syncable.h"
61 #include "chrome/test/base/ui_test_utils.h" 62 #include "chrome/test/base/ui_test_utils.h"
62 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" 63 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
63 #include "components/user_prefs/user_prefs.h" 64 #include "components/user_prefs/user_prefs.h"
64 #include "content/public/browser/browser_thread.h" 65 #include "content/public/browser/browser_thread.h"
66 #include "content/public/browser/cookie_store_factory.h"
65 #include "content/public/browser/notification_service.h" 67 #include "content/public/browser/notification_service.h"
66 #include "content/public/browser/render_process_host.h" 68 #include "content/public/browser/render_process_host.h"
67 #include "content/public/browser/storage_partition.h" 69 #include "content/public/browser/storage_partition.h"
68 #include "content/public/test/mock_resource_context.h" 70 #include "content/public/test/mock_resource_context.h"
69 #include "content/public/test/test_utils.h" 71 #include "content/public/test/test_utils.h"
70 #include "extensions/common/constants.h" 72 #include "extensions/common/constants.h"
71 #include "net/cookies/cookie_monster.h" 73 #include "net/cookies/cookie_monster.h"
72 #include "net/url_request/url_request_context.h" 74 #include "net/url_request/url_request_context.h"
73 #include "net/url_request/url_request_context_getter.h" 75 #include "net/url_request/url_request_context_getter.h"
74 #include "net/url_request/url_request_test_util.h" 76 #include "net/url_request/url_request_test_util.h"
(...skipping 29 matching lines...) Expand all
104 virtual void DoneRunOnMainThread() OVERRIDE { 106 virtual void DoneRunOnMainThread() OVERRIDE {
105 base::MessageLoop::current()->Quit(); 107 base::MessageLoop::current()->Quit();
106 } 108 }
107 109
108 private: 110 private:
109 virtual ~QuittingHistoryDBTask() {} 111 virtual ~QuittingHistoryDBTask() {}
110 112
111 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask); 113 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
112 }; 114 };
113 115
114 class TestExtensionURLRequestContext : public net::URLRequestContext {
115 public:
116 TestExtensionURLRequestContext() {
117 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
118 const char* schemes[] = {extensions::kExtensionScheme};
119 cookie_monster->SetCookieableSchemes(schemes, 1);
120 set_cookie_store(cookie_monster);
121 }
122
123 virtual ~TestExtensionURLRequestContext() {}
124 };
125
126 class TestExtensionURLRequestContextGetter
127 : public net::URLRequestContextGetter {
128 public:
129 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
130 if (!context_.get())
131 context_.reset(new TestExtensionURLRequestContext());
132 return context_.get();
133 }
134 virtual scoped_refptr<base::SingleThreadTaskRunner>
135 GetNetworkTaskRunner() const OVERRIDE {
136 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
137 }
138
139 protected:
140 virtual ~TestExtensionURLRequestContextGetter() {}
141
142 private:
143 scoped_ptr<net::URLRequestContext> context_;
144 };
145
146 BrowserContextKeyedService* CreateTestDesktopNotificationService( 116 BrowserContextKeyedService* CreateTestDesktopNotificationService(
147 content::BrowserContext* profile) { 117 content::BrowserContext* profile) {
148 #if defined(ENABLE_NOTIFICATIONS) 118 #if defined(ENABLE_NOTIFICATIONS)
149 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL); 119 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL);
150 #else 120 #else
151 return NULL; 121 return NULL;
152 #endif 122 #endif
153 } 123 }
154 124
155 } // namespace 125 } // namespace
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 extension_special_storage_policy_ = extension_special_storage_policy; 535 extension_special_storage_policy_ = extension_special_storage_policy;
566 } 536 }
567 537
568 ExtensionSpecialStoragePolicy* 538 ExtensionSpecialStoragePolicy*
569 TestingProfile::GetExtensionSpecialStoragePolicy() { 539 TestingProfile::GetExtensionSpecialStoragePolicy() {
570 if (!extension_special_storage_policy_.get()) 540 if (!extension_special_storage_policy_.get())
571 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); 541 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
572 return extension_special_storage_policy_.get(); 542 return extension_special_storage_policy_.get();
573 } 543 }
574 544
575 net::CookieMonster* TestingProfile::GetCookieMonster() {
576 if (!GetRequestContext())
577 return NULL;
578 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
579 GetCookieMonster();
580 }
581
582 void TestingProfile::CreateTestingPrefService() { 545 void TestingProfile::CreateTestingPrefService() {
583 DCHECK(!prefs_.get()); 546 DCHECK(!prefs_.get());
584 testing_prefs_ = new TestingPrefServiceSyncable(); 547 testing_prefs_ = new TestingPrefServiceSyncable();
585 prefs_.reset(testing_prefs_); 548 prefs_.reset(testing_prefs_);
586 user_prefs::UserPrefs::Set(this, prefs_.get()); 549 user_prefs::UserPrefs::Set(this, prefs_.get());
587 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); 550 chrome::RegisterUserProfilePrefs(testing_prefs_->registry());
588 } 551 }
589 552
590 void TestingProfile::CreateProfilePolicyConnector() { 553 void TestingProfile::CreateProfilePolicyConnector() {
591 scoped_ptr<policy::PolicyService> service; 554 scoped_ptr<policy::PolicyService> service;
(...skipping 24 matching lines...) Expand all
616 } 579 }
617 580
618 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { 581 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
619 return top_sites_.get(); 582 return top_sites_.get();
620 } 583 }
621 584
622 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { 585 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
623 return NULL; 586 return NULL;
624 } 587 }
625 588
589 void TestingProfile::OverrideCookieStoreConfigs(
590 const base::FilePath& partition_path,
591 bool in_memory_partition,
592 bool is_default_partition,
593 CookieSchemeMap* configs) {
594 // Force this to be in-memory.
595 chrome_browser_net::SetCookieStoreConfigs(
596 base::FilePath(), true, is_default_partition,
597 content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
598 GetSpecialStoragePolicy(), NULL, configs);
599 }
600
626 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { 601 net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
627 return GetDefaultStoragePartition(this)->GetURLRequestContext(); 602 return GetDefaultStoragePartition(this)->GetURLRequestContext();
628 } 603 }
629 604
630 net::URLRequestContextGetter* TestingProfile::CreateRequestContext( 605 net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
631 content::ProtocolHandlerMap* protocol_handlers) { 606 content::ProtocolHandlerMap* protocol_handlers) {
632 return new net::TestURLRequestContextGetter( 607 return new net::TestURLRequestContextGetter(
633 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 608 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
634 } 609 }
635 610
(...skipping 23 matching lines...) Expand all
659 634
660 void TestingProfile::RequestMIDISysExPermission( 635 void TestingProfile::RequestMIDISysExPermission(
661 int render_process_id, 636 int render_process_id,
662 int render_view_id, 637 int render_view_id,
663 const GURL& requesting_frame, 638 const GURL& requesting_frame,
664 const MIDISysExPermissionCallback& callback) { 639 const MIDISysExPermissionCallback& callback) {
665 // Always reject requests for testing. 640 // Always reject requests for testing.
666 callback.Run(false); 641 callback.Run(false);
667 } 642 }
668 643
669 net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
670 if (!extensions_request_context_.get())
671 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
672 return extensions_request_context_.get();
673 }
674
675 net::SSLConfigService* TestingProfile::GetSSLConfigService() { 644 net::SSLConfigService* TestingProfile::GetSSLConfigService() {
676 if (!GetRequestContext()) 645 if (!GetRequestContext())
677 return NULL; 646 return NULL;
678 return GetRequestContext()->GetURLRequestContext()->ssl_config_service(); 647 return GetRequestContext()->GetURLRequestContext()->ssl_config_service();
679 } 648 }
680 649
681 net::URLRequestContextGetter* 650 net::URLRequestContextGetter*
682 TestingProfile::CreateRequestContextForStoragePartition( 651 TestingProfile::CreateRequestContextForStoragePartition(
683 const base::FilePath& partition_path, 652 const base::FilePath& partition_path,
684 bool in_memory, 653 bool in_memory,
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 792
824 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { 793 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
825 DCHECK(!build_called_); 794 DCHECK(!build_called_);
826 build_called_ = true; 795 build_called_ = true;
827 return scoped_ptr<TestingProfile>(new TestingProfile( 796 return scoped_ptr<TestingProfile>(new TestingProfile(
828 path_, 797 path_,
829 delegate_, 798 delegate_,
830 extension_policy_, 799 extension_policy_,
831 pref_service_.Pass())); 800 pref_service_.Pass()));
832 } 801 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698