File: arc_accessibility_helper_bridge_browsertest.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (516 lines) | stat: -rw-r--r-- 21,395 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/arc/accessibility/arc_accessibility_helper_bridge.h"

#include <memory>
#include <utility>

#include "ash/accessibility/ui/accessibility_focus_ring_controller_impl.h"
#include "ash/accessibility/ui/accessibility_focus_ring_layer.h"
#include "ash/shell.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_base.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/ash/accessibility/accessibility_manager.h"
#include "chrome/browser/ash/accessibility/magnification_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/shelf/app_service/exo_app_type_resolver.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chromeos/ash/experiences/arc/session/arc_bridge_service.h"
#include "chromeos/ash/experiences/arc/session/arc_service_manager.h"
#include "chromeos/ash/experiences/arc/test/arc_util_test_support.h"
#include "chromeos/ash/experiences/arc/test/connection_holder_util.h"
#include "components/exo/buffer.h"
#include "components/exo/client_controlled_accelerators.h"
#include "components/exo/shell_surface.h"
#include "components/exo/shell_surface_util.h"
#include "components/exo/surface.h"
#include "components/exo/test/shell_surface_builder.h"
#include "components/exo/wm_helper.h"
#include "components/viz/common/features.h"
#include "content/public/test/browser_test.h"
#include "extensions/browser/api/automation_internal/automation_event_router_interface.h"
#include "services/accessibility/android/ax_tree_source_android.h"
#include "services/accessibility/android/public/mojom/accessibility_helper.mojom-shared.h"
#include "services/accessibility/android/test/fake_accessibility_helper_instance.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/compositor/layer.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/public/activation_client.h"

namespace arc {

using ::ash::AccessibilityManager;

namespace {

class MockAutomationEventRouter
    : public extensions::AutomationEventRouterInterface {
 public:
  MockAutomationEventRouter() = default;
  virtual ~MockAutomationEventRouter() = default;

  // extensions::AutomationEventRouterInterface:
  void DispatchAccessibilityEvents(
      const ui::AXTreeID& tree_id,
      const std::vector<ui::AXTreeUpdate>& updates,
      const gfx::Point& mouse_location,
      const std::vector<ui::AXEvent>& events) override {}

  void DispatchAccessibilityLocationChange(
      const ui::AXTreeID& tree_id,
      const ui::AXLocationChange& details) override {}

  void DispatchAccessibilityScrollChange(
      const ui::AXTreeID& tree_id,
      const ui::AXScrollChange& details) override {}

  void DispatchTreeDestroyedEvent(ui::AXTreeID tree_id) override {}

  void DispatchActionResult(
      const ui::AXActionData& data,
      bool result,
      content::BrowserContext* browser_context = nullptr) override {
    last_dispatched_action_data_ = data;
    last_dispatched_action_result_ = result;
  }

  void DispatchGetTextLocationDataResult(
      const ui::AXActionData& data,
      const std::optional<gfx::Rect>& rect) override {
    last_dispatched_action_data_ = data;
    last_dispatched_text_location_ = rect;
  }

  std::optional<ui::AXActionData> last_dispatched_action_data_;
  std::optional<bool> last_dispatched_action_result_;
  std::optional<gfx::Rect> last_dispatched_text_location_;
};

}  // namespace

class ArcAccessibilityHelperBridgeBrowserTest : public InProcessBrowserTest {
  void SetUpCommandLine(base::CommandLine* command_line) override {
    arc::SetArcAvailableCommandLineForTesting(command_line);
  }

  void SetUpOnMainThread() override {
    fake_accessibility_helper_instance_ =
        std::make_unique<FakeAccessibilityHelperInstance>();
    ArcServiceManager::Get()
        ->arc_bridge_service()
        ->accessibility_helper()
        ->SetInstance(fake_accessibility_helper_instance_.get());
    WaitForInstanceReady(
        ArcServiceManager::Get()->arc_bridge_service()->accessibility_helper());

    AccessibilityManager::Get()->SetProfileForTest(browser()->profile());

    wm_helper_ = std::make_unique<exo::WMHelper>();
    wm_helper_->RegisterAppPropertyResolver(
        std::make_unique<ExoAppTypeResolver>());
  }

