diff --git a/integrations/gnome-software/test-plugin.c b/integrations/gnome-software/test-plugin.c index f8de192..dd76fc0 100644 --- a/integrations/gnome-software/test-plugin.c +++ b/integrations/gnome-software/test-plugin.c @@ -5,8 +5,20 @@ static GMainLoop *loop; static GsAppList *result_list; static GError *result_error; static gboolean update_result, reject_stage; -static guint prepares, downloads, stages; +static guint prepares, downloads, stages, progress_polls; static gchar *last_method; +static GArray *app_progress, *related_progress; +static void record_progress(GObject *object, GParamSpec *pspec, gpointer data) +{ + guint value = gs_app_get_progress(GS_APP(object)); + g_array_append_val((GArray *) data, value); +} +static gboolean saw_progress(GArray *values, guint expected) +{ + for (guint i = 0; i < values->len; i++) + if (g_array_index(values, guint, i) == expected) return TRUE; + return FALSE; +} static const gchar target[] = "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"; static const gchar plan_id[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; static const gchar tx_path[] = ARCH_PATH "/transactions/op_00000000000000000000000000000001"; @@ -43,9 +55,21 @@ static void method(GDBusConnection *bus, const gchar *sender, const gchar *path, } else if (g_str_equal(name, "GetSnapshot")) { GVariantBuilder snapshot, result; gboolean failed = reject_stage && g_str_equal(last_method, "Stage"); + /* The first transaction reports two in-flight snapshots so the client's + * progress marshalling is exercised before the terminal state. */ + gboolean running = !failed && progress_polls < 2; g_variant_builder_init(&snapshot, G_VARIANT_TYPE_VARDICT); g_variant_builder_init(&result, G_VARIANT_TYPE_VARDICT); - g_variant_builder_add(&snapshot, "{sv}", "State", g_variant_new_string(failed ? "failed" : "succeeded")); + g_variant_builder_add(&snapshot, "{sv}", "State", + g_variant_new_string(failed ? "failed" : running ? "running" : "succeeded")); + if (running) { + GVariantBuilder progress; + g_variant_builder_init(&progress, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add(&progress, "{sv}", "percent", + g_variant_new_uint32(progress_polls == 0 ? 25 : 60)); + g_variant_builder_add(&snapshot, "{sv}", "Progress", g_variant_builder_end(&progress)); + progress_polls++; + } if (failed) g_variant_builder_add(&snapshot, "{sv}", "Error", map1("message", "fixture transaction rejected")); g_variant_builder_add(&result, "{sv}", "plan_id", g_variant_new_string(plan_id)); g_variant_builder_add(&result, "{sv}", "outcome", g_variant_new_string("planned")); @@ -118,10 +142,23 @@ int main(void) g_assert_true(gs_app_has_quirk(app, GS_APP_QUIRK_NEEDS_REBOOT)); g_assert_cmpuint(gs_app_list_length(gs_app_get_related(app)), ==, 1); g_assert_nonnull(strstr(gs_app_get_update_details_markup(app), "linux")); + app_progress = g_array_new(FALSE, FALSE, sizeof(guint)); + related_progress = g_array_new(FALSE, FALSE, sizeof(guint)); + g_signal_connect(app, "notify::progress", G_CALLBACK(record_progress), app_progress); + g_signal_connect(gs_app_list_index(gs_app_get_related(app), 0), "notify::progress", + G_CALLBACK(record_progress), related_progress); update_async(plugin, result_list, GS_PLUGIN_UPDATE_APPS_FLAGS_NO_APPLY, NULL, NULL, NULL, NULL, NULL, NULL, NULL, updated, NULL); g_main_loop_run(loop); g_assert_no_error(result_error); g_assert_true(update_result); g_assert_cmpuint(prepares, ==, 1); g_assert_cmpuint(downloads, ==, 1); g_assert_cmpuint(stages, ==, 0); + /* Progress snapshots are marshalled onto the caller's main context; the + * related package rows must mirror them or the updates list averages an + * unknown percentage and hides the aggregate bar. The terminal transition + * then sets 100, so assert on the observed sequence, not the final value. */ + g_assert_cmpuint(progress_polls, ==, 2); + g_assert_true(saw_progress(app_progress, 25)); g_assert_true(saw_progress(app_progress, 60)); + g_assert_true(saw_progress(related_progress, 25)); g_assert_true(saw_progress(related_progress, 60)); + g_assert_cmpuint(gs_app_get_progress(app), ==, 100); reject_stage = TRUE; update_async(plugin, result_list, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, updated, NULL); g_main_loop_run(loop); @@ -143,6 +180,8 @@ int main(void) g_dbus_connection_unregister_object(bus, manager); g_dbus_connection_unregister_object(bus, transaction); g_main_loop_unref(loop); g_free(last_method); + g_clear_pointer(&app_progress, g_array_unref); + g_clear_pointer(&related_progress, g_array_unref); g_clear_object(&bus); g_test_dbus_down(test_bus); g_print("PLUGIN_DBUS_DIFF_DOWNLOAD_STAGE_ERROR_STATES_PASS\n");