GN: Tighten up test target visibility + refactorings

Make all rtc_source_test target that contains tests that
are included in a test executable only be visible to the
rtc_test target. Doing this exposed a couple of errors and
dependency problems that were resolved. Having this could
have prevented duplicated execution of tests like the case that
was recently fixed by deadbeef@ in
https://codereview.webrtc.org/2820263004

New targets:
* //webrtc/modules/rtp_rtcp:fec_test_helper
* //webrtc/modules/rtp_rtcp:mock_rtp_rtcp
* //webrtc/modules/remote_bitrate_estimator:mock_remote_bitrate_observer

The mock files and targets should probably be moved into webrtc/test in
the future, but that's out of the scope of this CL.

BUG=webrtc:5716
NOTRY=True

Review-Url: https://codereview.webrtc.org/2828793003
Cr-Commit-Position: refs/heads/master@{#17863}
diff --git a/webrtc/BUILD.gn b/webrtc/BUILD.gn
index 6ed25c4..bde2b86 100644
--- a/webrtc/BUILD.gn
+++ b/webrtc/BUILD.gn
@@ -282,7 +282,6 @@
         ":video_engine_tests",
         ":webrtc_nonparallel_tests",
         ":webrtc_perf_tests",
-        "api:rtc_api_unittests",
         "base:rtc_base_tests_utils",
         "common_audio:common_audio_unittests",
         "common_video:common_video_unittests",
@@ -303,7 +302,6 @@
         "test",
         "video:screenshare_loopback",
         "video:video_loopback",
-        "video:video_tests",
         "voice_engine:voice_engine_unittests",
       ]
       if (is_android) {
@@ -475,7 +473,6 @@
       "modules/remote_bitrate_estimator:remote_bitrate_estimator_perf_tests",
       "test:test_main",
       "video:video_full_stack_tests",
-      "video:video_quality_test",
     ]
 
     data = webrtc_perf_tests_resources
diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn
index fdd441a..b8ad905 100644
--- a/webrtc/api/BUILD.gn
+++ b/webrtc/api/BUILD.gn
@@ -243,6 +243,13 @@
 
   rtc_source_set("rtc_api_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:rtc_unittests" ]
+    }
     sources = [
       "ortc/mediadescription_unittest.cc",
       "ortc/sessiondescription_unittest.cc",
diff --git a/webrtc/audio/BUILD.gn b/webrtc/audio/BUILD.gn
index 0de4229..b3d4e1d 100644
--- a/webrtc/audio/BUILD.gn
+++ b/webrtc/audio/BUILD.gn
@@ -54,6 +54,13 @@
   rtc_source_set("audio_tests") {
     testonly = true
 
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:video_engine_tests" ]
+    }
+
     # TODO(kjellander): Remove (bugs.webrtc.org/6828)
     # This needs remote_bitrate_estimator to be moved to webrtc/api first.
     check_includes = false
diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn
index 2a990e8..6014809 100644
--- a/webrtc/base/BUILD.gn
+++ b/webrtc/base/BUILD.gn
@@ -742,6 +742,13 @@
 
   rtc_source_set("rtc_base_nonparallel_tests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:webrtc_nonparallel_tests" ]
+    }
     sources = [
       "cpu_time_unittest.cc",
       "filerotatingstream_unittest.cc",
@@ -769,6 +776,13 @@
 
   rtc_source_set("rtc_base_approved_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:rtc_unittests" ]
+    }
     sources = [
       "array_view_unittest.cc",
       "atomicops_unittest.cc",
@@ -820,6 +834,13 @@
 
   rtc_source_set("rtc_task_queue_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:rtc_unittests" ]
+    }
     sources = [
       "sequenced_task_checker_unittest.cc",
       "task_queue_unittest.cc",
@@ -837,6 +858,13 @@
 
   rtc_source_set("rtc_numerics_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:rtc_unittests" ]
+    }
     sources = [
       "numerics/exp_filter_unittest.cc",
       "numerics/percentile_filter_unittest.cc",
@@ -854,6 +882,13 @@
   }
   rtc_source_set("rtc_base_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:rtc_unittests" ]
