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