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/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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 new content::MessageLoopRunner; | 357 new content::MessageLoopRunner; |
358 scoped_ptr<TemplateURLService::Subscription> subscription = | 358 scoped_ptr<TemplateURLService::Subscription> subscription = |
359 service->RegisterOnLoadedCallback( | 359 service->RegisterOnLoadedCallback( |
360 message_loop_runner->QuitClosure()); | 360 message_loop_runner->QuitClosure()); |
361 service->Load(); | 361 service->Load(); |
362 message_loop_runner->Run(); | 362 message_loop_runner->Run(); |
363 | 363 |
364 ASSERT_TRUE(service->loaded()); | 364 ASSERT_TRUE(service->loaded()); |
365 } | 365 } |
366 | 366 |
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) { | 367 void DownloadURL(Browser* browser, const GURL& download_url) { |
376 base::ScopedTempDir downloads_directory; | 368 base::ScopedTempDir downloads_directory; |
377 ASSERT_TRUE(downloads_directory.CreateUniqueTempDir()); | 369 ASSERT_TRUE(downloads_directory.CreateUniqueTempDir()); |
378 browser->profile()->GetPrefs()->SetFilePath( | 370 browser->profile()->GetPrefs()->SetFilePath( |
379 prefs::kDownloadDefaultDirectory, downloads_directory.path()); | 371 prefs::kDownloadDefaultDirectory, downloads_directory.path()); |
380 | 372 |
381 content::DownloadManager* download_manager = | 373 content::DownloadManager* download_manager = |
382 content::BrowserContext::GetDownloadManager(browser->profile()); | 374 content::BrowserContext::GetDownloadManager(browser->profile()); |
383 scoped_ptr<content::DownloadTestObserver> observer( | 375 scoped_ptr<content::DownloadTestObserver> observer( |
384 new content::DownloadTestObserverTerminal( | 376 new content::DownloadTestObserverTerminal( |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 HistoryEnumerator::~HistoryEnumerator() {} | 566 HistoryEnumerator::~HistoryEnumerator() {} |
575 | 567 |
576 void HistoryEnumerator::HistoryQueryComplete( | 568 void HistoryEnumerator::HistoryQueryComplete( |
577 const base::Closure& quit_task, | 569 const base::Closure& quit_task, |
578 history::QueryResults* results) { | 570 history::QueryResults* results) { |
579 for (size_t i = 0; i < results->size(); ++i) | 571 for (size_t i = 0; i < results->size(); ++i) |
580 urls_.push_back((*results)[i].url()); | 572 urls_.push_back((*results)[i].url()); |
581 quit_task.Run(); | 573 quit_task.Run(); |
582 } | 574 } |
583 | 575 |
576 WaitHistoryLoadedObserver::WaitHistoryLoadedObserver( | |
577 content::MessageLoopRunner* runner) | |
578 : runner_(runner) { | |
579 } | |
580 | |
581 WaitHistoryLoadedObserver::~WaitHistoryLoadedObserver() { | |
582 } | |
583 | |
584 void WaitHistoryLoadedObserver::HistoryServiceLoaded(HistoryService* service) { | |
585 runner_->Quit(); | |
586 } | |
587 | |
588 void WaitForHistoryToLoad(HistoryService* history_service) { | |
589 if (!history_service->BackendLoaded()) { | |
590 scoped_refptr<content::MessageLoopRunner> runner = | |
591 new content::MessageLoopRunner; | |
592 WaitHistoryLoadedObserver observer(runner.get()); | |
593 history_service->AddHistoryServiceObserver(&observer); | |
sdefresne
2014/10/20 13:15:42
Use ScopedObserver
nshaik
2014/10/29 08:43:39
Done.
| |
594 runner->Run(); | |
595 history_service->RemoveHistoryServiceObserver(&observer); | |
596 } | |
597 } | |
584 } // namespace ui_test_utils | 598 } // namespace ui_test_utils |
OLD | NEW |