322
327
DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/test/application_click", "com.ubuntu.Upstart0_6.Job", NULL);
324
329
/* Basic make sure we can send the event */
325
ASSERT_TRUE(ubuntu_app_launch_start_application("foolike", NULL));
330
ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.multiple_first_1.2.3", NULL));
326
331
EXPECT_EQ(1, dbus_test_dbus_mock_object_check_method_call(mock, obj, "Start", NULL, NULL));
328
333
ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL));
330
335
/* Now look at the details of the call */
331
ASSERT_TRUE(ubuntu_app_launch_start_application("foolike", NULL));
336
ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.multiple_first_1.2.3", NULL));
334
339
const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL);
424
429
/* Check bad params */
425
430
EXPECT_EQ(0, ubuntu_app_launch_get_primary_pid(NULL));
426
EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(0, "foo"));
431
EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(0, "com.test.good_application_1.2.3"));
427
432
EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(100, NULL));
429
434
/* Check primary pid, which comes from Upstart */
430
EXPECT_EQ(ubuntu_app_launch_get_primary_pid("foo"), getpid());
435
EXPECT_EQ(ubuntu_app_launch_get_primary_pid("com.test.good_application_1.2.3"), getpid());
431
436
EXPECT_EQ(ubuntu_app_launch_get_primary_pid("bar"), 5678);
433
438
/* Look at the full PID list from CG Manager */
438
443
/* Click in the set */
439
EXPECT_TRUE(ubuntu_app_launch_pid_in_app_id(100, "foo"));
444
EXPECT_TRUE(ubuntu_app_launch_pid_in_app_id(100, "com.test.good_application_1.2.3"));
440
445
calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasks", &len, NULL);
441
446
EXPECT_EQ(1, len);
442
447
EXPECT_STREQ("GetTasks", calls->name);
443
EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-click-foo")));
448
EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-click-com.test.good_application_1.2.3")));
444
449
ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL));
446
451
/* Click out of the set */
447
EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(101, "foo"));
452
EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(101, "com.test.good_application_1.2.3"));
448
453
calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasks", &len, NULL);
449
454
EXPECT_EQ(1, len);
450
455
EXPECT_STREQ("GetTasks", calls->name);
451
EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-click-foo")));
456
EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-click-com.test.good_application_1.2.3")));
452
457
ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL));
454
459
/* Legacy Single Instance */
532
537
/* Not enforcing order, but wanting to use the GTest functions
533
538
for "actually testing" so the errors look right. */
534
if (g_strcmp0(apps[0], "foo") == 0) {
535
ASSERT_STREQ(apps[0], "foo");
536
ASSERT_STREQ(apps[1], "bar");
539
if (g_strcmp0(apps[0], "com.test.good_application_1.2.3") == 0) {
540
ASSERT_STREQ("com.test.good_application_1.2.3", apps[0]);
541
ASSERT_STREQ("bar", apps[1]);
538
ASSERT_STREQ(apps[0], "bar");
539
ASSERT_STREQ(apps[1], "foo");
543
ASSERT_STREQ("bar", apps[0]);
544
ASSERT_STREQ("com.test.good_application_1.2.3", apps[1]);
542
547
g_strfreev(apps);
640
645
/* Test Noise Start */
641
646
start_data.count = 0;
642
start_data.name = "foo";
647
start_data.name = "com.test.good_application_1.2.3";
643
648
stop_data.count = 0;
644
stop_data.name = "foo";
649
stop_data.name = "com.test.good_application_1.2.3";
646
651
/* A full lifecycle */
647
652
dbus_test_dbus_mock_object_emit_signal(mock, obj,
649
654
G_VARIANT_TYPE("(sas)"),
650
g_variant_new_parsed("('starting', ['JOB=application-click', 'INSTANCE=foo'])"),
653
dbus_test_dbus_mock_object_emit_signal(mock, obj,
655
G_VARIANT_TYPE("(sas)"),
656
g_variant_new_parsed("('started', ['JOB=application-click', 'INSTANCE=foo'])"),
659
dbus_test_dbus_mock_object_emit_signal(mock, obj,
661
G_VARIANT_TYPE("(sas)"),
662
g_variant_new_parsed("('stopping', ['JOB=application-click', 'INSTANCE=foo'])"),
665
dbus_test_dbus_mock_object_emit_signal(mock, obj,
667
G_VARIANT_TYPE("(sas)"),
668
g_variant_new_parsed("('stopped', ['JOB=application-click', 'INSTANCE=foo'])"),
655
g_variant_new_parsed("('starting', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"),
658
dbus_test_dbus_mock_object_emit_signal(mock, obj,
660
G_VARIANT_TYPE("(sas)"),
661
g_variant_new_parsed("('started', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"),
664
dbus_test_dbus_mock_object_emit_signal(mock, obj,
666
G_VARIANT_TYPE("(sas)"),
667
g_variant_new_parsed("('stopping', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"),
670
dbus_test_dbus_mock_object_emit_signal(mock, obj,
672
G_VARIANT_TYPE("(sas)"),
673
g_variant_new_parsed("('stopped', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"),
722
727
"com.canonical.UbuntuAppLaunch", /* interface */
723
728
"UnityStartingBroadcast", /* signal */
724
g_variant_new("(s)", "foo"), /* params, the same */
729
g_variant_new("(s)", "com.test.good_application_1.2.3"), /* params, the same */
729
EXPECT_EQ("foo", last_observer);
734
EXPECT_EQ("com.test.good_application_1.2.3", last_observer);
730
735
EXPECT_EQ(1, starting_count);
732
737
EXPECT_TRUE(ubuntu_app_launch_observer_delete_app_starting(starting_observer, &last_observer));
765
770
GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
766
771
guint filter = g_dbus_connection_add_filter(session,
767
772
filter_func_good,
773
(gpointer)"/com_2etest_2egood_5fapplication_5f1_2e2_2e3",
771
776
const gchar * uris[] = {
772
777
"http://www.test.com",
775
ASSERT_TRUE(ubuntu_app_launch_start_application("foo", uris));
780
ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.good_application_1.2.3", uris));
776
781
pause(100); /* Ensure all the events come through */
778
EXPECT_EQ("foo", this->last_focus_appid);
779
EXPECT_EQ("foo", this->last_resume_appid);
783
EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid);
784
EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid);
781
786
g_dbus_connection_remove_filter(session, filter);
809
ASSERT_TRUE(ubuntu_app_launch_start_application("foo", uris));
814
ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.good_application_1.2.3", uris));
810
815
pause(100); /* Ensure all the events come through */
812
EXPECT_EQ("foo", this->last_focus_appid);
813
EXPECT_EQ("foo", this->last_resume_appid);
817
EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid);
818
EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid);
816
821
TEST_F(LibUAL, UnityTimeoutTest)
818
823
this->resume_timeout = 100;
820
ASSERT_TRUE(ubuntu_app_launch_start_application("foo", NULL));
825
ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.good_application_1.2.3", NULL));
821
826
pause(1000); /* Ensure all the events come through */
822
EXPECT_EQ("foo", this->last_focus_appid);
823
EXPECT_EQ("foo", this->last_resume_appid);
827
EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid);
828
EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid);
826
831
TEST_F(LibUAL, UnityTimeoutUriTest)
867
ASSERT_TRUE(ubuntu_app_launch_start_application("foo", uris));
872
ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.good_application_1.2.3", uris));
869
874
guint end = g_get_monotonic_time();
871
EXPECT_LT(end - start, 600 * 1000);
876
g_debug("Start call time: %d ms", (end - start) / 1000);
877
EXPECT_LT(end - start, 2000 * 1000);
873
879
pause(1000); /* Ensure all the events come through */
875
EXPECT_EQ("foo", this->last_focus_appid);
876
EXPECT_EQ("foo", this->last_resume_appid);
881
EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid);
882
EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid);
878
884
g_dbus_connection_remove_filter(session, filter);
879
885
g_object_unref(session);
950
956
"com.canonical.UbuntuAppLaunch", /* interface */
951
957
"ApplicationFailed", /* signal */
952
g_variant_new("(ss)", "foo", "crash"), /* params, the same */
957
EXPECT_EQ("foo", last_observer);
959
last_observer.clear();
961
g_dbus_connection_emit_signal(session,
962
NULL, /* destination */
964
"com.canonical.UbuntuAppLaunch", /* interface */
965
"ApplicationFailed", /* signal */
966
g_variant_new("(ss)", "foo", "blahblah"), /* params, the same */
971
EXPECT_EQ("foo", last_observer);
973
last_observer.clear();
975
g_dbus_connection_emit_signal(session,
976
NULL, /* destination */
978
"com.canonical.UbuntuAppLaunch", /* interface */
979
"ApplicationFailed", /* signal */
980
g_variant_new("(ss)", "foo", "start-failure"), /* params, the same */
958
g_variant_new("(ss)", "com.test.good_application_1.2.3", "crash"), /* params, the same */
963
EXPECT_EQ("com.test.good_application_1.2.3", last_observer);
965
last_observer.clear();
967
g_dbus_connection_emit_signal(session,
968
NULL, /* destination */
970
"com.canonical.UbuntuAppLaunch", /* interface */
971
"ApplicationFailed", /* signal */
972
g_variant_new("(ss)", "com.test.good_application_1.2.3", "blahblah"), /* params, the same */
977
EXPECT_EQ("com.test.good_application_1.2.3", last_observer);
979
last_observer.clear();
981
g_dbus_connection_emit_signal(session,
982
NULL, /* destination */
984
"com.canonical.UbuntuAppLaunch", /* interface */
985
"ApplicationFailed", /* signal */
986
g_variant_new("(ss)", "com.test.good_application_1.2.3", "start-failure"), /* params, the same */
994
1000
DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/test/untrusted/helper", "com.ubuntu.Upstart0_6.Job", NULL);
996
1002
/* Basic make sure we can send the event */
997
ASSERT_TRUE(ubuntu_app_launch_start_helper("untrusted-type", "foolike", NULL));
1003
ASSERT_TRUE(ubuntu_app_launch_start_helper("untrusted-type", "com.test.multiple_first_1.2.3", NULL));
998
1004
EXPECT_EQ(1, dbus_test_dbus_mock_object_check_method_call(mock, obj, "Start", NULL, NULL));
1000
1006
ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL));
1002
1008
/* Now look at the details of the call */
1003
ASSERT_TRUE(ubuntu_app_launch_start_helper("untrusted-type", "foolike", NULL));
1009
ASSERT_TRUE(ubuntu_app_launch_start_helper("untrusted-type", "com.test.multiple_first_1.2.3", NULL));
1006
1012
const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL);
1244
1250
ASSERT_TRUE(ubuntu_app_launch_observer_delete_helper_started(helper_observer_cb, "my-type-is-scorpio", &start_data));
1245
1251
ASSERT_TRUE(ubuntu_app_launch_observer_delete_helper_stop(helper_observer_cb, "my-type-is-libra", &stop_data));
1255
datain (GIOChannel * source, GIOCondition cond, gpointer data)
1257
gsize * datacnt = static_cast<gsize *>(data);
1260
GError * error = NULL;
1262
g_io_channel_read_line(source, &str, &len, NULL, &error);
1265
if (error != NULL) {
1266
g_warning("Unable to read from channel: %s", error->message);
1267
g_error_free(error);
1275
TEST_F(LibUAL, PauseResume)
1277
g_setenv("UBUNTU_APP_LAUNCH_NO_SET_OOM", "TRUE", 1);
1279
/* Setup some spew */
1281
gint spewstdout = 0;
1282
const gchar * spewline[] = { SPEW_UTILITY, NULL };
1283
ASSERT_TRUE(g_spawn_async_with_pipes(NULL,
1285
NULL, /* environment */
1287
NULL, NULL, /* child setup */
1295
GIOChannel * spewoutchan = g_io_channel_unix_new(spewstdout);
1296
g_io_channel_set_flags(spewoutchan, G_IO_FLAG_NONBLOCK, NULL);
1297
g_io_add_watch(spewoutchan, G_IO_IN, datain, &datacnt);
1299
/* Setup the cgroup */
1300
g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_NAME", "org.test.cgmock2", TRUE);
1301
DbusTestDbusMock * cgmock2 = dbus_test_dbus_mock_new("org.test.cgmock2");
1302
DbusTestDbusMockObject * cgobject = dbus_test_dbus_mock_get_object(cgmock2, "/org/linuxcontainers/cgmanager", "org.linuxcontainers.cgmanager0_0", NULL);
1303
gchar * pypids = g_strdup_printf("ret = [%d]", spewpid);
1304
dbus_test_dbus_mock_object_add_method(cgmock, cgobject,
1306
G_VARIANT_TYPE("(ss)"),
1307
G_VARIANT_TYPE("ai"),
1312
dbus_test_service_add_task(service, DBUS_TEST_TASK(cgmock2));
1313
dbus_test_task_run(DBUS_TEST_TASK(cgmock2));
1314
g_object_unref(G_OBJECT(cgmock2));
1317
DbusTestDbusMock * zgmock = dbus_test_dbus_mock_new("org.gnome.zeitgeist.Engine");
1318
DbusTestDbusMockObject * zgobj = dbus_test_dbus_mock_get_object(zgmock, "/org/gnome/zeitgeist/log/activity", "org.gnome.zeitgeist.Log", NULL);
1320
dbus_test_dbus_mock_object_add_method(zgmock, zgobj,
1322
G_VARIANT_TYPE("a(asaasay)"),
1323
G_VARIANT_TYPE("au"),
1327
dbus_test_service_add_task(service, DBUS_TEST_TASK(zgmock));
1328
dbus_test_task_run(DBUS_TEST_TASK(zgmock));
1329
g_object_unref(G_OBJECT(zgmock));
1331
/* Give things a chance to start */
1333
g_debug("Giving mocks a chance to start");
1335
} while (dbus_test_task_get_state(DBUS_TEST_TASK(cgmock2)) != DBUS_TEST_TASK_STATE_RUNNING &&
1336
dbus_test_task_get_state(DBUS_TEST_TASK(zgmock)) != DBUS_TEST_TASK_STATE_RUNNING);
1339
EXPECT_NE(0, datacnt);
1342
EXPECT_TRUE(ubuntu_app_launch_pause_application("com.test.good_application_1.2.3"));
1344
pause(0); /* Flush queued events */
1345
datacnt = 0; /* clear it */
1349
EXPECT_EQ(0, datacnt);
1351
/* Check to make sure we sent the event to ZG */
1353
const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(zgmock, zgobj, "InsertEvents", &numcalls, NULL);
1355
EXPECT_NE(nullptr, calls);
1356
EXPECT_EQ(1, numcalls);
1358
dbus_test_dbus_mock_object_clear_method_calls(zgmock, zgobj, NULL);
1360
/* No Resume the App */
1361
EXPECT_TRUE(ubuntu_app_launch_resume_application("com.test.good_application_1.2.3"));
1365
EXPECT_NE(0, datacnt);
1367
/* Check to make sure we sent the event to ZG */
1369
calls = dbus_test_dbus_mock_object_get_method_calls(zgmock, zgobj, "InsertEvents", &numcalls, NULL);
1371
EXPECT_NE(nullptr, calls);
1372
EXPECT_EQ(1, numcalls);
1375
gchar * killstr = g_strdup_printf("kill -9 %d", spewpid);
1376
ASSERT_TRUE(g_spawn_command_line_sync(killstr, NULL, NULL, NULL, NULL));
1379
g_io_channel_unref(spewoutchan);
1381
/* Kill ZG default instance :-( */
1382
ZeitgeistLog * log = zeitgeist_log_get_default();
1383
g_object_unref(log);
1384
g_object_unref(log);