Skip to content

Commit

Permalink
[116] CSC: Add VisualSearchSuggestionsServiceBrowserTest
Browse files Browse the repository at this point in the history
Also disables factory on Android - which was not meant to be enabled to begin with since this feature is built for Chrome desktop.

(cherry picked from commit 3869bda)

Bug: 1455543
Change-Id: I9165f534422e6a1615015207c6a924ce0d876405
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4616895
Reviewed-by: Michael Crouse <mcrouse@chromium.org>
Commit-Queue: Michael Crouse <mcrouse@chromium.org>
Auto-Submit: Serena Pascual <srna@google.com>
Cr-Original-Commit-Position: refs/heads/main@{#1161286}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4659682
Reviewed-by: Ali Stanfield <stanfield@google.com>
Reviewed-by: Stefan Kuhne <skuhne@chromium.org>
Commit-Queue: Pierre St Juste <pstjuste@google.com>
Cr-Commit-Position: refs/branch-heads/5845@{#266}
Cr-Branched-From: 5a5dff6-refs/heads/main@{#1160321}
  • Loading branch information
serenapascual authored and Chromium LUCI CQ committed Jun 30, 2023
1 parent dd05f89 commit 5336205
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 8 deletions.
6 changes: 3 additions & 3 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ static_library("browser") {
"command_updater_impl.h",
"commerce/shopping_service_factory.cc",
"commerce/shopping_service_factory.h",
"companion/visual_search/visual_search_suggestions_service_factory.cc",
"companion/visual_search/visual_search_suggestions_service_factory.h",
"complex_tasks/task_tab_helper.cc",
"complex_tasks/task_tab_helper.h",
"component_updater/chrome_client_side_phishing_component_installer.cc",
Expand Down Expand Up @@ -1979,7 +1977,6 @@ static_library("browser") {
"//chrome/browser/chrome_for_testing:buildflags",
"//chrome/browser/companion/core",
"//chrome/browser/companion/text_finder",
"//chrome/browser/companion/visual_search",
"//chrome/browser/crash_upload_list",
"//chrome/browser/devtools",
"//chrome/browser/enterprise/identifiers",
Expand Down Expand Up @@ -3529,6 +3526,8 @@ static_library("browser") {
"commerce/coupons/coupon_service_factory.cc",
"commerce/coupons/coupon_service_factory.h",
"commerce/coupons/coupon_service_observer.h",
"companion/visual_search/visual_search_suggestions_service_factory.cc",
"companion/visual_search/visual_search_suggestions_service_factory.h",
"component_updater/intervention_policy_database_component_installer.cc",
"component_updater/intervention_policy_database_component_installer.h",
"component_updater/soda_component_installer.cc",
Expand Down Expand Up @@ -4398,6 +4397,7 @@ static_library("browser") {
"//chrome/app/vector_icons",
"//chrome/browser/apps/app_service",
"//chrome/browser/cart:mojo_bindings",
"//chrome/browser/companion/visual_search",
"//chrome/browser/enterprise/connectors/analysis:features",
"//chrome/browser/enterprise/connectors/device_trust:prefs",
"//chrome/browser/enterprise/data_controls",
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/companion/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source_set("unit_tests") {
sources = []
deps = [ "core" ]

if (!is_ios) {
if (!is_ios && !is_android) {
deps += [
"core:unit_tests",
"text_finder:unit_tests",
Expand Down
20 changes: 20 additions & 0 deletions chrome/browser/companion/visual_search/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

assert(!is_android, "Visual Search is for desktop platforms only")

source_set("visual_search") {
sources = [
"features.cc",
Expand Down Expand Up @@ -42,3 +44,21 @@ source_set("unit_tests") {
"//testing/gtest",
]
}

source_set("browser_tests") {
testonly = true
sources = [ "visual_search_suggestions_service_browsertest.cc" ]
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
deps = [
":visual_search",
"//base",
"//base/test:test_support",
"//chrome/browser",
"//chrome/common",
"//chrome/test:test_support",
"//components/optimization_guide/core:test_support",
"//components/optimization_guide/proto:optimization_guide_proto",
"//testing/gmock",
"//testing/gtest",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2023 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/memory/scoped_refptr.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/companion/visual_search/features.h"
#include "chrome/browser/companion/visual_search/visual_search_suggestions_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/optimization_guide/core/test_model_info_builder.h"
#include "components/optimization_guide/core/test_optimization_guide_model_provider.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

class VisualSearchSuggestionsServiceDisabledBrowserTest
: public InProcessBrowserTest {
public:
VisualSearchSuggestionsServiceDisabledBrowserTest() {
scoped_feature_list_.InitAndDisableFeature(
companion::visual_search::features::kVisualSearchSuggestions);
}

void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
background_task_runner = base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::BEST_EFFORT});
test_model_provider_ = std::make_unique<
optimization_guide::TestOptimizationGuideModelProvider>();
}

private:
base::test::ScopedFeatureList scoped_feature_list_;
scoped_refptr<base::SequencedTaskRunner> background_task_runner;
std::unique_ptr<optimization_guide::TestOptimizationGuideModelProvider>
test_model_provider_;
};

IN_PROC_BROWSER_TEST_F(VisualSearchSuggestionsServiceDisabledBrowserTest,
VisualSearchSuggestionsServiceDisabled) {
EXPECT_FALSE(companion::visual_search::VisualSearchSuggestionsServiceFactory::
GetForProfile(browser()->profile()));
}

class VisualSearchSuggestionsServiceBrowserTest
: public VisualSearchSuggestionsServiceDisabledBrowserTest {
public:
VisualSearchSuggestionsServiceBrowserTest() {
scoped_feature_list_.InitWithFeatures(
{companion::visual_search::features::kVisualSearchSuggestions}, {});
}

companion::visual_search::VisualSearchSuggestionsService*
visual_search_suggestions_service() {
return companion::visual_search::VisualSearchSuggestionsServiceFactory::
GetForProfile(browser()->profile());
}

~VisualSearchSuggestionsServiceBrowserTest() override = default;

private:
base::test::ScopedFeatureList scoped_feature_list_;
};

IN_PROC_BROWSER_TEST_F(VisualSearchSuggestionsServiceBrowserTest,
VisualSearchSuggestionsServiceEnabled) {
EXPECT_TRUE(visual_search_suggestions_service());
}

} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "chrome/browser/companion/visual_search/features.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -28,7 +29,12 @@ VisualSearchSuggestionsServiceFactory::VisualSearchSuggestionsServiceFactory()
ProfileSelections::Builder()
.WithRegular(ProfileSelection::kOriginalOnly)
.WithGuest(ProfileSelection::kOriginalOnly)
.Build()) {}
.Build()) {
if (base::FeatureList::IsEnabled(
companion::visual_search::features::kVisualSearchSuggestions)) {
DependsOn(OptimizationGuideKeyedServiceFactory::GetInstance());
}
}

// static
VisualSearchSuggestionsServiceFactory*
Expand All @@ -39,6 +45,11 @@ VisualSearchSuggestionsServiceFactory::GetInstance() {

KeyedService* VisualSearchSuggestionsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
if (!base::FeatureList::IsEnabled(
companion::visual_search::features::kVisualSearchSuggestions)) {
return nullptr;
}

// The optimization guide service must be available for the translate model
// service to be created.
auto* opt_guide = OptimizationGuideKeyedServiceFactory::GetForProfile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,9 @@ void ChromeBrowserMainExtraPartsProfiles::
ClipboardRestrictionServiceFactory::GetInstance();
#if !BUILDFLAG(IS_ANDROID)
ClosedTabCacheServiceFactory::GetInstance();
#endif
companion::visual_search::VisualSearchSuggestionsServiceFactory::
GetInstance();
#endif
ConsentAuditorFactory::GetInstance();
ContentIndexProviderFactory::GetInstance();
#if BUILDFLAG(IS_ANDROID)
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@ static_library("ui") {
"//chrome/browser/breadcrumbs",
"//chrome/browser/chrome_for_testing:buildflags",
"//chrome/browser/companion/core",
"//chrome/browser/companion/visual_search",
"//chrome/browser/devtools",
"//chrome/browser/favicon",
"//chrome/browser/google",
Expand Down Expand Up @@ -1930,6 +1929,7 @@ static_library("ui") {
"//chrome/browser/cart:mojo_bindings",
"//chrome/browser/companion/core/mojom:mojo_bindings",
"//chrome/browser/companion/text_finder",
"//chrome/browser/companion/visual_search",
"//chrome/browser/headless:command_processor",
"//chrome/browser/image_editor",
"//chrome/browser/image_editor:image_editor_component_util",
Expand Down
3 changes: 2 additions & 1 deletion chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,7 @@ if (!is_android) {
"//chrome/browser/companion/core",
"//chrome/browser/companion/core/mojom:mojo_bindings",
"//chrome/browser/companion/core/proto",
"//chrome/browser/companion/visual_search:browser_tests",
"//chrome/browser/devtools",
"//chrome/browser/devtools:test_support",
"//chrome/browser/dips:browser_tests",
Expand Down Expand Up @@ -6217,7 +6218,6 @@ test("unit_tests") {
"//chrome/common/profiler:unit_tests",
"//chrome/common/themes:autogenerated_theme_util",
"//chrome/common/themes:unit_tests",
"//chrome/renderer/companion/visual_search:unit_tests",
"//chrome/services/file_util:unit_tests",
"//chrome/services/qrcode_generator/public/cpp",
"//components/account_id",
Expand Down Expand Up @@ -7542,6 +7542,7 @@ test("unit_tests") {
"//chrome/browser/companion/core",
"//chrome/browser/companion/core/mojom:mojo_bindings",
"//chrome/browser/companion/core/proto",
"//chrome/browser/companion/visual_search:visual_search",
"//chrome/browser/enterprise/connectors/analysis:features",
"//chrome/browser/enterprise/data_controls",
"//chrome/browser/enterprise/data_controls:test_support",
Expand Down

0 comments on commit 5336205

Please sign in to comment.