File: help_bubble_view_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (527 lines) | stat: -rw-r--r-- 20,670 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
517
518
519
520
521
522
523
524
525
526
527
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/user_education/views/help_bubble_view.h"

#include <memory>
#include <vector>

#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/test/mock_callback.h"
#include "components/user_education/common/feature_promo/feature_promo_specification.h"
#include "components/user_education/common/help_bubble/help_bubble.h"
#include "components/user_education/common/help_bubble/help_bubble_params.h"
#include "components/user_education/common/user_education_events.h"
#include "components/user_education/views/help_bubble_delegate.h"
#include "components/user_education/views/help_bubble_factory_views.h"
#include "components/user_education/views/help_bubble_views.h"
#include "components/user_education/views/help_bubble_views_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_test_util.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/interaction/expect_call_in_scope.h"
#include "ui/base/interaction/interaction_test_util.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/interaction/interaction_test_util_views.h"
#include "ui/views/layout/flex_layout_view.h"
#include "ui/views/layout/layout_types.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/test/views_test_utils.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"

namespace user_education {

namespace {
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kTestElementId);
const ui::ElementContext kTestElementContext{1};
constexpr gfx::Rect kWidgetBounds{400, 200, 200, 200};
}  // namespace

// Unit tests for HelpBubbleView. Timeout functionality isn't tested here due to
// the vagaries of trying to get simulated timed events to run without a full
// execution environment (specifically, Mac tests were extremely flaky without
// the browser).
//
// Timeouts are tested in:
// chrome/browser/ui/views/user_education/help_bubble_view_timeout_unittest.cc
class HelpBubbleViewTest : public views::ViewsTestBase {
 public:
  HelpBubbleViewTest() = default;
  ~HelpBubbleViewTest() override = default;

  void SetUp() override {
    ViewsTestBase::SetUp();
    widget_ = std::make_unique<test::TestThemedWidget>();
    widget_->Init(CreateParamsForTestWidget());
    view_ = widget_->SetContentsView(std::make_unique<views::View>());
    widget_->Show();
    widget_->SetBounds(kWidgetBounds);
  }

  void TearDown() override {
    widget_.reset();
    ViewsTestBase::TearDown();
  }

 protected:
  gfx::Rect GetWidgetClientBounds() const {
    return widget_->GetClientAreaBoundsInScreen();
  }

  HelpBubbleView* CreateHelpBubbleView(
      HelpBubbleParams params,
      std::optional<gfx::Rect> bounds = std::nullopt,
      std::optional<views::View*> view = std::nullopt) {
    internal::HelpBubbleAnchorParams anchor_params;
    anchor_params.view = view.value_or(view_);
    anchor_params.rect = bounds;
    return new HelpBubbleView(&test_delegate_, anchor_params,
                              std::move(params));
  }

  HelpBubbleView* CreateHelpBubbleView(base::RepeatingClosure button_callback) {
    HelpBubbleParams params;
    params.body_text = u"To X, do Y";
    params.arrow = HelpBubbleArrow::kTopRight;

    if (button_callback) {
      HelpBubbleButtonParams button_params;
      button_params.text = u"Go away";
      button_params.is_default = true;
      button_params.callback = std::move(button_callback);
      params.buttons.push_back(std::move(button_params));
    }

    return CreateHelpBubbleView(std::move(params));
  }

  test::TestHelpBubbleDelegate test_delegate_;
  raw_ptr<views::View, DanglingUntriaged> view_;
  std::unique_ptr<views::Widget> widget_;
};

TEST_F(HelpBubbleViewTest, DefaultMaxWidth) {
  HelpBubbleParams params;

  // Choose body text that will wrap.
  params.body_text =
      u"The quick brown fox jumped over the lazy dogs. How now brown cow.";
  HelpBubbleButtonParams button1;
  button1.is_default = true;
  button1.text = u"button1";
  params.buttons.emplace_back(std::move(button1));
  HelpBubbleButtonParams button2;
  button2.is_default = false;
  button2.text = u"button2";
  params.buttons.emplace_back(std::move(button2));

  HelpBubbleView* const bubble = CreateHelpBubbleView(std::move(params));
  EXPECT_EQ(HelpBubbleView::kMaxWidthDip, bubble->GetPreferredSize().width());
  bubble->GetWidget()->Close();
}

