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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 #include "chrome/browser/webdata/web_data_service_factory.h" | 46 #include "chrome/browser/webdata/web_data_service_factory.h" |
47 #include "chrome/common/chrome_constants.h" | 47 #include "chrome/common/chrome_constants.h" |
48 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
49 #include "chrome/common/pref_names.h" | 49 #include "chrome/common/pref_names.h" |
50 #include "chrome/common/url_constants.h" | 50 #include "chrome/common/url_constants.h" |
51 #include "chrome/test/base/history_index_restore_observer.h" | 51 #include "chrome/test/base/history_index_restore_observer.h" |
52 #include "chrome/test/base/testing_pref_service_syncable.h" | 52 #include "chrome/test/base/testing_pref_service_syncable.h" |
53 #include "chrome/test/base/ui_test_utils.h" | 53 #include "chrome/test/base/ui_test_utils.h" |
54 #include "components/bookmarks/browser/bookmark_model.h" | 54 #include "components/bookmarks/browser/bookmark_model.h" |
55 #include "components/bookmarks/common/bookmark_constants.h" | 55 #include "components/bookmarks/common/bookmark_constants.h" |
56 #include "components/history/core/browser/top_sites_observer.h" | |
56 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 57 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
57 #include "components/policy/core/common/policy_service.h" | 58 #include "components/policy/core/common/policy_service.h" |
58 #include "components/user_prefs/user_prefs.h" | 59 #include "components/user_prefs/user_prefs.h" |
59 #include "content/public/browser/browser_thread.h" | 60 #include "content/public/browser/browser_thread.h" |
60 #include "content/public/browser/cookie_store_factory.h" | 61 #include "content/public/browser/cookie_store_factory.h" |
61 #include "content/public/browser/notification_service.h" | 62 #include "content/public/browser/notification_service.h" |
62 #include "content/public/browser/render_process_host.h" | 63 #include "content/public/browser/render_process_host.h" |
63 #include "content/public/browser/storage_partition.h" | 64 #include "content/public/browser/storage_partition.h" |
64 #include "content/public/test/mock_resource_context.h" | 65 #include "content/public/test/mock_resource_context.h" |
65 #include "content/public/test/test_utils.h" | 66 #include "content/public/test/test_utils.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 #endif | 99 #endif |
99 | 100 |
100 using base::Time; | 101 using base::Time; |
101 using content::BrowserThread; | 102 using content::BrowserThread; |
102 using content::DownloadManagerDelegate; | 103 using content::DownloadManagerDelegate; |
103 using testing::NiceMock; | 104 using testing::NiceMock; |
104 using testing::Return; | 105 using testing::Return; |
105 | 106 |
106 namespace { | 107 namespace { |
107 | 108 |
109 // Used to make sure TopSites has finished loading | |
110 class WaitTopSitesLoadedObserver : public history::TopSitesObserver { | |
111 public: | |
112 explicit WaitTopSitesLoadedObserver(content::MessageLoopRunner* runner) | |
113 : runner_(runner) {} | |
114 virtual void TopSitesLoaded(history::TopSites* top_sites) OVERRIDE { | |
115 runner_->Quit(); | |
116 } | |
117 virtual void TopSitesChanged(history::TopSites* top_sites) OVERRIDE {} | |
118 | |
119 private: | |
120 content::MessageLoopRunner* runner_; | |
sdefresne
2014/09/05 17:57:53
nit: add // weak
| |
121 }; | |
122 | |
108 // Task used to make sure history has finished processing a request. Intended | 123 // Task used to make sure history has finished processing a request. Intended |
109 // for use with BlockUntilHistoryProcessesPendingRequests. | 124 // for use with BlockUntilHistoryProcessesPendingRequests. |
110 | 125 |
111 class QuittingHistoryDBTask : public history::HistoryDBTask { | 126 class QuittingHistoryDBTask : public history::HistoryDBTask { |
112 public: | 127 public: |
113 QuittingHistoryDBTask() {} | 128 QuittingHistoryDBTask() {} |
114 | 129 |
115 virtual bool RunOnDBThread(history::HistoryBackend* backend, | 130 virtual bool RunOnDBThread(history::HistoryBackend* backend, |
116 history::HistoryDatabase* db) OVERRIDE { | 131 history::HistoryDatabase* db) OVERRIDE { |
117 return true; | 132 return true; |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 } | 544 } |
530 | 545 |
531 static KeyedService* BuildChromeBookmarkClient( | 546 static KeyedService* BuildChromeBookmarkClient( |
532 content::BrowserContext* context) { | 547 content::BrowserContext* context) { |
533 return new ChromeBookmarkClient(static_cast<Profile*>(context)); | 548 return new ChromeBookmarkClient(static_cast<Profile*>(context)); |
534 } | 549 } |
535 | 550 |
536 static KeyedService* BuildChromeHistoryClient( | 551 static KeyedService* BuildChromeHistoryClient( |
537 content::BrowserContext* context) { | 552 content::BrowserContext* context) { |
538 Profile* profile = static_cast<Profile*>(context); | 553 Profile* profile = static_cast<Profile*>(context); |
539 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile)); | 554 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile), |
555 profile, | |
556 profile->GetTopSites()); | |
540 } | 557 } |
541 | 558 |
542 void TestingProfile::CreateBookmarkModel(bool delete_file) { | 559 void TestingProfile::CreateBookmarkModel(bool delete_file) { |
543 if (delete_file) { | 560 if (delete_file) { |
544 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); | 561 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); |
545 base::DeleteFile(path, false); | 562 base::DeleteFile(path, false); |
546 } | 563 } |
547 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( | 564 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( |
548 this, BuildChromeHistoryClient); | 565 this, BuildChromeHistoryClient); |
549 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( | 566 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( |
(...skipping 25 matching lines...) Expand all Loading... | |
575 HistoryIndexRestoreObserver observer( | 592 HistoryIndexRestoreObserver observer( |
576 content::GetQuitTaskForRunLoop(&run_loop)); | 593 content::GetQuitTaskForRunLoop(&run_loop)); |
577 index->set_restore_cache_observer(&observer); | 594 index->set_restore_cache_observer(&observer); |
578 run_loop.Run(); | 595 run_loop.Run(); |
579 index->set_restore_cache_observer(NULL); | 596 index->set_restore_cache_observer(NULL); |
580 DCHECK(index->restored()); | 597 DCHECK(index->restored()); |
581 } | 598 } |
582 | 599 |
583 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? | 600 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? |
584 void TestingProfile::BlockUntilTopSitesLoaded() { | 601 void TestingProfile::BlockUntilTopSitesLoaded() { |
585 content::WindowedNotificationObserver top_sites_loaded_observer( | 602 scoped_refptr<content::MessageLoopRunner> runner = |
586 chrome::NOTIFICATION_TOP_SITES_LOADED, | 603 new content::MessageLoopRunner; |
587 content::NotificationService::AllSources()); | 604 WaitTopSitesLoadedObserver observer(runner); |
588 top_sites_loaded_observer.Wait(); | 605 top_sites_->AddObserver(&observer); |
606 runner->Run(); | |
607 top_sites_->RemoveObserver(&observer); | |
589 } | 608 } |
590 | 609 |
591 void TestingProfile::SetGuestSession(bool guest) { | 610 void TestingProfile::SetGuestSession(bool guest) { |
592 guest_session_ = guest; | 611 guest_session_ = guest; |
593 } | 612 } |
594 | 613 |
595 base::FilePath TestingProfile::GetPath() const { | 614 base::FilePath TestingProfile::GetPath() const { |
596 return profile_path_; | 615 return profile_path_; |
597 } | 616 } |
598 | 617 |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
982 #if defined(ENABLE_EXTENSIONS) | 1001 #if defined(ENABLE_EXTENSIONS) |
983 extension_policy_, | 1002 extension_policy_, |
984 #endif | 1003 #endif |
985 pref_service_.Pass(), | 1004 pref_service_.Pass(), |
986 incognito_, | 1005 incognito_, |
987 guest_session_, | 1006 guest_session_, |
988 supervised_user_id_, | 1007 supervised_user_id_, |
989 policy_service_.Pass(), | 1008 policy_service_.Pass(), |
990 testing_factories_)); | 1009 testing_factories_)); |
991 } | 1010 } |
OLD | NEW |