ceftests: Add support for scaling default test timeout values
This commit is contained in:
parent
7b14b637bb
commit
c12701592e
|
@ -84,7 +84,7 @@ class ResourceManagerTestHandler : public RoutingTestHandler {
|
|||
// Create the browser.
|
||||
CreateBrowser(GetNextURL());
|
||||
|
||||
SetTestTimeout(IsChromeRuntimeEnabled() ? 10000 : 5000);
|
||||
SetTestTimeout(5000);
|
||||
}
|
||||
|
||||
cef_return_value_t OnBeforeResourceLoad(
|
||||
|
|
|
@ -651,8 +651,8 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
|
|||
|
||||
void SetTestTimeout(int timeout_ms) {
|
||||
EXPECT_UI_THREAD();
|
||||
if (CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||
"disable-test-timeout")) {
|
||||
const auto timeout = GetConfiguredTestTimeout(timeout_ms);
|
||||
if (!timeout) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -660,8 +660,8 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
|
|||
// test runner can be destroyed before the timeout expires.
|
||||
GetUIThreadHelper()->PostDelayedTask(
|
||||
base::BindOnce(&HttpTestRunner::OnTestTimeout, base::Unretained(this),
|
||||
timeout_ms),
|
||||
timeout_ms);
|
||||
*timeout),
|
||||
*timeout);
|
||||
}
|
||||
|
||||
void OnTestTimeout(int timeout_ms) {
|
||||
|
|
|
@ -7,16 +7,17 @@
|
|||
#include "include/cef_task.h"
|
||||
#include "include/wrapper/cef_closure_task.h"
|
||||
#include "tests/ceftests/test_handler.h"
|
||||
#include "tests/ceftests/test_util.h"
|
||||
#include "tests/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void WaitForEvent(CefRefPtr<CefWaitableEvent> event) {
|
||||
if (CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||
"disable-test-timeout")) {
|
||||
const auto timeout = GetConfiguredTestTimeout(/*timeout_ms=*/1000);
|
||||
if (!timeout) {
|
||||
event->Wait();
|
||||
} else {
|
||||
EXPECT_TRUE(event->TimedWait(1000));
|
||||
EXPECT_TRUE(event->TimedWait(*timeout));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "include/wrapper/cef_closure_task.h"
|
||||
#include "include/wrapper/cef_stream_resource_handler.h"
|
||||
#include "tests/ceftests/test_request.h"
|
||||
#include "tests/ceftests/test_util.h"
|
||||
#include "tests/shared/common/client_switches.h"
|
||||
|
||||
namespace {
|
||||
|
@ -442,8 +443,8 @@ void TestHandler::SetTestTimeout(int timeout_ms, bool treat_as_error) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (treat_as_error && CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||
"disable-test-timeout")) {
|
||||
const auto timeout = GetConfiguredTestTimeout(timeout_ms);
|
||||
if (treat_as_error && !timeout) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -451,8 +452,8 @@ void TestHandler::SetTestTimeout(int timeout_ms, bool treat_as_error) {
|
|||
// can be destroyed before the timeout expires.
|
||||
GetUIThreadHelper()->PostDelayedTask(
|
||||
base::BindOnce(&TestHandler::OnTestTimeout, base::Unretained(this),
|
||||
timeout_ms, treat_as_error),
|
||||
timeout_ms);
|
||||
*timeout, treat_as_error),
|
||||
*timeout);
|
||||
}
|
||||
|
||||
void TestHandler::TestComplete() {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "include/wrapper/cef_helpers.h"
|
||||
#include "tests/ceftests/test_request.h"
|
||||
#include "tests/ceftests/test_server_observer.h"
|
||||
#include "tests/ceftests/test_util.h"
|
||||
#include "tests/ceftests/track_callback.h"
|
||||
#include "tests/gtest/include/gtest/gtest.h"
|
||||
|
||||
|
@ -165,11 +166,11 @@ void SignalIfDone(CefRefPtr<CefWaitableEvent> event,
|
|||
}
|
||||
|
||||
void Wait(CefRefPtr<CefWaitableEvent> event) {
|
||||
if (CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||
"disable-test-timeout")) {
|
||||
const auto timeout = GetConfiguredTestTimeout(/*timeout_ms=*/2000);
|
||||
if (!timeout) {
|
||||
event->Wait();
|
||||
} else {
|
||||
event->TimedWait(2000);
|
||||
event->TimedWait(*timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -373,8 +373,8 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
|
|||
|
||||
void SetTestTimeout(int timeout_ms) {
|
||||
EXPECT_UI_THREAD();
|
||||
if (CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||
"disable-test-timeout")) {
|
||||
const auto timeout = GetConfiguredTestTimeout(timeout_ms);
|
||||
if (!timeout) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -382,8 +382,8 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
|
|||
// test runner can be destroyed before the timeout expires.
|
||||
GetUIThreadHelper()->PostDelayedTask(
|
||||
base::BindOnce(&HttpTestRunner::OnTestTimeout, base::Unretained(this),
|
||||
timeout_ms),
|
||||
timeout_ms);
|
||||
*timeout),
|
||||
*timeout);
|
||||
}
|
||||
|
||||
void OnTestTimeout(int timeout_ms) {
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include "tests/ceftests/test_util.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "include/cef_base.h"
|
||||
#include "include/cef_command_line.h"
|
||||
|
@ -278,23 +280,19 @@ void TestStringVectorEqual(const std::vector<CefString>& val1,
|
|||
}
|
||||
|
||||
bool TestOldResourceAPI() {
|
||||
static int state = -1;
|
||||
if (state == -1) {
|
||||
CefRefPtr<CefCommandLine> command_line =
|
||||
CefCommandLine::GetGlobalCommandLine();
|
||||
state = command_line->HasSwitch("test-old-resource-api") ? 1 : 0;
|
||||
}
|
||||
return state ? true : false;
|
||||
static bool state = []() {
|
||||
return CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||
"test-old-resource-api");
|
||||
}();
|
||||
return state;
|
||||
}
|
||||
|
||||
bool IsChromeRuntimeEnabled() {
|
||||
static int state = -1;
|
||||
if (state == -1) {
|
||||
CefRefPtr<CefCommandLine> command_line =
|
||||
CefCommandLine::GetGlobalCommandLine();
|
||||
state = command_line->HasSwitch("enable-chrome-runtime") ? 1 : 0;
|
||||
}
|
||||
return state ? true : false;
|
||||
static bool state = []() {
|
||||
return CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||
"enable-chrome-runtime");
|
||||
}();
|
||||
return state;
|
||||
}
|
||||
|
||||
bool IsBFCacheEnabled() {
|
||||
|
@ -303,15 +301,13 @@ bool IsBFCacheEnabled() {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Enabled by default starting in M96.
|
||||
static int state = -1;
|
||||
if (state == -1) {
|
||||
CefRefPtr<CefCommandLine> command_line =
|
||||
CefCommandLine::GetGlobalCommandLine();
|
||||
const std::string& value = command_line->GetSwitchValue("disable-features");
|
||||
state = value.find("BackForwardCache") == std::string::npos ? 1 : 0;
|
||||
}
|
||||
return state ? true : false;
|
||||
static bool state = []() {
|
||||
const std::string& value =
|
||||
CefCommandLine::GetGlobalCommandLine()->GetSwitchValue(
|
||||
"disable-features");
|
||||
return value.find("BackForwardCache") == std::string::npos;
|
||||
}();
|
||||
return state;
|
||||
}
|
||||
|
||||
bool IsSameSiteBFCacheEnabled() {
|
||||
|
@ -325,6 +321,31 @@ bool IgnoreURL(const std::string& url) {
|
|||
url.find("/favicon.ico") != std::string::npos;
|
||||
}
|
||||
|
||||
std::optional<int> GetConfiguredTestTimeout(int timeout_ms) {
|
||||
static std::optional<double> multiplier = []() -> std::optional<double> {
|
||||
auto command_line = CefCommandLine::GetGlobalCommandLine();
|
||||
if (command_line->HasSwitch("disable-test-timeout")) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const std::string& sval =
|
||||
command_line->GetSwitchValue("test-timeout-multiplier");
|
||||
if (!sval.empty()) {
|
||||
if (double dval = std::atof(sval.c_str())) {
|
||||
return dval;
|
||||
}
|
||||
}
|
||||
return IsChromeRuntimeEnabled() ? 2.0 : 1.0;
|
||||
}();
|
||||
|
||||
if (!multiplier) {
|
||||
// Test timeout is disabled.
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return static_cast<int>(
|
||||
std::round(static_cast<double>(timeout_ms) * (*multiplier)));
|
||||
}
|
||||
|
||||
CefRefPtr<CefRequestContext> CreateTestRequestContext(
|
||||
TestRequestContextMode mode,
|
||||
const std::string& cache_path) {
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#define CEF_TESTS_CEFTESTS_TEST_UTIL_H_
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "include/cef_process_message.h"
|
||||
#include "include/cef_request.h"
|
||||
#include "include/cef_request_context.h"
|
||||
|
@ -96,6 +98,10 @@ bool IsSameSiteBFCacheEnabled();
|
|||
// Returns true if requests for |url| should be ignored by tests.
|
||||
bool IgnoreURL(const std::string& url);
|
||||
|
||||
// Returns |timeout_ms| as scaled by the current configuration, or std::nullopt
|
||||
// if timeouts are disabled.
|
||||
std::optional<int> GetConfiguredTestTimeout(int timeout_ms);
|
||||
|
||||
// Return a RequestContext object matching the specified |mode|.
|
||||
// |cache_path| may be specified for CUSTOM modes.
|
||||
// Use the RC_TEST_GROUP_BASE macro to test all valid combinations.
|
||||
|
|
|
@ -2760,7 +2760,7 @@ class RequestTestHandler : public TestHandler {
|
|||
|
||||
void RunTest() override {
|
||||
// Time out the test after a reasonable period of time.
|
||||
SetTestTimeout(IsChromeRuntimeEnabled() ? 10000 : 5000);
|
||||
SetTestTimeout(5000);
|
||||
|
||||
// Start pre-setup actions.
|
||||
PreSetupStart();
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "include/views/cef_window.h"
|
||||
#include "include/views/cef_window_delegate.h"
|
||||
#include "include/wrapper/cef_closure_task.h"
|
||||
#include "tests/ceftests/test_util.h"
|
||||
#include "tests/ceftests/thread_helper.h"
|
||||
#include "tests/gtest/include/gtest/gtest.h"
|
||||
|
||||
|
@ -125,14 +126,16 @@ void TestWindowDelegate::OnWindowCreated(CefRefPtr<CefWindow> window) {
|
|||
// Close the window asynchronously.
|
||||
CefPostTask(TID_UI,
|
||||
base::BindOnce(&TestWindowDelegate::OnCloseWindow, this));
|
||||
} else if (!CefCommandLine::GetGlobalCommandLine()->HasSwitch(
|
||||
"disable-test-timeout")) {
|
||||
} else {
|
||||
const auto timeout = GetConfiguredTestTimeout(kTestTimeout);
|
||||
if (timeout) {
|
||||
// Timeout the test after a reasonable delay. Use a WeakPtr so that the
|
||||
// delayed task doesn't keep this object alive.
|
||||
CefPostDelayedTask(TID_UI,
|
||||
base::BindOnce(&TestWindowDelegate::OnTimeoutWindow,
|
||||
weak_ptr_factory_.GetWeakPtr()),
|
||||
kTestTimeout);
|
||||
*timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue