Commit ee753333 authored by Adam Ettenberger's avatar Adam Ettenberger Committed by Commit Bot

Filter RUN-UNTIL-EVENTS by platform

If a single platform requires the behavior of RUN-UNTIL-EVENTS, but the
test is run for multiple platforms, then RUN-UNTIL-EVENTS would need to
be defined for an event per-platform.

This change applies the same concept as filters for WIN-ALLOW/DENY so
we can enable this behavior per-platform for event dump tests.
e.g. WIN-RUN-UNTIL-EVENTS

Bug: none
Change-Id: I0b4eda70c64dea685ed4df8014465297c66a925c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2320417
Commit-Queue: Adam Ettenberger <Adam.Ettenberger@microsoft.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Reviewed-by: default avatarKevin Babbitt <kbabbitt@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#795083}
parent 0d2d3775
......@@ -9,6 +9,7 @@
#include <string>
#include <vector>
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/macros.h"
#include "base/process/process_handle.h"
......@@ -68,6 +69,8 @@ class CONTENT_EXPORT AccessibilityEventRecorder {
callback_ = std::move(callback);
}
void StopListeningToEvents() { callback_ = base::NullCallback(); }
// Called to ensure the event recorder has finished recording async events.
virtual void FlushAsyncEvents() {}
......
......@@ -89,6 +89,7 @@ class AccessibilityTreeFormatterAndroid
const std::string GetAllowString() override;
const std::string GetDenyString() override;
const std::string GetDenyNodeString() override;
const std::string GetRunUntilEventString() override;
void RecursiveBuildAccessibilityTree(const BrowserAccessibility& node,
base::DictionaryValue* dict) const;
......@@ -324,4 +325,8 @@ const std::string AccessibilityTreeFormatterAndroid::GetDenyNodeString() {
return "@ANDROID-DENY-NODE:";
}
const std::string AccessibilityTreeFormatterAndroid::GetRunUntilEventString() {
return "@ANDROID-RUN-UNTIL-EVENT:";
}
} // namespace content
......@@ -36,6 +36,7 @@ class AccessibilityTreeFormatterAuraLinux
const std::string GetAllowString() override;
const std::string GetDenyString() override;
const std::string GetDenyNodeString() override;
const std::string GetRunUntilEventString() override;
base::string16 ProcessTreeForOutput(
const base::DictionaryValue& node,
......@@ -747,4 +748,9 @@ const std::string AccessibilityTreeFormatterAuraLinux::GetDenyNodeString() {
return "@AURALINUX-DENY-NODE:";
}
const std::string
AccessibilityTreeFormatterAuraLinux::GetRunUntilEventString() {
return "@AURALINUX-RUN-UNTIL-EVENT:";
}
} // namespace content
......@@ -632,4 +632,8 @@ const std::string AccessibilityTreeFormatterBlink::GetDenyNodeString() {
return "@BLINK-DENY-NODE:";
}
const std::string AccessibilityTreeFormatterBlink::GetRunUntilEventString() {
return "@BLINK-RUN-UNTIL-EVENT:";
}
} // namespace content
......@@ -42,6 +42,7 @@ class CONTENT_EXPORT AccessibilityTreeFormatterBlink
const std::string GetAllowString() override;
const std::string GetDenyString() override;
const std::string GetDenyNodeString() override;
const std::string GetRunUntilEventString() override;
void RecursiveBuildAccessibilityTree(const BrowserAccessibility& node,
base::DictionaryValue* dict) const;
......
......@@ -110,6 +110,7 @@ class AccessibilityTreeFormatterMac : public AccessibilityTreeFormatterBase {
const std::string GetAllowString() override;
const std::string GetDenyString() override;
const std::string GetDenyNodeString() override;
const std::string GetRunUntilEventString() override;
void AddProperties(const BrowserAccessibilityCocoa* node,
const LineIndexesMap& line_indexes_map,
......@@ -817,6 +818,10 @@ const string AccessibilityTreeFormatterMac::GetDenyNodeString() {
return "@MAC-DENY-NODE:";
}
const std::string AccessibilityTreeFormatterMac::GetRunUntilEventString() {
return "@MAC-RUN-UNTIL-EVENT:";
}
} // namespace content
#pragma clang diagnostic pop
......@@ -1200,4 +1200,8 @@ const std::string AccessibilityTreeFormatterUia::GetDenyNodeString() {
return "@UIA-WIN-DENY-NODE:";
}
const std::string AccessibilityTreeFormatterUia::GetRunUntilEventString() {
return "@UIA-WIN-RUN-UNTIL-EVENT:";
}
} // namespace content
......@@ -100,6 +100,7 @@ class AccessibilityTreeFormatterUia : public AccessibilityTreeFormatterBase {
const std::string GetAllowString() override;
const std::string GetDenyString() override;
const std::string GetDenyNodeString() override;
const std::string GetRunUntilEventString() override;
base::string16 ProcessTreeForOutput(
const base::DictionaryValue& node,
base::DictionaryValue* filtered_result = nullptr) override;
......
......@@ -71,6 +71,7 @@ class AccessibilityTreeFormatterWin : public AccessibilityTreeFormatterBase {
const std::string GetAllowString() override;
const std::string GetDenyString() override;
const std::string GetDenyNodeString() override;
const std::string GetRunUntilEventString() override;
void AddProperties(const Microsoft::WRL::ComPtr<IAccessible>,
base::DictionaryValue* dict,
LONG root_x,
......@@ -1036,4 +1037,8 @@ const std::string AccessibilityTreeFormatterWin::GetDenyNodeString() {
return "@WIN-DENY-NODE:";
}
const std::string AccessibilityTreeFormatterWin::GetRunUntilEventString() {
return "@WIN-RUN-UNTIL-EVENT:";
}
} // namespace content
......@@ -171,7 +171,7 @@ void DumpAccessibilityTestBase::ParseHtmlForExtraDirectives(
const std::string& no_load_expected_str = "@NO-LOAD-EXPECTED:";
const std::string& wait_str = "@WAIT-FOR:";
const std::string& execute_str = "@EXECUTE-AND-WAIT-FOR:";
const std::string& until_str = "@RUN-UNTIL-EVENT:";
const std::string& until_str = formatter_->GetRunUntilEventString();
const std::string& default_action_on_str = "@DEFAULT-ACTION-ON:";
if (base::StartsWith(line, allow_empty_str, base::CompareCase::SENSITIVE)) {
property_filters_.push_back(
......
......@@ -93,13 +93,18 @@ class DumpAccessibilityEventsTest : public DumpAccessibilityTestBase {
void RunEventTest(const base::FilePath::CharType* file_path);
private:
void OnEventRecorded(AccessibilityNotificationWaiter* waiter,
const std::string& event) {
waiter->Quit();
}
base::string16 initial_tree_;
base::string16 final_tree_;
};
bool IsRecordingComplete(AccessibilityEventRecorder& event_recorder,
std::vector<std::string>& run_until) {
// If no @RUN-UNTIL-EVENT directives, then having any events is enough.
// If no @*-RUN-UNTIL-EVENT directives, then having any events is enough.
LOG(ERROR) << "=== IsRecordingComplete#1 run_until size=" << run_until.size();
if (run_until.empty())
return true;
......@@ -145,16 +150,27 @@ std::vector<std::string> DumpAccessibilityEventsTest::Dump(
waiter.reset(new AccessibilityNotificationWaiter(
shell()->web_contents(), ui::kAXModeComplete, ax::mojom::Event::kNone));
// It's possible for platform events to be received after all blink or
// generated events have been fired. Unblock the |waiter| when this happens.
event_recorder->ListenToEvents(
base::BindRepeating(&DumpAccessibilityEventsTest::OnEventRecorded,
base::Unretained(this), waiter.get()));
base::Value go_results =
ExecuteScriptAndGetValue(web_contents->GetMainFrame(), "go()");
run_go_again = go_results.is_bool() && go_results.GetBool();
for (;;) {
waiter->WaitForNotification(); // Run at least once.
// Wait for at least one event. This may unblock either when |waiter|
// observes either an ax::mojom::Event or ui::AXEventGenerator::Event, or
// when |event_recorder| records a platform event.
waiter->WaitForNotification();
if (IsRecordingComplete(*event_recorder, run_until))
break;
}
event_recorder->StopListeningToEvents();
// More than one accessibility event could have been generated.
// To make sure we've received all accessibility events, add a
// sentinel by calling SignalEndOfTest and waiting for a kEndOfTest
......
......@@ -186,6 +186,17 @@ class CONTENT_EXPORT AccessibilityTreeFormatter
virtual const std::string GetAllowString() = 0;
virtual const std::string GetDenyString() = 0;
virtual const std::string GetDenyNodeString() = 0;
// A string that indicates event recording should continue at least until a
// specific event has been received.
// Overridden by each platform subclass.
// Example win value:
// GetRunUntilEventString() -> "@WIN-RUN-UNTIL-EVENT"
// Example html:
// <!--
// @WIN-RUN-UNTIL-EVENT:IA2_EVENT_TEXT_CARET_MOVED
// -->
virtual const std::string GetRunUntilEventString() = 0;
};
} // namespace content
......
......@@ -208,4 +208,8 @@ void AccessibilityNotificationWaiter::RenderFrameHostChanged(
ListenToFrame(static_cast<RenderFrameHostImpl*>(new_host));
}
void AccessibilityNotificationWaiter::Quit() {
loop_runner_->Quit();
}
} // namespace content
......@@ -67,6 +67,9 @@ class AccessibilityNotificationWaiter : public WebContentsObserver {
void RenderFrameHostChanged(RenderFrameHost* old_host,
RenderFrameHost* new_host) override;
// Quits listening and unblocks WaitForNotification* calls.
void Quit();
private:
// Listen to all frames within the frame tree of this WebContents.
void ListenToAllFrames(WebContents* web_contents);
......
<!--
@RUN-UNTIL-EVENT:EVENT_OBJECT_VALUECHANGE
@WIN-RUN-UNTIL-EVENT:EVENT_OBJECT_VALUECHANGE
@WIN-DENY:IA2_EVENT_TEXT_INSERTED*
@WIN-DENY:IA2_EVENT_TEXT_REMOVED*
-->
......
<!--
@RUN-UNTIL-EVENT:EVENT_OBJECT_VALUECHANGE
@WIN-RUN-UNTIL-EVENT:EVENT_OBJECT_VALUECHANGE
@WIN-DENY:IA2_EVENT_TEXT_INSERTED*
@WIN-DENY:IA2_EVENT_TEXT_REMOVED*
-->
......
......@@ -127,14 +127,15 @@ ready and all `@WAIT-FOR:` strings have been found.
Example: `@EXECUTE-AND-WAIT-FOR: foo()`
Or, you may need to write an event test that keeps dumping events until a
specific event line. In this case, use `@RUN-UNTIL-EVENT` with a substring that
should occur in the event log, e.g.,
`@RUN-UNTIL-EVENT:IA2_EVENT_TEXT_CARET_MOVED`. Note that `@RUN-UNTIL-EVENT` is
only used in dump events tests, and not used in dump tree tests.
If you add multiple `@RUN-UNTIL-EVENT` directives, the test will finish once any
of them are satisfied. Note that any other events that come along with the last
event will also be logged.
specific event line. In this case, use `@WIN-RUN-UNTIL-EVENT` (or similar for
other platforms) with a substring that should occur in the event log, e.g.,
`@WIN-RUN-UNTIL-EVENT:IA2_EVENT_TEXT_CARET_MOVED`.
Note that `@*-RUN-UNTIL-EVENT` is only used in dump events tests, and not used
in dump tree tests.
If you add multiple `@*-RUN-UNTIL-EVENT` directives, the test will finish once
any of them are satisfied. Note that any other events that come along with the
last event will also be logged.
To skip dumping a particular element, make its accessible name equal to
`@NO_DUMP`, for example `<div aria-label="@NO_DUMP"></div>`.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment