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/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 Loading... |
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" | |
41 #include "chrome/browser/net/pref_proxy_config_tracker.h" | 40 #include "chrome/browser/net/pref_proxy_config_tracker.h" |
42 #include "chrome/browser/net/proxy_service_factory.h" | 41 #include "chrome/browser/net/proxy_service_factory.h" |
43 #include "chrome/browser/notifications/desktop_notification_service.h" | 42 #include "chrome/browser/notifications/desktop_notification_service.h" |
44 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 43 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
45 #include "chrome/browser/policy/profile_policy_connector.h" | 44 #include "chrome/browser/policy/profile_policy_connector.h" |
46 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 45 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
47 #include "chrome/browser/prefs/browser_prefs.h" | 46 #include "chrome/browser/prefs/browser_prefs.h" |
48 #include "chrome/browser/prefs/pref_service_syncable.h" | 47 #include "chrome/browser/prefs/pref_service_syncable.h" |
49 #include "chrome/browser/prerender/prerender_manager.h" | 48 #include "chrome/browser/prerender/prerender_manager.h" |
50 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" | 49 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" |
51 #include "chrome/browser/profiles/storage_partition_descriptor.h" | 50 #include "chrome/browser/profiles/storage_partition_descriptor.h" |
52 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" | 51 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" |
53 #include "chrome/browser/webdata/web_data_service.h" | 52 #include "chrome/browser/webdata/web_data_service.h" |
54 #include "chrome/browser/webdata/web_data_service_factory.h" | 53 #include "chrome/browser/webdata/web_data_service_factory.h" |
55 #include "chrome/common/chrome_constants.h" | 54 #include "chrome/common/chrome_constants.h" |
56 #include "chrome/common/chrome_switches.h" | 55 #include "chrome/common/chrome_switches.h" |
57 #include "chrome/common/pref_names.h" | 56 #include "chrome/common/pref_names.h" |
58 #include "chrome/common/url_constants.h" | 57 #include "chrome/common/url_constants.h" |
59 #include "chrome/test/base/bookmark_load_observer.h" | 58 #include "chrome/test/base/bookmark_load_observer.h" |
60 #include "chrome/test/base/history_index_restore_observer.h" | 59 #include "chrome/test/base/history_index_restore_observer.h" |
61 #include "chrome/test/base/testing_pref_service_syncable.h" | 60 #include "chrome/test/base/testing_pref_service_syncable.h" |
62 #include "chrome/test/base/ui_test_utils.h" | 61 #include "chrome/test/base/ui_test_utils.h" |
63 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 62 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
64 #include "components/user_prefs/user_prefs.h" | 63 #include "components/user_prefs/user_prefs.h" |
65 #include "content/public/browser/browser_thread.h" | 64 #include "content/public/browser/browser_thread.h" |
66 #include "content/public/browser/cookie_store_factory.h" | |
67 #include "content/public/browser/notification_service.h" | 65 #include "content/public/browser/notification_service.h" |
68 #include "content/public/browser/render_process_host.h" | 66 #include "content/public/browser/render_process_host.h" |
69 #include "content/public/browser/storage_partition.h" | 67 #include "content/public/browser/storage_partition.h" |
70 #include "content/public/test/mock_resource_context.h" | 68 #include "content/public/test/mock_resource_context.h" |
71 #include "content/public/test/test_utils.h" | 69 #include "content/public/test/test_utils.h" |
72 #include "extensions/common/constants.h" | 70 #include "extensions/common/constants.h" |
73 #include "net/cookies/cookie_monster.h" | 71 #include "net/cookies/cookie_monster.h" |
74 #include "net/url_request/url_request_context.h" | 72 #include "net/url_request/url_request_context.h" |
75 #include "net/url_request/url_request_context_getter.h" | 73 #include "net/url_request/url_request_context_getter.h" |
76 #include "net/url_request/url_request_test_util.h" | 74 #include "net/url_request/url_request_test_util.h" |
(...skipping 29 matching lines...) Expand all Loading... |
106 virtual void DoneRunOnMainThread() OVERRIDE { | 104 virtual void DoneRunOnMainThread() OVERRIDE { |
107 base::MessageLoop::current()->Quit(); | 105 base::MessageLoop::current()->Quit(); |
108 } | 106 } |
109 | 107 |
110 private: | 108 private: |
111 virtual ~QuittingHistoryDBTask() {} | 109 virtual ~QuittingHistoryDBTask() {} |
112 | 110 |
113 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask); | 111 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask); |
114 }; | 112 }; |
115 | 113 |
| 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 |
116 BrowserContextKeyedService* CreateTestDesktopNotificationService( | 146 BrowserContextKeyedService* CreateTestDesktopNotificationService( |
117 content::BrowserContext* profile) { | 147 content::BrowserContext* profile) { |
118 #if defined(ENABLE_NOTIFICATIONS) | 148 #if defined(ENABLE_NOTIFICATIONS) |
119 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL); | 149 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL); |
120 #else | 150 #else |
121 return NULL; | 151 return NULL; |
122 #endif | 152 #endif |
123 } | 153 } |
124 | 154 |
125 } // namespace | 155 } // namespace |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 extension_special_storage_policy_ = extension_special_storage_policy; | 585 extension_special_storage_policy_ = extension_special_storage_policy; |
556 } | 586 } |
557 | 587 |
558 ExtensionSpecialStoragePolicy* | 588 ExtensionSpecialStoragePolicy* |
559 TestingProfile::GetExtensionSpecialStoragePolicy() { | 589 TestingProfile::GetExtensionSpecialStoragePolicy() { |
560 if (!extension_special_storage_policy_.get()) | 590 if (!extension_special_storage_policy_.get()) |
561 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); | 591 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); |
562 return extension_special_storage_policy_.get(); | 592 return extension_special_storage_policy_.get(); |
563 } | 593 } |
564 | 594 |
| 595 net::CookieMonster* TestingProfile::GetCookieMonster() { |
| 596 if (!GetRequestContext()) |
| 597 return NULL; |
| 598 return GetRequestContext()->GetURLRequestContext()->cookie_store()-> |
| 599 GetCookieMonster(); |
| 600 } |
| 601 |
565 void TestingProfile::CreateTestingPrefService() { | 602 void TestingProfile::CreateTestingPrefService() { |
566 DCHECK(!prefs_.get()); | 603 DCHECK(!prefs_.get()); |
567 testing_prefs_ = new TestingPrefServiceSyncable(); | 604 testing_prefs_ = new TestingPrefServiceSyncable(); |
568 prefs_.reset(testing_prefs_); | 605 prefs_.reset(testing_prefs_); |
569 user_prefs::UserPrefs::Set(this, prefs_.get()); | 606 user_prefs::UserPrefs::Set(this, prefs_.get()); |
570 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); | 607 chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); |
571 } | 608 } |
572 | 609 |
573 void TestingProfile::CreateProfilePolicyConnector() { | 610 void TestingProfile::CreateProfilePolicyConnector() { |
574 scoped_ptr<policy::PolicyService> service; | 611 scoped_ptr<policy::PolicyService> service; |
(...skipping 24 matching lines...) Expand all Loading... |
599 } | 636 } |
600 | 637 |
601 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { | 638 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { |
602 return top_sites_.get(); | 639 return top_sites_.get(); |
603 } | 640 } |
604 | 641 |
605 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { | 642 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { |
606 return NULL; | 643 return NULL; |
607 } | 644 } |
608 | 645 |
609 void TestingProfile::OverrideCookieStoreConfigs( | |
610 const base::FilePath& partition_path, | |
611 bool in_memory_partition, | |
612 bool is_default_partition, | |
613 CookieSchemeMap* configs) { | |
614 // Force this to be in-memory. | |
615 chrome_browser_net::SetCookieStoreConfigs( | |
616 base::FilePath(), true, is_default_partition, | |
617 content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, | |
618 GetSpecialStoragePolicy(), NULL, configs); | |
619 } | |
620 | |
621 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { | 646 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { |
622 return GetDefaultStoragePartition(this)->GetURLRequestContext(); | 647 return GetDefaultStoragePartition(this)->GetURLRequestContext(); |
623 } | 648 } |
624 | 649 |
625 net::URLRequestContextGetter* TestingProfile::CreateRequestContext( | 650 net::URLRequestContextGetter* TestingProfile::CreateRequestContext( |
626 content::ProtocolHandlerMap* protocol_handlers) { | 651 content::ProtocolHandlerMap* protocol_handlers) { |
627 return new net::TestURLRequestContextGetter( | 652 return new net::TestURLRequestContextGetter( |
628 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 653 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
629 } | 654 } |
630 | 655 |
(...skipping 23 matching lines...) Expand all Loading... |
654 | 679 |
655 void TestingProfile::RequestMIDISysExPermission( | 680 void TestingProfile::RequestMIDISysExPermission( |
656 int render_process_id, | 681 int render_process_id, |
657 int render_view_id, | 682 int render_view_id, |
658 const GURL& requesting_frame, | 683 const GURL& requesting_frame, |
659 const MIDISysExPermissionCallback& callback) { | 684 const MIDISysExPermissionCallback& callback) { |
660 // Always reject requests for testing. | 685 // Always reject requests for testing. |
661 callback.Run(false); | 686 callback.Run(false); |
662 } | 687 } |
663 | 688 |
| 689 net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() { |
| 690 if (!extensions_request_context_.get()) |
| 691 extensions_request_context_ = new TestExtensionURLRequestContextGetter(); |
| 692 return extensions_request_context_.get(); |
| 693 } |
| 694 |
664 net::SSLConfigService* TestingProfile::GetSSLConfigService() { | 695 net::SSLConfigService* TestingProfile::GetSSLConfigService() { |
665 if (!GetRequestContext()) | 696 if (!GetRequestContext()) |
666 return NULL; | 697 return NULL; |
667 return GetRequestContext()->GetURLRequestContext()->ssl_config_service(); | 698 return GetRequestContext()->GetURLRequestContext()->ssl_config_service(); |
668 } | 699 } |
669 | 700 |
670 net::URLRequestContextGetter* | 701 net::URLRequestContextGetter* |
671 TestingProfile::CreateRequestContextForStoragePartition( | 702 TestingProfile::CreateRequestContextForStoragePartition( |
672 const base::FilePath& partition_path, | 703 const base::FilePath& partition_path, |
673 bool in_memory, | 704 bool in_memory, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 DCHECK(!build_called_); | 856 DCHECK(!build_called_); |
826 build_called_ = true; | 857 build_called_ = true; |
827 return scoped_ptr<TestingProfile>(new TestingProfile( | 858 return scoped_ptr<TestingProfile>(new TestingProfile( |
828 path_, | 859 path_, |
829 delegate_, | 860 delegate_, |
830 extension_policy_, | 861 extension_policy_, |
831 pref_service_.Pass(), | 862 pref_service_.Pass(), |
832 incognito_, | 863 incognito_, |
833 testing_factories_)); | 864 testing_factories_)); |
834 } | 865 } |
OLD | NEW |