1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/test/base/search_test_utils.h"
6 
7 #include "base/memory/ref_counted.h"
8 #include "base/test/bind.h"
9 #include "components/search_engines/template_url_service.h"
10 #include "content/public/test/test_utils.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 
13 namespace search_test_utils {
14 
WaitForTemplateURLServiceToLoad(TemplateURLService * service)15 void WaitForTemplateURLServiceToLoad(TemplateURLService* service) {
16   if (service->loaded())
17     return;
18   scoped_refptr<content::MessageLoopRunner> message_loop_runner =
19       new content::MessageLoopRunner;
20   std::unique_ptr<TemplateURLService::Subscription> subscription =
21       service->RegisterOnLoadedCallback(
22           base::BindLambdaForTesting([&]() { message_loop_runner->Quit(); }));
23   service->Load();
24   message_loop_runner->Run();
25 
26   ASSERT_TRUE(service->loaded());
27 }
28 
29 }  // namespace search_test_utils
30