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

Unified Diff: remoting/jingle_glue/jingle_thread_unittest.cc

Issue 9086002: base::Bind: Remove Task. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style fix. Created 8 years, 12 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/base/plugin_message_loop_proxy.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/jingle_glue/jingle_thread_unittest.cc
diff --git a/remoting/jingle_glue/jingle_thread_unittest.cc b/remoting/jingle_glue/jingle_thread_unittest.cc
index 287af056eb007ae5271a3f96b04cc202dadb4c56..8142482b87721321235a0e50cde8687dbebeecf3 100644
--- a/remoting/jingle_glue/jingle_thread_unittest.cc
+++ b/remoting/jingle_glue/jingle_thread_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/message_loop.h"
#include "base/time.h"
#include "base/synchronization/waitable_event.h"
@@ -11,35 +13,39 @@
namespace remoting {
-class MockTask : public Task {
+class MockCallback {
public:
MOCK_METHOD0(Run, void());
};
namespace {
+
// Delay used to test delayed tasks. Shouldn't be too big, so that we don't
// slow down the test, yet, should be big enough to be measurable.
int kDelayMs = 50; // 0.05 s.
int kDelayTimeoutMs = 10000; // 10 s.
+
} // namespace
TEST(JingleThreadTest, PostTask) {
JingleThread thread;
- MockTask* task = new MockTask();
- EXPECT_CALL(*task, Run());
+ MockCallback task;
+ EXPECT_CALL(task, Run());
thread.Start();
- thread.message_loop()->PostTask(FROM_HERE, task);
+ thread.message_loop()->PostTask(
+ FROM_HERE, base::Bind(&MockCallback::Run, base::Unretained(&task)));
thread.Stop();
}
TEST(JingleThreadTest, PostNonNestableTask) {
JingleThread thread;
- MockTask* task = new MockTask();
- EXPECT_CALL(*task, Run());
+ MockCallback task;
+ EXPECT_CALL(task, Run());
thread.Start();
- thread.message_loop()->PostNonNestableTask(FROM_HERE, task);
+ thread.message_loop()->PostNonNestableTask(
+ FROM_HERE, base::Bind(&MockCallback::Run, base::Unretained(&task)));
thread.Stop();
}
@@ -49,13 +55,15 @@ ACTION_P(SignalEvent, event) {
TEST(JingleThreadTest, PostDelayedTask) {
JingleThread thread;
- MockTask* task = new MockTask();
+ MockCallback task;
base::WaitableEvent event(true, false);
- EXPECT_CALL(*task, Run()).WillOnce(SignalEvent(&event));
+ EXPECT_CALL(task, Run()).WillOnce(SignalEvent(&event));
thread.Start();
base::Time start = base::Time::Now();
- thread.message_loop()->PostDelayedTask(FROM_HERE, task, kDelayMs);
+ thread.message_loop()->PostDelayedTask(
+ FROM_HERE, base::Bind(&MockCallback::Run, base::Unretained(&task)),
+ kDelayMs);
event.TimedWait(base::TimeDelta::FromMilliseconds(kDelayTimeoutMs));
base::Time end = base::Time::Now();
thread.Stop();
@@ -65,13 +73,15 @@ TEST(JingleThreadTest, PostDelayedTask) {
TEST(JingleThreadTest, PostNonNestableDelayedTask) {
JingleThread thread;
- MockTask* task = new MockTask();
+ MockCallback task;
base::WaitableEvent event(true, false);
- EXPECT_CALL(*task, Run()).WillOnce(SignalEvent(&event));
+ EXPECT_CALL(task, Run()).WillOnce(SignalEvent(&event));
thread.Start();
base::Time start = base::Time::Now();
- thread.message_loop()->PostNonNestableDelayedTask(FROM_HERE, task, kDelayMs);
+ thread.message_loop()->PostNonNestableDelayedTask(
+ FROM_HERE, base::Bind(&MockCallback::Run, base::Unretained(&task)),
+ kDelayMs);
event.TimedWait(base::TimeDelta::FromMilliseconds(kDelayTimeoutMs));
base::Time end = base::Time::Now();
thread.Stop();
« no previous file with comments | « remoting/base/plugin_message_loop_proxy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698