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

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

Issue 15808008: GTTF: Remove message loop hooks from TestLauncherDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « content/public/test/test_utils.h ('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/lazy_instance.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "base/run_loop.h" 10 #include "base/run_loop.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/render_view_host.h" 14 #include "content/public/browser/render_view_host.h"
14 #include "content/public/test/test_launcher.h" 15 #include "content/public/test/test_launcher.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace content { 18 namespace content {
18 19
19 namespace { 20 namespace {
20 21
22 base::LazyInstance<std::vector<RunMessageLoopHook> >::Leaky
23 g_pre_run_message_loop_hooks = LAZY_INSTANCE_INITIALIZER;
24
25 base::LazyInstance<std::vector<RunMessageLoopHook> >::Leaky
26 g_post_run_message_loop_hooks = LAZY_INSTANCE_INITIALIZER;
27
21 // Number of times to repost a Quit task so that the MessageLoop finishes up 28 // Number of times to repost a Quit task so that the MessageLoop finishes up
22 // pending tasks and tasks posted by those pending tasks without risking the 29 // pending tasks and tasks posted by those pending tasks without risking the
23 // potential hang behavior of MessageLoop::QuitWhenIdle. 30 // potential hang behavior of MessageLoop::QuitWhenIdle.
24 // The criteria for choosing this number: it should be high enough to make the 31 // The criteria for choosing this number: it should be high enough to make the
25 // quit act like QuitWhenIdle, while taking into account that any page which is 32 // quit act like QuitWhenIdle, while taking into account that any page which is
26 // animating may be rendering another frame for each quit deferral. For an 33 // animating may be rendering another frame for each quit deferral. For an
27 // animating page, the potential delay to quitting the RunLoop would be 34 // animating page, the potential delay to quitting the RunLoop would be
28 // kNumQuitDeferrals * frame_render_time. Some perf tests run slow, such as 35 // kNumQuitDeferrals * frame_render_time. Some perf tests run slow, such as
29 // 200ms/frame. 36 // 200ms/frame.
30 static const int kNumQuitDeferrals = 10; 37 static const int kNumQuitDeferrals = 10;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 78
72 void RunMessageLoop() { 79 void RunMessageLoop() {
73 base::RunLoop run_loop; 80 base::RunLoop run_loop;
74 RunThisRunLoop(&run_loop); 81 RunThisRunLoop(&run_loop);
75 } 82 }
76 83
77 void RunThisRunLoop(base::RunLoop* run_loop) { 84 void RunThisRunLoop(base::RunLoop* run_loop) {
78 base::MessageLoop::ScopedNestableTaskAllower allow( 85 base::MessageLoop::ScopedNestableTaskAllower allow(
79 base::MessageLoop::current()); 86 base::MessageLoop::current());
80 87
81 // If we're running inside a browser test, we might need to allow the test 88 for (size_t i = 0; i < g_pre_run_message_loop_hooks.Get().size(); i++)
sky 2013/05/31 19:27:03 Should this use ObserverList for the case of the l
Paweł Hajdan Jr. 2013/05/31 19:50:15 Good question. ObserverList<RunMessageLoopHook>::
82 // launcher to do extra work before/after running a nested message loop. 89 g_pre_run_message_loop_hooks.Get()[i].Run(run_loop);
83 TestLauncherDelegate* delegate = NULL; 90
84 #if !defined(OS_IOS)
85 delegate = GetCurrentTestLauncherDelegate();
86 #endif
87 if (delegate)
88 delegate->PreRunMessageLoop(run_loop);
89 run_loop->Run(); 91 run_loop->Run();
90 if (delegate) 92
91 delegate->PostRunMessageLoop(); 93 for (size_t i = 0; i < g_pre_run_message_loop_hooks.Get().size(); i++)
94 g_post_run_message_loop_hooks.Get()[i].Run(run_loop);
95 }
96
97 void AddPreRunMessageLoopHook(const RunMessageLoopHook& hook) {
98 g_pre_run_message_loop_hooks.Get().push_back(hook);
99 }
100
101 void AddPostRunMessageLoopHook(const RunMessageLoopHook& hook) {
102 g_post_run_message_loop_hooks.Get().push_back(hook);
92 } 103 }
93 104
94 void RunAllPendingInMessageLoop() { 105 void RunAllPendingInMessageLoop() {
95 base::MessageLoop::current()->PostTask( 106 base::MessageLoop::current()->PostTask(
96 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 107 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
97 RunMessageLoop(); 108 RunMessageLoop();
98 } 109 }
99 110
100 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) { 111 void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) {
101 if (BrowserThread::CurrentlyOn(thread_id)) { 112 if (BrowserThread::CurrentlyOn(thread_id)) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 details_ = details; 207 details_ = details;
197 seen_ = true; 208 seen_ = true;
198 if (!running_) 209 if (!running_)
199 return; 210 return;
200 211
201 message_loop_runner_->Quit(); 212 message_loop_runner_->Quit();
202 running_ = false; 213 running_ = false;
203 } 214 }
204 215
205 } // namespace content 216 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698