TEST_F(HelpBubbleViewTest, ExpandedMaxWidth) {
  HelpBubbleParams params;

  // Choose body text that will wrap.
  params.body_text =
      u"The quick brown fox jumped over the lazy dogs. How now brown cow.";
  HelpBubbleButtonParams button1;
  button1.is_default = true;
  button1.text = u"Lorem ipsum dolor sit amet, consectetur adipiscing elit";
  params.buttons.emplace_back(std::move(button1));
  HelpBubbleButtonParams button2;
  button2.is_default = false;
  button2.text = u"button2";
  params.buttons.emplace_back(std::move(button2));

  HelpBubbleView* const bubble = CreateHelpBubbleView(std::move(params));
  EXPECT_GT(bubble->GetPreferredSize().width(), HelpBubbleView::kMaxWidthDip);
  bubble->GetWidget()->Close();
}

TEST_F(HelpBubbleViewTest, CallButtonCallback_Mouse) {
  UNCALLED_MOCK_CALLBACK(base::RepeatingClosure, mock_callback);

  HelpBubbleView* const bubble = CreateHelpBubbleView(mock_callback.Get());

  // Simulate clicks on dismiss button.
  EXPECT_CALL_IN_SCOPE(
      mock_callback, Run,
      views::test::InteractionTestUtilSimulatorViews::PressButton(
          bubble->GetDefaultButtonForTesting(),
          ui::test::InteractionTestUtil::InputType::kMouse));

  bubble->GetWidget()->Close();
}

TEST_F(HelpBubbleViewTest, CallButtonCallback_Keyboard) {
  UNCALLED_MOCK_CALLBACK(base::RepeatingClosure, mock_callback);

  HelpBubbleView* const bubble = CreateHelpBubbleView(mock_callback.Get());

  // Simulate clicks on dismiss button.
  EXPECT_CALL_IN_SCOPE(
      mock_callback, Run,
      views::test::InteractionTestUtilSimulatorViews::PressButton(
          bubble->GetDefaultButtonForTesting(),
          ui::test::InteractionTestUtil::InputType::kKeyboard));

  bubble->GetWidget()->Close();
}

TEST_F(HelpBubbleViewTest, StableButtonOrder) {
  HelpBubbleParams params;
  params.body_text = u"To X, do Y";
  params.arrow = HelpBubbleArrow::kTopRight;

  constexpr char16_t kButton1Text[] = u"button 1";
  constexpr char16_t kButton2Text[] = u"button 2";
  constexpr char16_t kButton3Text[] = u"button 3";

  HelpBubbleButtonParams button1;
  button1.text = kButton1Text;
  button1.is_default = false;
  params.buttons.push_back(std::move(button1));

  HelpBubbleButtonParams button2;
  button2.text = kButton2Text;
  button2.is_default = true;
  params.buttons.push_back(std::move(button2));

  HelpBubbleButtonParams button3;
  button3.text = kButton3Text;
  button3.is_default = false;
  params.buttons.push_back(std::move(button3));

  auto* bubble = new HelpBubbleView(
      &test_delegate_, internal::HelpBubbleAnchorParams{view_.get()},
      std::move(params));
  EXPECT_EQ(kButton1Text, bubble->GetNonDefaultButtonForTesting(0)->GetText());
  EXPECT_EQ(kButton2Text, bubble->GetDefaultButtonForTesting()->GetText());
  EXPECT_EQ(kButton3Text, bubble->GetNonDefaultButtonForTesting(1)->GetText());
}

TEST_F(HelpBubbleViewTest, AnchorToRect) {
  HelpBubbleParams params;
  params.body_text = u"To X, do Y";
  params.arrow = HelpBubbleArrow::kRightCenter;

  const auto widget_bounds = GetWidgetClientBounds();
  gfx::Rect anchor_bounds = widget_bounds;
  anchor_bounds.Inset(50);

  HelpBubbleView* const bubble =
      CreateHelpBubbleView(std::move(params), anchor_bounds);

  // CreateHelpBubbleView() will trigger an asynchronous autosize task.
  views::test::RunScheduledLayout(bubble->GetWidget());
  const auto bubble_bounds = bubble->GetWidget()->GetWindowBoundsInScreen();

  // The right side of the bubble should overlap the widget.
  EXPECT_TRUE(widget_bounds.Contains(bubble_bounds.right_center()));

  // The right side of the widget should be outside and aligned with the center
  // of the anchor bounds. Allow for rounding error when checking alignment.
  EXPECT_LT(bubble_bounds.right(), anchor_bounds.x());
  EXPECT_LE(std::abs(bubble_bounds.CenterPoint().y() -
                     anchor_bounds.CenterPoint().y()),
            2);
}

