summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/base/bookmark_load_observer.cc9
-rw-r--r--chrome/test/base/bookmark_load_observer.h7
-rw-r--r--chrome/test/base/in_process_browser_test.cc6
-rw-r--r--chrome/test/base/test_web_dialog_observer.cc5
-rw-r--r--chrome/test/base/test_web_dialog_observer.h2
-rw-r--r--chrome/test/base/testing_profile.cc7
-rw-r--r--chrome/test/base/tracing.cc7
-rw-r--r--chrome/test/base/ui_test_utils.cc192
-rw-r--r--chrome/test/base/ui_test_utils.h55
-rw-r--r--chrome/test/perf/rendering/throughput_tests.cc23
10 files changed, 178 insertions, 135 deletions
diff --git a/chrome/test/base/bookmark_load_observer.cc b/chrome/test/base/bookmark_load_observer.cc
index 5b80070..3bc1b7f 100644
--- a/chrome/test/base/bookmark_load_observer.cc
+++ b/chrome/test/base/bookmark_load_observer.cc
@@ -1,15 +1,16 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/base/bookmark_load_observer.h"
-#include "base/message_loop.h"
+#include "chrome/test/base/ui_test_utils.h"
-BookmarkLoadObserver::BookmarkLoadObserver() {}
+BookmarkLoadObserver::BookmarkLoadObserver(const base::Closure& quit_task)
+ : quit_task_(quit_task) {}
BookmarkLoadObserver::~BookmarkLoadObserver() {}
void BookmarkLoadObserver::Loaded(BookmarkModel* model, bool ids_reassigned) {
- MessageLoop::current()->Quit();
+ quit_task_.Run();
}
diff --git a/chrome/test/base/bookmark_load_observer.h b/chrome/test/base/bookmark_load_observer.h
index 0619838e..bb21615 100644
--- a/chrome/test/base/bookmark_load_observer.h
+++ b/chrome/test/base/bookmark_load_observer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,7 +7,9 @@
#pragma once
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
#include "chrome/browser/bookmarks/bookmark_model_observer.h"
// BookmarkLoadObserver is used when blocking until the BookmarkModel
@@ -15,7 +17,7 @@
// loop is quit.
class BookmarkLoadObserver : public BookmarkModelObserver {
public:
- BookmarkLoadObserver();
+ explicit BookmarkLoadObserver(const base::Closure& quit_task);
virtual ~BookmarkLoadObserver();
virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE;
@@ -40,6 +42,7 @@ class BookmarkLoadObserver : public BookmarkModelObserver {
const BookmarkNode* node) OVERRIDE {}
private:
+ base::Closure quit_task_;
DISALLOW_COPY_AND_ASSIGN(BookmarkLoadObserver);
};
diff --git a/chrome/test/base/in_process_browser_test.cc b/chrome/test/base/in_process_browser_test.cc
index 34a9c70..30a2eca 100644
--- a/chrome/test/base/in_process_browser_test.cc
+++ b/chrome/test/base/in_process_browser_test.cc
@@ -374,6 +374,12 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
autorelease_pool_->Recycle();
#endif
+ // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's
+ // run all pending messages here to avoid preempting the QuitBrowsers tasks.
+ // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it
+ // will not be possible to post Quit tasks.
+ ui_test_utils::RunAllPendingInMessageLoop();
+
QuitBrowsers();
CHECK(BrowserList::empty());
}
diff --git a/chrome/test/base/test_web_dialog_observer.cc b/chrome/test/base/test_web_dialog_observer.cc
index 2056592..75b7a34 100644
--- a/chrome/test/base/test_web_dialog_observer.cc
+++ b/chrome/test/base/test_web_dialog_observer.cc
@@ -42,7 +42,7 @@ void TestWebDialogObserver::Observe(
// If the message loop is running stop it.
if (running_) {
running_ = false;
- MessageLoopForUI::current()->Quit();
+ message_loop_runner_->Quit();
}
break;
default:
@@ -73,7 +73,8 @@ content::WebUI* TestWebDialogObserver::GetWebUI() {
if (!done_) {
EXPECT_FALSE(running_);
running_ = true;
- ui_test_utils::RunMessageLoop();
+ message_loop_runner_ = new ui_test_utils::MessageLoopRunner;
+ message_loop_runner_->Run();
}
return web_ui_;
}
diff --git a/chrome/test/base/test_web_dialog_observer.h b/chrome/test/base/test_web_dialog_observer.h
index b77d667..67f1f74 100644
--- a/chrome/test/base/test_web_dialog_observer.h
+++ b/chrome/test/base/test_web_dialog_observer.h
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/web_dialogs/web_dialog_observer.h"
@@ -55,6 +56,7 @@ class TestWebDialogObserver : public content::NotificationObserver,
content::WebUI* web_ui_;
bool done_;
bool running_;
+ scoped_refptr<ui_test_utils::MessageLoopRunner> message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(TestWebDialogObserver);
};
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index a652086..c69447f 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -11,6 +11,7 @@
#include "base/file_util.h"
#include "base/message_loop_proxy.h"
#include "base/path_service.h"
+#include "base/run_loop.h"
#include "base/string_number_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
@@ -378,9 +379,11 @@ void TestingProfile::BlockUntilBookmarkModelLoaded() {
DCHECK(GetBookmarkModel());
if (GetBookmarkModel()->IsLoaded())
return;
- BookmarkLoadObserver observer;
+ base::RunLoop run_loop;
+ BookmarkLoadObserver observer(
+ ui_test_utils::GetQuitTaskForRunLoop(&run_loop));
GetBookmarkModel()->AddObserver(&observer);
- MessageLoop::current()->Run();
+ run_loop.Run();
GetBookmarkModel()->RemoveObserver(&observer);
DCHECK(GetBookmarkModel()->IsLoaded());
}
diff --git a/chrome/test/base/tracing.cc b/chrome/test/base/tracing.cc
index 790ab3c..3c29bba 100644
--- a/chrome/test/base/tracing.cc
+++ b/chrome/test/base/tracing.cc
@@ -38,7 +38,8 @@ class InProcessTraceController : public content::TraceSubscriber {
return false;
// Wait for OnEndTracingComplete() to quit the message loop.
// OnTraceDataCollected may be called multiple times while blocking here.
- ui_test_utils::RunMessageLoop();
+ message_loop_runner_ = new ui_test_utils::MessageLoopRunner;
+ message_loop_runner_->Run();
trace_buffer_.Finish();
trace_buffer_.SetOutputCallback(TraceResultBuffer::OutputCallback());
@@ -51,7 +52,7 @@ class InProcessTraceController : public content::TraceSubscriber {
// TraceSubscriber
virtual void OnEndTracingComplete() OVERRIDE {
- MessageLoopForUI::current()->Quit();
+ message_loop_runner_->Quit();
}
// TraceSubscriber
@@ -63,6 +64,8 @@ class InProcessTraceController : public content::TraceSubscriber {
// For collecting trace data asynchronously.
base::debug::TraceResultBuffer trace_buffer_;
+ scoped_refptr<ui_test_utils::MessageLoopRunner> message_loop_runner_;
+
DISALLOW_COPY_AND_ASSIGN(InProcessTraceController);
};
diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc
index f3f51b7..7b4af42 100644
--- a/chrome/test/base/ui_test_utils.cc
+++ b/chrome/test/base/ui_test_utils.cc
@@ -93,6 +93,17 @@ using content::WebContents;
static const int kDefaultWsPort = 8880;
+// Number of times to repost a Quit task so that the MessageLoop finishes up
+// pending tasks and tasks posted by those pending tasks without risking the
+// potential hang behavior of MessageLoop::QuitWhenIdle.
+// The criteria for choosing this number: it should be high enough to make the
+// quit act like QuitWhenIdle, while taking into account that any page which is
+// animating may be rendering another frame for each quit deferral. For an
+// animating page, the potential delay to quitting the RunLoop would be
+// kNumQuitDeferrals * frame_render_time. Some perf tests run slow, such as
+// 200ms/frame.
+static const int kNumQuitDeferrals = 10;
+
namespace ui_test_utils {
namespace {
@@ -106,7 +117,8 @@ class DOMOperationObserver : public content::NotificationObserver,
did_respond_(false) {
registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE,
content::Source<RenderViewHost>(render_view_host));
- ui_test_utils::RunMessageLoop();
+ message_loop_runner_ = new MessageLoopRunner;
+ message_loop_runner_->Run();
}
virtual void Observe(int type,
@@ -116,12 +128,12 @@ class DOMOperationObserver : public content::NotificationObserver,
content::Details<DomOperationNotificationDetails> dom_op_details(details);
response_ = dom_op_details->json;
did_respond_ = true;
- MessageLoopForUI::current()->Quit();
+ message_loop_runner_->Quit();
}
// Overridden from content::WebContentsObserver:
virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE {
- MessageLoopForUI::current()->Quit();
+ message_loop_runner_->Quit();
}
bool GetResponse(std::string* response) WARN_UNUSED_RESULT {
@@ -133,6 +145,7 @@ class DOMOperationObserver : public content::NotificationObserver,
content::NotificationRegistrar registrar_;
std::string response_;
bool did_respond_;
+ scoped_refptr<MessageLoopRunner> message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver);
};
@@ -147,7 +160,8 @@ class FindInPageNotificationObserver : public content::NotificationObserver {
parent_tab->find_tab_helper()->current_find_request_id();
registrar_.Add(this, chrome::NOTIFICATION_FIND_RESULT_AVAILABLE,
content::Source<WebContents>(parent_tab_->web_contents()));
- ui_test_utils::RunMessageLoop();
+ message_loop_runner_ = new MessageLoopRunner;
+ message_loop_runner_->Run();
}
int active_match_ordinal() const { return active_match_ordinal_; }
@@ -165,7 +179,7 @@ class FindInPageNotificationObserver : public content::NotificationObserver {
active_match_ordinal_ = find_details->active_match_ordinal();
if (find_details->final_update()) {
number_of_matches_ = find_details->number_of_matches();
- MessageLoopForUI::current()->Quit();
+ message_loop_runner_->Quit();
} else {
DVLOG(1) << "Ignoring, since we only care about the final message";
}
@@ -185,6 +199,7 @@ class FindInPageNotificationObserver : public content::NotificationObserver {
// The id of the current find request, obtained from WebContents. Allows us
// to monitor when the search completes.
int current_find_request_id_;
+ scoped_refptr<MessageLoopRunner> message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver);
};
@@ -263,39 +278,52 @@ bool ExecuteJavaScriptHelper(RenderViewHost* render_view_host,
return true;
}
-void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) {
- MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
+void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id,
+ const base::Closure& quit_task) {
+ MessageLoop::current()->PostTask(FROM_HERE,
+ MessageLoop::QuitWhenIdleClosure());
RunMessageLoop();
- content::BrowserThread::PostTask(thread_id, FROM_HERE,
- MessageLoop::QuitClosure());
+ content::BrowserThread::PostTask(thread_id, FROM_HERE, quit_task);
}
} // namespace
void RunMessageLoop() {
- MessageLoop* loop = MessageLoop::current();
- MessageLoopForUI* ui_loop =
- content::BrowserThread::CurrentlyOn(content::BrowserThread::UI) ?
- MessageLoopForUI::current() : NULL;
- MessageLoop::ScopedNestableTaskAllower allow(loop);
- if (ui_loop) {
-#if defined(USE_AURA)
- ui_loop->Run();
-#elif defined(TOOLKIT_VIEWS)
- views::AcceleratorHandler handler;
- ui_loop->RunWithDispatcher(&handler);
-#elif defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
- ui_loop->RunWithDispatcher(NULL);
-#else
- ui_loop->Run();
+ base::RunLoop run_loop;
+ RunThisRunLoop(&run_loop);
+}
+
+void RunThisRunLoop(base::RunLoop* run_loop) {
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
+#if !defined(USE_AURA) && defined(TOOLKIT_VIEWS)
+ scoped_ptr<views::AcceleratorHandler> handler;
+ if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
+ handler.reset(new views::AcceleratorHandler);
+ run_loop->set_dispatcher(handler.get());
+ }
#endif
+ run_loop->Run();
+}
+
+// TODO(jbates) move this to a new test_utils.cc in content/test/
+static void DeferredQuitRunLoop(const base::Closure& quit_task,
+ int num_quit_deferrals) {
+ if (num_quit_deferrals <= 0) {
+ quit_task.Run();
} else {
- loop->Run();
+ MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(&DeferredQuitRunLoop, quit_task, num_quit_deferrals - 1));
}
}
+base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) {
+ return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(),
+ kNumQuitDeferrals);
+}
+
void RunAllPendingInMessageLoop() {
- MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
+ MessageLoop::current()->PostTask(FROM_HERE,
+ MessageLoop::QuitWhenIdleClosure());
ui_test_utils::RunMessageLoop();
}
@@ -309,10 +337,12 @@ void RunAllPendingInMessageLoop(content::BrowserThread::ID thread_id) {
NOTREACHED();
return;
}
- content::BrowserThread::PostTask(thread_id, FROM_HERE,
- base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id));
- ui_test_utils::RunMessageLoop();
+ base::RunLoop run_loop;
+ content::BrowserThread::PostTask(thread_id, FROM_HERE,
+ base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id,
+ run_loop.QuitClosure()));
+ ui_test_utils::RunThisRunLoop(&run_loop);
}
bool GetCurrentTabTitle(const Browser* browser, string16* title) {
@@ -331,10 +361,10 @@ void WaitForNavigations(NavigationController* controller,
content::TestNavigationObserver observer(
content::Source<NavigationController>(controller), NULL,
number_of_navigations);
+ base::RunLoop run_loop;
observer.WaitForObservation(
- base::Bind(&ui_test_utils::RunMessageLoop),
- base::Bind(&MessageLoop::Quit,
- base::Unretained(MessageLoopForUI::current())));
+ base::Bind(&ui_test_utils::RunThisRunLoop, base::Unretained(&run_loop)),
+ ui_test_utils::GetQuitTaskForRunLoop(&run_loop));
}
void WaitForNewTab(Browser* browser) {
@@ -377,11 +407,10 @@ void NavigateToURL(browser::NavigateParams* params) {
content::TestNavigationObserver observer(
content::NotificationService::AllSources(), NULL, 1);
browser::Navigate(params);
+ base::RunLoop run_loop;
observer.WaitForObservation(
- base::Bind(&ui_test_utils::RunMessageLoop),
- base::Bind(&MessageLoop::Quit,
- base::Unretained(MessageLoopForUI::current())));
-
+ base::Bind(&ui_test_utils::RunThisRunLoop, base::Unretained(&run_loop)),
+ ui_test_utils::GetQuitTaskForRunLoop(&run_loop));
}
void NavigateToURL(Browser* browser, const GURL& url) {
@@ -451,10 +480,10 @@ static void NavigateToURLWithDispositionBlockUntilNavigationsComplete(
web_contents = browser->GetActiveWebContents();
}
if (disposition == CURRENT_TAB) {
+ base::RunLoop run_loop;
same_tab_observer.WaitForObservation(
- base::Bind(&ui_test_utils::RunMessageLoop),
- base::Bind(&MessageLoop::Quit,
- base::Unretained(MessageLoopForUI::current())));
+ base::Bind(&ui_test_utils::RunThisRunLoop, base::Unretained(&run_loop)),
+ ui_test_utils::GetQuitTaskForRunLoop(&run_loop));
return;
} else if (web_contents) {
NavigationController* controller = &web_contents->GetController();
@@ -704,9 +733,10 @@ void RegisterAndWait(content::NotificationObserver* observer,
void WaitForBookmarkModelToLoad(BookmarkModel* model) {
if (model->IsLoaded())
return;
- BookmarkLoadObserver observer;
+ base::RunLoop run_loop;
+ BookmarkLoadObserver observer(GetQuitTaskForRunLoop(&run_loop));
model->AddObserver(&observer);
- RunMessageLoop();
+ RunThisRunLoop(&run_loop);
model->RemoveObserver(&observer);
ASSERT_TRUE(model->IsLoaded());
}
@@ -764,14 +794,14 @@ bool SendKeyPressSync(const Browser* browser,
gfx::NativeWindow window = NULL;
if (!GetNativeWindow(browser, &window))
return false;
-
+ scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner;
bool result;
result = ui_controls::SendKeyPressNotifyWhenDone(
- window, key, control, shift, alt, command, MessageLoop::QuitClosure());
+ window, key, control, shift, alt, command, runner->QuitClosure());
#if defined(OS_WIN)
if (!result && BringBrowserWindowToFront(browser)) {
result = ui_controls::SendKeyPressNotifyWhenDone(
- window, key, control, shift, alt, command, MessageLoop::QuitClosure());
+ window, key, control, shift, alt, command, runner->QuitClosure());
}
#endif
if (!result) {
@@ -782,7 +812,7 @@ bool SendKeyPressSync(const Browser* browser,
// Run the message loop. It'll stop running when either the key was received
// or the test timed out (in which case testing::Test::HasFatalFailure should
// be set).
- RunMessageLoop();
+ runner->Run();
return !testing::Test::HasFatalFailure();
}
@@ -804,51 +834,41 @@ bool SendKeyPressAndWait(const Browser* browser,
}
bool SendMouseMoveSync(const gfx::Point& location) {
- if (!ui_controls::SendMouseMoveNotifyWhenDone(location.x(), location.y(),
- MessageLoop::QuitClosure())) {
+ scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner;
+ if (!ui_controls::SendMouseMoveNotifyWhenDone(
+ location.x(), location.y(), runner->QuitClosure())) {
return false;
}
- RunMessageLoop();
+ runner->Run();
return !testing::Test::HasFatalFailure();
}
bool SendMouseEventsSync(ui_controls::MouseButton type, int state) {
+ scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner;
if (!ui_controls::SendMouseEventsNotifyWhenDone(
- type, state, MessageLoop::QuitClosure())) {
+ type, state, runner->QuitClosure())) {
return false;
}
- RunMessageLoop();
+ runner->Run();
return !testing::Test::HasFatalFailure();
}
-TimedMessageLoopRunner::TimedMessageLoopRunner()
- : loop_(new MessageLoopForUI()),
- owned_(true),
- quit_loop_invoked_(false) {
+MessageLoopRunner::MessageLoopRunner() {
}
-TimedMessageLoopRunner::~TimedMessageLoopRunner() {
- if (owned_)
- delete loop_;
+MessageLoopRunner::~MessageLoopRunner() {
}
-void TimedMessageLoopRunner::RunFor(int ms) {
- QuitAfter(ms);
- quit_loop_invoked_ = false;
- loop_->Run();
+void MessageLoopRunner::Run() {
+ ui_test_utils::RunThisRunLoop(&run_loop_);
}
-void TimedMessageLoopRunner::Quit() {
- quit_loop_invoked_ = true;
- loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure());
+base::Closure MessageLoopRunner::QuitClosure() {
+ return base::Bind(&MessageLoopRunner::Quit, this);
}
-void TimedMessageLoopRunner::QuitAfter(int ms) {
- quit_loop_invoked_ = true;
- loop_->PostDelayedTask(
- FROM_HERE,
- MessageLoop::QuitClosure(),
- base::TimeDelta::FromMilliseconds(ms));
+void MessageLoopRunner::Quit() {
+ ui_test_utils::GetQuitTaskForRunLoop(&run_loop_).Run();
}
TestWebSocketServer::TestWebSocketServer()
@@ -1013,7 +1033,8 @@ void WindowedNotificationObserver::Wait() {
return;
running_ = true;
- ui_test_utils::RunMessageLoop();
+ message_loop_runner_ = new MessageLoopRunner;
+ message_loop_runner_->Run();
EXPECT_TRUE(seen_);
}
@@ -1027,7 +1048,7 @@ void WindowedNotificationObserver::Observe(
if (!running_)
return;
- MessageLoopForUI::current()->Quit();
+ message_loop_runner_->Quit();
running_ = false;
}
@@ -1078,7 +1099,8 @@ const string16& TitleWatcher::WaitAndGetTitle() {
if (expected_title_observed_)
return observed_title_;
quit_loop_on_observation_ = true;
- ui_test_utils::RunMessageLoop();
+ message_loop_runner_ = new MessageLoopRunner;
+ message_loop_runner_->Run();
return observed_title_;
}
@@ -1104,8 +1126,11 @@ void TitleWatcher::Observe(int type,
return;
observed_title_ = *it;
expected_title_observed_ = true;
- if (quit_loop_on_observation_)
- MessageLoopForUI::current()->Quit();
+ if (quit_loop_on_observation_) {
+ // Only call Quit once, on first Observe:
+ quit_loop_on_observation_ = false;
+ message_loop_runner_->Quit();
+ }
}
BrowserAddedObserver::BrowserAddedObserver()
@@ -1140,7 +1165,7 @@ void DOMMessageQueue::Observe(int type,
message_queue_.push(dom_op_details->json);
if (waiting_for_message_) {
waiting_for_message_ = false;
- MessageLoopForUI::current()->Quit();
+ message_loop_runner_->Quit();
}
}
@@ -1152,7 +1177,8 @@ bool DOMMessageQueue::WaitForMessage(std::string* message) {
if (message_queue_.empty()) {
waiting_for_message_ = true;
// This will be quit when a new message comes in.
- RunMessageLoop();
+ message_loop_runner_ = new MessageLoopRunner;
+ message_loop_runner_->Run();
}
// The queue should not be empty, unless we were quit because of a timeout.
if (message_queue_.empty())
@@ -1180,7 +1206,8 @@ class SnapshotTaker {
base::Bind(&SnapshotTaker::OnSnapshotTaken, base::Unretained(this)),
page_size,
desired_size);
- ui_test_utils::RunMessageLoop();
+ message_loop_runner_ = new MessageLoopRunner;
+ message_loop_runner_->Run();
return snapshot_taken_;
}
@@ -1215,13 +1242,14 @@ class SnapshotTaker {
void OnSnapshotTaken(const SkBitmap& bitmap) {
*bitmap_ = bitmap;
snapshot_taken_ = true;
- MessageLoop::current()->Quit();
+ message_loop_runner_->Quit();
}
SkBitmap* bitmap_;
// Whether the snapshot was actually taken and received by this SnapshotTaker.
// This will be false if the test times out.
bool snapshot_taken_;
+ scoped_refptr<MessageLoopRunner> message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(SnapshotTaker);
};
@@ -1247,9 +1275,9 @@ void OverrideGeolocation(double latitude, double longitude) {
position.altitude = 0.;
position.accuracy = 0.;
position.timestamp = base::Time::Now();
- content::OverrideLocationForTesting(position,
- base::Bind(MessageLoop::QuitClosure()));
- RunMessageLoop();
+ scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner;
+ content::OverrideLocationForTesting(position, runner->QuitClosure());
+ runner->Run();
}
namespace internal {
diff --git a/chrome/test/base/ui_test_utils.h b/chrome/test/base/ui_test_utils.h
index 9af9372..a2ec811 100644
--- a/chrome/test/base/ui_test_utils.h
+++ b/chrome/test/base/ui_test_utils.h
@@ -13,8 +13,8 @@
#include <vector>
#include "base/basictypes.h"
-#include "base/message_loop.h"
#include "base/process.h"
+#include "base/run_loop.h"
#include "base/scoped_temp_dir.h"
#include "base/string16.h"
#include "chrome/browser/ui/view_ids.h"
@@ -96,6 +96,13 @@ enum BrowserTestWaitFlags {
// process browser tests that need to block until a condition is met.
void RunMessageLoop();
+// Variant of RunMessageLoop that takes RunLoop.
+void RunThisRunLoop(base::RunLoop* run_loop);
+
+// Get task to quit the given RunLoop. It allows a few generations of pending
+// tasks to run as opposed to run_loop->QuitClosure().
+base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop);
+
// Turns on nestable tasks, runs all pending tasks in the message loop,
// then resets nestable tasks to what they were originally. Prefer this
// over MessageLoop::RunAllPending for in process browser tests to run
@@ -300,37 +307,34 @@ bool SendMouseMoveSync(const gfx::Point& location) WARN_UNUSED_RESULT;
bool SendMouseEventsSync(ui_controls::MouseButton type,
int state) WARN_UNUSED_RESULT;
-// Run a message loop only for the specified amount of time.
-class TimedMessageLoopRunner {
+// Helper class to Run and Quit the message loop. Run and Quit can only happen
+// once per instance. Make a new instance for each use. Calling Quit after Run
+// has returned is safe and has no effect.
+class MessageLoopRunner
+ : public base::RefCounted<MessageLoopRunner> {
public:
- // Create new MessageLoopForUI and attach to it.
- TimedMessageLoopRunner();
-
- // Attach to an existing message loop.
- explicit TimedMessageLoopRunner(MessageLoop* loop)
- : loop_(loop), owned_(false), quit_loop_invoked_(false) {}
-
- ~TimedMessageLoopRunner();
+ MessageLoopRunner();
- // Run the message loop for ms milliseconds.
- void RunFor(int ms);
+ // Run the current MessageLoop.
+ void Run();
- // Post Quit task to the message loop.
+ // Quit the matching call to Run (nested MessageLoops are unaffected).
void Quit();
- // Post delayed Quit task to the message loop.
- void QuitAfter(int ms);
-
- bool WasTimedOut() const {
- return !quit_loop_invoked_;
- }
+ // Hand this closure off to code that uses callbacks to notify completion.
+ // Example:
+ // scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner;
+ // kick_off_some_api(runner.QuitNowClosure());
+ // runner.Run();
+ base::Closure QuitClosure();
private:
- MessageLoop* loop_;
- bool owned_;
- bool quit_loop_invoked_;
+ friend class base::RefCounted<MessageLoopRunner>;
+ ~MessageLoopRunner();
+
+ base::RunLoop run_loop_;
- DISALLOW_COPY_AND_ASSIGN(TimedMessageLoopRunner);
+ DISALLOW_COPY_AND_ASSIGN(MessageLoopRunner);
};
// This is a utility class for running a python websocket server
@@ -445,6 +449,7 @@ class WindowedNotificationObserver : public content::NotificationObserver {
content::NotificationSource source_;
content::NotificationDetails details_;
+ scoped_refptr<MessageLoopRunner> message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver);
};
@@ -538,6 +543,7 @@ class TitleWatcher : public content::NotificationObserver {
content::WebContents* web_contents_;
std::vector<string16> expected_titles_;
content::NotificationRegistrar notification_registrar_;
+ scoped_refptr<MessageLoopRunner> message_loop_runner_;
// The most recently observed expected title, if any.
string16 observed_title_;
@@ -637,6 +643,7 @@ class DOMMessageQueue : public content::NotificationObserver {
content::NotificationRegistrar registrar_;
std::queue<std::string> message_queue_;
bool waiting_for_message_;
+ scoped_refptr<MessageLoopRunner> message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue);
};
diff --git a/chrome/test/perf/rendering/throughput_tests.cc b/chrome/test/perf/rendering/throughput_tests.cc
index 606fb94..18965ca 100644
--- a/chrome/test/perf/rendering/throughput_tests.cc
+++ b/chrome/test/perf/rendering/throughput_tests.cc
@@ -8,6 +8,7 @@
#include "base/json/json_reader.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
+#include "base/run_loop.h"
#include "base/string_number_conversions.h"
#include "base/stringprintf.h"
#include "base/test/trace_event_analyzer.h"
@@ -195,11 +196,11 @@ class ThroughputTest : public BrowserPerfTest {
}
void Wait(int ms) {
+ base::RunLoop run_loop;
MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- MessageLoop::QuitClosure(),
+ FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromMilliseconds(ms));
- ui_test_utils::RunMessageLoop();
+ ui_test_utils::RunThisRunLoop(&run_loop);
}
// Take snapshot of the current tab, encode it as PNG, and save to a SkBitmap.
@@ -468,13 +469,7 @@ IN_PROC_BROWSER_TEST_F(ThroughputTestGPU, DISABLED_TestURL) {
RunTestWithURL(kAllowExternalDNS);
}
-// crbug.com/124049
-#if defined(OS_MACOSX)
-#define MAYBE_Particles DISABLED_Particles
-#else
-#define MAYBE_Particles Particles
-#endif
-IN_PROC_BROWSER_TEST_F(ThroughputTestGPU, MAYBE_Particles) {
+IN_PROC_BROWSER_TEST_F(ThroughputTestGPU, Particles) {
RunTest("particles", kInternal);
}
@@ -527,13 +522,7 @@ IN_PROC_BROWSER_TEST_F(ThroughputTestSW, CanvasTextSW) {
RunTest("canvas2d_balls_text", kNone);
}
-// crbug.com/124049
-#if defined(OS_MACOSX)
-#define MAYBE_CanvasTextGPU DISABLED_CanvasTextGPU
-#else
-#define MAYBE_CanvasTextGPU CanvasTextGPU
-#endif
-IN_PROC_BROWSER_TEST_F(ThroughputTestGPU, MAYBE_CanvasTextGPU) {
+IN_PROC_BROWSER_TEST_F(ThroughputTestGPU, CanvasTextGPU) {
RunTest("canvas2d_balls_text", kNone | kIsGpuCanvasTest);
}