chromium/third_party/blink/renderer/platform/testing/exception_state_matchers.h

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_EXCEPTION_STATE_MATCHERS_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_EXCEPTION_STATE_MATCHERS_H_

#include <string>

#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"

namespace blink {

// Teach gTest how to print the actual value of the exception state.
void PrintTo(const ExceptionState& exception_state, std::ostream* os);

namespace internal {

std::string ExceptionCodeToString(ExceptionCode code);

}  // namespace internal

MATCHER(HadException, "") {}

MATCHER_P(HadException,
          code,
          internal::ExceptionCodeToString(ToExceptionCode(code))) {}

MATCHER_P2(HadException,
           code,
           message,
           internal::ExceptionCodeToString(ToExceptionCode(code)) + ": " +
               testing::PrintToString(message)) {}

MATCHER(HadNoException, "") {}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_TESTING_EXCEPTION_STATE_MATCHERS_H_