Add FieldTrialsRegistry that verifies looked up field trials
This new class implements the existing FieldTrialsView interface,
extending it with the verification functionality. For now, the
verification will only be performed if the rtc_strict_field_trials GN
arg is set.
Most classes extending FieldTrialsView today have been converted to
extend from FieldTrialsRegistry instead to automatically perform
verification.
Bug: webrtc:14154
Change-Id: I4819724cd66a04507e62fcc2bb1019187b6ba8c7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/276270
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Emil Lundmark <lndmrk@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38453}
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 8d226d9..f2e574a 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -255,7 +255,7 @@
   ]
 
   deps = [
-    "../api:field_trials_view",
+    "../api:field_trials_registry",
     "../rtc_base:checks",
   ]
   absl_deps = [ "//third_party/abseil-cpp/absl/strings:strings" ]
@@ -271,7 +271,7 @@
 
   deps = [
     ":field_trial",
-    "../api:field_trials_view",
+    "../api:field_trials_registry",
     "../rtc_base:checks",
     "../system_wrappers:field_trial",
   ]
diff --git a/test/explicit_key_value_config.cc b/test/explicit_key_value_config.cc
index c9e5ac1..90690c0 100644
--- a/test/explicit_key_value_config.cc
+++ b/test/explicit_key_value_config.cc
@@ -11,7 +11,6 @@
 #include "test/explicit_key_value_config.h"
 
 #include "absl/strings/string_view.h"
-#include "api/field_trials_view.h"
 #include "rtc_base/checks.h"
 
 namespace webrtc {
@@ -46,7 +45,7 @@
   RTC_CHECK_EQ(field_start, s.size());
 }
 
-std::string ExplicitKeyValueConfig::Lookup(absl::string_view key) const {
+std::string ExplicitKeyValueConfig::GetValue(absl::string_view key) const {
   auto it = key_value_map_.find(key);
   if (it != key_value_map_.end())
     return it->second;
diff --git a/test/explicit_key_value_config.h b/test/explicit_key_value_config.h
index 5685c13..f14a104 100644
--- a/test/explicit_key_value_config.h
+++ b/test/explicit_key_value_config.h
@@ -16,17 +16,18 @@
 #include <string>
 
 #include "absl/strings/string_view.h"
-#include "api/field_trials_view.h"
+#include "api/field_trials_registry.h"
 
 namespace webrtc {
 namespace test {
 
-class ExplicitKeyValueConfig : public FieldTrialsView {
+class ExplicitKeyValueConfig : public FieldTrialsRegistry {
  public:
   explicit ExplicitKeyValueConfig(absl::string_view s);
-  std::string Lookup(absl::string_view key) const override;
 
  private:
+  std::string GetValue(absl::string_view key) const override;
+
   // Unlike std::less<std::string>, std::less<> is transparent and allows
   // heterogeneous lookup directly with absl::string_view.
   std::map<std::string, std::string, std::less<>> key_value_map_;
diff --git a/test/scoped_key_value_config.cc b/test/scoped_key_value_config.cc
index 449d5f0..df84462 100644
--- a/test/scoped_key_value_config.cc
+++ b/test/scoped_key_value_config.cc
@@ -10,7 +10,6 @@
 
 #include "test/scoped_key_value_config.h"
 
-#include "api/field_trials_view.h"
 #include "rtc_base/checks.h"
 #include "system_wrappers/include/field_trial.h"
 #include "test/field_trial.h"
@@ -97,7 +96,7 @@
   return n;
 }
 
-std::string ScopedKeyValueConfig::Lookup(absl::string_view key) const {
+std::string ScopedKeyValueConfig::GetValue(absl::string_view key) const {
   if (parent_ == nullptr) {
     return leaf_->LookupRecurse(key);
   } else {
diff --git a/test/scoped_key_value_config.h b/test/scoped_key_value_config.h
index db90ca3..c0023f8 100644
--- a/test/scoped_key_value_config.h
+++ b/test/scoped_key_value_config.h
@@ -17,24 +17,23 @@
 #include <string>
 
 #include "absl/strings/string_view.h"
-#include "api/field_trials_view.h"
+#include "api/field_trials_registry.h"
 #include "test/field_trial.h"
 
 namespace webrtc {
 namespace test {
 
-class ScopedKeyValueConfig : public FieldTrialsView {
+class ScopedKeyValueConfig : public FieldTrialsRegistry {
  public:
   virtual ~ScopedKeyValueConfig();
   ScopedKeyValueConfig();
   explicit ScopedKeyValueConfig(absl::string_view s);
   ScopedKeyValueConfig(ScopedKeyValueConfig& parent, absl::string_view s);
 
-  std::string Lookup(absl::string_view key) const override;
-
  private:
   ScopedKeyValueConfig(ScopedKeyValueConfig* parent, absl::string_view s);
   ScopedKeyValueConfig* GetRoot(ScopedKeyValueConfig* n);
+  std::string GetValue(absl::string_view key) const override;
   std::string LookupRecurse(absl::string_view key) const;
 
   ScopedKeyValueConfig* const parent_;