File: intent_picker_dialog_browsertest.cc

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (115 lines) | stat: -rw-r--r-- 4,313 bytes parent folder | download
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
// Copyright 2018 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 <string>
#include <utility>
#include <vector>

#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/apps/link_capturing/link_capturing_feature_test_support.h"
#include "chrome/browser/favicon/favicon_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/intent_picker_tab_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/intent_picker_bubble_view.h"
#include "chrome/browser/ui/views/location_bar/intent_chip_button.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "ui/base/models/image_model.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image.h"
#include "ui/views/widget/widget_utils.h"
#include "url/gurl.h"

class IntentPickerDialogTest : public DialogBrowserTest {
 public:
  IntentPickerDialogTest() = default;
  IntentPickerDialogTest(const IntentPickerDialogTest&) = delete;
  IntentPickerDialogTest& operator=(const IntentPickerDialogTest&) = delete;

  // DialogBrowserTest:
  void ShowUi(const std::string& name) override {
    std::vector<apps::IntentPickerAppInfo> app_info;
    const auto add_entry = [&app_info](const std::string& str) {
      auto icon_size = IntentPickerTabHelper::GetIntentPickerBubbleIconSize();
      app_info.emplace_back(
          apps::PickerEntryType::kUnknown,
          ui::ImageModel::FromImage(
              gfx::Image::CreateFrom1xBitmap(favicon::GenerateMonogramFavicon(
                  GURL("https://" + str + ".com"), icon_size, icon_size))),
          "Launch name " + str, "Display name " + str);
    };
    add_entry("a");
    add_entry("b");
    add_entry("c");
    add_entry("d");
    IntentPickerBubbleView::ShowBubble(
        BrowserView::GetBrowserViewForBrowser(browser())->GetLocationBarView(),
        GetAnchorButton(), IntentPickerBubbleView::BubbleType::kLinkCapturing,
        browser()->tab_strip_model()->GetActiveWebContents(),
        std::move(app_info), true, true,
        url::Origin::Create(GURL("https://c.com")), base::DoNothing());
  }

 private:
  virtual views::Button* GetAnchorButton() {
    return BrowserView::GetBrowserViewForBrowser(browser())
        ->toolbar_button_provider()
        ->GetPageActionIconView(PageActionIconType::kIntentPicker);
  }
};

#if BUILDFLAG(IS_MAC)
// Flaky on Mac. See https://crbug.com/1330302.
#define MAYBE_InvokeUi_default DISABLED_InvokeUi_default
#else
#define MAYBE_InvokeUi_default InvokeUi_default
#endif
IN_PROC_BROWSER_TEST_F(IntentPickerDialogTest, MAYBE_InvokeUi_default) {
  set_baseline("3742640");
  ShowAndVerifyUi();
}

class IntentPickerDialogGridViewTest : public IntentPickerDialogTest {
 public:
  IntentPickerDialogGridViewTest() {
    apps::EnableLinkCapturingUXForTesting(feature_list_);
  }

  void ShowUi(const std::string& name) override {
    IntentPickerDialogTest::ShowUi(name);

    // Click the first item in the list so we can verify the selection state.
    auto* bubble = IntentPickerBubbleView::intent_picker_bubble();
    auto event_generator =
        ui::test::EventGenerator(views::GetRootWindow(bubble->GetWidget()));
    auto* button =
        bubble->GetViewByID(IntentPickerBubbleView::ViewId::kItemContainer)
            ->children()[0];
    event_generator.MoveMouseTo(button->GetBoundsInScreen().CenterPoint());
    event_generator.ClickLeftButton();
  }

 private:
  views::Button* GetAnchorButton() override {
    return BrowserView::GetBrowserViewForBrowser(browser())
        ->toolbar_button_provider()
        ->GetIntentChipButton();
  }

  base::test::ScopedFeatureList feature_list_;
};

IN_PROC_BROWSER_TEST_F(IntentPickerDialogGridViewTest, InvokeUi_default) {
  set_baseline("3742640");
  ShowAndVerifyUi();
}