ceftests: Fix OSRTest flakyness

This commit is contained in:
Marshall Greenblatt 2023-02-06 16:26:20 -05:00
parent b3f93d506f
commit 59b475790b
9 changed files with 609 additions and 573 deletions

View File

@ -540,18 +540,7 @@ class DownloadTestHandler : public TestHandler {
mouse_event.x = 20; mouse_event.x = 20;
mouse_event.y = 20; mouse_event.y = 20;
mouse_event.modifiers = modifiers; mouse_event.modifiers = modifiers;
SendMouseClickEvent(browser, mouse_event);
// Add some delay to avoid having events dropped or rate limited.
CefPostDelayedTask(
TID_UI,
base::BindOnce(&CefBrowserHost::SendMouseClickEvent, browser->GetHost(),
mouse_event, MBT_LEFT, false, 1),
50);
CefPostDelayedTask(
TID_UI,
base::BindOnce(&CefBrowserHost::SendMouseClickEvent, browser->GetHost(),
mouse_event, MBT_LEFT, true, 1),
100);
} }
const TestMode test_mode_; const TestMode test_mode_;

View File

@ -1883,10 +1883,7 @@ class LoadNavTestHandler : public TestHandler {
cef_mouse_button_type_t button_type = cef_mouse_button_type_t button_type =
(mode_ == MIDDLE_CLICK ? MBT_MIDDLE : MBT_LEFT); (mode_ == MIDDLE_CLICK ? MBT_MIDDLE : MBT_LEFT);
browser->GetHost()->SendMouseClickEvent(mouse_event, button_type, false, SendMouseClickEvent(browser, mouse_event, button_type);
1);
browser->GetHost()->SendMouseClickEvent(mouse_event, button_type, true,
1);
} }
if (cancel_in_open_url_) { if (cancel_in_open_url_) {

File diff suppressed because it is too large Load Diff

View File

@ -148,8 +148,7 @@ class PdfViewerTestHandler : public TestHandler, public CefContextMenuHandler {
} }
// Send right-click mouse down and mouse up to tigger context menu. // Send right-click mouse down and mouse up to tigger context menu.
browser->GetHost()->SendMouseClickEvent(mouse_event, MBT_RIGHT, false, 1); SendMouseClickEvent(browser, mouse_event, MBT_RIGHT);
browser->GetHost()->SendMouseClickEvent(mouse_event, MBT_RIGHT, true, 1);
} }
bool RunContextMenu(CefRefPtr<CefBrowser> browser, bool RunContextMenu(CefRefPtr<CefBrowser> browser,

View File

@ -5,7 +5,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "include/base/cef_bind.h" #include "include/base/cef_callback.h"
#include "include/cef_parser.h" #include "include/cef_parser.h"
#include "include/cef_permission_handler.h" #include "include/cef_permission_handler.h"
#include "include/cef_request_context_handler.h" #include "include/cef_request_context_handler.h"
@ -13,6 +13,7 @@
#include "include/wrapper/cef_stream_resource_handler.h" #include "include/wrapper/cef_stream_resource_handler.h"
#include "tests/ceftests/test_handler.h" #include "tests/ceftests/test_handler.h"
#include "tests/ceftests/test_suite.h" #include "tests/ceftests/test_suite.h"
#include "tests/ceftests/test_util.h"
#include "tests/gtest/include/gtest/gtest.h" #include "tests/gtest/include/gtest/gtest.h"
#include "tests/shared/browser/client_app_browser.h" #include "tests/shared/browser/client_app_browser.h"
@ -264,18 +265,7 @@ class PermissionPromptTestHandler : public TestHandler,
CefMouseEvent mouse_event; CefMouseEvent mouse_event;
mouse_event.x = 20; mouse_event.x = 20;
mouse_event.y = 20; mouse_event.y = 20;
SendMouseClickEvent(browser, mouse_event);
// Add some delay to avoid having events dropped or rate limited.
CefPostDelayedTask(
TID_UI,
base::BindOnce(&CefBrowserHost::SendMouseClickEvent, browser->GetHost(),
mouse_event, MBT_LEFT, false, 1),
50);
CefPostDelayedTask(
TID_UI,
base::BindOnce(&CefBrowserHost::SendMouseClickEvent, browser->GetHost(),
mouse_event, MBT_LEFT, true, 1),
100);
} }
CefRefPtr<CefDictionaryValue> ParseURLData(const std::string& url) { CefRefPtr<CefDictionaryValue> ParseURLData(const std::string& url) {

View File

@ -324,18 +324,7 @@ class PopupTestHandler : public TestHandler {
mouse_event.x = 20; mouse_event.x = 20;
mouse_event.y = 20; mouse_event.y = 20;
mouse_event.modifiers = 0; mouse_event.modifiers = 0;
SendMouseClickEvent(browser, mouse_event);
// Add some delay to avoid having events dropped or rate limited.
CefPostDelayedTask(
TID_UI,
base::BindOnce(&CefBrowserHost::SendMouseClickEvent,
browser->GetHost(), mouse_event, MBT_LEFT, false, 1),
50);
CefPostDelayedTask(
TID_UI,
base::BindOnce(&CefBrowserHost::SendMouseClickEvent,
browser->GetHost(), mouse_event, MBT_LEFT, true, 1),
100);
} else { } else {
ADD_FAILURE(); // Not reached. ADD_FAILURE(); // Not reached.
} }

View File

@ -8,9 +8,11 @@
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include "include/base/cef_callback.h"
#include "include/cef_base.h" #include "include/cef_base.h"
#include "include/cef_command_line.h" #include "include/cef_command_line.h"
#include "include/cef_request_context_handler.h" #include "include/cef_request_context_handler.h"
#include "include/wrapper/cef_closure_task.h"
#include "tests/gtest/include/gtest/gtest.h" #include "tests/gtest/include/gtest/gtest.h"
#include "tests/shared/common/string_util.h" #include "tests/shared/common/string_util.h"
@ -346,6 +348,20 @@ std::optional<int> GetConfiguredTestTimeout(int timeout_ms) {
std::round(static_cast<double>(timeout_ms) * (*multiplier))); std::round(static_cast<double>(timeout_ms) * (*multiplier)));
} }
void SendMouseClickEvent(CefRefPtr<CefBrowser> browser,
const CefMouseEvent& mouse_event,
cef_mouse_button_type_t mouse_button_type) {
auto host = browser->GetHost();
CefPostDelayedTask(TID_UI,
base::BindOnce(&CefBrowserHost::SendMouseClickEvent, host,
mouse_event, mouse_button_type, false, 1),
50);
CefPostDelayedTask(TID_UI,
base::BindOnce(&CefBrowserHost::SendMouseClickEvent, host,
mouse_event, mouse_button_type, true, 1),
100);
}
CefRefPtr<CefRequestContext> CreateTestRequestContext( CefRefPtr<CefRequestContext> CreateTestRequestContext(
TestRequestContextMode mode, TestRequestContextMode mode,
const std::string& cache_path) { const std::string& cache_path) {

View File

@ -102,6 +102,12 @@ bool IgnoreURL(const std::string& url);
// if timeouts are disabled. // if timeouts are disabled.
std::optional<int> GetConfiguredTestTimeout(int timeout_ms); std::optional<int> GetConfiguredTestTimeout(int timeout_ms);
// Send a mouse click event with the necessary delay to avoid having events
// dropped or rate limited.
void SendMouseClickEvent(CefRefPtr<CefBrowser> browser,
const CefMouseEvent& mouse_event,
cef_mouse_button_type_t mouse_button_type = MBT_LEFT);
// Return a RequestContext object matching the specified |mode|. // Return a RequestContext object matching the specified |mode|.
// |cache_path| may be specified for CUSTOM modes. // |cache_path| may be specified for CUSTOM modes.
// Use the RC_TEST_GROUP_BASE macro to test all valid combinations. // Use the RC_TEST_GROUP_BASE macro to test all valid combinations.

View File

@ -100,6 +100,11 @@
window.testQuery({request: param}); window.testQuery({request: param});
} }
function onFocusTest(ev) {
if (window.testQuery)
window.testQuery({request: "osrfocus" + ev.target.id});
}
function allowDrop(ev) { function allowDrop(ev) {
ev.preventDefault(); ev.preventDefault();
} }
@ -169,7 +174,7 @@
</li> </li>
<li id='LI07'>Invalidate should trigger OnPaint once</li> <li id='LI07'>Invalidate should trigger OnPaint once</li>
<li id='LI08'>Click and write here with SendKeyEvent to trigger repaints: <li id='LI08'>Click and write here with SendKeyEvent to trigger repaints:
<input id='editbox' type='text' value='' size="5"></li> <input id='editbox' type='text' value='' size="5" onfocus="onFocusTest(event)"></li>
<li id='LI09'>Click here with SendMouseClickEvent to navigate: <li id='LI09'>Click here with SendMouseClickEvent to navigate:
<input id='btnnavigate' type='button' onclick='navigate()' <input id='btnnavigate' type='button' onclick='navigate()'
value='Click here to navigate' /></li> value='Click here to navigate' /></li>