Move initialization of GoogleMock and flags to main from test_main_lib

Bug: None
Change-Id: Ie3aed382d4e468c4adbfdbcc1bdb3f069d3eaae2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/181364
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Andrey Logvin <landrey@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31909}
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 1cad688..f544353 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -422,7 +422,6 @@
     ]
     absl_deps = [
       "//third_party/abseil-cpp/absl/flags:flag",
-      "//third_party/abseil-cpp/absl/flags:parse",
       "//third_party/abseil-cpp/absl/memory",
       "//third_party/abseil-cpp/absl/strings:strings",
       "//third_party/abseil-cpp/absl/types:optional",
@@ -434,10 +433,15 @@
     testonly = true
     sources = [ "test_main.cc" ]
 
-    deps = [ ":test_main_lib" ]
+    deps = [
+      ":test_main_lib",
+      ":test_support",
+    ]
+
     absl_deps = [
       "//third_party/abseil-cpp/absl/debugging:failure_signal_handler",
       "//third_party/abseil-cpp/absl/debugging:symbolize",
+      "//third_party/abseil-cpp/absl/flags:parse",
     ]
   }
 
diff --git a/test/test_main.cc b/test/test_main.cc
index 5046979..f919c4b 100644
--- a/test/test_main.cc
+++ b/test/test_main.cc
@@ -12,17 +12,21 @@
 
 #include "absl/debugging/failure_signal_handler.h"
 #include "absl/debugging/symbolize.h"
+#include "absl/flags/parse.h"
+#include "test/gmock.h"
 #include "test/test_main_lib.h"
 
 int main(int argc, char* argv[]) {
   // Initialize the symbolizer to get a human-readable stack trace
   absl::InitializeSymbolizer(argv[0]);
+  testing::InitGoogleMock(&argc, argv);
+  absl::ParseCommandLine(argc, argv);
 
   absl::FailureSignalHandlerOptions options;
   absl::InstallFailureSignalHandler(options);
 
   std::unique_ptr<webrtc::TestMain> main = webrtc::TestMain::Create();
-  int err_code = main->Init(&argc, argv);
+  int err_code = main->Init();
   if (err_code != 0) {
     return err_code;
   }
diff --git a/test/test_main_lib.cc b/test/test_main_lib.cc
index f5e0234..7170163 100644
--- a/test/test_main_lib.cc
+++ b/test/test_main_lib.cc
@@ -15,7 +15,6 @@
 #include <string>
 
 #include "absl/flags/flag.h"
-#include "absl/flags/parse.h"
 #include "absl/memory/memory.h"
 #include "absl/strings/match.h"
 #include "absl/types/optional.h"
@@ -28,7 +27,6 @@
 #include "system_wrappers/include/field_trial.h"
 #include "system_wrappers/include/metrics.h"
 #include "test/field_trial.h"
-#include "test/gmock.h"
 #include "test/gtest.h"
 #include "test/testsupport/perf_test.h"
 #include "test/testsupport/resources_dir_flag.h"
@@ -157,10 +155,9 @@
     std::unique_ptr<rtc::Thread> thread_;
   };
 
-  int Init(int* argc, char* argv[]) override {
-    ::testing::InitGoogleMock(argc, argv);
-    absl::ParseCommandLine(*argc, argv);
+  int Init(int* argc, char* argv[]) override { return Init(); }
 
+  int Init() override {
     // Make sure we always pull in the --resources_dir flag, even if the test
     // binary doesn't link with fileutils (downstream expects all test mains to
     // have this flag).
diff --git a/test/test_main_lib.h b/test/test_main_lib.h
index bdb0afb..2233171 100644
--- a/test/test_main_lib.h
+++ b/test/test_main_lib.h
@@ -25,6 +25,8 @@
   // Initializes test environment. Clients can add their own initialization
   // steps after call to this method and before running tests.
   // Returns 0 if initialization was successful and non 0 otherwise.
+  virtual int Init() = 0;
+  // Temporary for backward compatibility
   virtual int Init(int* argc, char* argv[]) = 0;
 
   // Runs test end return result error code. 0 - no errors.