chromium/chrome/test/base/web_ui_mocha_browser_test_browsertest.cc

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

#include <string>

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/web_ui_mocha_browser_test.h"
#include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest-spi.h"

// Test that code coverage metrics are reported from WebUIMochaBrowserTest
// subclasses.
class WebUIMochaCoverageTest : public WebUIMochaBrowserTest {};

IN_PROC_BROWSER_TEST_F(WebUIMochaCoverageTest, TestCoverageEmits) {}

// Test that various cases of errors or success are correctly detected.
class WebUIMochaSuccessFailureTest : public WebUIMochaBrowserTest {};

WebUIMochaSuccessFailureTest* WebUIMochaSuccessFailureTest::s_test_ =;

// Test that when the script injected to trigger the Mocha tests contains an
// error, the test fails.
IN_PROC_BROWSER_TEST_F(WebUIMochaSuccessFailureTest, TriggerErrorFails) {}

// Test that when the requested host does not exist the test fails.
IN_PROC_BROWSER_TEST_F(WebUIMochaSuccessFailureTest, HostErrorFails) {}

// Test that when the requested test file does not exist the test fails.
IN_PROC_BROWSER_TEST_F(WebUIMochaSuccessFailureTest, TestFileErrorFails) {}

// Test that when the underlying Mocha test fails, the C++ test also fails.
IN_PROC_BROWSER_TEST_F(WebUIMochaSuccessFailureTest, TestFailureFails) {}

// Test that when the underlying Mocha test succeeds, the C++ test also passes.
IN_PROC_BROWSER_TEST_F(WebUIMochaSuccessFailureTest, TestSuccessPasses) {}

// Test that various cases of errors or success are correctly detected when
// RunTestWithoutTestLoader() is used.
class WebUIMochaSuccessFailureWithoutTestLoaderTest
    : public WebUIMochaSuccessFailureTest {};

// Test that when the script injected to trigger the Mocha tests contains an
// error, the test fails.
IN_PROC_BROWSER_TEST_F(WebUIMochaSuccessFailureWithoutTestLoaderTest,
                       TriggerErrorFails) {}

// Test that when the requested host does not exist the test fails.
IN_PROC_BROWSER_TEST_F(WebUIMochaSuccessFailureWithoutTestLoaderTest,
                       HostErrorFails) {}

// Test that when the requested test file does not exist the test fails.
IN_PROC_BROWSER_TEST_F(WebUIMochaSuccessFailureWithoutTestLoaderTest,
                       TestFileErrorFails) {}

// Test that when the underlying Mocha test fails, the C++ test also fails.
IN_PROC_BROWSER_TEST_F(WebUIMochaSuccessFailureWithoutTestLoaderTest,
                       TestFailureFails) {}

// Test that when the underlying Mocha test succeeds, the C++ test also passes.
IN_PROC_BROWSER_TEST_F(WebUIMochaSuccessFailureWithoutTestLoaderTest,
                       TestSuccessPasses) {}