tor-browser

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

mock_local_network_access_permission.cc (2085B)


      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 #include "api/test/mock_local_network_access_permission.h"
     12 
     13 #include <memory>
     14 #include <utility>
     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 "rtc_base/thread.h"
     20 #include "test/gmock.h"
     21 #include "test/gtest.h"
     22 
     23 using ::testing::_;
     24 
     25 namespace webrtc {
     26 
     27 FakeLocalNetworkAccessPermissionFactory::
     28    FakeLocalNetworkAccessPermissionFactory(Result result) {
     29  EXPECT_CALL(*this, Create()).WillRepeatedly([result]() {
     30    auto mock_lna_permission =
     31        std::make_unique<MockLocalNetworkAccessPermission>();
     32    EXPECT_CALL(*mock_lna_permission, ShouldRequestPermission(_))
     33        .WillRepeatedly(
     34            ::testing::Return(result != Result::kPermissionNotNeeded));
     35    if (result != Result::kPermissionNotNeeded) {
     36      EXPECT_CALL(*mock_lna_permission, RequestPermission(_, _))
     37          .WillRepeatedly(
     38              [result](
     39                  const SocketAddress& /* addr */,
     40                  absl::AnyInvocable<void(
     41                      webrtc::LocalNetworkAccessPermissionStatus)> callback) {
     42                Thread::Current()->PostTask([callback = std::move(callback),
     43                                             result]() mutable {
     44                  callback(result == Result::kPermissionGranted
     45                               ? LocalNetworkAccessPermissionStatus::kGranted
     46                               : LocalNetworkAccessPermissionStatus::kDenied);
     47                });
     48              });
     49    }
     50    return mock_lna_permission;
     51  });
     52 }
     53 
     54 FakeLocalNetworkAccessPermissionFactory::
     55    ~FakeLocalNetworkAccessPermissionFactory() = default;
     56 
     57 }  // namespace webrtc