summaryrefslogtreecommitdiff
path: root/installed-tests
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2022-08-08 23:56:43 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2022-08-08 23:56:43 -0700
commit0a28bf36b1fb073f4b01400a57d88dbd75f8c8f3 (patch)
treeabcb56c1575f6edbd1f3f06ad5647a6f6c20d973 /installed-tests
parent0bf046114c38468f55ebc1c04cbab2e41b39c230 (diff)
downloadgjs-0a28bf36b1fb073f4b01400a57d88dbd75f8c8f3.tar.gz
Gio: Add overrides for File.set_attribute and FileInfo.set_attribute
These functions can crash if used from JS, because they take a raw pointer. Add an override that calls the appropriate type-safe method instead, on a best-effort basis; not all of these exist. In any case, the crashes should be prevented. Closes: #496
Diffstat (limited to 'installed-tests')
-rw-r--r--installed-tests/js/testGio.js79
1 files changed, 79 insertions, 0 deletions
diff --git a/installed-tests/js/testGio.js b/installed-tests/js/testGio.js
index fc94bb58..c2281fae 100644
--- a/installed-tests/js/testGio.js
+++ b/installed-tests/js/testGio.js
@@ -341,3 +341,82 @@ describe('Gio.FileEnumerator overrides', function () {
expect(count).toBeGreaterThan(0);
});
});
+
+describe('Non-introspectable file attribute overrides', function () {
+ let numExpectedWarnings, file, info;
+ const flags = [Gio.FileQueryInfoFlags.NONE, null];
+
+ function expectWarnings(count) {
+ numExpectedWarnings = count;
+ for (let c = 0; c < count; c++) {
+ GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_WARNING,
+ '*not introspectable*');
+ }
+ }
+
+ function assertWarnings(testName) {
+ for (let c = 0; c < numExpectedWarnings; c++) {
+ GLib.test_assert_expected_messages_internal('Gjs', 'testGio.js', 0,
+ `test Gio.${testName}`);
+ }
+ numExpectedWarnings = 0;
+ }
+
+ beforeEach(function () {
+ numExpectedWarnings = 0;
+ [file] = Gio.File.new_tmp('XXXXXX');
+ info = file.query_info('standard::*', ...flags);
+ });
+
+ it('invalid means unsetting the attribute', function () {
+ expectWarnings(2);
+ expect(() =>
+ file.set_attribute('custom::remove', Gio.FileAttributeType.INVALID, null, ...flags))
+ .toThrowError(/not introspectable/);
+ expect(() => info.set_attribute('custom::remove', Gio.FileAttributeType.INVALID)).not.toThrow();
+ assertWarnings();
+ });
+
+ it('works for boolean', function () {
+ expectWarnings(2);
+ expect(() =>
+ file.set_attribute(Gio.FILE_ATTRIBUTE_STANDARD_IS_HIDDEN, Gio.FileAttributeType.BOOLEAN, false, ...flags))
+ .toThrowError(/not introspectable/);
+ expect(() => info.set_attribute(Gio.FILE_ATTRIBUTE_STANDARD_IS_HIDDEN, Gio.FileAttributeType.BOOLEAN, false))
+ .not.toThrow();
+ assertWarnings();
+ });
+
+ it('works for uint32', function () {
+ expectWarnings(2);
+ expect(() => file.set_attribute(Gio.FILE_ATTRIBUTE_TIME_MODIFIED_USEC, Gio.FileAttributeType.UINT32, 123456, ...flags))
+ .not.toThrow();
+ expect(() => info.set_attribute(Gio.FILE_ATTRIBUTE_TIME_MODIFIED_USEC, Gio.FileAttributeType.UINT32, 654321))
+ .not.toThrow();
+ assertWarnings();
+ });
+
+ it('works for uint64', function () {
+ expectWarnings(2);
+ expect(() => file.set_attribute(Gio.FILE_ATTRIBUTE_TIME_MODIFIED, Gio.FileAttributeType.UINT64, Date.now() / 1000, ...flags))
+ .not.toThrow();
+ expect(() => info.set_attribute(Gio.FILE_ATTRIBUTE_TIME_MODIFIED, Gio.FileAttributeType.UINT64, Date.now() / 1000))
+ .not.toThrow();
+ assertWarnings();
+ });
+
+ it('works for object', function () {
+ expectWarnings(2);
+ const icon = Gio.ThemedIcon.new_from_names(['list-add-symbolic']);
+ expect(() =>
+ file.set_attribute(Gio.FILE_ATTRIBUTE_STANDARD_ICON, Gio.FileAttributeType.OBJECT, icon, ...flags))
+ .toThrowError(/not introspectable/);
+ expect(() => info.set_attribute(Gio.FILE_ATTRIBUTE_STANDARD_ICON, Gio.FileAttributeType.OBJECT, icon))
+ .not.toThrow();
+ assertWarnings();
+ });
+
+ afterEach(function () {
+ file.delete_async(GLib.PRIORITY_DEFAULT, null, (obj, res) => obj.delete_finish(res));
+ });
+});