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

Side by Side Diff: chrome/browser/history/top_sites_extension_test.cc

Issue 8363041: top sites: re-enable test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: change var name and fix a TODO Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_function_test_utils.h" 7 #include "chrome/browser/extensions/extension_function_test_utils.h"
8 #include "chrome/browser/history/top_sites.h"
8 #include "chrome/browser/history/top_sites_extension_api.h" 9 #include "chrome/browser/history/top_sites_extension_api.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h"
9 #include "chrome/test/base/in_process_browser_test.h" 12 #include "chrome/test/base/in_process_browser_test.h"
10 13
11 using namespace extension_function_test_utils; 14 using namespace extension_function_test_utils;
12 15
13 namespace { 16 namespace {
14 17
15 class TopSitesExtensionTest : public InProcessBrowserTest { 18 class TopSitesExtensionTest : public InProcessBrowserTest {
19 public:
20 TopSitesExtensionTest() : top_sites_inited_(false), waiting_(false) {
21 }
22
23 void SetUpOnMainThread() {
24 history::TopSites* top_sites = browser()->profile()->GetTopSites();
25
26 // This may return async or sync. If sync, top_sites_inited_ will be true
27 // before we get to the conditional below. Otherwise, we'll run a nested
28 // message loop until the async callback.
29 top_sites->GetMostVisitedURLs(
30 &consumer_,
31 base::Bind(&TopSitesExtensionTest::OnTopSitesAvailable, this));
32
33 if (!top_sites_inited_) {
34 waiting_ = true;
35 MessageLoop::current()->Run();
36 }
37
38 // By this point, we know topsites has loaded. We can run the tests now.
39 }
40
41 private:
42 void OnTopSitesAvailable(const history::MostVisitedURLList& data) {
43 if (waiting_) {
44 MessageLoop::current()->Quit();
45 waiting_ = false;
46 }
47 top_sites_inited_ = true;
48 }
49
50 CancelableRequestConsumer consumer_;
51 bool top_sites_inited_;
52 bool waiting_;
16 }; 53 };
17 54
18 } // namespace 55 } // namespace
19 56
20 // Test started failing soon after commit. http://crbug.com/101783 57 IN_PROC_BROWSER_TEST_F(TopSitesExtensionTest, GetTopSites) {
21 #if defined(OS_WIN)
22 #define MAYBE_GetTopSites FAILS_GetTopSites
23 #elif defined(OS_LINUX)
24 #define MAYBE_GetTopSites FLAKY_GetTopSites
25 #else
26 #define MAYBE_GetTopSites GetTopSites
27 #endif
28
29 IN_PROC_BROWSER_TEST_F(TopSitesExtensionTest, MAYBE_GetTopSites) {
30 scoped_refptr<GetTopSitesFunction> get_top_sites_function( 58 scoped_refptr<GetTopSitesFunction> get_top_sites_function(
31 new GetTopSitesFunction()); 59 new GetTopSitesFunction());
32 // Without a callback the function will not generate a result. 60 // Without a callback the function will not generate a result.
33 get_top_sites_function->set_has_callback(true); 61 get_top_sites_function->set_has_callback(true);
34 62
35 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 63 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
36 get_top_sites_function.get(), "[]", browser())); 64 get_top_sites_function.get(), "[]", browser()));
37 EXPECT_EQ(base::Value::TYPE_LIST, result->GetType()); 65 base::ListValue* list;
38 // This should return at least 2 items (the prepopulated items). 66 ASSERT_TRUE(result->GetAsList(&list));
39 // TODO(estade): change 2 to arraylen(kPrepopulatedPages) after that 67 EXPECT_GE(list->GetSize(), arraysize(history::kPrepopulatedPages));
40 // patch lands.
41 EXPECT_GE(result->GetType(), 2);
42 } 68 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698