TEST_F(HelpBubbleViewTest, AnchorRectUpdated) {
  HelpBubbleParams params;
  params.body_text = u"To X, do Y";
  params.arrow = HelpBubbleArrow::kRightCenter;

  const auto widget_bounds = GetWidgetClientBounds();
  gfx::Rect anchor_bounds = widget_bounds;
  anchor_bounds.Inset(50);

  HelpBubbleView* const bubble =
      CreateHelpBubbleView(std::move(params), anchor_bounds);

  // CreateHelpBubbleView() will trigger an asynchronous autosize task.
  views::test::RunScheduledLayout(bubble->GetWidget());
  const auto bubble_bounds = bubble->GetWidget()->GetWindowBoundsInScreen();

  constexpr gfx::Vector2d kAnchorOffset{9, 13};
  anchor_bounds.Offset(kAnchorOffset);
  bubble->SetForceAnchorRect(anchor_bounds);
  bubble->OnAnchorBoundsChanged();

  // Bubble's anchor change will trigger an asynchronous autosize task.
  views::test::RunScheduledLayout(bubble->GetWidget());
  gfx::Rect expected = bubble_bounds;
  expected.Offset(kAnchorOffset);
  EXPECT_EQ(expected, bubble->GetWidget()->GetWindowBoundsInScreen());
}

TEST_F(HelpBubbleViewTest, ScrollAnchorViewToVisible) {
  views::ScrollView* scroll_view = nullptr;
  views::View* anchor_view = nullptr;

  // Add an `anchor_view` to the `view_` hierarchy that is hosted within a
  // `scroll_view` and is initially outside the viewport.
  views::Builder<views::View>(view_)
      .SetUseDefaultFillLayout(true)
      .AddChildren(
          views::Builder<views::ScrollView>()
              .CopyAddressTo(&scroll_view)
              .ClipHeightTo(/*min_height=*/0, /*max_height=*/view_->height())
              .SetContents(
                  views::Builder<views::FlexLayoutView>()
                      .SetCrossAxisAlignment(views::LayoutAlignment::kEnd)
                      .SetMainAxisAlignment(views::LayoutAlignment::kEnd)
                      .SetOrientation(views::LayoutOrientation::kVertical)
                      .AddChildren(
                          views::Builder<views::View>().SetPreferredSize(
                              view_->size()),
                          views::Builder<views::View>()
                              .CopyAddressTo(&anchor_view)
                              .SetPreferredSize(gfx::Size(10, 10)))))
      .BuildChildren();

  // Ensure `widget_` has finished processing the layout changes.
  views::test::RunScheduledLayout(widget_.get());

  // Initially `anchor_view` should not be visible.
  EXPECT_FALSE(scroll_view->GetBoundsInScreen().Contains(
      anchor_view->GetBoundsInScreen()));

  // Expect that `scroll_view` will scroll when creating a help bubble anchored
  // to `anchor_view` since it is outside the viewport.
  base::MockRepeatingClosure callback;
  EXPECT_CALL(callback, Run()).Times(testing::AtLeast(1));
  base::CallbackListSubscription subscription =
      scroll_view->AddContentsScrolledCallback(callback.Get());

  // Create the help bubble anchored to `anchor_view`.
  HelpBubbleParams params;
  params.body_text = u"To X, do Y";
  params.arrow = HelpBubbleArrow::kTopRight;
  CreateHelpBubbleView(std::move(params), /*bounds=*/std::nullopt, anchor_view);

  // Expect that `anchor_view` is now visible.
  EXPECT_TRUE(scroll_view->GetBoundsInScreen().Contains(
      anchor_view->GetBoundsInScreen()));
}

class HelpBubbleViewsTest : public HelpBubbleViewTest {
 public:
  HelpBubbleViewsTest() = default;
  ~HelpBubbleViewsTest() override = default;

  // This simulates logic used by e.g. FloatingWebUIHelpBubbleFactory.
  std::unique_ptr<HelpBubbleViews> CreateHelpBubble(
      HelpBubbleParams params,
      ui::TrackedElement* element) {
    HelpBubbleView* const bubble_view =
        CreateHelpBubbleView(std::move(params), element->GetScreenBounds());
    return base::WrapUnique(new HelpBubbleViews(bubble_view, element));
  }

  void SetUp() override {
    HelpBubbleViewTest::SetUp();

    HelpBubbleParams params;
    params.body_text = u"To X, do Y";
    params.arrow = HelpBubbleArrow::kRightCenter;

    gfx::Rect anchor_bounds = GetWidgetClientBounds();
    anchor_bounds.Inset(50);

    test_element_ = std::make_unique<ui::test::TestElement>(
        kTestElementId, kTestElementContext);
    test_element_->SetScreenBounds(anchor_bounds);
    test_element_->Show();

    help_bubble_ = CreateHelpBubble(std::move(params), test_element_.get());

    // CreateHelpBubble() will trigger an asynchronous autosize task.
    views::test::RunScheduledLayout(help_bubble_->bubble_view_for_testing());
  }

