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

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

Issue 10825085: Move RunAllPendingInMessageLoop from ui_test_utils.h to test_utils.h, so that it can be reused by c… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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_content_client.cc ('k') | 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) 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 "content/public/test/test_utils.h" 5 #include "content/public/test/test_utils.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/public/browser/notification_service.h" 10 #include "content/public/browser/notification_service.h"
(...skipping 16 matching lines...) Expand all
27 static void DeferredQuitRunLoop(const base::Closure& quit_task, 27 static void DeferredQuitRunLoop(const base::Closure& quit_task,
28 int num_quit_deferrals) { 28 int num_quit_deferrals) {
29 if (num_quit_deferrals <= 0) { 29 if (num_quit_deferrals <= 0) {
30 quit_task.Run(); 30 quit_task.Run();
31 } else { 31 } else {
32 MessageLoop::current()->PostTask(FROM_HERE, 32 MessageLoop::current()->PostTask(FROM_HERE,
33 base::Bind(&DeferredQuitRunLoop, quit_task, num_quit_deferrals - 1)); 33 base::Bind(&DeferredQuitRunLoop, quit_task, num_quit_deferrals - 1));
34 } 34 }
35 } 35 }
36 36
37 void RunAllPendingMessageAndSendQuit(BrowserThread::ID thread_id,
38 const base::Closure& quit_task) {
39 MessageLoop::current()->PostTask(FROM_HERE,
40 MessageLoop::QuitWhenIdleClosure());
41 RunMessageLoop();
scottmg 2012/07/30 20:23:26 Replace 39-41 with content::RunAllPendingInMessage
jam 2012/07/30 20:34:21 Done.
42 BrowserThread::PostTask(thread_id, FROM_HERE, quit_task);
37 } 43 }
38 44
45 } // namespace
46
39 namespace content { 47 namespace content {
40 48
41 void RunMessageLoop() { 49 void RunMessageLoop() {
42 base::RunLoop run_loop; 50 base::RunLoop run_loop;
43 RunThisRunLoop(&run_loop); 51 RunThisRunLoop(&run_loop);
44 } 52 }
45 53
46 void RunThisRunLoop(base::RunLoop* run_loop) { 54 void RunThisRunLoop(base::RunLoop* run_loop) {
47 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); 55 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
48 56
49 // If we're running inside a browser test, we might need to allow the test 57 // If we're running inside a browser test, we might need to allow the test
50 // launcher to do extra work before/after running a nested message loop. 58 // launcher to do extra work before/after running a nested message loop.
51 test_launcher::TestLauncherDelegate* delegate = 59 test_launcher::TestLauncherDelegate* delegate =
52 test_launcher::GetCurrentTestLauncherDelegate(); 60 test_launcher::GetCurrentTestLauncherDelegate();
53 if (delegate) 61 if (delegate)
54 delegate->PreRunMessageLoop(run_loop); 62 delegate->PreRunMessageLoop(run_loop);
55 run_loop->Run(); 63 run_loop->Run();
56 if (delegate) 64 if (delegate)
57 delegate->PostRunMessageLoop(); 65 delegate->PostRunMessageLoop();
58 } 66 }
59 67
68 void RunAllPendingInMessageLoop() {
69 MessageLoop::current()->PostTask(FROM_HERE,
70 MessageLoop::QuitWhenIdleClosure());
71 RunMessageLoop();
72 }
73
74 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) {
75 if (BrowserThread::CurrentlyOn(thread_id)) {
76 RunAllPendingInMessageLoop();
77 return;
78 }
79 BrowserThread::ID current_thread_id;
80 if (!BrowserThread::GetCurrentThreadIdentifier(&current_thread_id)) {
81 NOTREACHED();
82 return;
83 }
84
85 base::RunLoop run_loop;
86 BrowserThread::PostTask(thread_id, FROM_HERE,
87 base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id,
88 run_loop.QuitClosure()));
89 RunThisRunLoop(&run_loop);
90 }
91
60 base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) { 92 base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) {
61 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(), 93 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(),
62 kNumQuitDeferrals); 94 kNumQuitDeferrals);
63 } 95 }
64 96
65 MessageLoopRunner::MessageLoopRunner() { 97 MessageLoopRunner::MessageLoopRunner() {
66 } 98 }
67 99
68 MessageLoopRunner::~MessageLoopRunner() { 100 MessageLoopRunner::~MessageLoopRunner() {
69 } 101 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 details_ = details; 141 details_ = details;
110 seen_ = true; 142 seen_ = true;
111 if (!running_) 143 if (!running_)
112 return; 144 return;
113 145
114 message_loop_runner_->Quit(); 146 message_loop_runner_->Quit();
115 running_ = false; 147 running_ = false;
116 } 148 }
117 149
118 } // namespace content 150 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/shell_content_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698