File: quick_insert_interactive_uitest.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 (898 lines) | stat: -rw-r--r-- 42,531 bytes parent folder | download | duplicates (6)
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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>
#include <vector>

#include "ash/ash_element_identifiers.h"
#include "ash/constants/ash_features.h"
#include "ash/quick_insert/quick_insert_controller.h"
#include "ash/quick_insert/views/quick_insert_emoji_item_view.h"
#include "ash/quick_insert/views/quick_insert_gif_view.h"
#include "ash/quick_insert/views/quick_insert_image_item_row_view.h"
#include "ash/quick_insert/views/quick_insert_image_item_view.h"
#include "ash/quick_insert/views/quick_insert_list_item_view.h"
#include "ash/shell.h"
#include "base/files/file_util.h"
#include "base/json/json_string_value_serializer.h"
#include "base/strings/string_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/values_test_util.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time_override.h"
#include "chrome/browser/ash/file_manager/path_util.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/test/base/ash/interactive/interactive_ash_test.h"
#include "components/history/core/browser/history_database_params.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/test/history_service_test_util.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "extensions/browser/browsertest_util.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/state_observer.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/view_observer.h"

namespace {

using ::testing::SizeIs;

DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kWebContentsElementId);
DEFINE_LOCAL_CUSTOM_ELEMENT_EVENT_TYPE(kWebInputFieldFocusedEvent);
DEFINE_LOCAL_CUSTOM_ELEMENT_EVENT_TYPE(kWebInputFieldValueEvent);

class ViewFocusObserver
    : public ui::test::
          ObservationStateObserver<bool, views::View, views::ViewObserver> {
 public:
  explicit ViewFocusObserver(views::View* view)
      : ObservationStateObserver(view) {}
  ~ViewFocusObserver() override = default;

  // ui::test::ObservationStateObserver:
  bool GetStateObserverInitialState() const override {
    return source()->HasFocus();
  }

  // views::ViewObserver:
  void OnViewFocused(views::View* observed_view) override {
    if (observed_view == source()) {
      OnStateObserverStateChanged(true);
    }
  }
  void OnViewBlurred(views::View* observed_view) override {
    if (observed_view == source()) {
      OnStateObserverStateChanged(false);
    }
  }
  void OnViewIsDeleting(views::View* observed_view) override {
    OnObservationStateObserverSourceDestroyed();
  }
};

DEFINE_LOCAL_STATE_IDENTIFIER_VALUE(ViewFocusObserver,
                                    kSearchFieldFocusedState);

void TogglePickerByAccelerator() {
  ui_controls::SendKeyPress(/*window=*/nullptr, ui::VKEY_F,
                            /*control=*/false, /*shift=*/false,
                            /*alt=*/false, /*command=*/true);
}

void SendKeyPressWithoutModifiers(ui::KeyboardCode key) {
  ui_controls::SendKeyPress(/*window=*/nullptr, key,
                            /*control=*/false, /*shift=*/false,
                            /*alt=*/false, /*command=*/false);
}

void AddUrlToHistory(Profile* profile,
                     GURL url,
                     base::Time last_visit = base::Time::Now()) {
  history::HistoryService* history_service =
      HistoryServiceFactory::GetForProfile(profile,
                                           ServiceAccessType::EXPLICIT_ACCESS);
  history_service->AddPageWithDetails(url, /*title=*/u"", /*visit_count=*/1,
                                      /*typed_count=*/1,
                                      /*last_visit=*/last_visit,
                                      /*hidden=*/false,
                                      history::SOURCE_BROWSED);
  history::BlockUntilHistoryProcessesPendingRequests(history_service);
}

bool AddLocalFileToDownloads(Profile* profile, const std::string& file_name) {
  const base::FilePath mount_path =
      file_manager::util::GetDownloadsFolderForProfile(profile);
  base::FilePath absolute_path = mount_path.AppendASCII(file_name);
  {
    base::ScopedAllowBlockingForTesting allow_blocking;
    return base::WriteFile(absolute_path, file_name);
  }
}