  void TearDown() override {
    test_element_.reset();
    HelpBubbleViewTest::TearDown();
  }

 protected:
  gfx::Rect GetHelpBubbleAnchorRect() const {
    return help_bubble_->bubble_view_for_testing()->GetAnchorRect();
  }

  std::unique_ptr<ui::test::TestElement> test_element_;
  std::unique_ptr<HelpBubbleViews> help_bubble_;
};

// This duplicates the HelpBubbleViewTest, but with a HelpBubbleViews object.
TEST_F(HelpBubbleViewsTest, AnchorToRect) {
  const auto widget_bounds = GetWidgetClientBounds();
  const auto anchor_bounds = test_element_->GetScreenBounds();
  const auto bubble_bounds = help_bubble_->GetBoundsInScreen();

  // The right side of the bubble should overlap the widget.
  EXPECT_TRUE(widget_bounds.Contains(bubble_bounds.right_center()));

  // The right side of the widget should be outside and aligned with the center
  // of the anchor bounds. Allow for rounding error when checking alignment.
  EXPECT_LT(bubble_bounds.right(), anchor_bounds.x());
  EXPECT_LE(std::abs(bubble_bounds.CenterPoint().y() -
                     anchor_bounds.CenterPoint().y()),
            2);
}

// This duplicates the HelpBubbleViewTest, but with a HelpBubbleViews object.
TEST_F(HelpBubbleViewsTest, AnchorRectUpdated) {
  const gfx::Rect old_bounds = help_bubble_->GetBoundsInScreen();

  // Move the anchor target by a small but noticeable amount.
  auto new_bounds = test_element_->GetScreenBounds();
  constexpr gfx::Vector2d kAnchorOffset{9, 13};
  new_bounds.Offset(kAnchorOffset);
  test_element_->SetScreenBounds(new_bounds);
  ui::ElementTracker::GetFrameworkDelegate()->NotifyCustomEvent(
      test_element_.get(), kHelpBubbleAnchorBoundsChangedEvent);

  // Verify that the help bubble has moved by a similar amount.
  gfx::Rect expected = old_bounds;
  expected.Offset(kAnchorOffset);
  EXPECT_EQ(expected, help_bubble_->GetBoundsInScreen());
}

// This checks a case where the target anchor region scrolls partially out of
// the host view. The anchor rect should be the intersection of the two.
TEST_F(HelpBubbleViewsTest, AnchorRectOverlapsEdge) {
  const gfx::Rect old_bounds = help_bubble_->GetBoundsInScreen();

  // Move the anchor target so that the upper left is beyond the edge of the
  // anchor view.
  auto new_bounds = test_element_->GetScreenBounds();
  new_bounds.Offset(-100, -100);
  test_element_->SetScreenBounds(new_bounds);
  ui::ElementTracker::GetFrameworkDelegate()->NotifyCustomEvent(
      test_element_.get(), kHelpBubbleAnchorBoundsChangedEvent);

  // Verify that the help bubble has moved.
  constexpr gfx::Rect kNewAnchorBounds{kWidgetBounds.x(), kWidgetBounds.y(), 50,
                                       50};
  EXPECT_EQ(kNewAnchorBounds, GetHelpBubbleAnchorRect());
  const gfx::Rect help_bubble_bounds = help_bubble_->GetBoundsInScreen();
  EXPECT_LT(help_bubble_bounds.y(), old_bounds.y());
  EXPECT_GT(help_bubble_bounds.CenterPoint().y(), kNewAnchorBounds.y());
  EXPECT_LT(help_bubble_bounds.CenterPoint().y(), kNewAnchorBounds.bottom());

  // Bubble may have mirrored horizontally. Check which orientation it's in and
  // verify the position is appropriate to the new anchor region.
  switch (help_bubble_->bubble_view_for_testing()
              ->GetBubbleFrameView()
              ->GetArrow()) {
    case views::BubbleBorder::RIGHT_CENTER:
      EXPECT_LT(help_bubble_bounds.x(), old_bounds.x());
      EXPECT_LT(help_bubble_bounds.right(), kNewAnchorBounds.x());
      break;
    case views::BubbleBorder::LEFT_CENTER:
      EXPECT_GT(help_bubble_bounds.x(), old_bounds.x());
      EXPECT_GT(help_bubble_bounds.x(), kNewAnchorBounds.right());
      break;
    default:
      NOTREACHED() << "Arrow should only be right-center or left-center.";
  }
}

