summaryrefslogtreecommitdiff
path: root/installed-tests
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2022-10-29 22:43:49 +0000
committerPhilip Chimento <philip.chimento@gmail.com>2022-10-29 22:43:49 +0000
commit95483a4efed376e44bfa036fe4a86c3cb82881c4 (patch)
tree53cc224d3a5478d382012af3b885370d279515c0 /installed-tests
parent693050b667bf8ee75e15a6d42b6a47d334d3cd2c (diff)
parent9828094d2cccd777001776086849397e038467b0 (diff)
downloadgjs-95483a4efed376e44bfa036fe4a86c3cb82881c4.tar.gz
Merge branch 'promisify-gdbus-async-init' into 'master'
Gio: Promisify GDBusProxy.init_async by default Closes #494 See merge request GNOME/gjs!790
Diffstat (limited to 'installed-tests')
-rw-r--r--installed-tests/js/testGDBus.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/installed-tests/js/testGDBus.js b/installed-tests/js/testGDBus.js
index 70418e44..b6e01b0f 100644
--- a/installed-tests/js/testGDBus.js
+++ b/installed-tests/js/testGDBus.js
@@ -837,3 +837,81 @@ describe('Exported DBus object', function () {
expect(invalidatedProps).toContain('PropReadOnly');
});
});
+
+
+describe('DBus Proxy wrapper', function () {
+ let loop;
+ let wasPromise;
+ let writerFunc;
+
+ beforeAll(function () {
+ loop = new GLib.MainLoop(null, false);
+
+ wasPromise = Gio.DBusProxy.prototype._original_init_async instanceof Function;
+ Gio._promisify(Gio.DBusProxy.prototype, 'init_async');
+
+ writerFunc = jasmine.createSpy(
+ 'log writer func', (level, fields) => {
+ const decoder = new TextDecoder('utf-8');
+ const domain = decoder.decode(fields?.GLIB_DOMAIN);
+ const message = `${decoder.decode(fields?.MESSAGE)}\n`;
+ level |= GLib.LogLevelFlags.FLAG_RECURSION;
+ GLib.log_default_handler(domain, level, message, null);
+ return GLib.LogWriterOutput.HANDLED;
+ });
+
+ writerFunc.and.callThrough();
+ GLib.log_set_writer_func(writerFunc);
+ });
+
+ beforeEach(function () {
+ writerFunc.calls.reset();
+ });
+
+ it('init failures are reported in sync mode', function () {
+ const cancellable = new Gio.Cancellable();
+ cancellable.cancel();
+ expect(() => new ProxyClass(Gio.DBus.session, 'org.gnome.gjs.Test',
+ '/org/gnome/gjs/Test',
+ Gio.DBusProxyFlags.NONE,
+ cancellable)).toThrow();
+ });
+
+ it('init failures are reported in async mode', function () {
+ const cancellable = new Gio.Cancellable();
+ cancellable.cancel();
+ const initDoneSpy = jasmine.createSpy(
+ 'init finish func', () => loop.quit());
+ initDoneSpy.and.callThrough();
+ new ProxyClass(Gio.DBus.session, 'org.gnome.gjs.Test',
+ '/org/gnome/gjs/Test',
+ initDoneSpy, cancellable, Gio.DBusProxyFlags.NONE);
+ loop.run();
+
+ expect(initDoneSpy).toHaveBeenCalledTimes(1);
+ const {args: callArgs} = initDoneSpy.calls.mostRecent();
+ expect(callArgs.at(0)).toBeNull();
+ expect(callArgs.at(1).matches(
+ Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)).toBeTrue();
+ });
+
+ it('can init a proxy asynchronously when promisified', function () {
+ new ProxyClass(Gio.DBus.session, 'org.gnome.gjs.Test',
+ '/org/gnome/gjs/Test',
+ () => loop.quit(),
+ Gio.DBusProxyFlags.NONE);
+ loop.run();
+
+ expect(writerFunc).not.toHaveBeenCalled();
+ });
+
+ afterAll(function () {
+ if (!wasPromise) {
+ // Remove stuff added by Gio._promisify, this can be not needed in future
+ // nor should break other tests, but we didn't want to depend on those.
+ expect(Gio.DBusProxy.prototype._original_init_async).toBeInstanceOf(Function);
+ Gio.DBusProxy.prototype.init_async = Gio.DBusProxy.prototype._original_init_async;
+ delete Gio.DBusProxy.prototype._original_init_async;
+ }
+ });
+});