class QuickInsertInteractiveUiTest : public InteractiveAshTest {
 public:
  const WebContentsInteractionTestUtil::DeepQuery kInputFieldQuery{
      "input[type=\"text\"]",
  };

  QuickInsertInteractiveUiTest() {
    ash::QuickInsertController::DisableFeatureTourForTesting();
  }

  void SetUpOnMainThread() override {
    InteractiveAshTest::SetUpOnMainThread();

    // Set up context for element tracking for InteractiveAshTest.
    SetupContextWidget();
  }

  auto WaitForWebInputFieldFocus() {
    StateChange expected_state;
    expected_state.type = StateChange::Type::kExistsAndConditionTrue;
    expected_state.where = kInputFieldQuery;
    expected_state.test_function = "el => el === document.activeElement";
    expected_state.event = kWebInputFieldFocusedEvent;

    return Steps(WaitForStateChange(kWebContentsElementId, expected_state));
  }

  auto WaitForWebInputFieldValue(std::u16string_view value) {
    StateChange expected_state;
    expected_state.type = StateChange::Type::kExistsAndConditionTrue;
    expected_state.where = kInputFieldQuery;
    expected_state.test_function =
        content::JsReplace("el => el.value === $1", value);
    expected_state.event = kWebInputFieldValueEvent;

    return Steps(WaitForStateChange(kWebContentsElementId, expected_state));
  }

  // Same as `NameDescendantView` but matches on a property of the view.
  template <typename V, typename R, typename T>
  auto NameDescendantViewByProperty(ElementSpecifier view,
                                    std::string_view name,
                                    R (V::*property)() const,
                                    T&& value) {
    return NameDescendantView(
        view, name,
        base::BindLambdaForTesting([property, value](const views::View* view) {
          if (const auto* v = views::AsViewClass<V>(view)) {
            return (v->*property)() == value;
          }
          return false;
        }));
  }
};

// Searches for 'thumbs up', checks the top emoji result is '👍', and inserts it
// into a web input field.
IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest, SearchAndInsertEmoji) {
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  constexpr std::string_view kFirstEmojiResultName = "FirstEmojiResult";
  constexpr std::u16string_view kExpectedFirstEmoji = u"👍";
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"thumbs up"),
      WaitForShow(ash::kQuickInsertEmojiItemElementId,
                  /*transition_only_on_event=*/true),
      NameDescendantViewByProperty(
          ash::kQuickInsertEmojiBarElementId, kFirstEmojiResultName,
          &ash::QuickInsertEmojiItemView::GetTextForTesting,
          kExpectedFirstEmoji),
      PressButton(kFirstEmojiResultName),
      WaitForHide(ash::kQuickInsertElementId),
      InContext(browser_context,
                WaitForWebInputFieldValue(kExpectedFirstEmoji)));
}

// Searches for 'greek letter alpha', checks the top emoji result is 'α'; and
// inserts it into a web input field.
IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest, SearchAndInsertSymbol) {
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  constexpr std::string_view kFirstSymbolResultName = "FirstSymbolResult";
  constexpr std::u16string_view kExpectedFirstSymbol = u"α";
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId,
                u"greek letter alpha"),
      WaitForShow(ash::kQuickInsertEmojiItemElementId,
                  /*transition_only_on_event=*/true),
      NameDescendantViewByProperty(
          ash::kQuickInsertEmojiBarElementId, kFirstSymbolResultName,
          &ash::QuickInsertEmojiItemView::GetTextForTesting,
          kExpectedFirstSymbol),
      PressButton(kFirstSymbolResultName),
      WaitForHide(ash::kQuickInsertElementId),
      InContext(browser_context,
                WaitForWebInputFieldValue(kExpectedFirstSymbol)));
}

