Skip to content

Commit

Permalink
[AssistData] Add fieldtrial param to stress test experiment
Browse files Browse the repository at this point in the history
AX-Relnotes: N/A
Bug: b/303655535
Change-Id: Ibac27b3a4f62912bdf2d302fdd76aa30e0fb1c7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5087735
Reviewed-by: Akihiro Ota <akihiroota@chromium.org>
Commit-Queue: Mark Schillaci <mschillaci@google.com>
Cr-Commit-Position: refs/heads/main@{#1233603}
  • Loading branch information
mschillaci authored and Chromium LUCI CQ committed Dec 5, 2023
1 parent 0dd3e4a commit 367e4eb
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
54 changes: 54 additions & 0 deletions content/browser/accessibility/snapshot_ax_tree_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -601,4 +601,58 @@ IN_PROC_BROWSER_TEST_F(SnapshotAXTreeBrowserTest, Metadata) {
"<script type=\"application/ld+json\">{}</script>"));
}

// For Android, test the field trial param to change the number of max nodes.
#if BUILDFLAG(IS_ANDROID)
class SnapshotAXTreeMaxNodesParamBrowserTest : public ContentBrowserTest {
public:
SnapshotAXTreeMaxNodesParamBrowserTest() {
scoped_feature_list_.InitAndEnableFeatureWithParameters(
features::kAccessibilitySnapshotStressTests,
{{"AccessibilitySnapshotStressTestsMaxNodes", "500"}});
}
~SnapshotAXTreeMaxNodesParamBrowserTest() override = default;

private:
base::test::ScopedFeatureList scoped_feature_list_;
};

IN_PROC_BROWSER_TEST_F(SnapshotAXTreeMaxNodesParamBrowserTest, MaxNodes) {
GURL url(R"HTML(data:text/html,<body>
<style> p { margin: 50px; } </style>
<script>
let outerDiv = document.createElement('div');
for (let i = 0; i < 200; i++) {
let div = document.createElement('div');
for (let j = 0; j < 20; j++) {
let p = document.createElement('p');
p.innerHTML = j;
div.appendChild(p);
}
outerDiv.appendChild(div);
}
document.body.appendChild(outerDiv);
</script>
</body>)HTML");
EXPECT_TRUE(NavigateToURL(shell(), url));

WebContentsImpl* web_contents =
static_cast<WebContentsImpl*>(shell()->web_contents());

AXTreeSnapshotWaiter waiter;
web_contents->RequestAXTreeSnapshot(
base::BindOnce(&AXTreeSnapshotWaiter::ReceiveSnapshot,
base::Unretained(&waiter)),
ui::kAXModeComplete,
/* max_nodes= */ 10,
/* timeout= */ {});
waiter.Wait();

// If the feature flag and param was honored, we should see more than 100
// nodes (which was the value set on the method call), but less than all the
// possible nodes.
EXPECT_GT(waiter.snapshot().nodes.size(), 100U);
EXPECT_LT(waiter.snapshot().nodes.size(), 800U);
}

#endif
} // namespace content
13 changes: 12 additions & 1 deletion content/renderer/accessibility/ax_tree_snapshotter_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "content/renderer/accessibility/ax_tree_snapshotter_impl.h"

#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
Expand Down Expand Up @@ -147,9 +148,19 @@ bool AXTreeSnapshotterImpl::SerializeTreeWithLimits(
}

bool AXTreeSnapshotterImpl::SerializeTree(ui::AXTreeUpdate* response) {
#if !BUILDFLAG(IS_ANDROID)
int max_nodes_count = 0;
#else
// Experiment with different max values for end-to-end timing. An arbitrarily
// large value will simulate there being no max nodes count.
int max_nodes_count = base::GetFieldTrialParamByFeatureAsInt(
features::kAccessibilitySnapshotStressTests,
"AccessibilitySnapshotStressTestsMaxNodes", 100000);
#endif

base::ElapsedTimer timer = base::ElapsedTimer();
timer.start_time();
if (!context_->SerializeEntireTree(0, {}, response)) {
if (!context_->SerializeEntireTree(max_nodes_count, {}, response)) {
return false;
}

Expand Down
41 changes: 40 additions & 1 deletion testing/variations/fieldtrial_testing_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,46 @@
],
"experiments": [
{
"name": "Enabled_20231108",
"name": "Enabled_Max3500_20231206",
"params": {
"AccessibilitySnapshotStressTestsMaxNodes": "3500"
},
"enable_features": [
"AccessibilitySnapshotStressTests"
]
},
{
"name": "Enabled_Max2000_20231206",
"params": {
"AccessibilitySnapshotStressTestsMaxNodes": "2000"
},
"enable_features": [
"AccessibilitySnapshotStressTests"
]
},
{
"name": "Enabled_Max1500_20231206",
"params": {
"AccessibilitySnapshotStressTestsMaxNodes": "1500"
},
"enable_features": [
"AccessibilitySnapshotStressTests"
]
},
{
"name": "Enabled_Max1000_20231206",
"params": {
"AccessibilitySnapshotStressTestsMaxNodes": "1000"
},
"enable_features": [
"AccessibilitySnapshotStressTests"
]
},
{
"name": "Control_NoMax_20231206",
"params": {
"AccessibilitySnapshotStressTestsMaxNodes": "100000"
},
"enable_features": [
"AccessibilitySnapshotStressTests"
]
Expand Down
8 changes: 8 additions & 0 deletions ui/accessibility/accessibility_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define UI_ACCESSIBILITY_ACCESSIBILITY_FEATURES_H_

#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "ui/accessibility/ax_base_export.h"
Expand Down Expand Up @@ -189,6 +190,13 @@ AX_BASE_EXPORT bool IsAccessibilityPerformanceFilteringEnabled();
// AXTreeSnapshotter's Snapshot method, and track related histograms.
AX_BASE_EXPORT BASE_DECLARE_FEATURE(kAccessibilitySnapshotStressTests);
AX_BASE_EXPORT bool IsAccessibilitySnapshotStressTestsEnabled();
// Controls the maximum amount of nodes in a given snapshot. We set an
// arbitrarily high value as the default to simulate there being no max nodes
// limit.
AX_BASE_EXPORT const base::FeatureParam<int>
kAccessibilitySnapshotStressTestsMaxNodes{
&kAccessibilitySnapshotStressTests,
"AccessibilitySnapshotStressTestsMaxNodes", 100000};
#endif // BUILDFLAG(IS_ANDROID)

#if !BUILDFLAG(IS_ANDROID)
Expand Down

0 comments on commit 367e4eb

Please sign in to comment.