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

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: 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
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 delegate->PreRunMessageLoop(run_loop);
45 run_loop->Run();
46 delegate->PostRunMessageLoop();
47 }
48
49 base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) {
50 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(),
51 kNumQuitDeferrals);
52 }
53
54 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698