[gnome-software] Fix popular-overrides



commit 8ce7a300fc9b480d562eb2771a9496b5a5b0b939
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Fri Mar 31 21:41:32 2017 +0200

    Fix popular-overrides
    
    When the popular overrides setting is set, we need to refine the apps in
    order for them to be valid in the end.
    
    This patch also updates the tests and covers the popular apps overrides.

 lib/gs-plugin-loader.c       |    9 +++++++++
 plugins/dummy/gs-self-test.c |   32 ++++++++++++++++++++++++++++----
 2 files changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 600e2f7..6410d29 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1794,6 +1794,15 @@ gs_plugin_loader_get_popular_thread_cb (GTask *task,
                        gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
                        gs_app_list_add (job->list, app);
                }
+
+               /* prepare refine job */
+               job->action = GS_PLUGIN_ACTION_REFINE;
+               job->function_name = "gs_plugin_refine";
+               job->failure_flags = GS_PLUGIN_FAILURE_FLAGS_USE_EVENTS;
+               if (!gs_plugin_loader_run_refine (job, job->list, cancellable, &error)) {
+                       g_task_return_error (task, error);
+                       return;
+               }
        } else {
                /* do things that would block */
                job->function_name = "gs_plugin_add_popular";
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index 0e3cceb..c0a56ba 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -503,17 +503,40 @@ static void
 gs_plugins_dummy_wildcard_func (GsPluginLoader *plugin_loader)
 {
        g_autoptr(GError) error = NULL;
-       g_autoptr(GsAppList) list = NULL;
+       g_autoptr(GsAppList) list1 = NULL;
+       g_autoptr(GsAppList) list2 = NULL;
+       const gchar *popular_override = "chiron.desktop,zeus.desktop";
+       g_auto(GStrv) apps = NULL;
 
-       list = gs_plugin_loader_get_popular (plugin_loader,
+       /* use the plugin's add_popular function */
+       list1 = gs_plugin_loader_get_popular (plugin_loader,
                                             GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON,
                                             GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY,
                                             NULL,
                                             &error);
        gs_test_flush_main_context ();
        g_assert_no_error (error);
-       g_assert (list != NULL);
-       g_assert_cmpint (gs_app_list_length (list), ==, 1);
+       g_assert (list1 != NULL);
+       g_assert_cmpint (gs_app_list_length (list1), ==, 1);
+
+       /* override the popular list (do not use the add_popular function) */
+       g_setenv ("GNOME_SOFTWARE_POPULAR", popular_override, TRUE);
+       list2 = gs_plugin_loader_get_popular (plugin_loader,
+                                            GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON,
+                                            GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY,
+                                            NULL,
+                                            &error);
+       gs_test_flush_main_context ();
+       g_assert_no_error (error);
+       g_assert (list2 != NULL);
+
+       apps = g_strsplit (popular_override, ",", 0);
+       g_assert_cmpint (gs_app_list_length (list2), ==, g_strv_length (apps));
+
+       for (guint i = 0; i < gs_app_list_length (list2); ++i) {
+               GsApp *app = gs_app_list_index (list2, i);
+               g_assert (g_strv_contains ((const gchar * const *) apps, gs_app_get_id (app)));
+       }
 }
 
 int
@@ -546,6 +569,7 @@ main (int argc, char **argv)
        g_setenv ("GS_SELF_TEST_PROVENANCE_SOURCES", "london*,boston", TRUE);
        g_setenv ("GS_SELF_TEST_PROVENANCE_LICENSE_SOURCES", "london*,boston", TRUE);
        g_setenv ("GS_SELF_TEST_PROVENANCE_LICENSE_URL", "https://www.debian.org/";, TRUE);
+       g_setenv ("GNOME_SOFTWARE_POPULAR", "", TRUE);
 
        xml = g_strdup ("<?xml version=\"1.0\"?>\n"
                "<components version=\"0.9\">\n"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]