// Searches for 'denko of disapproval', checks the top emoji result is 'ಠωಠ';
// and inserts it into a web input field.
IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest, SearchAndInsertEmoticon) {
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  constexpr std::string_view kFirstEmoticonResultName = "FirstEmoticonResult";
  constexpr std::u16string_view kExpectedFirstEmoticon = u"ಠωಠ";
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId,
                u"denko of disapproval"),
      WaitForShow(ash::kQuickInsertEmojiItemElementId,
                  /*transition_only_on_event=*/true),
      NameDescendantViewByProperty(
          ash::kQuickInsertEmojiBarElementId, kFirstEmoticonResultName,
          &ash::QuickInsertEmojiItemView::GetTextForTesting,
          kExpectedFirstEmoticon),
      PressButton(kFirstEmoticonResultName),
      WaitForHide(ash::kQuickInsertElementId),
      InContext(browser_context,
                WaitForWebInputFieldValue(kExpectedFirstEmoticon)));
}

IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest,
                       SearchAndSelectMoreEmojis) {
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"thumbs"),
      WaitForShow(ash::kQuickInsertMoreEmojisElementId),
      PressButton(ash::kQuickInsertMoreEmojisElementId),
      WaitForHide(ash::kQuickInsertElementId),
      WaitForShow(ash::kEmojiPickerElementId));
}

class QuickInsertWithGifsDisabledInteractiveUiTest
    : public QuickInsertInteractiveUiTest {
 public:
  QuickInsertWithGifsDisabledInteractiveUiTest() {
    feature_list_.InitAndDisableFeature(ash::features::kPickerGifs);
  }

 private:
  base::test::ScopedFeatureList feature_list_;
};

IN_PROC_BROWSER_TEST_F(QuickInsertWithGifsDisabledInteractiveUiTest,
                       SearchGifs) {
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"happy"),
      WaitForShow(ash::kQuickInsertGifElementId),
      PressButton(ash::kQuickInsertGifElementId),
      WaitForHide(ash::kQuickInsertElementId),
      WaitForShow(ash::kEmojiPickerElementId));
}

// Intercepts network requests to Tenor and respond with fake GIFs.
// This must be deleted while there's a SingleThreadTaskRunner.
class FakeTenorServer {
 public:
  FakeTenorServer()
      :  // This class outlives `url_loader_interceptor_`.
        url_loader_interceptor_(std::make_unique<content::URLLoaderInterceptor>(
            base::BindRepeating(&FakeTenorServer::MaybeInterceptRequest,
                                base::Unretained(this)))) {}

  bool MaybeInterceptRequest(
      content::URLLoaderInterceptor::RequestParams* params) {
    GURL url = params->url_request.url;
    // tenor.googleapis.com hosts the API endpoints for Tenor.
    if (url.DomainIs("tenor.googleapis.com")) {
      if (url.path_piece().ends_with("/search") ||
          url.path_piece().ends_with("/featured")) {
        return HandleSearchOrFeatured(params);
      }
      return false;
    }

    // media.tenor.com hosts the actual GIFs and preview images themselves.
    if (url.DomainIs("media.tenor.com")) {
      content::URLLoaderInterceptor::WriteResponse(
          "chrome/test/data/google/logo.gif", params->client.get());
      return true;
    }

    return false;
  }

 private:
  bool HandleSearchOrFeatured(
      content::URLLoaderInterceptor::RequestParams* params) {
    // Build up a fake set of GIFs
    base::Value::List results;
    for (int i = 0; i < 10; ++i) {
      results.Append(base::test::ParseJson(R"json({
          "id": "0",
          "content_description": "Google logo",
          "media_formats": {
            "gif": {
              "dims": [276, 110],
              "url": "https://media.tenor.com/full.gif"
            },
            "tinygif": {
              "dims": [276, 110],
              "url": "https://media.tenor.com/full.gif"
            },
            "tinygifpreview": {
              "url": "https://media.tenor.com/full.gif"
            }
          }
        })json"));
    }

    constexpr std::string_view headers =
        "HTTP/1.1 200 OK\nContent-Type: text/json\n\n";
    content::URLLoaderInterceptor::WriteResponse(
        headers,
        *base::WriteJson(
            base::Value::Dict().Set("results", std::move(results))),
        params->client.get());
    return true;
  }

  std::unique_ptr<content::URLLoaderInterceptor> url_loader_interceptor_;
};

