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
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/global_features.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/views/infobars/confirm_infobar.h"
#include "chrome/browser/win/installer_downloader/installer_downloader_controller.h"
#include "chrome/browser/win/installer_downloader/installer_downloader_feature.h"
#include "chrome/browser/win/installer_downloader/installer_downloader_pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "content/public/test/browser_test.h"
#include "url/gurl.h"
namespace installer_downloader {
namespace {
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kSecondTabContents);
// A valid template; IIDGUID and STATS are substituted at runtime.
constexpr char kUrlTemplate[] =
"https://example.com/installer.exe?iid=IIDGUID&stats=STATS";
class InstallerDownloaderInteractiveUiTest : public InteractiveBrowserTest {
protected:
void SetUp() override {
feature_list_.InitAndEnableFeatureWithParameters(
kInstallerDownloader,
{{kInstallerUrlTemplateParam.name, kUrlTemplate}});
InteractiveBrowserTest::SetUp();
}
InteractiveTestApi::MultiStep ShowInfobarOnNewTab() {
return Steps(AddInstrumentedTab(kSecondTabContents,
GURL(chrome::kChromeUINewTabURL)),
WaitForShow(ConfirmInfoBar::kInfoBarElementId));
}
// Switches back to the first tab and verifies that the infobar is gone
// everywhere.
InteractiveTestApi::MultiStep VerifyNoInfobarInAnyTab() {
return Steps(WaitForHide(ConfirmInfoBar::kInfoBarElementId),
SelectTab(kTabStripElementId, 0),
WaitForHide(ConfirmInfoBar::kInfoBarElementId));
}
// Assumes that actual window have infobar visible. As a result, new window
// will also get the infobar.
InteractiveTestApi::MultiStep ShowInfobarInNewWindow() {
return Steps(Do([&]() { CreateBrowser(browser()->profile()); }),
WaitForShow(ConfirmInfoBar::kInfoBarElementId));
}
// Should be invoked from window 1 and that window just removed infobar.
InteractiveTestApi::MultiStep VerifyNoInfobarInAnyContext() {
return Steps(WaitForHide(ConfirmInfoBar::kInfoBarElementId),
SelectTab(kTabStripElementId, 0),
WaitForHide(ConfirmInfoBar::kInfoBarElementId));
}
void TriggerInfobar() {
g_browser_process->local_state()->SetBoolean(
prefs::kInstallerDownloaderBypassEligibilityCheck, true);
g_browser_process->GetFeatures()
->installer_downloader_controller()
->MaybeShowInfoBar();
}
private:
base::test::ScopedFeatureList feature_list_;
};
IN_PROC_BROWSER_TEST_F(InstallerDownloaderInteractiveUiTest,
AcceptRemovesInfobarFromAllTabs) {
TriggerInfobar();
RunTestSequence(WaitForShow(ConfirmInfoBar::kInfoBarElementId),
ShowInfobarOnNewTab(),
PressButton(ConfirmInfoBar::kOkButtonElementId),
VerifyNoInfobarInAnyTab());
}
IN_PROC_BROWSER_TEST_F(InstallerDownloaderInteractiveUiTest,
DismissRemovesInfobarFromAllTabs) {
TriggerInfobar();
RunTestSequence(WaitForShow(ConfirmInfoBar::kInfoBarElementId),
ShowInfobarOnNewTab(),
PressButton(ConfirmInfoBar::kDismissButtonElementId),
VerifyNoInfobarInAnyTab());
}
IN_PROC_BROWSER_TEST_F(InstallerDownloaderInteractiveUiTest,
InfobarVisibleInFullscreen) {
TriggerInfobar();
RunTestSequence(WaitForShow(ConfirmInfoBar::kInfoBarElementId), Do([&]() {
ui_test_utils::ToggleFullscreenModeAndWait(browser());
}),
EnsurePresent(ConfirmInfoBar::kInfoBarElementId));
}
IN_PROC_BROWSER_TEST_F(InstallerDownloaderInteractiveUiTest,
AcceptRemovesInfobarAcrossWindows) {
TriggerInfobar();
RunTestSequence(WaitForShow(ConfirmInfoBar::kInfoBarElementId),
ShowInfobarInNewWindow(),
PressButton(ConfirmInfoBar::kOkButtonElementId),
VerifyNoInfobarInAnyContext());
}
IN_PROC_BROWSER_TEST_F(InstallerDownloaderInteractiveUiTest,
DismissRemovesInfobarAcrossWindows) {
TriggerInfobar();
RunTestSequence(WaitForShow(ConfirmInfoBar::kInfoBarElementId),
ShowInfobarInNewWindow(),
PressButton(ConfirmInfoBar::kDismissButtonElementId),
VerifyNoInfobarInAnyContext());
}
IN_PROC_BROWSER_TEST_F(InstallerDownloaderInteractiveUiTest,
MetricsAcceptPath) {
base::HistogramTester histograms;
TriggerInfobar();
RunTestSequence(WaitForShow(ConfirmInfoBar::kInfoBarElementId),
PressButton(ConfirmInfoBar::kOkButtonElementId),
WaitForHide(ConfirmInfoBar::kInfoBarElementId));
histograms.ExpectUniqueSample("Windows.InstallerDownloader.InfobarShown",
/*sample=*/1, /*expected_count=*/1);
histograms.ExpectUniqueSample("Windows.InstallerDownloader.RequestAccepted",
/*sample=*/1, /*expected_count=*/1);
}
IN_PROC_BROWSER_TEST_F(InstallerDownloaderInteractiveUiTest,
MetricsDismissPath) {
base::HistogramTester histograms;
TriggerInfobar();
RunTestSequence(WaitForShow(ConfirmInfoBar::kInfoBarElementId),
PressButton(ConfirmInfoBar::kDismissButtonElementId),
WaitForHide(ConfirmInfoBar::kInfoBarElementId));
histograms.ExpectUniqueSample("Windows.InstallerDownloader.InfobarShown",
/*sample=*/1, /*expected_count=*/1);
histograms.ExpectUniqueSample("Windows.InstallerDownloader.RequestAccepted",
/*sample=*/0, /*expected_count=*/1);
}
IN_PROC_BROWSER_TEST_F(InstallerDownloaderInteractiveUiTest,
Metrics_InfobarShownOnceAcrossTabsAndWindows) {
base::HistogramTester histograms;
TriggerInfobar();
RunTestSequence(WaitForShow(ConfirmInfoBar::kInfoBarElementId),
ShowInfobarOnNewTab(), ShowInfobarInNewWindow(),
PressButton(ConfirmInfoBar::kDismissButtonElementId),
VerifyNoInfobarInAnyContext());
histograms.ExpectUniqueSample("Windows.InstallerDownloader.InfobarShown",
/*sample=*/1, /*expected_count=*/1);
}
} // namespace
} // namespace installer_downloader
|