// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "components/services/app_service/public/cpp/preferred_apps_list.h" #include <optional> #include "base/containers/contains.h" #include "components/services/app_service/public/cpp/intent_filter.h" #include "components/services/app_service/public/cpp/intent_filter_util.h" #include "components/services/app_service/public/cpp/intent_test_util.h" #include "components/services/app_service/public/cpp/intent_util.h" #include "components/services/app_service/public/cpp/preferred_app.h" #include "testing/gtest/include/gtest/gtest.h" namespace { const char kAppId1[] = …; const char kAppId2[] = …; const char kAppId3[] = …; } // namespace class PreferredAppListTest : public testing::Test { … }; // Test that for a single preferred app with URL filter, we can add // and find (or not find) the correct preferred app id for different // URLs. TEST_F(PreferredAppListTest, AddPreferredAppForURL) { … } // Test for preferred app with filter that does not have all condition // types. E.g. add preferred app with intent filter that only have scheme. TEST_F(PreferredAppListTest, TopLayerFilters) { … } // Test for multiple preferred app setting with different number of condition // types. TEST_F(PreferredAppListTest, MixLayerFilters) { … } // Test that when there are multiple preferred apps for one intent, the best // matching one will be picked. TEST_F(PreferredAppListTest, MultiplePreferredApps) { … } // Test that we can properly add and search for filters that has multiple // condition values for a condition type. TEST_F(PreferredAppListTest, MultipleConditionValues) { … } // Test for more than one pattern available, we can find the correct match. TEST_F(PreferredAppListTest, DifferentPatterns) { … } // Test that for same intent filter, the app id will overwrite the old setting. TEST_F(PreferredAppListTest, OverwritePreferredApp) { … } // Test that when overlap happens, the previous setting will be removed. TEST_F(PreferredAppListTest, OverlapPreferredApp) { … } // Test that the replaced app preferences is correct. TEST_F(PreferredAppListTest, ReplacedAppPreference) { … } TEST_F(PreferredAppListTest, ReplacedAppPreferencesSameApp) { … } TEST_F(PreferredAppListTest, OverlapPreferencesSameApp) { … } TEST_F(PreferredAppListTest, AddSameEntry) { … } // Test that for a single preferred app with URL filter, we can delete // the preferred app id. TEST_F(PreferredAppListTest, DeletePreferredAppForURL) { … } // Test for preferred app with filter that does not have all condition // types. E.g. delete preferred app with intent filter that only have scheme. TEST_F(PreferredAppListTest, DeleteForTopLayerFilters) { … } // Test that we can properly delete for filters that has multiple // condition values for a condition type. TEST_F(PreferredAppListTest, DeleteMultipleConditionValues) { … } // Test for more than one pattern available, we can delete the filter. TEST_F(PreferredAppListTest, DeleteDifferentPatterns) { … } // Test that can delete properly for super set filters. E.g. the filter // to delete has more condition values compare with filter that was set. TEST_F(PreferredAppListTest, DeleteForNotCompletedFilter) { … } // Test that when there are more than one entry has overlap filter. TEST_F(PreferredAppListTest, DeleteOverlapFilters) { … } // Test that DeleteAppId() can delete the setting for one filter. TEST_F(PreferredAppListTest, DeleteAppIdForOneFilter) { … } // Test that when multiple filters set to the same app id, DeleteAppId() can // delete all of them. TEST_F(PreferredAppListTest, DeleteAppIdForMultipleFilters) { … } // Test that for filter with multiple condition values, DeleteAppId() can // delete them all. TEST_F(PreferredAppListTest, DeleteAppIdForMultipleConditionValues) { … } // Test that for multiple filters set to different app ids, DeleteAppId() only // deletes the correct app id. TEST_F(PreferredAppListTest, DeleteAppIdForMultipleAppIds) { … } TEST_F(PreferredAppListTest, DeleteSupportedLinks) { … } // Test that DeleteSupportedLinks removes the entire preference, including // condition values other than http/https links. TEST_F(PreferredAppListTest, DeleteSupportedLinksForMultipleConditionValues) { … } TEST_F(PreferredAppListTest, ApplyBulkUpdateAdditions) { … } TEST_F(PreferredAppListTest, ApplyBulkUpdateDuplicateAdditions) { … } // Test that you can add and remove overlapping filters with a single call to // ApplyBulkUpdate. TEST_F(PreferredAppListTest, ApplyBulkUpdateAddAndRemove) { … } // Test that removing a filter using ApplyBulkUpdate only removes filters which // match exactly, and not anything that overlaps. TEST_F(PreferredAppListTest, ApplyBulkUpdateRemoveMatchesExactly) { … } // Test that FindPreferredAppsForFilters() returns an empty flat_set if there // are no matches. TEST_F(PreferredAppListTest, FindNoPreferredApps) { … } // Tests that FindPreferredAppsForFilters() returns an app id if a match is // found. TEST_F(PreferredAppListTest, FindOnePreferredApps) { … } // Tests that FindPreferredAppsForFilters() returns multiple app ids if matches // are made. TEST_F(PreferredAppListTest, FindMultiplePreferredApps) { … }