class QuickInsertWithGifsEnabledInteractiveUiTest
    : public QuickInsertInteractiveUiTest {
 public:
  QuickInsertWithGifsEnabledInteractiveUiTest()
      : feature_list_(ash::features::kPickerGifs) {}

 private:
  base::test::ScopedFeatureList feature_list_;
};

IN_PROC_BROWSER_TEST_F(QuickInsertWithGifsEnabledInteractiveUiTest,
                       SearchGifs) {
  FakeTenorServer fake_tenor_server;
  // TODO: b/360229206 - Use a contenteditable input field so the file can be
  // inserted.
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  views::Textfield* quick_insert_search_field = nullptr;
  constexpr std::string_view kGifName = "Gif";

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"happy"),
      WaitForShow(ash::kQuickInsertSearchResultsPageElementId),
      WaitForShow(ash::kQuickInsertGifElementId),
      PressButton(ash::kQuickInsertGifElementId),
      WaitForShow(ash::kQuickInsertSearchResultsImageItemElementId),
      NameDescendantViewByType<ash::QuickInsertGifView>(
          ash::kQuickInsertSearchResultsImageItemElementId, kGifName, 0),
      CheckView(kGifName,
                [](ash::QuickInsertGifView* view) {
                  return !view->GetImageBounds().IsEmpty();
                }),
      PressButton(ash::kQuickInsertSearchResultsImageItemElementId),
      WaitForHide(ash::kQuickInsertElementId));
}

IN_PROC_BROWSER_TEST_F(QuickInsertWithGifsEnabledInteractiveUiTest,
                       FeatureGifs) {
  FakeTenorServer fake_tenor_server;
  // TODO: b/360229206 - Use a contenteditable input field so the file can be
  // inserted.
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  views::Textfield* quick_insert_search_field = nullptr;
  constexpr std::string_view kGifName = "Gif";

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      WaitForShow(ash::kQuickInsertGifElementId),
      PressButton(ash::kQuickInsertGifElementId),
      WaitForShow(ash::kQuickInsertSearchResultsPageElementId),
      WaitForShow(ash::kQuickInsertSearchResultsImageItemElementId),
      NameDescendantViewByType<ash::QuickInsertGifView>(
          ash::kQuickInsertSearchResultsImageItemElementId, kGifName, 0),
      CheckView(kGifName,
                [](ash::QuickInsertGifView* view) {
                  return !view->GetImageBounds().IsEmpty();
                }),
      PressButton(ash::kQuickInsertSearchResultsImageItemElementId),
      WaitForHide(ash::kQuickInsertElementId));
}

IN_PROC_BROWSER_TEST_F(QuickInsertWithGifsEnabledInteractiveUiTest,
                       ToggleGifs) {
  AddUrlToHistory(GetActiveUserProfile(), GURL("https://foo.com/history"));
  FakeTenorServer fake_tenor_server;
  // TODO: b/360229206 - Use a contenteditable input field so the file can be
  // inserted.
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      // Turn on GIFs
      WaitForShow(ash::kQuickInsertGifElementId),
      PressButton(ash::kQuickInsertGifElementId),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"foo.com"),
      WaitForShow(ash::kQuickInsertSearchResultsPageElementId),
      WaitForShow(ash::kQuickInsertSearchResultsImageItemElementId),
      // Turn off GIFs
      WaitForShow(ash::kQuickInsertGifElementId),
      PressButton(ash::kQuickInsertGifElementId),
      WaitForShow(ash::kQuickInsertSearchResultsListItemElementId),
      NameDescendantViewByProperty(
          ash::kQuickInsertSearchResultsPageElementId, "HistoryResult",
          &ash::QuickInsertListItemView::GetPrimaryTextForTesting,
          u"foo.com/history"));
}

IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest, SearchBrowsingHistory) {
  AddUrlToHistory(GetActiveUserProfile(), GURL("https://foo.com/history"));
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  constexpr std::string_view kHistoryResultName = "HistoryResult";
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"foo.com"),
      WaitForShow(ash::kQuickInsertSearchResultsPageElementId),
      WaitForShow(ash::kQuickInsertSearchResultsListItemElementId),
      NameDescendantViewByProperty(
          ash::kQuickInsertSearchResultsPageElementId, kHistoryResultName,
          &ash::QuickInsertListItemView::GetPrimaryTextForTesting,
          u"foo.com/history"),
      PressButton(kHistoryResultName), WaitForHide(ash::kQuickInsertElementId),
      InContext(browser_context,
                WaitForWebInputFieldValue(u"https://foo.com/history")));
}

IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest,
                       SearchBrowsingHistoryCategory) {
  AddUrlToHistory(GetActiveUserProfile(), GURL("https://foo.com/history"));
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  constexpr std::string_view kHistoryCategoryResultName =
      "HistoryCategoryResult";
  constexpr std::string_view kHistoryResultName = "HistoryResult";
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"history"),
      WaitForShow(ash::kQuickInsertSearchResultsPageElementId),
      WaitForShow(ash::kQuickInsertSearchResultsListItemElementId),
      NameDescendantViewByProperty(
          ash::kQuickInsertSearchResultsPageElementId,
          kHistoryCategoryResultName,
          &ash::QuickInsertListItemView::GetPrimaryTextForTesting,
          u"Browsing history"),
      PressButton(kHistoryCategoryResultName),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"f"),
      WaitForShow(ash::kQuickInsertSearchResultsPageElementId,
                  /*transition_only_on_event=*/true),
      WaitForShow(ash::kQuickInsertSearchResultsListItemElementId),
      NameDescendantViewByProperty(
          ash::kQuickInsertSearchResultsPageElementId, kHistoryResultName,
          &ash::QuickInsertListItemView::GetPrimaryTextForTesting,
          u"foo.com/history"),
      PressButton(kHistoryResultName), WaitForHide(ash::kQuickInsertElementId),
      InContext(browser_context,
                WaitForWebInputFieldValue(u"https://foo.com/history")));
}

IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest, SearchLocalFile) {
  ASSERT_TRUE(AddLocalFileToDownloads(GetActiveUserProfile(), "test.png"));
  // TODO: b/360229206 - Use a contenteditable input field so the file can be
  // inserted.
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  constexpr std::string_view kFileResultName = "FileResult";
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"test"),
      WaitForShow(ash::kQuickInsertSearchResultsPageElementId),
      WaitForShow(ash::kQuickInsertSearchResultsListItemElementId),
      NameDescendantViewByProperty(
          ash::kQuickInsertSearchResultsPageElementId, kFileResultName,
          &ash::QuickInsertListItemView::GetPrimaryTextForTesting, u"test.png"),
      PressButton(kFileResultName), WaitForHide(ash::kQuickInsertElementId));
}

IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest, SearchLocalFileCategory) {
  ASSERT_TRUE(AddLocalFileToDownloads(GetActiveUserProfile(), "test.png"));
  // TODO: b/360229206 - Use a contenteditable input field so the file can be
  // inserted.
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  constexpr std::string_view kFileCategoryResultName = "FileCategoryResult";
  constexpr std::string_view kFileResultName = "FileResult";
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      // Search for the file category
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"file"),
      WaitForShow(ash::kQuickInsertSearchResultsPageElementId),
      WaitForShow(ash::kQuickInsertSearchResultsListItemElementId),
      NameDescendantViewByProperty(
          ash::kQuickInsertSearchResultsPageElementId, kFileCategoryResultName,
          &ash::QuickInsertListItemView::GetPrimaryTextForTesting, u"Files"),
      // Press the file category and check the file grid.
      PressButton(kFileCategoryResultName),
      WaitForShow(ash::kQuickInsertSearchResultsImageItemElementId),
      // Search for a file and insert it.
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"t"),
      WaitForShow(ash::kQuickInsertSearchResultsListItemElementId),
      NameDescendantViewByProperty(
          ash::kQuickInsertSearchResultsPageElementId, kFileResultName,
          &ash::QuickInsertListItemView::GetPrimaryTextForTesting, u"test.png"),
      PressButton(kFileResultName), WaitForHide(ash::kQuickInsertElementId));
}

