Skip to content

Commit 914a28f

Browse files
committed
js: Move mount/autorun dialog test widgets to their own folder.
1 parent 7efb8a0 commit 914a28f

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

js/testing/testAutorunDialog.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Test helper - call from Looking Glass:
2+
// imports.testing.testAutorunDialog.show()
3+
// imports.testing.testAutorunDialog.show("My USB", "x-content/image-dcf")
4+
5+
const Gio = imports.gi.Gio;
6+
const AutorunManager = imports.ui.autorunManager;
7+
8+
function show(mountName, contentType) {
9+
mountName = mountName || "Test USB Drive";
10+
contentType = contentType || "x-content/unix-software";
11+
12+
let nextId = 1;
13+
let mount = {
14+
get_name() { return mountName; },
15+
can_eject() { return true; },
16+
get_root() { return Gio.File.new_for_path("/"); },
17+
connect() { return nextId++; },
18+
disconnect() {},
19+
eject_with_operation() {},
20+
unmount_with_operation() {},
21+
};
22+
23+
let apps = [];
24+
let app = Gio.app_info_get_default_for_type("inode/directory", false);
25+
if (app)
26+
apps.push(app);
27+
28+
let dialog = new AutorunManager.AutorunDialog(mount, apps, contentType);
29+
dialog.open();
30+
return dialog;
31+
}

js/testing/testMountDialogs.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Test helpers for mount operation dialogs.
2+
// Call from Looking Glass:
3+
//
4+
// imports.testing.testMountDialogs.askPassword()
5+
// imports.testing.testMountDialogs.askPassword("Unlock encrypted volume\nEnter password for 'My Drive'")
6+
// imports.testing.testMountDialogs.askPasswordTcrypt()
7+
// imports.testing.testMountDialogs.askQuestion()
8+
// imports.testing.testMountDialogs.askQuestion("Trust this certificate?\nThe identity of 'server.local' cannot be verified.", ["Cancel", "Trust", "Trust Always"])
9+
// imports.testing.testMountDialogs.showProcesses()
10+
11+
const Gio = imports.gi.Gio;
12+
const MountOp = imports.ui.cinnamonMountOperation;
13+
14+
function askPassword(message, flags) {
15+
message = message || "Enter a password to unlock the volume\nThe password is needed to access encrypted data on My Encrypted Drive.";
16+
flags = flags || Gio.AskPasswordFlags.NEED_PASSWORD;
17+
18+
let dialog = new MountOp.CinnamonMountPasswordDialog(message, flags);
19+
dialog.connect('response', (obj, choice, password, remember, hidden, system, pim) => {
20+
log(`[testMountDialogs] askPassword response: choice=${choice} password=${password}`);
21+
dialog.close();
22+
});
23+
dialog.open();
24+
return dialog;
25+
}
26+
27+
function askPasswordTcrypt(message) {
28+
message = message || "Enter a password to unlock the volume\nThe password is needed to access encrypted data on My VeraCrypt Drive.";
29+
let flags = Gio.AskPasswordFlags.NEED_PASSWORD | Gio.AskPasswordFlags.TCRYPT;
30+
31+
return askPassword(message, flags);
32+
}
33+
34+
function askQuestion(message, choices) {
35+
message = message || "Mount point is not empty\nThe mount point /mnt/data already contains files. Do you want to merge?";
36+
choices = choices || ["Cancel", "Merge"];
37+
38+
let dialog = new MountOp.CinnamonMountQuestionDialog();
39+
dialog.connect('response', (obj, choice) => {
40+
log(`[testMountDialogs] askQuestion response: choice=${choice}`);
41+
dialog.close();
42+
});
43+
dialog.update(message, choices);
44+
dialog.open();
45+
return dialog;
46+
}
47+
48+
function showProcesses(message, choices) {
49+
message = message || "Volume is busy\nOne or more applications are keeping the volume busy.";
50+
choices = choices || ["Cancel", "Unmount Anyway"];
51+
52+
let dialog = new MountOp.CinnamonProcessesDialog();
53+
dialog.connect('response', (obj, choice) => {
54+
log(`[testMountDialogs] showProcesses response: choice=${choice}`);
55+
dialog.close();
56+
});
57+
58+
// Use real PIDs of running apps if possible, otherwise empty
59+
let pids = [];
60+
dialog.update(message, pids, choices);
61+
dialog.open();
62+
return dialog;
63+
}

0 commit comments

Comments
 (0)