Add matchers for RTCError, rename old matcher for RTCErrorOr.

Needed for testing in a follow-up CL.
Using ToString rather than absl::StrCat because I want the name of the
enum (e.g. "INVALID_MODIFICATION") as opposed to the enum value (int).

Bug: none
Change-Id: I45a925fad65395d1e6a886a9f787c2f360fb8604
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374343
Reviewed-by: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43777}
diff --git a/api/test/rtc_error_matchers.h b/api/test/rtc_error_matchers.h
index cf923b2..2abc569 100644
--- a/api/test/rtc_error_matchers.h
+++ b/api/test/rtc_error_matchers.h
@@ -37,7 +37,41 @@
   return testing::ExplainMatchResult(matcher, arg.value(), result_listener);
 }
 
-MATCHER_P2(IsRtcErrorWithMessage,
+MATCHER_P(IsRtcErrorWithType, error_type, ToString(error_type)) {
+  if (arg.ok()) {
+    *result_listener << "Expected " << ToString(error_type) << ", got OK.";
+    return false;
+  }
+  if (arg.type() != error_type) {
+    *result_listener << "Expected " << ToString(error_type) << ", got "
+                     << ToString(arg.type());
+    return false;
+  }
+  return true;
+}
+
+MATCHER_P2(IsRtcErrorWithTypeAndMessage,
+           error_type,
+           message,
+           ToString(error_type)) {
+  if (arg.ok()) {
+    *result_listener << "Expected " << ToString(error_type) << ", got OK.";
+    return false;
+  }
+  if (arg.type() != error_type) {
+    *result_listener << "Expected " << ToString(error_type) << ", got "
+                     << ToString(arg.type());
+    return false;
+  }
+  if (std::string(arg.message()) != message) {
+    *result_listener << "Expected message \"" << message << "\", got \""
+                     << arg.message() << "\"";
+    return false;
+  }
+  return true;
+}
+
+MATCHER_P2(IsRtcErrorOrWithMessage,
            error_matcher,
            message_matcher,
            "RtcErrorOr that is holding an error that " +
diff --git a/test/wait_until_unittest.cc b/test/wait_until_unittest.cc
index 5f4ecf1..fffce70 100644
--- a/test/wait_until_unittest.cc
+++ b/test/wait_until_unittest.cc
@@ -54,7 +54,7 @@
   // flakiness.
   EXPECT_THAT(
       result,
-      IsRtcErrorWithMessage(
+      IsRtcErrorOrWithMessage(
           _, MatchesRegex(
                  "Value of: counter\nExpected: is equal to 1\nActual: -\\d+")));
 }
@@ -71,7 +71,7 @@
   // flakiness.
   EXPECT_THAT(
       result,
-      IsRtcErrorWithMessage(
+      IsRtcErrorOrWithMessage(
           _, MatchesRegex("Value of: counter\nExpected: \\(is > 0\\) and "
                           "\\(is < 10\\)\nActual: -\\d+, which doesn't match "
                           "\\(is > 0\\)")));