// Searches for 'today', checks the top result is the date, and inserts it
// into a web input field.
IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest, SearchAndInsertDate) {
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  constexpr std::string_view kDateResultName = "DateResult";
  constexpr std::u16string_view kExpectedDate = u"Feb 19";
  views::Textfield* quick_insert_search_field = nullptr;
  base::subtle::ScopedTimeClockOverrides time_override(
      []() {
        base::Time date;
        bool result = base::Time::FromString("19 Feb 2024 12:00 GMT", &date);
        CHECK(result);
        return date;
      },
      /*time_ticks_override=*/nullptr,
      /*thread_ticks_override=*/nullptr);

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"today"),
      WaitForShow(ash::kQuickInsertSearchResultsPageElementId),
      WaitForShow(ash::kQuickInsertSearchResultsListItemElementId),
      NameDescendantViewByProperty(
          ash::kQuickInsertSearchResultsPageElementId, kDateResultName,
          &ash::QuickInsertListItemView::GetPrimaryTextForTesting,
          kExpectedDate),
      PressButton(kDateResultName), WaitForHide(ash::kQuickInsertElementId),
      InContext(browser_context, WaitForWebInputFieldValue(kExpectedDate)));
}

// Searches for '1 + 1', checks the top result is '2', and inserts it
// into a web input field.
// TODO: crbug.com/355618977 - Fix flakiness.
IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest,
                       DISABLED_SearchAndInsertMath) {
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  constexpr std::string_view kMathResultName = "MathResult";
  constexpr std::u16string_view kExpectedResult = u"2";
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"1 + 1"),
      WaitForShow(ash::kQuickInsertSearchResultsPageElementId),
      WaitForShow(ash::kQuickInsertSearchResultsListItemElementId),
      NameDescendantViewByProperty(
          ash::kQuickInsertSearchResultsPageElementId, kMathResultName,
          &ash::QuickInsertListItemView::GetPrimaryTextForTesting,
          kExpectedResult),
      PressButton(kMathResultName), WaitForHide(ash::kQuickInsertElementId),
      InContext(browser_context, WaitForWebInputFieldValue(kExpectedResult)));
}

// TODO(crbug.com/376317307): Re-enable once flakiness is fixed.
IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest,
                       DISABLED_ZeroStateShowsSuggestions) {
  ASSERT_TRUE(AddLocalFileToDownloads(GetActiveUserProfile(), "test1.png"));
  ASSERT_TRUE(AddLocalFileToDownloads(GetActiveUserProfile(), "test2.png"));
  ASSERT_TRUE(AddLocalFileToDownloads(GetActiveUserProfile(), "test3.png"));
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  constexpr std::string_view kFile1Name = "File1";
  constexpr std::string_view kFile2Name = "File2";
  constexpr std::string_view kFile3Name = "File3";
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      WaitForShow(ash::kQuickInsertSearchResultsImageRowElementId),
      WaitForViewProperty(ash::kQuickInsertSearchResultsImageRowElementId,
                          ash::QuickInsertImageItemRowView, Items, SizeIs(3)),
      NameDescendantViewByType<ash::QuickInsertImageItemView>(
          ash::kQuickInsertElementId, kFile1Name, 0),
      NameDescendantViewByType<ash::QuickInsertImageItemView>(
          ash::kQuickInsertElementId, kFile2Name, 1),
      NameDescendantViewByType<ash::QuickInsertImageItemView>(
          ash::kQuickInsertElementId, kFile3Name, 2),
      CheckViewProperty(kFile1Name, &views::View::GetAccessibleName,
                        u"Insert test1.png"),
      CheckViewProperty(kFile2Name, &views::View::GetAccessibleName,
                        u"Insert test2.png"),
      CheckViewProperty(kFile3Name, &views::View::GetAccessibleName,
                        u"Insert test3.png"));
}

