chromium/chrome/test/interaction/interactive_browser_test_internal.h

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

#ifndef CHROME_TEST_INTERACTION_INTERACTIVE_BROWSER_TEST_INTERNAL_H_
#define CHROME_TEST_INTERACTION_INTERACTIVE_BROWSER_TEST_INTERNAL_H_

#include <memory>
#include <utility>
#include <vector>

#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chrome/test/interaction/interaction_test_util_browser.h"
#include "chrome/test/interaction/tracked_element_webcontents.h"
#include "chrome/test/interaction/webcontents_interaction_test_util.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/interaction/interaction_sequence.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/interaction/interactive_views_test_internal.h"

class DevToolsAgentCoverageObserver;
class InteractiveBrowserTestApi;

namespace internal {

// Class that provides functionality needed by InteractiveBrowserTestApi but
// which should not be directly visible to tests inheriting from the API class.
class InteractiveBrowserTestPrivate
    : public views::test::internal::InteractiveViewsTestPrivate {};

// Provides a template-specialized method for converting base::Value objects to
// an expected type for a testing::Matcher<T>.
template <typename T>
struct JsValueExtractor {};

template <>
struct JsValueExtractor<base::Value> {};

template <>
struct JsValueExtractor<int> {};

template <>
struct JsValueExtractor<double> {};

template <>
struct JsValueExtractor<bool> {};

template <>
struct JsValueExtractor<std::string> {};

// Provides implementations for CheckJsResult[At]().
//
// The default implementation assumes an arbitrary value or and builds an
// equality testing::Matcher<T> to use for the check; e.g.:
//
//   const std::string kExpectedHtmlContents = "...";
//   ...
//   CheckJsResult(id, "() => document.innerHtml", kExpectedHtmlContents)
//   CheckJsResult(id, "() => getFooCount()", 3)
//
template <typename T>
struct JsResultChecker {};

// This implementation allows for a javascript string to be matched against am
// inline string literal, e.g.:
//
//   CheckJsResultAt(id, {"#id"}, "el => el.innerText", "The Quick Brown Fox")
//
JsResultChecker<const char (&)[N]>;

// This implementation allows for a javascript string ot be matched against a
// constant C-style string, e.g.:
//
//   const char* const kExpectedString = "The Quick Brown Fox";
//   ...
//   CheckJsResultAt(id, {#id}m "el => el.innerText", kExpectedString)
//
template <>
struct JsResultChecker<const char*> : public JsResultChecker<std::string> {};

// This implementation allows for a testing::Matcher of any kind to be passed
// in directly; e.g.:
//
//   CheckJsResult(id,
//                 "() => document.documentElement.clientWidth",
//                 testing::Gt(500))
//
JsResultChecker<M<T>>;

}  // namespace internal

#endif  // CHROME_TEST_INTERACTION_INTERACTIVE_BROWSER_TEST_INTERNAL_H_