Introduce TaskQueueForTest.

This class adds a convenience method that allows *sending* a task
to the queue (as opposed to posting). Sending is essentially
Post+Wait, a pattern that we don't want to encourage use of
in production code, but is convenient to have from a testing
perspective and there are already several places in the
source code where we use it.

Change-Id: I6efd1b2257e6c641294bb6e4eb53b0021d9553ca
Bug: webrtc:8848
Reviewed-on: https://webrtc-review.googlesource.com/50441
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22022}
diff --git a/rtc_base/task_queue_unittest.cc b/rtc_base/task_queue_unittest.cc
index d70a5fb..51956d2 100644
--- a/rtc_base/task_queue_unittest.cc
+++ b/rtc_base/task_queue_unittest.cc
@@ -21,10 +21,13 @@
 #include "rtc_base/bind.h"
 #include "rtc_base/event.h"
 #include "rtc_base/gunit.h"
-#include "rtc_base/task_queue.h"
+#include "rtc_base/task_queue_for_test.h"
 #include "rtc_base/timeutils.h"
 
+using rtc::test::TaskQueueForTest;
+
 namespace rtc {
+
 namespace {
 // Noop on all platforms except Windows, where it turns on high precision
 // multimedia timers which increases the precision of TimeMillis() while in
@@ -44,9 +47,7 @@
   const bool enabled_;
 #endif
 };
-}
 
-namespace {
 void CheckCurrent(Event* signal, TaskQueue* queue) {
   EXPECT_TRUE(queue->IsCurrent());
   if (signal)
@@ -76,34 +77,31 @@
 
 TEST(TaskQueueTest, PostCustomTask) {
   static const char kQueueName[] = "PostCustomImplementation";
-  Event event(false, false);
-  TaskQueue queue(kQueueName);
+  TaskQueueForTest queue(kQueueName);
 
   class CustomTask : public QueuedTask {
    public:
-    explicit CustomTask(Event* event) : event_(event) {}
+    CustomTask() {}
+    bool ran() const { return ran_; }
 
    private:
     bool Run() override {
-      event_->Set();
-      return false;  // Never allows the task to be deleted by the queue.
+      ran_ = true;
+      return false;  // Never allow the task to be deleted by the queue.
     }
 
-    Event* const event_;
-  } my_task(&event);
+    bool ran_ = false;
+  } my_task;
 
-  // Please don't do this in production code! :)
-  queue.PostTask(std::unique_ptr<QueuedTask>(&my_task));
-  EXPECT_TRUE(event.Wait(1000));
+  queue.SendTask(&my_task);
+  EXPECT_TRUE(my_task.ran());
 }
 
 TEST(TaskQueueTest, PostLambda) {
-  static const char kQueueName[] = "PostLambda";
-  Event event(false, false);
-  TaskQueue queue(kQueueName);
-
-  queue.PostTask([&event]() { event.Set(); });
-  EXPECT_TRUE(event.Wait(1000));
+  TaskQueueForTest queue("PostLambda");
+  bool ran = false;
+  queue.SendTask([&ran]() { ran = true; });
+  EXPECT_TRUE(ran);
 }
 
 TEST(TaskQueueTest, PostDelayedZero) {