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

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: Address review comments Created 6 years, 1 month 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_dialogs/app_modal_dialog.h" 49 #include "components/app_modal_dialogs/app_modal_dialog.h"
50 #include "components/app_modal_dialogs/app_modal_dialog_queue.h" 50 #include "components/app_modal_dialogs/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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 new content::MessageLoopRunner; 357 new content::MessageLoopRunner;
357 scoped_ptr<TemplateURLService::Subscription> subscription = 358 scoped_ptr<TemplateURLService::Subscription> subscription =
358 service->RegisterOnLoadedCallback( 359 service->RegisterOnLoadedCallback(
359 message_loop_runner->QuitClosure()); 360 message_loop_runner->QuitClosure());
360 service->Load(); 361 service->Load();
361 message_loop_runner->Run(); 362 message_loop_runner->Run();
362 363
363 ASSERT_TRUE(service->loaded()); 364 ASSERT_TRUE(service->loaded());
364 } 365 }
365 366
366 void WaitForHistoryToLoad(HistoryService* history_service) {
367 content::WindowedNotificationObserver history_loaded_observer(
368 chrome::NOTIFICATION_HISTORY_LOADED,
369 content::NotificationService::AllSources());
370 if (!history_service->BackendLoaded())
371 history_loaded_observer.Wait();
372 }
373
374 void DownloadURL(Browser* browser, const GURL& download_url) { 367 void DownloadURL(Browser* browser, const GURL& download_url) {
375 base::ScopedTempDir downloads_directory; 368 base::ScopedTempDir downloads_directory;
376 ASSERT_TRUE(downloads_directory.CreateUniqueTempDir()); 369 ASSERT_TRUE(downloads_directory.CreateUniqueTempDir());
377 browser->profile()->GetPrefs()->SetFilePath( 370 browser->profile()->GetPrefs()->SetFilePath(
378 prefs::kDownloadDefaultDirectory, downloads_directory.path()); 371 prefs::kDownloadDefaultDirectory, downloads_directory.path());
379 372
380 content::DownloadManager* download_manager = 373 content::DownloadManager* download_manager =
381 content::BrowserContext::GetDownloadManager(browser->profile()); 374 content::BrowserContext::GetDownloadManager(browser->profile());
382 scoped_ptr<content::DownloadTestObserver> observer( 375 scoped_ptr<content::DownloadTestObserver> observer(
383 new content::DownloadTestObserverTerminal( 376 new content::DownloadTestObserverTerminal(
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 HistoryEnumerator::~HistoryEnumerator() {} 526 HistoryEnumerator::~HistoryEnumerator() {}
534 527
535 void HistoryEnumerator::HistoryQueryComplete( 528 void HistoryEnumerator::HistoryQueryComplete(
536 const base::Closure& quit_task, 529 const base::Closure& quit_task,
537 history::QueryResults* results) { 530 history::QueryResults* results) {
538 for (size_t i = 0; i < results->size(); ++i) 531 for (size_t i = 0; i < results->size(); ++i)
539 urls_.push_back((*results)[i].url()); 532 urls_.push_back((*results)[i].url());
540 quit_task.Run(); 533 quit_task.Run();
541 } 534 }
542 535
536 // Wait for HistoryService to load.
537 class WaitHistoryLoadedObserver : public history::HistoryServiceObserver {
538 public:
539 explicit WaitHistoryLoadedObserver(content::MessageLoopRunner* runner)
540 : runner_(runner) {}
541 virtual ~WaitHistoryLoadedObserver() {}
sdefresne 2014/10/30 17:37:04 style: remove virtual, add override
nshaik 2014/10/30 21:48:36 Done.
542 // history::HistoryServiceObserver:
543 virtual void OnHistoryServiceLoaded(HistoryService* service) override {
sdefresne 2014/10/30 17:37:04 style: remove virtual
nshaik 2014/10/30 21:48:36 Done.
544 runner_->Quit();
545 }
546
547 private:
548 // weak
549 content::MessageLoopRunner* runner_;
550 };
551
552 void WaitForHistoryToLoad(HistoryService* history_service) {
553 if (!history_service->BackendLoaded()) {
554 scoped_refptr<content::MessageLoopRunner> runner =
555 new content::MessageLoopRunner;
556 WaitHistoryLoadedObserver observer(runner.get());
557 ScopedObserver<HistoryService, history::HistoryServiceObserver>
558 scoped_observer(&observer);
559 scoped_observer.Add(history_service);
560 runner->Run();
561 }
562 }
563
543 } // namespace ui_test_utils 564 } // namespace ui_test_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698