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" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/content_settings/host_content_settings_map.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map.h" |
19 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 19 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
20 #include "chrome/browser/extensions/extension_pref_value_map.h" | 20 #include "chrome/browser/extensions/extension_pref_value_map.h" |
21 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
22 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 22 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
23 #include "chrome/browser/extensions/extension_system.h" | |
24 #include "chrome/browser/extensions/extension_system_factory.h" | |
25 #include "chrome/browser/extensions/test_extension_system.h" | |
26 #include "chrome/browser/favicon/favicon_service.h" | 23 #include "chrome/browser/favicon/favicon_service.h" |
27 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 24 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
28 #include "chrome/browser/history/history.h" | 25 #include "chrome/browser/history/history.h" |
29 #include "chrome/browser/history/history_backend.h" | 26 #include "chrome/browser/history/history_backend.h" |
30 #include "chrome/browser/history/top_sites.h" | 27 #include "chrome/browser/history/top_sites.h" |
31 #include "chrome/browser/net/proxy_service_factory.h" | 28 #include "chrome/browser/net/proxy_service_factory.h" |
32 #include "chrome/browser/notifications/desktop_notification_service.h" | 29 #include "chrome/browser/notifications/desktop_notification_service.h" |
33 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 30 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
34 #include "chrome/browser/prefs/browser_prefs.h" | 31 #include "chrome/browser/prefs/browser_prefs.h" |
35 #include "chrome/browser/prefs/testing_pref_store.h" | 32 #include "chrome/browser/prefs/testing_pref_store.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 if (delegate_) { | 188 if (delegate_) { |
192 MessageLoop::current()->PostTask(FROM_HERE, | 189 MessageLoop::current()->PostTask(FROM_HERE, |
193 base::Bind(&TestingProfile::FinishInit, | 190 base::Bind(&TestingProfile::FinishInit, |
194 base::Unretained(this))); | 191 base::Unretained(this))); |
195 } else { | 192 } else { |
196 FinishInit(); | 193 FinishInit(); |
197 } | 194 } |
198 } | 195 } |
199 | 196 |
200 void TestingProfile::Init() { | 197 void TestingProfile::Init() { |
201 ExtensionSystemFactory::GetInstance()->SetTestingFactory( | |
202 this, TestExtensionSystem::Build); | |
203 | |
204 profile_dependency_manager_->CreateProfileServices(this, true); | 198 profile_dependency_manager_->CreateProfileServices(this, true); |
205 | 199 |
206 #if defined(ENABLE_NOTIFICATIONS) | 200 #if defined(ENABLE_NOTIFICATIONS) |
207 // Install profile keyed service factory hooks for dummy/test services | 201 // Install profile keyed service factory hooks for dummy/test services |
208 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( | 202 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( |
209 this, CreateTestDesktopNotificationService); | 203 this, CreateTestDesktopNotificationService); |
210 #endif | 204 #endif |
211 } | 205 } |
212 | 206 |
213 void TestingProfile::FinishInit() { | 207 void TestingProfile::FinishInit() { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 if (turl_model->loaded()) | 379 if (turl_model->loaded()) |
386 return; | 380 return; |
387 | 381 |
388 ui_test_utils::WindowedNotificationObserver turl_service_load_observer( | 382 ui_test_utils::WindowedNotificationObserver turl_service_load_observer( |
389 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 383 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
390 content::NotificationService::AllSources()); | 384 content::NotificationService::AllSources()); |
391 turl_model->Load(); | 385 turl_model->Load(); |
392 turl_service_load_observer.Wait(); | 386 turl_service_load_observer.Wait(); |
393 } | 387 } |
394 | 388 |
| 389 void TestingProfile::CreateExtensionProcessManager() { |
| 390 extension_process_manager_.reset(ExtensionProcessManager::Create(this)); |
| 391 } |
| 392 |
| 393 ExtensionService* TestingProfile::CreateExtensionService( |
| 394 const CommandLine* command_line, |
| 395 const FilePath& install_directory, |
| 396 bool autoupdate_enabled) { |
| 397 // Extension pref store, created for use by |extension_prefs_|. |
| 398 |
| 399 extension_pref_value_map_.reset(new ExtensionPrefValueMap); |
| 400 |
| 401 bool extensions_disabled = |
| 402 command_line && command_line->HasSwitch(switches::kDisableExtensions); |
| 403 |
| 404 // Note that the GetPrefs() creates a TestingPrefService, therefore |
| 405 // the extension controlled pref values set in extension_prefs_ |
| 406 // are not reflected in the pref service. One would need to |
| 407 // inject a new ExtensionPrefStore(extension_pref_value_map_.get(), false). |
| 408 extension_prefs_.reset( |
| 409 new ExtensionPrefs(GetPrefs(), |
| 410 install_directory, |
| 411 extension_pref_value_map_.get())); |
| 412 extension_prefs_->Init(extensions_disabled); |
| 413 extension_service_.reset(new ExtensionService(this, |
| 414 command_line, |
| 415 install_directory, |
| 416 extension_prefs_.get(), |
| 417 autoupdate_enabled, |
| 418 true)); |
| 419 return extension_service_.get(); |
| 420 } |
| 421 |
395 FilePath TestingProfile::GetPath() { | 422 FilePath TestingProfile::GetPath() { |
396 return profile_path_; | 423 return profile_path_; |
397 } | 424 } |
398 | 425 |
399 TestingPrefService* TestingProfile::GetTestingPrefService() { | 426 TestingPrefService* TestingProfile::GetTestingPrefService() { |
400 if (!prefs_.get()) | 427 if (!prefs_.get()) |
401 CreateTestingPrefService(); | 428 CreateTestingPrefService(); |
402 DCHECK(testing_prefs_); | 429 DCHECK(testing_prefs_); |
403 return testing_prefs_; | 430 return testing_prefs_; |
404 } | 431 } |
(...skipping 27 matching lines...) Expand all Loading... |
432 } | 459 } |
433 | 460 |
434 Profile* TestingProfile::GetOriginalProfile() { | 461 Profile* TestingProfile::GetOriginalProfile() { |
435 return this; | 462 return this; |
436 } | 463 } |
437 | 464 |
438 VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() { | 465 VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() { |
439 return NULL; | 466 return NULL; |
440 } | 467 } |
441 | 468 |
442 ExtensionPrefValueMap* TestingProfile::GetExtensionPrefValueMap() { | |
443 return NULL; | |
444 } | |
445 | |
446 ExtensionService* TestingProfile::GetExtensionService() { | 469 ExtensionService* TestingProfile::GetExtensionService() { |
447 return ExtensionSystemFactory::GetForProfile(this)->extension_service(); | 470 return extension_service_.get(); |
448 } | 471 } |
449 | 472 |
450 UserScriptMaster* TestingProfile::GetUserScriptMaster() { | 473 UserScriptMaster* TestingProfile::GetUserScriptMaster() { |
451 return ExtensionSystemFactory::GetForProfile(this)->user_script_master(); | 474 return NULL; |
| 475 } |
| 476 |
| 477 ExtensionDevToolsManager* TestingProfile::GetExtensionDevToolsManager() { |
| 478 return NULL; |
452 } | 479 } |
453 | 480 |
454 ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() { | 481 ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() { |
455 return ExtensionSystemFactory::GetForProfile(this)->process_manager(); | 482 return extension_process_manager_.get(); |
| 483 } |
| 484 |
| 485 ExtensionMessageService* TestingProfile::GetExtensionMessageService() { |
| 486 return NULL; |
456 } | 487 } |
457 | 488 |
458 ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() { | 489 ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() { |
459 return ExtensionSystemFactory::GetForProfile(this)->event_router(); | 490 return NULL; |
460 } | 491 } |
461 | 492 |
462 void TestingProfile::SetExtensionSpecialStoragePolicy( | 493 void TestingProfile::SetExtensionSpecialStoragePolicy( |
463 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { | 494 ExtensionSpecialStoragePolicy* extension_special_storage_policy) { |
464 extension_special_storage_policy_ = extension_special_storage_policy; | 495 extension_special_storage_policy_ = extension_special_storage_policy; |
465 } | 496 } |
466 | 497 |
467 ExtensionSpecialStoragePolicy* | 498 ExtensionSpecialStoragePolicy* |
468 TestingProfile::GetExtensionSpecialStoragePolicy() { | 499 TestingProfile::GetExtensionSpecialStoragePolicy() { |
469 if (!extension_special_storage_policy_.get()) | 500 if (!extension_special_storage_policy_.get()) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 DownloadManager* TestingProfile::GetDownloadManager() { | 575 DownloadManager* TestingProfile::GetDownloadManager() { |
545 return NULL; | 576 return NULL; |
546 } | 577 } |
547 | 578 |
548 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { | 579 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { |
549 return request_context_.get(); | 580 return request_context_.get(); |
550 } | 581 } |
551 | 582 |
552 net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess( | 583 net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess( |
553 int renderer_child_id) { | 584 int renderer_child_id) { |
554 ExtensionService* extension_service = | 585 if (extension_service_.get()) { |
555 ExtensionSystemFactory::GetForProfile(this)->extension_service(); | 586 const Extension* installed_app = extension_service_-> |
556 if (extension_service) { | |
557 const Extension* installed_app = extension_service-> | |
558 GetInstalledAppForRenderer(renderer_child_id); | 587 GetInstalledAppForRenderer(renderer_child_id); |
559 if (installed_app != NULL && installed_app->is_storage_isolated()) | 588 if (installed_app != NULL && installed_app->is_storage_isolated()) |
560 return GetRequestContextForIsolatedApp(installed_app->id()); | 589 return GetRequestContextForIsolatedApp(installed_app->id()); |
561 } | 590 } |
562 | 591 |
563 return GetRequestContext(); | 592 return GetRequestContext(); |
564 } | 593 } |
565 | 594 |
566 void TestingProfile::CreateRequestContext() { | 595 void TestingProfile::CreateRequestContext() { |
567 if (!request_context_) | 596 if (!request_context_) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 MessageLoop::current()->Run(); | 718 MessageLoop::current()->Run(); |
690 } | 719 } |
691 | 720 |
692 TokenService* TestingProfile::GetTokenService() { | 721 TokenService* TestingProfile::GetTokenService() { |
693 if (!token_service_.get()) { | 722 if (!token_service_.get()) { |
694 token_service_.reset(new TokenService()); | 723 token_service_.reset(new TokenService()); |
695 } | 724 } |
696 return token_service_.get(); | 725 return token_service_.get(); |
697 } | 726 } |
698 | 727 |
| 728 ExtensionInfoMap* TestingProfile::GetExtensionInfoMap() { |
| 729 return NULL; |
| 730 } |
| 731 |
699 PromoCounter* TestingProfile::GetInstantPromoCounter() { | 732 PromoCounter* TestingProfile::GetInstantPromoCounter() { |
700 return NULL; | 733 return NULL; |
701 } | 734 } |
702 | 735 |
703 ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() { | 736 ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() { |
704 if (!chrome_url_data_manager_.get()) | 737 if (!chrome_url_data_manager_.get()) |
705 chrome_url_data_manager_.reset( | 738 chrome_url_data_manager_.reset( |
706 new ChromeURLDataManager( | 739 new ChromeURLDataManager( |
707 base::Callback<ChromeURLDataManagerBackend*(void)>())); | 740 base::Callback<ChromeURLDataManagerBackend*(void)>())); |
708 return chrome_url_data_manager_.get(); | 741 return chrome_url_data_manager_.get(); |
(...skipping 18 matching lines...) Expand all Loading... |
727 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { | 760 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { |
728 return GetExtensionSpecialStoragePolicy(); | 761 return GetExtensionSpecialStoragePolicy(); |
729 } | 762 } |
730 | 763 |
731 void TestingProfile::DestroyWebDataService() { | 764 void TestingProfile::DestroyWebDataService() { |
732 if (!web_data_service_.get()) | 765 if (!web_data_service_.get()) |
733 return; | 766 return; |
734 | 767 |
735 web_data_service_->Shutdown(); | 768 web_data_service_->Shutdown(); |
736 } | 769 } |
OLD | NEW |