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 // weak |
| 121 content::MessageLoopRunner* runner_; |
| 122 }; |
| 123 |
108 // Task used to make sure history has finished processing a request. Intended | 124 // Task used to make sure history has finished processing a request. Intended |
109 // for use with BlockUntilHistoryProcessesPendingRequests. | 125 // for use with BlockUntilHistoryProcessesPendingRequests. |
110 | 126 |
111 class QuittingHistoryDBTask : public history::HistoryDBTask { | 127 class QuittingHistoryDBTask : public history::HistoryDBTask { |
112 public: | 128 public: |
113 QuittingHistoryDBTask() {} | 129 QuittingHistoryDBTask() {} |
114 | 130 |
115 virtual bool RunOnDBThread(history::HistoryBackend* backend, | 131 virtual bool RunOnDBThread(history::HistoryBackend* backend, |
116 history::HistoryDatabase* db) OVERRIDE { | 132 history::HistoryDatabase* db) OVERRIDE { |
117 return true; | 133 return true; |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 } | 545 } |
530 | 546 |
531 static KeyedService* BuildChromeBookmarkClient( | 547 static KeyedService* BuildChromeBookmarkClient( |
532 content::BrowserContext* context) { | 548 content::BrowserContext* context) { |
533 return new ChromeBookmarkClient(static_cast<Profile*>(context)); | 549 return new ChromeBookmarkClient(static_cast<Profile*>(context)); |
534 } | 550 } |
535 | 551 |
536 static KeyedService* BuildChromeHistoryClient( | 552 static KeyedService* BuildChromeHistoryClient( |
537 content::BrowserContext* context) { | 553 content::BrowserContext* context) { |
538 Profile* profile = static_cast<Profile*>(context); | 554 Profile* profile = static_cast<Profile*>(context); |
539 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile)); | 555 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile), |
| 556 profile, |
| 557 profile->GetTopSites()); |
540 } | 558 } |
541 | 559 |
542 void TestingProfile::CreateBookmarkModel(bool delete_file) { | 560 void TestingProfile::CreateBookmarkModel(bool delete_file) { |
543 if (delete_file) { | 561 if (delete_file) { |
544 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); | 562 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); |
545 base::DeleteFile(path, false); | 563 base::DeleteFile(path, false); |
546 } | 564 } |
547 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( | 565 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( |
548 this, BuildChromeHistoryClient); | 566 this, BuildChromeHistoryClient); |
549 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( | 567 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( |
(...skipping 25 matching lines...) Expand all Loading... |
575 HistoryIndexRestoreObserver observer( | 593 HistoryIndexRestoreObserver observer( |
576 content::GetQuitTaskForRunLoop(&run_loop)); | 594 content::GetQuitTaskForRunLoop(&run_loop)); |
577 index->set_restore_cache_observer(&observer); | 595 index->set_restore_cache_observer(&observer); |
578 run_loop.Run(); | 596 run_loop.Run(); |
579 index->set_restore_cache_observer(NULL); | 597 index->set_restore_cache_observer(NULL); |
580 DCHECK(index->restored()); | 598 DCHECK(index->restored()); |
581 } | 599 } |
582 | 600 |
583 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? | 601 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? |
584 void TestingProfile::BlockUntilTopSitesLoaded() { | 602 void TestingProfile::BlockUntilTopSitesLoaded() { |
585 content::WindowedNotificationObserver top_sites_loaded_observer( | 603 scoped_refptr<content::MessageLoopRunner> runner = |
586 chrome::NOTIFICATION_TOP_SITES_LOADED, | 604 new content::MessageLoopRunner; |
587 content::NotificationService::AllSources()); | 605 WaitTopSitesLoadedObserver observer(runner.get()); |
588 top_sites_loaded_observer.Wait(); | 606 top_sites_->AddObserver(&observer); |
| 607 runner->Run(); |
| 608 top_sites_->RemoveObserver(&observer); |
589 } | 609 } |
590 | 610 |
591 void TestingProfile::SetGuestSession(bool guest) { | 611 void TestingProfile::SetGuestSession(bool guest) { |
592 guest_session_ = guest; | 612 guest_session_ = guest; |
593 } | 613 } |
594 | 614 |
595 base::FilePath TestingProfile::GetPath() const { | 615 base::FilePath TestingProfile::GetPath() const { |
596 return profile_path_; | 616 return profile_path_; |
597 } | 617 } |
598 | 618 |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 #if defined(ENABLE_EXTENSIONS) | 1002 #if defined(ENABLE_EXTENSIONS) |
983 extension_policy_, | 1003 extension_policy_, |
984 #endif | 1004 #endif |
985 pref_service_.Pass(), | 1005 pref_service_.Pass(), |
986 incognito_, | 1006 incognito_, |
987 guest_session_, | 1007 guest_session_, |
988 supervised_user_id_, | 1008 supervised_user_id_, |
989 policy_service_.Pass(), | 1009 policy_service_.Pass(), |
990 testing_factories_)); | 1010 testing_factories_)); |
991 } | 1011 } |
OLD | NEW |