Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: chrome/test/base/ui_test_utils.cc

Issue 573553004: Eliminate NOTIFICATION_HISTORY_LOADED notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ScopedObserver to InMemoryHistoryBackend,PrerenderLocalPredictor,ChromeTemplateURLServiceClient Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ui_test_utils.h" 5 #include "chrome/test/base/ui_test_utils.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "chrome/browser/ui/host_desktop.h" 42 #include "chrome/browser/ui/host_desktop.h"
43 #include "chrome/browser/ui/location_bar/location_bar.h" 43 #include "chrome/browser/ui/location_bar/location_bar.h"
44 #include "chrome/browser/ui/omnibox/omnibox_view.h" 44 #include "chrome/browser/ui/omnibox/omnibox_view.h"
45 #include "chrome/browser/ui/tabs/tab_strip_model.h" 45 #include "chrome/browser/ui/tabs/tab_strip_model.h"
46 #include "chrome/common/chrome_paths.h" 46 #include "chrome/common/chrome_paths.h"
47 #include "chrome/common/pref_names.h" 47 #include "chrome/common/pref_names.h"
48 #include "chrome/test/base/find_in_page_observer.h" 48 #include "chrome/test/base/find_in_page_observer.h"
49 #include "components/app_modal/app_modal_dialog.h" 49 #include "components/app_modal/app_modal_dialog.h"
50 #include "components/app_modal/app_modal_dialog_queue.h" 50 #include "components/app_modal/app_modal_dialog_queue.h"
51 #include "components/bookmarks/browser/bookmark_model.h" 51 #include "components/bookmarks/browser/bookmark_model.h"
52 #include "components/history/core/browser/history_service_observer.h"
52 #include "components/search_engines/template_url_service.h" 53 #include "components/search_engines/template_url_service.h"
53 #include "content/public/browser/dom_operation_notification_details.h" 54 #include "content/public/browser/dom_operation_notification_details.h"
54 #include "content/public/browser/download_item.h" 55 #include "content/public/browser/download_item.h"
55 #include "content/public/browser/download_manager.h" 56 #include "content/public/browser/download_manager.h"
56 #include "content/public/browser/geolocation_provider.h" 57 #include "content/public/browser/geolocation_provider.h"
57 #include "content/public/browser/navigation_controller.h" 58 #include "content/public/browser/navigation_controller.h"
58 #include "content/public/browser/navigation_entry.h" 59 #include "content/public/browser/navigation_entry.h"
59 #include "content/public/browser/notification_service.h" 60 #include "content/public/browser/notification_service.h"
60 #include "content/public/browser/render_process_host.h" 61 #include "content/public/browser/render_process_host.h"
61 #include "content/public/browser/render_view_host.h" 62 #include "content/public/browser/render_view_host.h"
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 new content::MessageLoopRunner; 358 new content::MessageLoopRunner;
358 scoped_ptr<TemplateURLService::Subscription> subscription = 359 scoped_ptr<TemplateURLService::Subscription> subscription =
359 service->RegisterOnLoadedCallback( 360 service->RegisterOnLoadedCallback(
360 message_loop_runner->QuitClosure()); 361 message_loop_runner->QuitClosure());
361 service->Load(); 362 service->Load();
362 message_loop_runner->Run(); 363 message_loop_runner->Run();
363 364
364 ASSERT_TRUE(service->loaded()); 365 ASSERT_TRUE(service->loaded());
365 } 366 }
366 367
367 void WaitForHistoryToLoad(HistoryService* history_service) {
368 content::WindowedNotificationObserver history_loaded_observer(
369 chrome::NOTIFICATION_HISTORY_LOADED,
370 content::NotificationService::AllSources());
371 if (!history_service->BackendLoaded())
372 history_loaded_observer.Wait();
373 }
374
375 void DownloadURL(Browser* browser, const GURL& download_url) { 368 void DownloadURL(Browser* browser, const GURL& download_url) {
376 base::ScopedTempDir downloads_directory; 369 base::ScopedTempDir downloads_directory;
377 ASSERT_TRUE(downloads_directory.CreateUniqueTempDir()); 370 ASSERT_TRUE(downloads_directory.CreateUniqueTempDir());
378 browser->profile()->GetPrefs()->SetFilePath( 371 browser->profile()->GetPrefs()->SetFilePath(
379 prefs::kDownloadDefaultDirectory, downloads_directory.path()); 372 prefs::kDownloadDefaultDirectory, downloads_directory.path());
380 373
381 content::DownloadManager* download_manager = 374 content::DownloadManager* download_manager =
382 content::BrowserContext::GetDownloadManager(browser->profile()); 375 content::BrowserContext::GetDownloadManager(browser->profile());
383 scoped_ptr<content::DownloadTestObserver> observer( 376 scoped_ptr<content::DownloadTestObserver> observer(
384 new content::DownloadTestObserverTerminal( 377 new content::DownloadTestObserverTerminal(
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 HistoryEnumerator::~HistoryEnumerator() {} 527 HistoryEnumerator::~HistoryEnumerator() {}
535 528
536 void HistoryEnumerator::HistoryQueryComplete( 529 void HistoryEnumerator::HistoryQueryComplete(
537 const base::Closure& quit_task, 530 const base::Closure& quit_task,
538 history::QueryResults* results) { 531 history::QueryResults* results) {
539 for (size_t i = 0; i < results->size(); ++i) 532 for (size_t i = 0; i < results->size(); ++i)
540 urls_.push_back((*results)[i].url()); 533 urls_.push_back((*results)[i].url());
541 quit_task.Run(); 534 quit_task.Run();
542 } 535 }
543 536
537 // Wait for HistoryService to load.
538 class WaitHistoryLoadedObserver : public history::HistoryServiceObserver {
539 public:
540 explicit WaitHistoryLoadedObserver(content::MessageLoopRunner* runner);
541 ~WaitHistoryLoadedObserver() override;
542
543 // history::HistoryServiceObserver:
544 void OnHistoryServiceLoaded(HistoryService* service) override;
545
546 private:
547 // weak
548 content::MessageLoopRunner* runner_;
549 };
550
551 WaitHistoryLoadedObserver::WaitHistoryLoadedObserver(
552 content::MessageLoopRunner* runner)
553 : runner_(runner) {
554 }
555
556 WaitHistoryLoadedObserver::~WaitHistoryLoadedObserver() {
557 }
558
559 void WaitHistoryLoadedObserver::OnHistoryServiceLoaded(
560 HistoryService* service) {
561 runner_->Quit();
562 }
563
564 void WaitForHistoryToLoad(HistoryService* history_service) {
565 if (!history_service->BackendLoaded()) {
566 scoped_refptr<content::MessageLoopRunner> runner =
567 new content::MessageLoopRunner;
568 WaitHistoryLoadedObserver observer(runner.get());
569 ScopedObserver<HistoryService, history::HistoryServiceObserver>
570 scoped_observer(&observer);
571 scoped_observer.Add(history_service);
572 runner->Run();
573 }
574 }
575
544 } // namespace ui_test_utils 576 } // namespace ui_test_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698