  void TearDownOnMainThread() override {
    wm_helper_.reset();

    ArcServiceManager::Get()
        ->arc_bridge_service()
        ->accessibility_helper()
        ->CloseInstance(fake_accessibility_helper_instance_.get());
    fake_accessibility_helper_instance_.reset();
  }

 protected:
  // Create and initialize a window for this test, i.e. an Arc++-specific
  // version of ExoTestHelper::CreateWindow.
  std::unique_ptr<exo::ClientControlledShellSurface> MakeTestArcWindow(
      std::string name) {
    return exo::test::ShellSurfaceBuilder({640, 480})
        .SetApplicationId(name)
        .BuildClientControlledShellSurface();
  }

  std::unique_ptr<exo::ShellSurface> MakeNonArcTestWindow() {
    return exo::test::ShellSurfaceBuilder({640, 480}).BuildShellSurface();
  }

  std::unique_ptr<FakeAccessibilityHelperInstance>
      fake_accessibility_helper_instance_;
  std::unique_ptr<exo::WMHelper> wm_helper_;
};

IN_PROC_BROWSER_TEST_F(ArcAccessibilityHelperBridgeBrowserTest,
                       PreferenceChange) {
  ASSERT_EQ(ax::android::mojom::AccessibilityFilterType::OFF,
            fake_accessibility_helper_instance_->filter_type());
  EXPECT_FALSE(fake_accessibility_helper_instance_->explore_by_touch_enabled());

  auto shell_surface1 = MakeTestArcWindow("org.chromium.arc.1");
  auto shell_surface2 = MakeTestArcWindow("org.chromium.arc.2");

  wm::ActivationClient* activation_client =
      ash::Shell::Get()->activation_client();
  activation_client->ActivateWindow(
      shell_surface1->GetWidget()->GetNativeWindow());
  ASSERT_EQ(shell_surface1->GetWidget()->GetNativeWindow(),
            activation_client->GetActiveWindow());
  ASSERT_FALSE(shell_surface1->GetWidget()->GetNativeWindow()->GetProperty(
      aura::client::kAccessibilityTouchExplorationPassThrough));
  ASSERT_FALSE(shell_surface2->GetWidget()->GetNativeWindow()->GetProperty(
      aura::client::kAccessibilityTouchExplorationPassThrough));

  AccessibilityManager::Get()->EnableSpokenFeedback(true);

  // Confirm that filter type is updated with preference change.
  EXPECT_EQ(ax::android::mojom::AccessibilityFilterType::ALL,
            fake_accessibility_helper_instance_->filter_type());

  // Use ChromeVox by default. Touch exploration pass through is still false.
  EXPECT_FALSE(shell_surface1->GetWidget()->GetNativeWindow()->GetProperty(
      aura::client::kAccessibilityTouchExplorationPassThrough));

  ArcAccessibilityHelperBridge* bridge =
      ArcAccessibilityHelperBridge::GetForBrowserContext(browser()->profile());

  // Enable TalkBack. Touch exploration pass through of shell_surface1
  // (current active window) would become true.
  bridge->SetNativeChromeVoxArcSupport(
      false,
      base::BindOnce(
          [](extensions::api::accessibility_private::SetNativeChromeVoxResponse
                 response) {}));

  EXPECT_TRUE(shell_surface1->GetWidget()->GetNativeWindow()->GetProperty(
      aura::client::kAccessibilityTouchExplorationPassThrough));

  // Activate shell_surface2 and confirm that it still be false.
  activation_client->ActivateWindow(
      shell_surface2->GetWidget()->GetNativeWindow());
  ASSERT_EQ(shell_surface2->GetWidget()->GetNativeWindow(),
            activation_client->GetActiveWindow());
  EXPECT_FALSE(shell_surface2->GetWidget()->GetNativeWindow()->GetProperty(
      aura::client::kAccessibilityTouchExplorationPassThrough));

  EXPECT_TRUE(fake_accessibility_helper_instance_->explore_by_touch_enabled());
}

IN_PROC_BROWSER_TEST_F(ArcAccessibilityHelperBridgeBrowserTest,
                       RequestTreeSyncOnWindowIdChange) {
  auto shell_surface1 = MakeTestArcWindow("org.chromium.arc.1");
  aura::Window* window1 = shell_surface1->GetWidget()->GetNativeWindow();
  aura::Window child_window1 = aura::Window(nullptr);
  child_window1.Init(ui::LAYER_NOT_DRAWN);
  window1->AddChild(&child_window1);

  auto shell_surface2 = MakeTestArcWindow("org.chromium.arc.2");
  aura::Window* window2 = shell_surface2->GetWidget()->GetNativeWindow();
  aura::Window child_window2 = aura::Window(nullptr);
  child_window2.Init(ui::LAYER_NOT_DRAWN);
  window2->AddChild(&child_window2);

  wm::ActivationClient* activation_client =
      ash::Shell::Get()->activation_client();
  activation_client->ActivateWindow(window1);

  AccessibilityManager::Get()->EnableSpokenFeedback(true);

  exo::SetShellClientAccessibilityId(&child_window1, 10);

  EXPECT_TRUE(
      fake_accessibility_helper_instance_->last_requested_tree_window_key()
          ->is_window_id());
  EXPECT_EQ(
      10U, fake_accessibility_helper_instance_->last_requested_tree_window_key()
               ->get_window_id());

  exo::SetShellClientAccessibilityId(&child_window2, 20);

  EXPECT_EQ(
      20U, fake_accessibility_helper_instance_->last_requested_tree_window_key()
               ->get_window_id());

  exo::SetShellClientAccessibilityId(&child_window2, 21);

  EXPECT_EQ(
      21U, fake_accessibility_helper_instance_->last_requested_tree_window_key()
               ->get_window_id());
}

IN_PROC_BROWSER_TEST_F(ArcAccessibilityHelperBridgeBrowserTest,
                       ExploreByTouchMode) {
  AccessibilityManager::Get()->EnableSpokenFeedback(true);
  EXPECT_TRUE(fake_accessibility_helper_instance_->explore_by_touch_enabled());

  // Check that explore by touch doesn't get disabled as long as ChromeVox
  // remains enabled.
  AccessibilityManager::Get()->SetSelectToSpeakEnabled(true);
  EXPECT_TRUE(fake_accessibility_helper_instance_->explore_by_touch_enabled());

  AccessibilityManager::Get()->EnableSpokenFeedback(false);
  EXPECT_FALSE(fake_accessibility_helper_instance_->explore_by_touch_enabled());

  AccessibilityManager::Get()->SetSelectToSpeakEnabled(false);
  EXPECT_FALSE(fake_accessibility_helper_instance_->explore_by_touch_enabled());
}

IN_PROC_BROWSER_TEST_F(ArcAccessibilityHelperBridgeBrowserTest,
                       FocusHighlight) {
  AccessibilityManager::Get()->SetFocusHighlightEnabled(true);

  auto shell_surface = MakeTestArcWindow("org.chromium.arc.1");
  wm::ActivationClient* activation_client =
      ash::Shell::Get()->activation_client();
  activation_client->ActivateWindow(
      shell_surface->GetWidget()->GetNativeWindow());

  const gfx::Rect node_rect1 = gfx::Rect(50, 50, 50, 50);

  auto event = ax::android::mojom::AccessibilityEventData::New();
  event->event_type = ax::android::mojom::AccessibilityEventType::VIEW_FOCUSED;
  event->task_id = 1;
  event->node_data.push_back(
      ax::android::mojom::AccessibilityNodeInfoData::New());
  auto& node = event->node_data.back();
  node->bounds_in_screen = node_rect1;

  ArcAccessibilityHelperBridge* bridge =
      ArcAccessibilityHelperBridge::GetForBrowserContext(browser()->profile());
  bridge->OnAccessibilityEvent(event.Clone());

  ash::AccessibilityFocusRingControllerImpl* ring_controller =
      ash::Shell::Get()->accessibility_focus_ring_controller();
  const std::vector<std::unique_ptr<ash::AccessibilityFocusRingLayer>>&
      layers1 =
          ring_controller->GetFocusRingGroupForTesting("HighlightController")
              ->focus_layers_for_testing();
  EXPECT_EQ(1u, layers1.size());
  // Focus ring bounds has some extra margin, so only check some attributes.
  const gfx::Rect drawn_rect1 = layers1[0]->layer()->bounds();
  EXPECT_EQ(node_rect1.CenterPoint(), drawn_rect1.CenterPoint());
  EXPECT_TRUE(drawn_rect1.Contains(node_rect1))
      << "drawn_rect " << drawn_rect1.ToString()
      << " should contain the given rect " << node_rect1.ToString();

  // Next, set the filter type to ALL by enabling Select-to-Speak.
  // We still expect that the focus highlight is updated on a focus event.
  AccessibilityManager::Get()->SetSelectToSpeakEnabled(true);

  const gfx::Rect node_rect2 = gfx::Rect(100, 100, 100, 100);

  // Create a full event data.
  event->source_id = 10;
  event->window_data =
      std::vector<ax::android::mojom::AccessibilityWindowInfoDataPtr>();
  event->window_data->push_back(
      ax::android::mojom::AccessibilityWindowInfoData::New());
  auto& window = event->window_data->back();
  window->window_id = 100;
  window->root_node_id = 10;
  node->id = 10;
  node->bounds_in_screen = node_rect2;

  bridge->OnAccessibilityEvent(event.Clone());

  const std::vector<std::unique_ptr<ash::AccessibilityFocusRingLayer>>&
      layers2 =
          ring_controller->GetFocusRingGroupForTesting("HighlightController")
              ->focus_layers_for_testing();
  EXPECT_EQ(1u, layers2.size());
  // Focus ring bounds has some extra margin, so only check some attributes.
  const gfx::Rect drawn_rect2 = layers2[0]->layer()->bounds();
  EXPECT_EQ(node_rect2.CenterPoint(), drawn_rect2.CenterPoint());
  EXPECT_TRUE(drawn_rect2.Contains(node_rect2))
      << "drawn_rect " << drawn_rect2.ToString()
      << " should contain the given rect " << node_rect2.ToString();
}

IN_PROC_BROWSER_TEST_F(ArcAccessibilityHelperBridgeBrowserTest, PerformAction) {
  auto shell_surface = MakeTestArcWindow("org.chromium.arc.1");
  AccessibilityManager::Get()->EnableSpokenFeedback(true);

  ArcAccessibilityHelperBridge* bridge =
      ArcAccessibilityHelperBridge::GetForBrowserContext(browser()->profile());
  auto& tree_map = bridge->trees_for_test();
  ASSERT_EQ(1u, tree_map.size());
  ax::android::AXTreeSourceAndroid* tree_source =
      tree_map.begin()->second.get();
  MockAutomationEventRouter router;
  tree_source->set_automation_event_router_for_test(&router);
  tree_source->set_window_id_for_test(5);

  ui::AXActionData action_data;
  action_data.target_node_id = 10;
  action_data.target_tree_id = tree_source->ax_tree_id();
  action_data.action = ax::mojom::Action::kDoDefault;
  bridge->OnAction(action_data);

  ax::android::mojom::AccessibilityActionData* requested_action =
      fake_accessibility_helper_instance_->last_requested_action();
  EXPECT_EQ(10, requested_action->node_id);
  EXPECT_EQ(ax::android::mojom::AccessibilityActionType::CLICK,
            requested_action->action_type);
  EXPECT_EQ(5, requested_action->window_id);

  ui::AXActionData dispatched_action =
      router.last_dispatched_action_data_.value();
  EXPECT_EQ(10, dispatched_action.target_node_id);
  EXPECT_EQ(tree_source->ax_tree_id(), dispatched_action.target_tree_id);
  EXPECT_EQ(ax::mojom::Action::kDoDefault, dispatched_action.action);

  EXPECT_TRUE(router.last_dispatched_action_result_.has_value());
  EXPECT_TRUE(router.last_dispatched_action_result_.value());

  // Clear event router to prevent invalid access.
  tree_source->set_automation_event_router_for_test(nullptr);
}

IN_PROC_BROWSER_TEST_F(ArcAccessibilityHelperBridgeBrowserTest,
                       PerformActionWithParams) {
  auto shell_surface = MakeTestArcWindow("org.chromium.arc.1");
  AccessibilityManager::Get()->EnableSpokenFeedback(true);

  ArcAccessibilityHelperBridge* bridge =
      ArcAccessibilityHelperBridge::GetForBrowserContext(browser()->profile());
  auto& tree_map = bridge->trees_for_test();
  ASSERT_EQ(1u, tree_map.size());
  ax::android::AXTreeSourceAndroid* tree_source =
      tree_map.begin()->second.get();
  MockAutomationEventRouter router;
  tree_source->set_automation_event_router_for_test(&router);
  tree_source->set_window_id_for_test(5);

  ui::AXActionData action_data;
  action_data.target_node_id = 10;
  action_data.target_tree_id = tree_source->ax_tree_id();
  action_data.action = ax::mojom::Action::kScrollToPositionAtRowColumn;
  action_data.row_column = {1, 3};
  bridge->OnAction(action_data);

  ax::android::mojom::AccessibilityActionData* requested_action =
      fake_accessibility_helper_instance_->last_requested_action();
  EXPECT_EQ(10, requested_action->node_id);
  EXPECT_EQ(ax::android::mojom::AccessibilityActionType::SCROLL_TO_POSITION,
            requested_action->action_type);
  EXPECT_EQ(5, requested_action->window_id);
  EXPECT_EQ(1, requested_action->int_parameters->at(
                   ax::android::mojom::ActionIntArgumentType::ROW_INT));
  EXPECT_EQ(3, requested_action->int_parameters->at(
                   ax::android::mojom::ActionIntArgumentType::COLUMN_INT));

  ui::AXActionData dispatched_action =
      router.last_dispatched_action_data_.value();
  EXPECT_EQ(10, dispatched_action.target_node_id);
  EXPECT_EQ(tree_source->ax_tree_id(), dispatched_action.target_tree_id);
  EXPECT_EQ(ax::mojom::Action::kScrollToPositionAtRowColumn,
            dispatched_action.action);

  EXPECT_TRUE(router.last_dispatched_action_result_.has_value());
  EXPECT_TRUE(router.last_dispatched_action_result_.value());

  // Clear event router to prevent invalid access.
  tree_source->set_automation_event_router_for_test(nullptr);
}

IN_PROC_BROWSER_TEST_F(ArcAccessibilityHelperBridgeBrowserTest,
                       GetTextLocation) {
  auto shell_surface = MakeTestArcWindow("org.chromium.arc.1");
  AccessibilityManager::Get()->SetSelectToSpeakEnabled(true);

  ArcAccessibilityHelperBridge* bridge =
      ArcAccessibilityHelperBridge::GetForBrowserContext(browser()->profile());
  auto& tree_map = bridge->trees_for_test();
  ASSERT_EQ(1u, tree_map.size());
  ax::android::AXTreeSourceAndroid* tree_source =
      tree_map.begin()->second.get();
  MockAutomationEventRouter router;
  tree_source->set_automation_event_router_for_test(&router);
  tree_source->set_window_id_for_test(5);

  ui::AXActionData action_data;
  action_data.target_node_id = 10;
  action_data.target_tree_id = tree_source->ax_tree_id();
  action_data.action = ax::mojom::Action::kGetTextLocation;
  action_data.start_index = 3;
  action_data.end_index = 6;
  bridge->OnAction(action_data);

  ax::android::mojom::AccessibilityActionData* requested_action =
      fake_accessibility_helper_instance_->last_requested_action();
  fake_accessibility_helper_instance_->refresh_with_extra_data_callback().Run(
      gfx::Rect(10, 20, 30, 40));

  EXPECT_EQ(10, requested_action->node_id);
  EXPECT_EQ(ax::android::mojom::AccessibilityActionType::GET_TEXT_LOCATION,
            requested_action->action_type);
  EXPECT_EQ(5, requested_action->window_id);
  EXPECT_EQ(3, requested_action->start_index);
  EXPECT_EQ(6, requested_action->end_index);

  EXPECT_TRUE(router.last_dispatched_text_location_.has_value());
  EXPECT_EQ(gfx::Rect(10, 20, 30, 40),
            router.last_dispatched_text_location_.value());

  // General action path should not be used.
  EXPECT_FALSE(router.last_dispatched_action_result_.has_value());

  // Clear event router to prevent invalid access.
  tree_source->set_automation_event_router_for_test(nullptr);
}

IN_PROC_BROWSER_TEST_F(ArcAccessibilityHelperBridgeBrowserTest, Histogram) {
  base::HistogramTester histogram_tester;

  // Prepare ARC and non-ARC windows
  auto arc_shell_surface = MakeTestArcWindow("org.chromium.arc.1");
  wm::ActivationClient* activation_client =
      ash::Shell::Get()->activation_client();

  auto non_arc_shell_surface = MakeNonArcTestWindow();

  // Turn on and off a feature while an ARC window is focused and then it will
  // be counted.
  activation_client->ActivateWindow(
      arc_shell_surface->GetWidget()->GetNativeWindow());
  histogram_tester.ExpectBucketCount("Arc.Accessibility.WindowCount", 1, 0);
  ash::MagnificationManager::Get()->SetMagnifierEnabled(true);
  histogram_tester.ExpectBucketCount("Arc.Accessibility.WindowCount", 1, 1);
  EXPECT_EQ(ax::android::mojom::AccessibilityFilterType::ALL,
            fake_accessibility_helper_instance_->filter_type());
  histogram_tester.ExpectTotalCount(
      "Arc.Accessibility.ActiveTime.FullscreenMagnifier", 0);
  ash::MagnificationManager::Get()->SetMagnifierEnabled(false);
  histogram_tester.ExpectTotalCount(
      "Arc.Accessibility.ActiveTime.FullscreenMagnifier", 1);

  // Focus on an ARC window and focus on a non-ARC window while a feature is on
  // and then it will be counted.
  activation_client->ActivateWindow(
      non_arc_shell_surface->GetWidget()->GetNativeWindow());
  ash::MagnificationManager::Get()->SetMagnifierEnabled(true);
  histogram_tester.ExpectBucketCount("Arc.Accessibility.WindowCount", 1, 2);
  activation_client->ActivateWindow(
      arc_shell_surface->GetWidget()->GetNativeWindow());
  histogram_tester.ExpectTotalCount(
      "Arc.Accessibility.ActiveTime.FullscreenMagnifier", 1);
  activation_client->ActivateWindow(
      non_arc_shell_surface->GetWidget()->GetNativeWindow());
  histogram_tester.ExpectTotalCount(
      "Arc.Accessibility.ActiveTime.FullscreenMagnifier", 2);

  // Close the focused ARC window while a feature is on and then it will be
  // counted.
  activation_client->ActivateWindow(
      arc_shell_surface->GetWidget()->GetNativeWindow());
  arc_shell_surface.reset();
  histogram_tester.ExpectTotalCount(
      "Arc.Accessibility.ActiveTime.FullscreenMagnifier", 3);

  histogram_tester.ExpectBucketCount("Arc.Accessibility.WindowCount", 1, 2);
}

}  // namespace arc