Update VPN proxy client behavior
This commit is contained in:
@@ -93,6 +93,74 @@ test('copy uses the synchronous native path available on gateway HTTP', async ()
|
||||
assert.equal(textarea.removed, true);
|
||||
});
|
||||
|
||||
test('copy prefers the Clipboard API when it is available', async () => {
|
||||
const writes = [];
|
||||
let legacyCalls = 0;
|
||||
|
||||
await copyText('socks5://127.0.0.1:8082', {
|
||||
clipboard: { writeText: async (text) => writes.push(text) },
|
||||
documentRef: { execCommand: () => { legacyCalls += 1; } },
|
||||
});
|
||||
|
||||
assert.deepEqual(writes, ['socks5://127.0.0.1:8082']);
|
||||
assert.equal(legacyCalls, 0);
|
||||
});
|
||||
|
||||
test('copy falls back after the Clipboard API rejects', async () => {
|
||||
const textarea = {
|
||||
style: {},
|
||||
setAttribute() {},
|
||||
select() {},
|
||||
remove() { this.removed = true; },
|
||||
};
|
||||
const documentRef = {
|
||||
body: { append() {} },
|
||||
createElement: () => textarea,
|
||||
execCommand: () => true,
|
||||
};
|
||||
|
||||
await copyText('192.168.50.111', {
|
||||
clipboard: { writeText: async () => { throw new Error('denied'); } },
|
||||
documentRef,
|
||||
});
|
||||
|
||||
assert.equal(textarea.removed, true);
|
||||
});
|
||||
|
||||
test('copy rejects and removes the temporary textarea when the fallback fails', async () => {
|
||||
const textarea = {
|
||||
style: {},
|
||||
setAttribute() {},
|
||||
select() {},
|
||||
remove() { this.removed = true; },
|
||||
};
|
||||
const documentRef = {
|
||||
body: { append() {} },
|
||||
createElement: () => textarea,
|
||||
execCommand: () => false,
|
||||
};
|
||||
|
||||
await assert.rejects(copyText('192.168.50.111', { documentRef }), /Copy failed/);
|
||||
assert.equal(textarea.removed, true);
|
||||
});
|
||||
|
||||
test('copy removes the temporary textarea when the fallback throws', async () => {
|
||||
const textarea = {
|
||||
style: {},
|
||||
setAttribute() {},
|
||||
select() {},
|
||||
remove() { this.removed = true; },
|
||||
};
|
||||
const documentRef = {
|
||||
body: { append() {} },
|
||||
createElement: () => textarea,
|
||||
execCommand: () => { throw new Error('legacy failed'); },
|
||||
};
|
||||
|
||||
await assert.rejects(copyText('192.168.50.111', { documentRef }), /legacy failed/);
|
||||
assert.equal(textarea.removed, true);
|
||||
});
|
||||
|
||||
test('subscription usage combines traffic and caps progress', () => {
|
||||
assert.deepEqual(subscriptionUsage({ upload: 30, download: 80, total: 100, expire: 2 }), {
|
||||
upload: 30,
|
||||
|
||||
Reference in New Issue
Block a user