+    }
     sources = [
       "callback_unittest.cc",
       "crc32_unittest.cc",
diff --git a/webrtc/call/BUILD.gn b/webrtc/call/BUILD.gn
index b56b4a2..9cc3c18 100644
--- a/webrtc/call/BUILD.gn
+++ b/webrtc/call/BUILD.gn
@@ -73,6 +73,13 @@
 if (rtc_include_tests) {
   rtc_source_set("call_tests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:video_engine_tests" ]
+    }
     sources = [
       "bitrate_allocator_unittest.cc",
       "bitrate_estimator_tests.cc",
@@ -105,6 +112,13 @@
 
   rtc_source_set("call_perf_tests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:webrtc_perf_tests" ]
+    }
     sources = [
       "call_perf_tests.cc",
       "rampup_tests.cc",
diff --git a/webrtc/modules/audio_coding/BUILD.gn b/webrtc/modules/audio_coding/BUILD.gn
index 9c7e5ee..4a2fdca 100644
--- a/webrtc/modules/audio_coding/BUILD.gn
+++ b/webrtc/modules/audio_coding/BUILD.gn
@@ -1168,6 +1168,13 @@
 
   rtc_source_set("audio_coding_modules_tests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_tests" ]
+    }
     sources = [
       "test/APITest.cc",
       "test/Channel.cc",
@@ -1212,6 +1219,13 @@
 
   rtc_source_set("audio_coding_perf_tests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:webrtc_perf_tests" ]
+    }
     sources = [
       "codecs/opus/opus_complexity_unittest.cc",
       "neteq/test/neteq_performance_unittest.cc",
@@ -2015,6 +2029,12 @@
   rtc_source_set("audio_coding_unittests") {
     testonly = true
 
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "acm2/acm_receiver_unittest.cc",
       "acm2/audio_coding_module_unittest.cc",
diff --git a/webrtc/modules/audio_conference_mixer/BUILD.gn b/webrtc/modules/audio_conference_mixer/BUILD.gn
index 428bcac..fc9904c 100644
--- a/webrtc/modules/audio_conference_mixer/BUILD.gn
+++ b/webrtc/modules/audio_conference_mixer/BUILD.gn
@@ -50,6 +50,13 @@
 if (rtc_include_tests) {
   rtc_source_set("audio_conference_mixer_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "test/audio_conference_mixer_unittest.cc",
     ]
diff --git a/webrtc/modules/audio_device/BUILD.gn b/webrtc/modules/audio_device/BUILD.gn
index da05f5f..1e691fa 100644
--- a/webrtc/modules/audio_device/BUILD.gn
+++ b/webrtc/modules/audio_device/BUILD.gn
@@ -255,6 +255,13 @@
 if (rtc_include_tests) {
   rtc_source_set("audio_device_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "fine_audio_buffer_unittest.cc",
     ]
diff --git a/webrtc/modules/audio_mixer/BUILD.gn b/webrtc/modules/audio_mixer/BUILD.gn
index b38769c..d8acc05 100644
--- a/webrtc/modules/audio_mixer/BUILD.gn
+++ b/webrtc/modules/audio_mixer/BUILD.gn
@@ -66,6 +66,13 @@
 if (rtc_include_tests) {
   rtc_source_set("audio_mixer_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "audio_frame_manipulator_unittest.cc",
       "audio_mixer_impl_unittest.cc",
diff --git a/webrtc/modules/audio_processing/BUILD.gn b/webrtc/modules/audio_processing/BUILD.gn
index 5686dc6..0f6de09 100644
--- a/webrtc/modules/audio_processing/BUILD.gn
+++ b/webrtc/modules/audio_processing/BUILD.gn
@@ -485,6 +485,13 @@
 
   rtc_source_set("audio_processing_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "aec/echo_cancellation_unittest.cc",
       "aec/system_delay_unittest.cc",
@@ -651,6 +658,13 @@
     #  //webrtc/modules:_modules_unittests__library
     check_includes = false
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:webrtc_perf_tests" ]
+    }
     sources = [
       "audio_processing_performance_unittest.cc",
       "level_controller/level_controller_complexity_unittest.cc",
diff --git a/webrtc/modules/bitrate_controller/BUILD.gn b/webrtc/modules/bitrate_controller/BUILD.gn
index 58398f3..33a2886 100644
--- a/webrtc/modules/bitrate_controller/BUILD.gn
+++ b/webrtc/modules/bitrate_controller/BUILD.gn
@@ -46,6 +46,13 @@
 if (rtc_include_tests) {
   rtc_source_set("bitrate_controller_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "bitrate_controller_unittest.cc",
       "send_side_bandwidth_estimation_unittest.cc",
diff --git a/webrtc/modules/congestion_controller/BUILD.gn b/webrtc/modules/congestion_controller/BUILD.gn
index b57d606..647079a 100644
--- a/webrtc/modules/congestion_controller/BUILD.gn
+++ b/webrtc/modules/congestion_controller/BUILD.gn
@@ -62,6 +62,13 @@
 if (rtc_include_tests) {
   rtc_source_set("congestion_controller_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "congestion_controller_unittest.cc",
       "congestion_controller_unittests_helper.cc",
@@ -83,8 +90,8 @@
       "../../test:test_support",
       "../bitrate_controller:bitrate_controller",
       "../pacing:pacing",
+      "../remote_bitrate_estimator:mock_remote_bitrate_observer",
       "../remote_bitrate_estimator:remote_bitrate_estimator",
-      "../remote_bitrate_estimator:remote_bitrate_estimator_unittests",
       "../rtp_rtcp:rtp_rtcp",
       "//testing/gmock",
     ]
diff --git a/webrtc/modules/desktop_capture/BUILD.gn b/webrtc/modules/desktop_capture/BUILD.gn
index 35ca3a4..5854b34 100644
--- a/webrtc/modules/desktop_capture/BUILD.gn
+++ b/webrtc/modules/desktop_capture/BUILD.gn
@@ -35,6 +35,13 @@
 if (rtc_include_tests) {
   rtc_source_set("desktop_capture_modules_tests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_tests" ]
+    }
     sources = []
     deps = []
     if (rtc_desktop_capture_supported) {
@@ -57,6 +64,13 @@
 
   rtc_source_set("desktop_capture_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "blank_detector_desktop_capturer_wrapper_unittest.cc",
       "desktop_and_cursor_composer_unittest.cc",
diff --git a/webrtc/modules/media_file/BUILD.gn b/webrtc/modules/media_file/BUILD.gn
index 32825af..4f8fbbc 100644
--- a/webrtc/modules/media_file/BUILD.gn
+++ b/webrtc/modules/media_file/BUILD.gn
@@ -43,6 +43,13 @@
 if (rtc_include_tests) {
   rtc_source_set("media_file_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "media_file_unittest.cc",
     ]
diff --git a/webrtc/modules/pacing/BUILD.gn b/webrtc/modules/pacing/BUILD.gn
index d1cf656..ce2356e 100644
--- a/webrtc/modules/pacing/BUILD.gn
+++ b/webrtc/modules/pacing/BUILD.gn
@@ -39,6 +39,13 @@
 if (rtc_include_tests) {
   rtc_source_set("pacing_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "alr_detector_unittest.cc",
       "bitrate_prober_unittest.cc",
@@ -52,7 +59,7 @@
       "../../system_wrappers:system_wrappers",
       "../../test:test_support",
       "../rtp_rtcp",
-      "../rtp_rtcp:rtp_rtcp_unittests",
+      "../rtp_rtcp:mock_rtp_rtcp",
       "//testing/gmock",
     ]
 
diff --git a/webrtc/modules/remote_bitrate_estimator/BUILD.gn b/webrtc/modules/remote_bitrate_estimator/BUILD.gn
index 702d3e7..c2e5d31 100644
--- a/webrtc/modules/remote_bitrate_estimator/BUILD.gn
+++ b/webrtc/modules/remote_bitrate_estimator/BUILD.gn
@@ -127,6 +127,13 @@
 
   rtc_source_set("remote_bitrate_estimator_perf_tests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:webrtc_perf_tests" ]
+    }
     sources = [
       "remote_bitrate_estimators_test.cc",
     ]
@@ -144,9 +151,15 @@
 
   rtc_source_set("remote_bitrate_estimator_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "aimd_rate_control_unittest.cc",
-      "include/mock/mock_remote_bitrate_observer.h",
       "inter_arrival_unittest.cc",
       "overuse_detector_unittest.cc",
       "remote_bitrate_estimator_abs_send_time_unittest.cc",
@@ -162,6 +175,7 @@
     ]
     deps = [
       ":bwe_simulator_lib",
+      ":mock_remote_bitrate_observer",
       ":remote_bitrate_estimator",
       "../..:webrtc_common",
       "../../base:rtc_base",
@@ -185,6 +199,17 @@
     }
   }
 
+  rtc_source_set("mock_remote_bitrate_observer") {
+    testonly = true
+    sources = [
+      "include/mock/mock_remote_bitrate_observer.h",
+    ]
+    deps = [
+      ":remote_bitrate_estimator",
+      "../../test:test_support",
+    ]
+  }
+
   rtc_test("bwe_simulations_tests") {
     testonly = true
 
diff --git a/webrtc/modules/rtp_rtcp/BUILD.gn b/webrtc/modules/rtp_rtcp/BUILD.gn
index ec17666..a369218 100644
--- a/webrtc/modules/rtp_rtcp/BUILD.gn
+++ b/webrtc/modules/rtp_rtcp/BUILD.gn
@@ -192,6 +192,25 @@
   }
 }
 
+rtc_source_set("fec_test_helper") {
+  testonly = true
+  sources = [
+    "source/fec_test_helper.cc",
+    "source/fec_test_helper.h",
+  ]
+  deps = [
+    ":rtp_rtcp",
+    "../../base:rtc_base_approved",
+  ]
+
+  # TODO(jschuh): bugs.webrtc.org/1348: fix this warning.
+  configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
+  if (!build_with_chromium && is_clang) {
+    # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
+    suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
+  }
+}
+
 if (rtc_include_tests) {
   rtc_executable("test_packet_masks_metrics") {
     testonly = true
@@ -210,6 +229,13 @@
 
   rtc_source_set("rtp_rtcp_modules_tests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_tests" ]
+    }
     sources = [
       "test/testFec/test_fec.cc",
     ]
@@ -224,13 +250,29 @@
     }
   }
 
-  rtc_source_set("rtp_rtcp_unittests") {
+  rtc_source_set("mock_rtp_rtcp") {
     testonly = true
     sources = [
       "mocks/mock_rtp_rtcp.h",
+    ]
+    deps = [
+      ":rtp_rtcp",
+      "../../base:rtc_base_approved",
+      "../../test:test_support",
+    ]
+  }
+
+  rtc_source_set("rtp_rtcp_unittests") {
+    testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
+    sources = [
       "source/byte_io_unittest.cc",
-      "source/fec_test_helper.cc",
-      "source/fec_test_helper.h",
       "source/flexfec_header_reader_writer_unittest.cc",
       "source/flexfec_receiver_unittest.cc",
       "source/flexfec_sender_unittest.cc",
@@ -291,6 +333,8 @@
       "test/testAPI/test_api_video.cc",
     ]
     deps = [
+      ":fec_test_helper",
+      ":mock_rtp_rtcp",
       ":rtp_rtcp",
       "../..:webrtc_common",
       "../../api:transport_api",
diff --git a/webrtc/modules/utility/BUILD.gn b/webrtc/modules/utility/BUILD.gn
index ae042d4..3d32ac2 100644
--- a/webrtc/modules/utility/BUILD.gn
+++ b/webrtc/modules/utility/BUILD.gn
@@ -42,6 +42,13 @@
 if (rtc_include_tests) {
   rtc_source_set("utility_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "source/process_thread_impl_unittest.cc",
     ]
diff --git a/webrtc/modules/video_coding/BUILD.gn b/webrtc/modules/video_coding/BUILD.gn
index 9b611bb..821e396 100644
--- a/webrtc/modules/video_coding/BUILD.gn
+++ b/webrtc/modules/video_coding/BUILD.gn
@@ -379,6 +379,12 @@
   rtc_source_set("video_coding_modules_tests") {
     testonly = true
 
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_tests" ]
+    }
     sources = [
       "codecs/h264/test/h264_impl_unittest.cc",
       "codecs/test/videoprocessor_integrationtest.cc",
@@ -479,6 +485,13 @@
 
   rtc_source_set("video_coding_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "codecs/test/packet_manipulator_unittest.cc",
       "codecs/test/stats_unittest.cc",
diff --git a/webrtc/modules/video_processing/BUILD.gn b/webrtc/modules/video_processing/BUILD.gn
index e43c88c..7c9391a 100644
--- a/webrtc/modules/video_processing/BUILD.gn
+++ b/webrtc/modules/video_processing/BUILD.gn
@@ -98,6 +98,13 @@
 if (rtc_include_tests) {
   rtc_source_set("video_processing_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/modules:modules_unittests" ]
+    }
     sources = [
       "test/denoiser_test.cc",
     ]
diff --git a/webrtc/p2p/BUILD.gn b/webrtc/p2p/BUILD.gn
index e4770cc..f7d5905 100644
--- a/webrtc/p2p/BUILD.gn
+++ b/webrtc/p2p/BUILD.gn
@@ -165,6 +165,13 @@
 
   rtc_source_set("rtc_p2p_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:rtc_unittests" ]
+    }
     sources = [
       "base/asyncstuntcpsocket_unittest.cc",
       "base/dtlstransportchannel_unittest.cc",
@@ -238,6 +245,13 @@
 if (rtc_include_tests) {
   rtc_source_set("libstunprober_unittests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:rtc_unittests" ]
+    }
     sources = [
       "stunprober/stunprober_unittest.cc",
     ]
diff --git a/webrtc/sdk/BUILD.gn b/webrtc/sdk/BUILD.gn
index 721580d..a352f9c 100644
--- a/webrtc/sdk/BUILD.gn
+++ b/webrtc/sdk/BUILD.gn
@@ -263,6 +263,13 @@
   if (rtc_include_tests) {
     rtc_source_set("rtc_sdk_peerconnection_objc_unittests") {
       testonly = true
+
+      # Skip restricting visibility on mobile platforms since the tests on those
+      # gets additional generated targets which would require many lines here to
+      # cover (which would be confusing to read and hard to maintain).
+      if (!is_android && !is_ios) {
+        visibility = [ "//webrtc:rtc_unittests" ]
+      }
       sources = [
         "objc/Framework/UnitTests/RTCConfigurationTest.mm",
         "objc/Framework/UnitTests/RTCDataChannelConfigurationTest.mm",
diff --git a/webrtc/test/BUILD.gn b/webrtc/test/BUILD.gn
index 36f3ba2..d7c1f8a 100644
--- a/webrtc/test/BUILD.gn
+++ b/webrtc/test/BUILD.gn
@@ -308,6 +308,7 @@
 }
 rtc_source_set("fileutils_unittests") {
   testonly = true
+  visibility = [ ":*" ]  # Only targets in this file can depend on this.
   sources = [
     "testsupport/fileutils_unittest.cc",
   ]
diff --git a/webrtc/test/fuzzers/BUILD.gn b/webrtc/test/fuzzers/BUILD.gn
index 031ed8b..74ea607 100644
--- a/webrtc/test/fuzzers/BUILD.gn
+++ b/webrtc/test/fuzzers/BUILD.gn
@@ -82,7 +82,7 @@
     "flexfec_header_reader_fuzzer.cc",
   ]
   deps = [
-    "../../modules/rtp_rtcp/",
+    "../../modules/rtp_rtcp",
   ]
 }
 
@@ -91,7 +91,7 @@
     "flexfec_sender_fuzzer.cc",
   ]
   deps = [
-    "../../modules/rtp_rtcp/",
+    "../../modules/rtp_rtcp",
   ]
   libfuzzer_options = [ "max_len=200" ]
 }
@@ -101,7 +101,8 @@
     "ulpfec_header_reader_fuzzer.cc",
   ]
   deps = [
-    "../../modules/rtp_rtcp/",
+    "../../modules/rtp_rtcp",
+    "../../modules/rtp_rtcp:fec_test_helper",
   ]
 }
 
@@ -110,7 +111,9 @@
     "ulpfec_generator_fuzzer.cc",
   ]
   deps = [
-    "../../modules/rtp_rtcp/",
+    "../../base:rtc_base_approved",
+    "../../modules/rtp_rtcp",
+    "../../modules/rtp_rtcp:fec_test_helper",
   ]
 }
 
@@ -119,7 +122,7 @@
     "flexfec_receiver_fuzzer.cc",
   ]
   deps = [
-    "../../modules/rtp_rtcp/",
+    "../../modules/rtp_rtcp",
   ]
   libfuzzer_options = [ "max_len=2000" ]
 }
@@ -139,7 +142,7 @@
     "rtcp_receiver_fuzzer.cc",
   ]
   deps = [
-    "../../modules/rtp_rtcp/",
+    "../../modules/rtp_rtcp",
   ]
   seed_corpus = "corpora/rtcp-corpus"
 }
@@ -149,7 +152,7 @@
     "rtp_packet_fuzzer.cc",
   ]
   deps = [
-    "../../modules/rtp_rtcp/",
+    "../../modules/rtp_rtcp",
   ]
   seed_corpus = "corpora/rtp-corpus"
 }
@@ -159,7 +162,7 @@
     "rtp_header_fuzzer.cc",
   ]
   deps = [
-    "../../modules/rtp_rtcp/",
+    "../../modules/rtp_rtcp",
   ]
 }
 
diff --git a/webrtc/tools/network_tester/BUILD.gn b/webrtc/tools/network_tester/BUILD.gn
index 1e290f6..5fd3ac9 100644
--- a/webrtc/tools/network_tester/BUILD.gn
+++ b/webrtc/tools/network_tester/BUILD.gn
@@ -68,11 +68,18 @@
   }
 
   rtc_source_set("network_tester_unittests") {
+    testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc/tools:tools_unittests" ]
+    }
     sources = [
       "network_tester_unittest.cc",
     ]
 
-    testonly = true
     deps = [
       ":network_tester",
       "//testing/gtest",
diff --git a/webrtc/video/BUILD.gn b/webrtc/video/BUILD.gn
index 52afc93..20b5d10 100644
--- a/webrtc/video/BUILD.gn
+++ b/webrtc/video/BUILD.gn
@@ -82,6 +82,7 @@
 if (rtc_include_tests) {
   rtc_source_set("video_quality_test") {
     testonly = true
+    visibility = [ ":*" ]  # Only targets in this file can depend on this.
     sources = [
       "video_quality_test.cc",
       "video_quality_test.h",
@@ -114,6 +115,13 @@
 
   rtc_source_set("video_full_stack_tests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:webrtc_perf_tests" ]
+    }
     sources = [
       "full_stack_tests.cc",
     ]
@@ -213,6 +221,13 @@
   # TODO(pbos): Rename test suite.
   rtc_source_set("video_tests") {
     testonly = true
+
+    # Skip restricting visibility on mobile platforms since the tests on those
+    # gets additional generated targets which would require many lines here to
+    # cover (which would be confusing to read and hard to maintain).
+    if (!is_android && !is_ios) {
+      visibility = [ "//webrtc:video_engine_tests" ]
+    }
     defines = []
     sources = [
       "call_stats_unittest.cc",
@@ -245,7 +260,7 @@
       "../media:rtc_media_tests_utils",
       "../modules/pacing",
       "../modules/rtp_rtcp",
-      "../modules/rtp_rtcp:rtp_rtcp_unittests",
+      "../modules/rtp_rtcp:mock_rtp_rtcp",
       "../modules/utility",
       "../modules/video_coding",
       "../modules/video_coding:video_coding_utility",