tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TestWebrtcTaskQueueWrapper.cpp (2085B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      6 
      7 #include "WebrtcTaskQueueWrapper.h"
      8 #include "gmock/gmock.h"
      9 #include "gtest/gtest.h"
     10 #include "mozilla/TaskQueue.h"
     11 #include "nsThreadUtils.h"
     12 
     13 using testing::InSequence;
     14 using testing::MockFunction;
     15 
     16 namespace mozilla {
     17 
     18 RefPtr<TaskQueue> MakeTestWebrtcTaskQueueWrapper() {
     19  return CreateWebrtcTaskQueueWrapper(do_AddRef(GetCurrentSerialEventTarget()),
     20                                      "TestWebrtcTaskQueueWrapper"_ns, true);
     21 }
     22 
     23 TEST(TestWebrtcTaskQueueWrapper, TestCurrent)
     24 {
     25  auto wt = MakeTestWebrtcTaskQueueWrapper();
     26 
     27  MockFunction<void(int)> checkpoint;
     28  {
     29    InSequence s;
     30    EXPECT_CALL(checkpoint, Call(1));
     31    EXPECT_CALL(checkpoint, Call(2));
     32  }
     33 
     34  EXPECT_TRUE(NS_SUCCEEDED(wt->Dispatch(NS_NewRunnableFunction(__func__, [&] {
     35    checkpoint.Call(2);
     36    EXPECT_TRUE(wt->IsCurrentThreadIn());
     37  }))));
     38  checkpoint.Call(1);
     39  NS_ProcessPendingEvents(nullptr);
     40 }
     41 
     42 TEST(TestWebrtcTaskQueueWrapper, TestDispatchDirectTask)
     43 {
     44  auto wt = MakeTestWebrtcTaskQueueWrapper();
     45 
     46  MockFunction<void(int)> checkpoint;
     47  {
     48    InSequence s;
     49    EXPECT_CALL(checkpoint, Call(1));
     50    EXPECT_CALL(checkpoint, Call(2));
     51    EXPECT_CALL(checkpoint, Call(3));
     52    EXPECT_CALL(checkpoint, Call(4));
     53  }
     54 
     55  EXPECT_TRUE(NS_SUCCEEDED(wt->Dispatch(NS_NewRunnableFunction(__func__, [&] {
     56    checkpoint.Call(2);
     57    AbstractThread::DispatchDirectTask(
     58        NS_NewRunnableFunction("TestDispatchDirectTask Inner", [&] {
     59          checkpoint.Call(3);
     60          EXPECT_TRUE(wt->IsCurrentThreadIn());
     61        }));
     62  }))));
     63 
     64  EXPECT_TRUE(NS_SUCCEEDED(wt->Dispatch(NS_NewRunnableFunction(__func__, [&] {
     65    checkpoint.Call(4);
     66    EXPECT_TRUE(wt->IsCurrentThreadIn());
     67  }))));
     68  checkpoint.Call(1);
     69  NS_ProcessPendingEvents(nullptr);
     70 }
     71 
     72 }  // namespace mozilla