// This checks a case where the target anchor region scrolls fully out of
// the host view. The anchor rect should be a one-pixel slice on the edge
// closest to the actual anchor.
TEST_F(HelpBubbleViewsTest, AnchorOutsideBoundsHorizontal) {
  const gfx::Rect old_bounds = help_bubble_->GetBoundsInScreen();

  // Move the anchor target entirely off the right side of the anchor view.
  auto new_bounds = test_element_->GetScreenBounds();
  new_bounds.Offset(200, 0);
  test_element_->SetScreenBounds(new_bounds);
  ui::ElementTracker::GetFrameworkDelegate()->NotifyCustomEvent(
      test_element_.get(), kHelpBubbleAnchorBoundsChangedEvent);

  // Verify that the help bubble has moved. It might be mirrored, however.
  constexpr gfx::Rect kNewAnchorBounds{kWidgetBounds.right() - 1,
                                       kWidgetBounds.y() + 50, 1, 100};
  EXPECT_EQ(kNewAnchorBounds, GetHelpBubbleAnchorRect());
  const gfx::Rect help_bubble_bounds = help_bubble_->GetBoundsInScreen();
  EXPECT_EQ(help_bubble_bounds.y(), old_bounds.y());
  EXPECT_GT(help_bubble_bounds.x(), old_bounds.x());
  EXPECT_LT(help_bubble_bounds.right(), kNewAnchorBounds.x());
}

// This checks a case where the target anchor region scrolls fully out of
// the host view. The anchor rect should be a one-pixel slice on the edge
// closest to the actual anchor.
TEST_F(HelpBubbleViewsTest, AnchorOutsideBoundsVertical) {
  const gfx::Rect old_bounds = help_bubble_->GetBoundsInScreen();

  // Move the anchor target entirely beyond the bottom of the anchor view.
  auto new_bounds = test_element_->GetScreenBounds();
  new_bounds.Offset(0, 200);
  test_element_->SetScreenBounds(new_bounds);
  ui::ElementTracker::GetFrameworkDelegate()->NotifyCustomEvent(
      test_element_.get(), kHelpBubbleAnchorBoundsChangedEvent);

  // Verify that the help bubble has moved. It might be mirrored, however.
  constexpr gfx::Rect kNewAnchorBounds{kWidgetBounds.x() + 50,
                                       kWidgetBounds.bottom() - 1, 100, 1};
  EXPECT_EQ(kNewAnchorBounds, GetHelpBubbleAnchorRect());
  const gfx::Rect help_bubble_bounds = help_bubble_->GetBoundsInScreen();
  EXPECT_EQ(help_bubble_bounds.x(), old_bounds.x());
  EXPECT_GT(help_bubble_bounds.y(), old_bounds.y());
  EXPECT_LT(help_bubble_bounds.y(), kNewAnchorBounds.y());
  EXPECT_GE(help_bubble_bounds.bottom(), kNewAnchorBounds.y());
  EXPECT_LT(help_bubble_bounds.right(), kNewAnchorBounds.x());
}

// Verifies that a bubble anchored to a region will still move with the owning
// Widget.
TEST_F(HelpBubbleViewsTest, MoveAnchorWidget) {
  const auto old_bubble_bounds = help_bubble_->GetBoundsInScreen();
  gfx::Rect widget_bounds = widget_->GetWindowBoundsInScreen();
  constexpr gfx::Vector2d kOffset{9, 13};
  widget_bounds.Offset(kOffset);
  widget_->SetBounds(widget_bounds);
  gfx::Rect expected = old_bubble_bounds;
  expected.Offset(kOffset);
  EXPECT_EQ(expected, help_bubble_->GetBoundsInScreen());
}

TEST_F(HelpBubbleViewsTest, RootViewAccessibleName) {
  ui::AXNodeData root_view_data;
  help_bubble_->bubble_view_for_testing()
      ->GetWidget()
      ->GetRootView()
      ->GetViewAccessibility()
      .GetAccessibleNodeData(&root_view_data);
  EXPECT_EQ(
      root_view_data.GetString16Attribute(ax::mojom::StringAttribute::kName),
      help_bubble_->bubble_view_for_testing()->GetAccessibleWindowTitle());
}

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC)
TEST_F(HelpBubbleViewsTest, MinimizeAnchorWidget) {
  views::test::WidgetDestroyedWaiter waiter(
      help_bubble_->bubble_view_for_testing()->GetWidget());
  widget_->Minimize();
  waiter.Wait();
}
#endif

}  // namespace user_education