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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 ASSERT_TRUE(model->loaded()); | 363 ASSERT_TRUE(model->loaded()); |
364 } | 364 } |
365 | 365 |
366 void WaitForBookmarkModelToLoad(Profile* profile) { | 366 void WaitForBookmarkModelToLoad(Profile* profile) { |
367 WaitForBookmarkModelToLoad(BookmarkModelFactory::GetForProfile(profile)); | 367 WaitForBookmarkModelToLoad(BookmarkModelFactory::GetForProfile(profile)); |
368 } | 368 } |
369 | 369 |
370 void WaitForTemplateURLServiceToLoad(TemplateURLService* service) { | 370 void WaitForTemplateURLServiceToLoad(TemplateURLService* service) { |
371 if (service->loaded()) | 371 if (service->loaded()) |
372 return; | 372 return; |
373 | |
374 using content::NotificationDetails; | |
375 using content::NotificationObserver; | |
376 using content::NotificationRegistrar; | |
377 using content::NotificationSource; | |
378 content::NotificationRegistrar registrar; | |
379 class LoadedObserver : public NotificationObserver { | |
380 public: | |
381 LoadedObserver(base::RunLoop* run_loop) : run_loop_(run_loop) {} | |
382 virtual void Observe(int type, | |
383 const NotificationSource& source, | |
384 const NotificationDetails& details) OVERRIDE { | |
385 CHECK_EQ(chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, type); | |
386 run_loop_->Quit(); | |
387 } | |
388 | |
389 private: | |
390 base::RunLoop* run_loop_; | |
391 }; | |
392 | |
393 | |
394 base::RunLoop run_loop; | |
395 LoadedObserver loaded_observer(&run_loop); | |
396 registrar.Add(&loaded_observer, | |
397 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | |
398 content::Source<TemplateURLService>(service)); | |
jam
2013/07/12 16:38:34
you can use content::WindowedNotificationObserver
awong
2013/07/16 21:27:28
Done.
| |
373 service->Load(); | 399 service->Load(); |
374 TemplateURLServiceTestUtil::BlockTillServiceProcessesRequests(); | 400 run_loop.Run(); |
401 | |
375 ASSERT_TRUE(service->loaded()); | 402 ASSERT_TRUE(service->loaded()); |
376 } | 403 } |
377 | 404 |
378 void WaitForHistoryToLoad(HistoryService* history_service) { | 405 void WaitForHistoryToLoad(HistoryService* history_service) { |
379 content::WindowedNotificationObserver history_loaded_observer( | 406 content::WindowedNotificationObserver history_loaded_observer( |
380 chrome::NOTIFICATION_HISTORY_LOADED, | 407 chrome::NOTIFICATION_HISTORY_LOADED, |
381 content::NotificationService::AllSources()); | 408 content::NotificationService::AllSources()); |
382 if (!history_service->BackendLoaded()) | 409 if (!history_service->BackendLoaded()) |
383 history_loaded_observer.Wait(); | 410 history_loaded_observer.Wait(); |
384 } | 411 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 void HistoryEnumerator::HistoryQueryComplete( | 577 void HistoryEnumerator::HistoryQueryComplete( |
551 const base::Closure& quit_task, | 578 const base::Closure& quit_task, |
552 HistoryService::Handle request_handle, | 579 HistoryService::Handle request_handle, |
553 history::QueryResults* results) { | 580 history::QueryResults* results) { |
554 for (size_t i = 0; i < results->size(); ++i) | 581 for (size_t i = 0; i < results->size(); ++i) |
555 urls_.push_back((*results)[i].url()); | 582 urls_.push_back((*results)[i].url()); |
556 quit_task.Run(); | 583 quit_task.Run(); |
557 } | 584 } |
558 | 585 |
559 } // namespace ui_test_utils | 586 } // namespace ui_test_utils |
OLD | NEW |