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

Side by Side Diff: chrome/browser/extensions/api/top_sites/top_sites_apitest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 months 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 | Annotate | Revision Log
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 "base/values.h" 5 #include "base/values.h"
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #include "chrome/browser/extensions/api/top_sites/top_sites_api.h" 7 #include "chrome/browser/extensions/api/top_sites/top_sites_api.h"
8 #include "chrome/browser/extensions/extension_function_test_utils.h" 8 #include "chrome/browser/extensions/extension_function_test_utils.h"
9 #include "chrome/browser/history/top_sites.h" 9 #include "chrome/browser/history/top_sites.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 15 matching lines...) Expand all
26 history::TopSites* top_sites = browser()->profile()->GetTopSites(); 26 history::TopSites* top_sites = browser()->profile()->GetTopSites();
27 27
28 // This may return async or sync. If sync, top_sites_inited_ will be true 28 // This may return async or sync. If sync, top_sites_inited_ will be true
29 // before we get to the conditional below. Otherwise, we'll run a nested 29 // before we get to the conditional below. Otherwise, we'll run a nested
30 // message loop until the async callback. 30 // message loop until the async callback.
31 top_sites->GetMostVisitedURLs( 31 top_sites->GetMostVisitedURLs(
32 base::Bind(&TopSitesExtensionTest::OnTopSitesAvailable, this)); 32 base::Bind(&TopSitesExtensionTest::OnTopSitesAvailable, this));
33 33
34 if (!top_sites_inited_) { 34 if (!top_sites_inited_) {
35 waiting_ = true; 35 waiting_ = true;
36 MessageLoop::current()->Run(); 36 base::MessageLoop::current()->Run();
37 } 37 }
38 38
39 // By this point, we know topsites has loaded. We can run the tests now. 39 // By this point, we know topsites has loaded. We can run the tests now.
40 } 40 }
41 41
42 private: 42 private:
43 void OnTopSitesAvailable(const history::MostVisitedURLList& data) { 43 void OnTopSitesAvailable(const history::MostVisitedURLList& data) {
44 if (waiting_) { 44 if (waiting_) {
45 MessageLoop::current()->Quit(); 45 base::MessageLoop::current()->Quit();
46 waiting_ = false; 46 waiting_ = false;
47 } 47 }
48 top_sites_inited_ = true; 48 top_sites_inited_ = true;
49 } 49 }
50 50
51 bool top_sites_inited_; 51 bool top_sites_inited_;
52 bool waiting_; 52 bool waiting_;
53 }; 53 };
54 54
55 } // namespace 55 } // namespace
56 56
57 IN_PROC_BROWSER_TEST_F(TopSitesExtensionTest, GetTopSites) { 57 IN_PROC_BROWSER_TEST_F(TopSitesExtensionTest, GetTopSites) {
58 scoped_refptr<TopSitesGetFunction> get_top_sites_function( 58 scoped_refptr<TopSitesGetFunction> get_top_sites_function(
59 new TopSitesGetFunction()); 59 new TopSitesGetFunction());
60 // Without a callback the function will not generate a result. 60 // Without a callback the function will not generate a result.
61 get_top_sites_function->set_has_callback(true); 61 get_top_sites_function->set_has_callback(true);
62 62
63 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 63 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
64 get_top_sites_function.get(), "[]", browser())); 64 get_top_sites_function.get(), "[]", browser()));
65 base::ListValue* list; 65 base::ListValue* list;
66 ASSERT_TRUE(result->GetAsList(&list)); 66 ASSERT_TRUE(result->GetAsList(&list));
67 EXPECT_GE(list->GetSize(), arraysize(history::kPrepopulatedPages)); 67 EXPECT_GE(list->GetSize(), arraysize(history::kPrepopulatedPages));
68 } 68 }
69 69
70 } // namespace extensions 70 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_api.cc ('k') | chrome/browser/extensions/api/web_request/web_request_api_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698