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

Side by Side Diff: content/test/browser_test_utils.cc

Issue 10803026: Get content_browsertest working. I've added a simple test for now, and will convert the tests in sr… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: get it working on mac + linux, fix unittests crash, and fix unittest link error and add missing dep… Created 8 years, 5 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
« no previous file with comments | « content/shell/shell_browser_main_parts.cc ('k') | content/test/content_browser_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/public/test/browser_test_utils.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop.h"
9 #include "base/run_loop.h"
10 #include "content/public/test/test_launcher.h"
11
12 namespace {
13
14 // Number of times to repost a Quit task so that the MessageLoop finishes up
15 // pending tasks and tasks posted by those pending tasks without risking the
16 // potential hang behavior of MessageLoop::QuitWhenIdle.
17 // The criteria for choosing this number: it should be high enough to make the
18 // quit act like QuitWhenIdle, while taking into account that any page which is
19 // animating may be rendering another frame for each quit deferral. For an
20 // animating page, the potential delay to quitting the RunLoop would be
21 // kNumQuitDeferrals * frame_render_time. Some perf tests run slow, such as
22 // 200ms/frame.
23 static const int kNumQuitDeferrals = 10;
24
25 static void DeferredQuitRunLoop(const base::Closure& quit_task,
26 int num_quit_deferrals) {
27 if (num_quit_deferrals <= 0) {
28 quit_task.Run();
29 } else {
30 MessageLoop::current()->PostTask(FROM_HERE,
31 base::Bind(&DeferredQuitRunLoop, quit_task, num_quit_deferrals - 1));
32 }
33 }
34
35 }
36
37 namespace content {
38
39 void RunThisRunLoop(base::RunLoop* run_loop) {
40 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
41
42 test_launcher::TestLauncherDelegate* delegate =
43 test_launcher::GetCurrentTestLauncherDelegate();
44 // TODO(jam): the null check shouldn't be needed, since this code should only
45 // be called from browser_tests. Unfortunately some unittests are calling this
46 // code.
47 if (delegate)
48 delegate->PreRunMessageLoop(run_loop);
49 run_loop->Run();
50 if (delegate)
51 delegate->PostRunMessageLoop();
52 }
53
54 base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) {
55 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(),
56 kNumQuitDeferrals);
57 }
58
59 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/shell_browser_main_parts.cc ('k') | content/test/content_browser_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698