GN: Add rtc_media_unittests

Changes:
* Set WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE on a global scope
  to match GYP.
* Enable sctpdataengine_unittest.cc for iOS, which should have
  been done in https://codereview.webrtc.org/1587193006
* Renamed GN target rtc_base_test_utils -> rtc_base_tests_utils
  to match GYP.
* Added dependencies on call, modules/video_coding and video for
  rtc_media.
* Added dependency on audio for rtc_media_unitttests (couldn't be
  added to rtc_media due to circular dependency problem).

BUG=webrtc:5949
TESTED=Built and ran the tests on Mac.
NOTRY=True

Review-Url: https://codereview.webrtc.org/2050313002
Cr-Original-Commit-Position: refs/heads/master@{#13106}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 82a94494b1fc211a9b9e0256fc207b012357f191
diff --git a/BUILD.gn b/BUILD.gn
index e2eeb7f..02a16d1 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -104,6 +104,10 @@
     defines += [ "WEBRTC_RESTRICT_LOGGING" ]
   }
 
+  if (rtc_include_internal_audio_device) {
+    defines += [ "WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE" ]
+  }
+
   if (rtc_have_dbus_glib) {
     defines += [ "HAVE_DBUS_GLIB" ]
 
@@ -424,8 +428,6 @@
       "base/event_tracer_unittest.cc",
       "base/event_unittest.cc",
       "base/exp_filter_unittest.cc",
-      "base/fakeclock.cc",
-      "base/fakeclock.h",
       "base/filerotatingstream_unittest.cc",
       "base/fileutils_unittest.cc",
       "base/helpers_unittest.cc",
@@ -476,7 +478,6 @@
       "base/testclient_unittest.cc",
       "base/thread_checker_unittest.cc",
       "base/thread_unittest.cc",
-      "base/timedelta.h",
       "base/timeutils_unittest.cc",
       "base/urlencode_unittest.cc",
       "base/versionparsing_unittest.cc",
@@ -567,7 +568,7 @@
 
     deps = [
       "base:rtc_base",
-      "base:rtc_base_test_utils",
+      "base:rtc_base_tests_utils",
       "base:rtc_task_queue",
       "p2p:libstunprober",
       "p2p:rtc_p2p",
diff --git a/base/BUILD.gn b/base/BUILD.gn
index 46c66a1..07678bf 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -641,15 +641,17 @@
 }
 
 if (rtc_include_tests) {
-  config("rtc_base_test_utils_exported_config") {
+  config("rtc_base_tests_utils_exported_config") {
     defines = [ "GTEST_RELATIVE_PATH" ]
   }
 
-  source_set("rtc_base_test_utils") {
+  source_set("rtc_base_tests_utils") {
     testonly = true
     sources = [
       # Also use this as a convenient dumping ground for misc files that are
       # included by multiple targets below.
+      "fakeclock.cc",
+      "fakeclock.h",
       "fakenetwork.h",
       "fakesslidentity.h",
       "faketaskrunner.h",
@@ -657,12 +659,13 @@
       "testbase64.h",
       "testechoserver.h",
       "testutils.h",
+      "timedelta.h",
       "unittest_main.cc",
     ]
     configs += [ "..:common_config" ]
     public_configs = [
       "..:common_inherited_config",
-      ":rtc_base_test_utils_exported_config",
+      ":rtc_base_tests_utils_exported_config",
     ]
     deps = [
       ":rtc_base",
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 2d97312..34e8155 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -8,6 +8,7 @@
 
 import("//build/config/linux/pkg_config.gni")
 import("../build/webrtc.gni")
+import("//testing/test.gni")
 
 group("media") {
   deps = [
@@ -123,10 +124,11 @@
   public_configs = [ "..:common_inherited_config" ]
 
   if (is_clang) {
-    # Suppress warnings from Chrome's Clang plugins.
-    # See http://code.google.com/p/webrtc/issues/detail?id=163 for details.
-    configs -= [ "//build/config/clang:extra_warnings" ]
-    configs -= [ "//build/config/clang:find_bad_constructs" ]
+    # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
+    configs -= [
+      "//build/config/clang:extra_warnings",
+      "//build/config/clang:find_bad_constructs",
+    ]
   }
 
   if (is_win) {
@@ -159,7 +161,6 @@
   if (build_with_chromium) {
     deps += [ "../modules/video_capture:video_capture" ]
   } else {
-    configs += [ ":rtc_media_defines_config" ]
     public_configs += [ ":rtc_media_defines_config" ]
     deps += [ "../modules/video_capture:video_capture_internal_impl" ]
   }
@@ -195,10 +196,166 @@
   deps += [
     "..:webrtc_common",
     "../base:rtc_base_approved",
+    "../call",
     "../libjingle/xmllite",
     "../libjingle/xmpp",
+    "../modules/video_coding",
     "../p2p",
     "../system_wrappers",
+    "../video",
     "../voice_engine",
   ]
 }
+
+if (rtc_include_tests) {
+  config("rtc_unittest_main_config") {
+    # GN orders flags on a target before flags from configs. The default config
+    # adds -Wall, and this flag have to be after -Wall -- so they need to
+    # come from a config and can"t be on the target directly.
+    if (is_clang && is_ios) {
+      cflags = [ "-Wno-unused-variable" ]
+    }
+  }
+
+  source_set("rtc_unittest_main") {
+    testonly = true
+
+    deps = []
+    sources = [
+      "base/fakemediaengine.h",
+      "base/fakenetworkinterface.h",
+      "base/fakertp.h",
+      "base/fakevideocapturer.h",
+      "base/fakevideorenderer.h",
+      "base/testutils.cc",
+      "base/testutils.h",
+      "engine/fakewebrtccall.cc",
+      "engine/fakewebrtccall.h",
+      "engine/fakewebrtccommon.h",
+      "engine/fakewebrtcdeviceinfo.h",
+      "engine/fakewebrtcvcmfactory.h",
+      "engine/fakewebrtcvideocapturemodule.h",
+      "engine/fakewebrtcvideoengine.h",
+      "engine/fakewebrtcvoiceengine.h",
+    ]
+
+    configs += [
+      "..:common_config",
+      ":rtc_unittest_main_config",
+    ]
+    public_configs = [ "..:common_inherited_config" ]
+
+    if (rtc_build_libyuv) {
+      deps += [ "$rtc_libyuv_dir" ]
+      public_deps = [
+        "$rtc_libyuv_dir",
+      ]
+    } else {
+      # Need to add a directory normally exported by libyuv.
+      include_dirs += [ "$rtc_libyuv_dir/include" ]
+    }
+
+    if (is_clang) {
+      # Suppress warnings from the Chromium Clang plugin.
+      # See http://code.google.com/p/webrtc/issues/detail?id=163 for details.
+      configs -= [ "//build/config/clang:find_bad_constructs" ]
+    }
+
+    deps += [
+      "../base:rtc_base_tests_utils",
+      "//testing/gtest",
+    ]
+    public_deps += [ "//testing/gmock" ]
+  }
+
+  config("rtc_media_unittests_config") {
+    # GN orders flags on a target before flags from configs. The default config
+    # adds -Wall, and this flag have to be after -Wall -- so they need to
+    # come from a config and can"t be on the target directly.
+    # TODO(kjellander): Make the code compile without disabling these flags.
+    # See https://bugs.webrtc.org/3307.
+    if (is_clang && is_win) {
+      cflags += [ "-Wno-unused-function" ]
+    }
+    if (!is_win) {
+      cflags = [ "-Wno-sign-compare" ]
+      cflags_cc = [ "-Wno-overloaded-virtual" ]
+    }
+  }
+
+  test("rtc_media_unittests") {
+    testonly = true
+
+    deps = []
+    sources = [
+      "base/codec_unittest.cc",
+      "base/rtpdataengine_unittest.cc",
+      "base/rtpdump_unittest.cc",
+      "base/rtputils_unittest.cc",
+      "base/streamparams_unittest.cc",
+      "base/turnutils_unittest.cc",
+      "base/videoadapter_unittest.cc",
+      "base/videobroadcaster_unittest.cc",
+      "base/videocapturer_unittest.cc",
+      "base/videocommon_unittest.cc",
+      "base/videoengine_unittest.h",
+      "base/videoframe_unittest.h",
+      "engine/nullwebrtcvideoengine_unittest.cc",
+      "engine/simulcast_unittest.cc",
+      "engine/webrtcmediaengine_unittest.cc",
+      "engine/webrtcvideocapturer_unittest.cc",
+      "engine/webrtcvideoengine2_unittest.cc",
+      "engine/webrtcvideoframe_unittest.cc",
+      "engine/webrtcvideoframefactory_unittest.cc",
+      "engine/webrtcvoiceengine_unittest.cc",
+      "sctp/sctpdataengine_unittest.cc",
+    ]
+
+    configs += [
+      "..:common_config",
+      ":rtc_media_unittests_config",
+    ]
+    public_configs = [ "..:common_inherited_config" ]
+
+    if (is_win) {
+      cflags = [
+        "/wd4245",  # conversion from int to size_t, signed/unsigned mismatch.
+        "/wd4373",  # virtual function override.
+        "/wd4389",  # signed/unsigned mismatch.
+      ]
+    }
+
+    if (is_clang) {
+      # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
+      configs -= [
+        "//build/config/clang:extra_warnings",
+        "//build/config/clang:find_bad_constructs",
+      ]
+    }
+
+    if (is_android) {
+      deps += [ "//testing/android/native_test:native_test_support" ]
+
+      # This needs to be kept in sync with the rtc_media_unittests.isolate file.
+      # TODO(kjellander); Move this to android_assets targets instead.
+      data = [
+        "//resources/media/captured-320x240-2s-48.frames",
+        "//resources/media/faces.1280x720_P420.yuv",
+        "//resources/media/faces_I420.jpg",
+        "//resources/media/faces_I422.jpg",
+        "//resources/media/faces_I444.jpg",
+        "//resources/media/faces_I411.jpg",
+        "//resources/media/faces_I400.jpg",
+      ]
+    }
+
+    deps += [
+      # TODO(kjellander): Move as part of work in bugs.webrtc.org/4243.
+      ":rtc_media",
+      ":rtc_unittest_main",
+      "../audio",
+      "../base:rtc_base_tests_utils",
+      "../system_wrappers:metrics_default",
+    ]
+  }
+}
diff --git a/media/media.gyp b/media/media.gyp
index 58b55bd..691bb1e 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -323,9 +323,6 @@
               },
             }],
             ['OS=="ios"', {
-              'sources!': [
-                'sctp/sctpdataengine_unittest.cc',
-              ],
               'mac_bundle_resources': [
                 '<(DEPTH)/resources/media/captured-320x240-2s-48.frames',
                 '<(DEPTH)/resources/media/faces.1280x720_P420.yuv',
diff --git a/modules/audio_device/BUILD.gn b/modules/audio_device/BUILD.gn
index 14c1525..b8aadee 100644
--- a/modules/audio_device/BUILD.gn
+++ b/modules/audio_device/BUILD.gn
@@ -68,7 +68,6 @@
   defines = []
   cflags = []
   if (rtc_include_internal_audio_device) {
-    defines += [ "WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE" ]
     sources += [
       "audio_device_impl.cc",
       "audio_device_impl.h",