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
|
// 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/ui_features.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/intent_chip_button_test_base.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("5428271");
ShowAndVerifyUi();
}
class IntentPickerDialogGridViewTest
: public IntentPickerDialogTest,
public testing::WithParamInterface<
std::tuple<apps::test::LinkCapturingFeatureVersion, bool>>,
public IntentChipButtonTestBase {
public:
IntentPickerDialogGridViewTest() {
std::vector<base::test::FeatureRefAndParams> features_to_enable =
apps::test::GetFeaturesToEnableLinkCapturingUX(
std::get<apps::test::LinkCapturingFeatureVersion>(GetParam()));
if (IsMigrationEnabled()) {
features_to_enable.push_back(
{::features::kPageActionsMigration,
{{::features::kPageActionsMigrationIntentPicker.name, "true"}}});
}
feature_list_.InitWithFeaturesAndParameters(features_to_enable, {});
}
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]
.get();
event_generator.MoveMouseTo(button->GetBoundsInScreen().CenterPoint());
event_generator.ClickLeftButton();
}
bool IsMigrationEnabled() const { return std::get<bool>(GetParam()); }
private:
views::Button* GetAnchorButton() override { return GetIntentChip(browser()); }
base::test::ScopedFeatureList feature_list_;
};
IN_PROC_BROWSER_TEST_P(IntentPickerDialogGridViewTest, InvokeUi_default) {
set_baseline("5428271");
ShowAndVerifyUi();
}
INSTANTIATE_TEST_SUITE_P(
,
IntentPickerDialogGridViewTest,
testing::Combine(
#if BUILDFLAG(IS_CHROMEOS)
testing::Values(apps::test::LinkCapturingFeatureVersion::kV1DefaultOff,
apps::test::LinkCapturingFeatureVersion::kV2DefaultOff),
#else
testing::Values(apps::test::LinkCapturingFeatureVersion::kV2DefaultOff,
apps::test::LinkCapturingFeatureVersion::kV2DefaultOn),
#endif // BUILDFLAG(IS_CHROMEOS)
testing::Bool()),
[](const testing::TestParamInfo<
std::tuple<apps::test::LinkCapturingFeatureVersion, bool>>& info) {
return IntentChipButtonTestBase::GenerateIntentChipTestName(info);
});
|