tor-browser

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

mock_task_queue.h (1790B)


      1 /*
      2 *  Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #ifndef AUDIO_VOIP_TEST_MOCK_TASK_QUEUE_H_
     12 #define AUDIO_VOIP_TEST_MOCK_TASK_QUEUE_H_
     13 
     14 #include <memory>
     15 
     16 #include "absl/strings/string_view.h"
     17 #include "api/task_queue/task_queue_base.h"
     18 #include "api/task_queue/task_queue_factory.h"
     19 #include "api/task_queue/test/mock_task_queue_base.h"
     20 
     21 namespace webrtc {
     22 
     23 // MockTaskQueue enables immediate task run from global TaskQueueBase.
     24 // It's necessary for some tests depending on TaskQueueBase internally.
     25 class MockTaskQueue : public MockTaskQueueBase {
     26 public:
     27  MockTaskQueue() : current_(this) {}
     28 
     29  // Delete is deliberately defined as no-op as MockTaskQueue is expected to
     30  // hold onto current global TaskQueueBase throughout the testing.
     31  void Delete() override {}
     32 
     33 private:
     34  CurrentTaskQueueSetter current_;
     35 };
     36 
     37 class MockTaskQueueFactory : public TaskQueueFactory {
     38 public:
     39  explicit MockTaskQueueFactory(MockTaskQueue* task_queue)
     40      : task_queue_(task_queue) {}
     41 
     42  std::unique_ptr<TaskQueueBase, TaskQueueDeleter> CreateTaskQueue(
     43      absl::string_view /* name */,
     44      Priority /* priority */) const override {
     45    // Default MockTaskQueue::Delete is no-op, therefore it's safe to pass the
     46    // raw pointer.
     47    return std::unique_ptr<TaskQueueBase, TaskQueueDeleter>(task_queue_);
     48  }
     49 
     50 private:
     51  MockTaskQueue* task_queue_;
     52 };
     53 
     54 }  // namespace webrtc
     55 
     56 #endif  // AUDIO_VOIP_TEST_MOCK_TASK_QUEUE_H_