#include "chrome/browser/ui/views/side_panel/lens/lens_core_tab_side_panel_helper.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/search_test_utils.h"
#include "components/lens/buildflags.h"
#include "components/lens/lens_features.h"
#include "components/search_engines/template_url_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/buildflags/buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace lens {
class LensCoreTabSidePanelHelperBrowserTest : public InProcessBrowserTest { … };
#if BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelperBrowserTest,
IsSidePanelEnabledForLensReturnsFalseForAndroid) {
auto* web_contents = GetBrowserWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledForLens(web_contents));
}
#endif
#if !BUILDFLAG(ENABLE_LENS_DESKTOP_GOOGLE_BRANDED_FEATURES)
IN_PROC_BROWSER_TEST_F(
LensCoreTabSidePanelHelperBrowserTest,
IsSidePanelEnabledForLensReturnsFalseIfGoogleBrandedFeaturesAreDisabled) { … }
#endif
#if BUILDFLAG(ENABLE_LENS_DESKTOP_GOOGLE_BRANDED_FEATURES)
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelperBrowserTest,
IsSidePanelEnabledForLensReturnsFalseForPwa) {
auto* pwa_web_contents = GetPwaWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledForLens(pwa_web_contents));
}
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelperBrowserTest,
IsSidePanelEnabledForLensReturnsTrueForBrowser) {
auto* web_contents = GetBrowserWebContents();
EXPECT_TRUE(lens::IsSidePanelEnabledForLens(web_contents));
}
IN_PROC_BROWSER_TEST_F(
LensCoreTabSidePanelHelperBrowserTest,
IsSidePanelEnabledForLensReturnsFalseForBrowserIfOptedOutInTemplateUrl) {
SetGoogleToOptOutOfSidePanel();
auto* web_contents = GetBrowserWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledForLens(web_contents));
}
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelperBrowserTest,
IsSidePanelEnabledForLensReturnsFalseFor3PDse) {
Setup3PImageSearchEngine( true);
auto* web_contents = GetBrowserWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledForLens(web_contents));
}
#endif
class LensCoreTabSidePanelHelperLensStandaloneDisabled
: public LensCoreTabSidePanelHelperBrowserTest { … };
#if BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelperLensStandaloneDisabled,
IsSidePanelEnabledForLensReturnsFalseForAndroid) {
auto* web_contents = GetBrowserWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledForLens(web_contents));
}
#endif
#if !BUILDFLAG(ENABLE_LENS_DESKTOP_GOOGLE_BRANDED_FEATURES)
IN_PROC_BROWSER_TEST_F(
LensCoreTabSidePanelHelperLensStandaloneDisabled,
IsSidePanelEnabledForLensReturnsFalseIfGoogleBrandedFeaturesAreDisabled) { … }
#endif
#if BUILDFLAG(ENABLE_LENS_DESKTOP_GOOGLE_BRANDED_FEATURES)
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelperLensStandaloneDisabled,
IsSidePanelEnabledForLensReturnsFalse) {
auto* web_contents = GetBrowserWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledForLens(web_contents));
}
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelperLensStandaloneDisabled,
IsSidePanelEnabledForLensReturnsFalseForPwa) {
auto* web_contents = GetPwaWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledForLens(web_contents));
}
#endif
class LensCoreTabSidePanelHelperRegionSearchBrowserTest
: public LensCoreTabSidePanelHelperBrowserTest { … };
class LensCoreTabSidePanelHelper3PDseEnabled
: public LensCoreTabSidePanelHelperBrowserTest { … };
#if BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelper3PDseEnabled,
IsSidePanelEnabledFor3PDseReturnsFalseForAndroid) {
Setup3PImageSearchEngine( true);
auto* web_contents = GetBrowserWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledFor3PDse(web_contents));
}
#endif
#if !BUILDFLAG(ENABLE_LENS_DESKTOP_GOOGLE_BRANDED_FEATURES)
IN_PROC_BROWSER_TEST_F(
LensCoreTabSidePanelHelper3PDseEnabled,
IsSidePanelEnabledFor3PDseReturnsFalseIfGoogleBrandedFeaturesAreDisabled) { … }
#endif
#if BUILDFLAG(ENABLE_LENS_DESKTOP_GOOGLE_BRANDED_FEATURES)
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelper3PDseEnabled,
IsSidePanelEnabledFor3PDseReturnsTrue) {
Setup3PImageSearchEngine( true);
auto* web_contents = GetBrowserWebContents();
EXPECT_TRUE(lens::IsSidePanelEnabledFor3PDse(web_contents));
}
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelper3PDseEnabled,
IsSidePanelEnabledFor3PDseReturnsFalseIf3POptedOut) {
Setup3PImageSearchEngine( false);
auto* web_contents = GetBrowserWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledFor3PDse(web_contents));
}
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelper3PDseEnabled,
IsSidePanelEnabledFor3PDseReturnsFalseForPwa) {
Setup3PImageSearchEngine( true);
auto* pwa_web_contents = GetPwaWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledFor3PDse(pwa_web_contents));
}
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelper3PDseEnabled,
IsSidePanelEnabledFor3PDseReturnsFalseForGoogle) {
auto* web_contents = GetBrowserWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledFor3PDse(web_contents));
}
class LensCoreTabSidePanelHelper3PDseDisabledUsingFlag
: public LensCoreTabSidePanelHelperBrowserTest {
protected:
void SetUp() override {
ASSERT_TRUE(embedded_test_server()->Start());
base::test::ScopedFeatureList features;
features.InitWithFeaturesAndParameters(
{{}, {}}, {{lens::features::kEnableImageSearchSidePanelFor3PDse}});
InProcessBrowserTest::SetUp();
}
};
IN_PROC_BROWSER_TEST_F(LensCoreTabSidePanelHelper3PDseDisabledUsingFlag,
IsSidePanelEnabledFor3PDseReturnsFalse) {
Setup3PImageSearchEngine( true);
auto* web_contents = GetBrowserWebContents();
EXPECT_FALSE(lens::IsSidePanelEnabledFor3PDse(web_contents));
}
#endif
}