// Navigates through the zero-state UI using only the keyboard.
IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest,
                       KeyboardNavigationInZeroState) {
  ASSERT_TRUE(CreateBrowserWindow(
      GURL("data:text/html,<input type=\"text\" autofocus/>")));
  const ui::ElementContext browser_context =
      chrome::FindLastActive()->window()->GetElementContext();
  constexpr std::string_view kItem1Name = "Item1";
  constexpr std::string_view kItem2Name = "Item2";
  constexpr std::string_view kEmoji1Name = "Emoji1";
  constexpr std::string_view kEmoji2Name = "Emoji2";
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      InContext(browser_context, Steps(InstrumentTab(kWebContentsElementId),
                                       WaitForWebInputFieldFocus())),
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      NameDescendantViewByType<ash::QuickInsertListItemView>(
          ash::kQuickInsertElementId, kItem1Name, 0),
      NameDescendantViewByType<ash::QuickInsertListItemView>(
          ash::kQuickInsertElementId, kItem2Name, 1),
      NameDescendantViewByType<ash::QuickInsertEmojiItemView>(
          ash::kQuickInsertElementId, kEmoji1Name, 0),
      NameDescendantViewByType<ash::QuickInsertEmojiItemView>(
          ash::kQuickInsertElementId, kEmoji2Name, 1),
      // The first item should be selected by default.
      CheckViewProperty(kItem1Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kPseudoFocused),
      // Down arrow should move to the next item.
      Do([]() { SendKeyPressWithoutModifiers(ui::VKEY_DOWN); }),
      CheckViewProperty(kItem2Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kPseudoFocused),
      CheckViewProperty(kItem1Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kNormal),
      // Up arrow should move to the previous item.
      Do([]() { SendKeyPressWithoutModifiers(ui::VKEY_UP); }),
      CheckViewProperty(kItem1Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kPseudoFocused),
      CheckViewProperty(kItem2Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kNormal),
      // Up arrow should move to the first emoji in the emoji bar.
      Do([]() { SendKeyPressWithoutModifiers(ui::VKEY_UP); }),
      CheckViewProperty(kEmoji1Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kPseudoFocused),
      CheckViewProperty(kItem1Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kNormal),
      // Right arrow should move to the second emoji in the emoji bar.
      Do([]() { SendKeyPressWithoutModifiers(ui::VKEY_RIGHT); }),
      CheckViewProperty(kEmoji2Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kPseudoFocused),
      CheckViewProperty(kEmoji1Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kNormal),
      // Left arrow should back move to the first emoji in the emoji bar.
      Do([]() { SendKeyPressWithoutModifiers(ui::VKEY_LEFT); }),
      CheckViewProperty(kEmoji1Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kPseudoFocused),
      CheckViewProperty(kEmoji2Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kNormal),
      // Down arrow should back move to the first item.
      Do([]() { SendKeyPressWithoutModifiers(ui::VKEY_DOWN); }),
      CheckViewProperty(kItem1Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kPseudoFocused),
      CheckViewProperty(kEmoji1Name, &ash::QuickInsertItemView::GetItemState,
                        ash::QuickInsertItemView::ItemState::kNormal));
}

IN_PROC_BROWSER_TEST_F(QuickInsertInteractiveUiTest, LocalFilePreview) {
  ASSERT_TRUE(AddLocalFileToDownloads(GetActiveUserProfile(), "test.png"));
  constexpr std::string_view kFileResultName = "FileResult";
  views::Textfield* quick_insert_search_field = nullptr;

  RunTestSequence(
      Do([]() { TogglePickerByAccelerator(); }),
      AfterShow(ash::kQuickInsertSearchFieldTextfieldElementId,
                [&quick_insert_search_field](ui::TrackedElement* el) {
                  quick_insert_search_field = AsView<views::Textfield>(el);
                }),
      ObserveState(kSearchFieldFocusedState,
                   std::ref(quick_insert_search_field)),
      WaitForState(kSearchFieldFocusedState, true),
      EnterText(ash::kQuickInsertSearchFieldTextfieldElementId, u"test"),
      WaitForShow(ash::kQuickInsertSearchResultsPageElementId),
      WaitForShow(ash::kQuickInsertSearchResultsListItemElementId),
      NameDescendantViewByProperty(
          ash::kQuickInsertSearchResultsPageElementId, kFileResultName,
          &ash::QuickInsertListItemView::GetPrimaryTextForTesting, u"test.png"),
      MoveMouseTo(kFileResultName),
      WaitForShow(ash::kQuickInsertPreviewBubbleElementId));
}

}  // namespace