| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/testing_profile.h" | 5 #include "chrome/test/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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "chrome/browser/ui/find_bar/find_bar_state.h" | 44 #include "chrome/browser/ui/find_bar/find_bar_state.h" |
| 45 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 45 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 46 #include "chrome/common/chrome_constants.h" | 46 #include "chrome/common/chrome_constants.h" |
| 47 #include "chrome/common/chrome_notification_types.h" | 47 #include "chrome/common/chrome_notification_types.h" |
| 48 #include "chrome/common/url_constants.h" | 48 #include "chrome/common/url_constants.h" |
| 49 #include "chrome/test/bookmark_load_observer.h" | 49 #include "chrome/test/bookmark_load_observer.h" |
| 50 #include "chrome/test/test_url_request_context_getter.h" | 50 #include "chrome/test/test_url_request_context_getter.h" |
| 51 #include "chrome/test/testing_pref_service.h" | 51 #include "chrome/test/testing_pref_service.h" |
| 52 #include "chrome/test/ui_test_utils.h" | 52 #include "chrome/test/ui_test_utils.h" |
| 53 #include "content/browser/browser_thread.h" | 53 #include "content/browser/browser_thread.h" |
| 54 #include "content/browser/file_system/browser_file_system_helper.h" |
| 54 #include "content/browser/in_process_webkit/webkit_context.h" | 55 #include "content/browser/in_process_webkit/webkit_context.h" |
| 55 #include "content/browser/mock_resource_context.h" | 56 #include "content/browser/mock_resource_context.h" |
| 56 #include "content/common/notification_service.h" | 57 #include "content/common/notification_service.h" |
| 57 #include "net/base/cookie_monster.h" | 58 #include "net/base/cookie_monster.h" |
| 58 #include "net/url_request/url_request_context.h" | 59 #include "net/url_request/url_request_context.h" |
| 59 #include "net/url_request/url_request_context_getter.h" | 60 #include "net/url_request/url_request_context_getter.h" |
| 60 #include "net/url_request/url_request_test_util.h" | 61 #include "net/url_request/url_request_test_util.h" |
| 61 #include "testing/gmock/include/gmock/gmock.h" | 62 #include "testing/gmock/include/gmock/gmock.h" |
| 62 #include "webkit/database/database_tracker.h" | 63 #include "webkit/database/database_tracker.h" |
| 63 #include "webkit/fileapi/file_system_context.h" | 64 #include "webkit/fileapi/file_system_context.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 } | 386 } |
| 386 | 387 |
| 387 bool TestingProfile::HasOffTheRecordProfile() { | 388 bool TestingProfile::HasOffTheRecordProfile() { |
| 388 return incognito_profile_.get() != NULL; | 389 return incognito_profile_.get() != NULL; |
| 389 } | 390 } |
| 390 | 391 |
| 391 Profile* TestingProfile::GetOriginalProfile() { | 392 Profile* TestingProfile::GetOriginalProfile() { |
| 392 return this; | 393 return this; |
| 393 } | 394 } |
| 394 | 395 |
| 395 void TestingProfile::SetAppCacheService( | |
| 396 ChromeAppCacheService* appcache_service) { | |
| 397 appcache_service_ = appcache_service; | |
| 398 } | |
| 399 | |
| 400 ChromeAppCacheService* TestingProfile::GetAppCacheService() { | 396 ChromeAppCacheService* TestingProfile::GetAppCacheService() { |
| 397 CreateQuotaManagerAndClients(); |
| 401 return appcache_service_.get(); | 398 return appcache_service_.get(); |
| 402 } | 399 } |
| 403 | 400 |
| 404 webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() { | 401 webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() { |
| 405 if (!db_tracker_) { | 402 CreateQuotaManagerAndClients(); |
| 406 db_tracker_ = new webkit_database::DatabaseTracker( | |
| 407 GetPath(), false, false, GetExtensionSpecialStoragePolicy(), | |
| 408 NULL, NULL); | |
| 409 } | |
| 410 return db_tracker_; | 403 return db_tracker_; |
| 411 } | 404 } |
| 412 | 405 |
| 413 VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() { | 406 VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() { |
| 414 return NULL; | 407 return NULL; |
| 415 } | 408 } |
| 416 | 409 |
| 417 ExtensionService* TestingProfile::GetExtensionService() { | 410 ExtensionService* TestingProfile::GetExtensionService() { |
| 418 return extension_service_.get(); | 411 return extension_service_.get(); |
| 419 } | 412 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 | 520 |
| 528 DownloadManager* TestingProfile::GetDownloadManager() { | 521 DownloadManager* TestingProfile::GetDownloadManager() { |
| 529 return NULL; | 522 return NULL; |
| 530 } | 523 } |
| 531 | 524 |
| 532 PersonalDataManager* TestingProfile::GetPersonalDataManager() { | 525 PersonalDataManager* TestingProfile::GetPersonalDataManager() { |
| 533 return NULL; | 526 return NULL; |
| 534 } | 527 } |
| 535 | 528 |
| 536 fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() { | 529 fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() { |
| 537 if (!file_system_context_) { | 530 CreateQuotaManagerAndClients(); |
| 538 file_system_context_ = new fileapi::FileSystemContext( | |
| 539 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | |
| 540 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | |
| 541 GetExtensionSpecialStoragePolicy(), | |
| 542 NULL, | |
| 543 GetPath(), | |
| 544 IsOffTheRecord(), | |
| 545 true, // Allow file access from files. | |
| 546 true, // Unlimited quota. | |
| 547 NULL); | |
| 548 } | |
| 549 return file_system_context_.get(); | 531 return file_system_context_.get(); |
| 550 } | 532 } |
| 551 | 533 |
| 552 quota::QuotaManager* TestingProfile::GetQuotaManager() { | 534 quota::QuotaManager* TestingProfile::GetQuotaManager() { |
| 553 return NULL; | 535 CreateQuotaManagerAndClients(); |
| 536 return quota_manager_.get(); |
| 537 } |
| 538 |
| 539 void TestingProfile::CreateQuotaManagerAndClients() { |
| 540 if (quota_manager_.get()) { |
| 541 DCHECK(appcache_service_.get()); |
| 542 DCHECK(db_tracker_.get()); |
| 543 DCHECK(file_system_context_.get()); |
| 544 DCHECK(webkit_context_.get()); |
| 545 return; |
| 546 } |
| 547 |
| 548 // All the clients have to be created and registered with the |
| 549 // quota manager prior to the manager being used. So, we do them |
| 550 // all together here prior to handing our a reference to anything |
| 551 // that uses the quota manager. |
| 552 quota_manager_ = new quota::QuotaManager( |
| 553 IsOffTheRecord(), |
| 554 GetPath(), |
| 555 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 556 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
| 557 GetExtensionSpecialStoragePolicy()); |
| 558 |
| 559 // Each consumer is responsible for registering its QuotaClient during |
| 560 // its construction. |
| 561 file_system_context_ = CreateFileSystemContext( |
| 562 GetPath(), IsOffTheRecord(), |
| 563 GetExtensionSpecialStoragePolicy(), |
| 564 quota_manager_->proxy()); |
| 565 db_tracker_ = new webkit_database::DatabaseTracker( |
| 566 GetPath(), IsOffTheRecord(), false, |
| 567 GetExtensionSpecialStoragePolicy(), |
| 568 quota_manager_->proxy(), |
| 569 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
| 570 webkit_context_ = new WebKitContext( |
| 571 IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(), |
| 572 false, quota_manager_->proxy(), |
| 573 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT)); |
| 574 appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy()); |
| 575 BrowserThread::PostTask( |
| 576 BrowserThread::IO, FROM_HERE, |
| 577 NewRunnableMethod( |
| 578 appcache_service_.get(), |
| 579 &ChromeAppCacheService::InitializeOnIOThread, |
| 580 IsOffTheRecord() |
| 581 ? FilePath() : GetPath().Append(chrome::kAppCacheDirname), |
| 582 &GetResourceContext(), |
| 583 make_scoped_refptr(GetExtensionSpecialStoragePolicy()), |
| 584 false)); |
| 585 |
| 586 // Block until the posted task is finished, otherwise the appcache service |
| 587 // won't be properly initialized. |
| 588 MessageLoop::current()->RunAllPending(); |
| 554 } | 589 } |
| 555 | 590 |
| 556 BrowserSignin* TestingProfile::GetBrowserSignin() { | 591 BrowserSignin* TestingProfile::GetBrowserSignin() { |
| 557 return NULL; | 592 return NULL; |
| 558 } | 593 } |
| 559 | 594 |
| 560 bool TestingProfile::HasCreatedDownloadManager() const { | 595 bool TestingProfile::HasCreatedDownloadManager() const { |
| 561 return false; | 596 return false; |
| 562 } | 597 } |
| 563 | 598 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 | 720 |
| 686 ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() { | 721 ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() { |
| 687 return protocol_handler_registry_.get(); | 722 return protocol_handler_registry_.get(); |
| 688 } | 723 } |
| 689 | 724 |
| 690 SpellCheckHost* TestingProfile::GetSpellCheckHost() { | 725 SpellCheckHost* TestingProfile::GetSpellCheckHost() { |
| 691 return NULL; | 726 return NULL; |
| 692 } | 727 } |
| 693 | 728 |
| 694 WebKitContext* TestingProfile::GetWebKitContext() { | 729 WebKitContext* TestingProfile::GetWebKitContext() { |
| 695 if (webkit_context_ == NULL) { | 730 CreateQuotaManagerAndClients(); |
| 696 webkit_context_ = new WebKitContext( | |
| 697 IsOffTheRecord(), GetPath(), | |
| 698 GetExtensionSpecialStoragePolicy(), | |
| 699 false, NULL, NULL); | |
| 700 } | |
| 701 return webkit_context_; | 731 return webkit_context_; |
| 702 } | 732 } |
| 703 | 733 |
| 704 WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() { | 734 WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() { |
| 705 return NULL; | 735 return NULL; |
| 706 } | 736 } |
| 707 | 737 |
| 708 FilePath TestingProfile::last_selected_directory() { | 738 FilePath TestingProfile::last_selected_directory() { |
| 709 return last_selected_directory_; | 739 return last_selected_directory_; |
| 710 } | 740 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { | 823 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { |
| 794 return GetExtensionSpecialStoragePolicy(); | 824 return GetExtensionSpecialStoragePolicy(); |
| 795 } | 825 } |
| 796 | 826 |
| 797 void TestingProfile::DestroyWebDataService() { | 827 void TestingProfile::DestroyWebDataService() { |
| 798 if (!web_data_service_.get()) | 828 if (!web_data_service_.get()) |
| 799 return; | 829 return; |
| 800 | 830 |
| 801 web_data_service_->Shutdown(); | 831 web_data_service_->Shutdown(); |
| 802 } | 832 } |
| OLD | NEW |