tor-browser

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

mock_local_network_access_permission.h (2187B)


      1 /*
      2 *  Copyright 2025 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 API_TEST_MOCK_LOCAL_NETWORK_ACCESS_PERMISSION_H_
     12 #define API_TEST_MOCK_LOCAL_NETWORK_ACCESS_PERMISSION_H_
     13 
     14 #include <memory>
     15 
     16 #include "absl/functional/any_invocable.h"
     17 #include "api/local_network_access_permission.h"
     18 #include "rtc_base/socket_address.h"
     19 #include "test/gmock.h"
     20 
     21 namespace webrtc {
     22 
     23 class MockLocalNetworkAccessPermission
     24    : public LocalNetworkAccessPermissionInterface {
     25 public:
     26  MOCK_METHOD(bool,
     27              ShouldRequestPermission,
     28              (const SocketAddress& addr),
     29              (override));
     30 
     31  MOCK_METHOD(
     32      void,
     33      RequestPermission,
     34      (const SocketAddress& addr,
     35       absl::AnyInvocable<void(LocalNetworkAccessPermissionStatus)> callback),
     36      (override));
     37 };
     38 
     39 class MockLocalNetworkAccessPermissionFactory
     40    : public LocalNetworkAccessPermissionFactoryInterface {
     41 public:
     42  MOCK_METHOD(std::unique_ptr<LocalNetworkAccessPermissionInterface>,
     43              Create,
     44              (),
     45              (override));
     46 };
     47 
     48 // Class that returns LocalNetworkAccessPermission's that run their callback
     49 // with the provided status.
     50 class FakeLocalNetworkAccessPermissionFactory
     51    : public MockLocalNetworkAccessPermissionFactory {
     52 public:
     53  enum class Result {
     54    // Use when the permission is not needed i.e. ShouldRequestPermission will
     55    // return false.
     56    kPermissionNotNeeded,
     57    // Use when the permission is needed i.e. ShouldRequestPermission will
     58    // return true, and RequestPermission will return kGranted/kDenied
     59    // respectively.
     60    kPermissionGranted,
     61    kPermissionDenied,
     62  };
     63 
     64  explicit FakeLocalNetworkAccessPermissionFactory(Result result);
     65  ~FakeLocalNetworkAccessPermissionFactory() override;
     66 };
     67 
     68 }  // namespace webrtc
     69 
     70 #endif  // API_TEST_MOCK_LOCAL_NETWORK_ACCESS_PERMISSION_H_