mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
More tests added + credits for source + fixed typings
This commit is contained in:
parent
888a13a608
commit
e9e984c161
81
types/chrome-apps/index.d.ts
vendored
81
types/chrome-apps/index.d.ts
vendored
@ -6468,13 +6468,11 @@ declare namespace chrome {
|
||||
namespace permissions {
|
||||
interface Permissions {
|
||||
/**
|
||||
* Optional.
|
||||
* List of named permissions (does not include hosts or origins).
|
||||
* Anything listed here must appear in the optional_permissions list in the manifest.
|
||||
*/
|
||||
origins?: chrome.runtime.OptionalPermissions[];
|
||||
permissions?: chrome.runtime.OptionalPermission[];
|
||||
/**
|
||||
* Optional.
|
||||
* List of origin permissions.
|
||||
* Anything listed here must be a subset of a host that appears in the
|
||||
* optional_permissions list in the manifest. For example, if
|
||||
@ -6482,33 +6480,33 @@ declare namespace chrome {
|
||||
* you can request an origin of http://help.example.com/.
|
||||
* Any path is ignored.
|
||||
*/
|
||||
permissions?: chrome.runtime.UrlMatches[] | string[];
|
||||
origins?: chrome.runtime.UrlMatches[] | string[];
|
||||
}
|
||||
|
||||
interface PermissionEvent extends chrome.events.Event<(permissions: chrome.runtime.Permission[]) => void> { }
|
||||
interface PermissionEvent extends chrome.events.Event<(permissions: Permissions) => void> { }
|
||||
|
||||
/**
|
||||
* Checks if the app has the specified permissions.
|
||||
* @param callback Parameter result: True if the app has the specified permissions.
|
||||
* @param callback Parameter *result*: True if the app has the specified permissions.
|
||||
*/
|
||||
function contains(permissions: chrome.runtime.Permission[], callback: (result: boolean) => void): void;
|
||||
function contains(permissions: Permissions, callback: (result: boolean) => void): void;
|
||||
/**
|
||||
* Gets the app's current set of permissions.
|
||||
* @param callback Parameter permissions: The app's active permissions.
|
||||
* @param callback Parameter *permissions*: The app's active permissions.
|
||||
*/
|
||||
function getAll(callback: (permissions: chrome.runtime.Permission[]) => void): void;
|
||||
function getAll(callback: (permissions: Permissions) => void): void;
|
||||
/**
|
||||
* Requests access to the specified permissions.
|
||||
* These permissions must be defined in the optional_permissions field of the manifest.
|
||||
* If there are any problems requesting the permissions, runtime.lastError will be set.
|
||||
* @param [callback] Parameter granted: True if the user granted the specified permissions.
|
||||
* @param [callback] Parameter *granted*: True if the user granted the specified permissions.
|
||||
*/
|
||||
function request(permissions: chrome.runtime.Permission[], callback?: (granted: boolean) => void): void;
|
||||
function request(permissions: Permissions, callback?: (granted: boolean) => void): void;
|
||||
/**
|
||||
* Removes access to the specified permissions. If there are any problems removing the permissions, runtime.lastError will be set.
|
||||
* @param [callback] Parameter removed: True if the permissions were removed.
|
||||
* @param [callback] Parameter *removed*: True if the permissions were removed.
|
||||
*/
|
||||
function remove(permissions: chrome.runtime.Permission[], callback?: (removed: boolean) => void): void;
|
||||
function remove(permissions: Permissions, callback?: (removed: boolean) => void): void;
|
||||
|
||||
/** Fired when access to permissions has been removed from the app. */
|
||||
const onRemoved: PermissionEvent;
|
||||
@ -6565,7 +6563,7 @@ declare namespace chrome {
|
||||
* empty list, however, certificates of any type will be returned.
|
||||
* @see ClientCertificateType
|
||||
*/
|
||||
certificateTypes: ToStringLiteral<typeof ClientCertificateType[]>;
|
||||
certificateTypes: ToStringLiteral<typeof ClientCertificateType>[];
|
||||
|
||||
/**
|
||||
* List of distinguished names of certificate authorities allowed by the
|
||||
@ -7072,12 +7070,11 @@ declare namespace chrome {
|
||||
'tts' |
|
||||
'wallpaper';
|
||||
|
||||
type OptionalPermission = Exclude<Permission, NotAllowedAsOptionalPermissions>;
|
||||
/**
|
||||
* Optional permissions
|
||||
* @see NotAllowedAsOptionalPermissions for permissions that you're not allowed to set.
|
||||
* @see NotAllowedAsOptionalPermissions for permissions that you're not allowed to set on demand.
|
||||
*/
|
||||
type OptionalPermissions = Array<OptionalPermission> | Array<OptionalPermission | string>;
|
||||
type OptionalPermission = Exclude<Permission, NotAllowedAsOptionalPermissions>;
|
||||
|
||||
type Permission =
|
||||
/** Gives your app access to the chrome.alarms API. */
|
||||
@ -7683,7 +7680,7 @@ declare namespace chrome {
|
||||
* at run time rather than install time, so users understand why the
|
||||
* permissions are needed and grant only those that are necessary.
|
||||
*/
|
||||
optional_permissions?: OptionalPermissions;
|
||||
optional_permissions?: OptionalPermission[] | Array<OptionalPermission | chrome.runtime.UrlMatches[]> | Array<OptionalPermission | chrome.runtime.UrlMatches[] | string>;
|
||||
|
||||
/**
|
||||
* Permissions help to limit damage if your app is compromised by malware.
|
||||
@ -10630,11 +10627,20 @@ declare namespace chrome {
|
||||
SHOW_CONFIGURE_DIALOG: 'showConfigureDialog'
|
||||
};
|
||||
interface VpnSessionParameters {
|
||||
/** IP address for the VPN interface in CIDR notation. IPv4 is currently the only supported mode. */
|
||||
/**
|
||||
* IP address for the VPN interface in CIDR notation.
|
||||
* IPv4 is currently the only supported mode.
|
||||
*/
|
||||
address: string;
|
||||
/** Broadcast address for the VPN interface. (default: deduced from IP address and mask) */
|
||||
/**
|
||||
* Broadcast address for the VPN interface.
|
||||
* (default: deduced from IP address and mask)
|
||||
*/
|
||||
broadcastAddress?: string;
|
||||
/** MTU setting for the VPN interface. (default: 1500 bytes) */
|
||||
/**
|
||||
* MTU setting for the VPN interface (default 1500 bytes).
|
||||
* @default '1500'
|
||||
*/
|
||||
mtu?: string;
|
||||
/**
|
||||
* Exclude network traffic to the list of IP blocks in CIDR notation from the tunnel.
|
||||
@ -10659,7 +10665,22 @@ declare namespace chrome {
|
||||
/** A list of search domains. (default: no search domain) */
|
||||
domainSearch?: string[];
|
||||
/** A list of IPs for the DNS servers. */
|
||||
dnsServer: string[];
|
||||
dnsServers: string[];
|
||||
/**
|
||||
* @since Chrome 51.
|
||||
* Whether or not the VPN extension implements auto-reconnection.
|
||||
* If true, the *linkDown*, *linkUp*, *linkChanged*, *suspend*, and *resume*
|
||||
* platform messages will be used to signal the respective events.
|
||||
*
|
||||
* If false, the system will forcibly disconnect the VPN if the network
|
||||
* topology changes, and the user will need to reconnect manually.
|
||||
*
|
||||
* This property is new in Chrome 51; it will generate an exception in
|
||||
* earlier versions. try/catch can be used to conditionally enable the
|
||||
* feature based on browser support.
|
||||
* @default false
|
||||
*/
|
||||
reconnect: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -10724,21 +10745,23 @@ declare namespace chrome {
|
||||
* @since Chrome 43.
|
||||
*/
|
||||
namespace wallpaper {
|
||||
const WallpaperLayout: {
|
||||
'STRETCH': 'STRETCH',
|
||||
'CENTER': 'CENTER',
|
||||
'CENTER_CROPPED': 'CENTER_CROPPED'
|
||||
};
|
||||
enum WallpaperLayout {
|
||||
STRETCH = 'STRETCH',
|
||||
CENTER = 'CENTER',
|
||||
CENTER_CROPPED = 'CENTER_CROPPED'
|
||||
}
|
||||
type WallpaperLayoutType = 'STRETCH' | 'CENTER' | 'CENTER_CROPPED';
|
||||
|
||||
interface WallpaperDetails {
|
||||
/** The jpeg or png encoded wallpaper image. */
|
||||
data?: any;
|
||||
data?: ArrayBuffer;
|
||||
/** The URL of the wallpaper to be set. */
|
||||
url?: string;
|
||||
/**
|
||||
* The supported wallpaper layouts.
|
||||
* @see WallpaperLayout
|
||||
*/
|
||||
layout: ToStringLiteral<typeof WallpaperLayout>;
|
||||
layout: WallpaperLayout | WallpaperLayoutType;
|
||||
/** The file name of the saved wallpaper. */
|
||||
filename: string;
|
||||
/** True if a 128x60 thumbnail should be generated. */
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* Some of the tests are based on examples found in the Chromium documentation or source.
|
||||
* @author Nikolai Ommundsen (niikoo {@link https://github.com/niikoo})
|
||||
* @author The Chromium Authors
|
||||
*/
|
||||
|
||||
import runtime = chrome.app.runtime;
|
||||
const cwindow = chrome.app.window;
|
||||
|
||||
@ -921,9 +927,116 @@ chrome.networking.onc.getNetworks({ 'networkType': 'All' }, (networkList) => {
|
||||
|
||||
chrome.notifications; // @todo TODO Tests
|
||||
|
||||
chrome.platformKeys; // @todo TODO Tests
|
||||
// #region chrome.platformKeys
|
||||
|
||||
chrome.permissions; // @todo TODO Tests
|
||||
var data = {
|
||||
trusted_l1_leaf_cert: 'l1_leaf.der',
|
||||
trusted_l1_interm_cert: 'l1_interm.der',
|
||||
trusted_l2_leaf_cert: 'l2_leaf.der',
|
||||
client_1: 'client_1.der',
|
||||
client_2: 'client_2.der',
|
||||
client_1_spki: 'client_1_spki.der',
|
||||
client_1_issuer_dn: {
|
||||
buffer: new ArrayBuffer(16)
|
||||
},
|
||||
raw_data: 'data',
|
||||
signature_nohash_pkcs: 'signature_nohash_pkcs',
|
||||
signature_client1_sha1_pkcs: 'signature_client1_sha1_pkcs',
|
||||
signature_client2_sha1_pkcs: 'signature_client2_sha1_pkcs',
|
||||
};
|
||||
function requestCA1(): chrome.platformKeys.ClientCertificateRequest {
|
||||
return {
|
||||
certificateTypes: [],
|
||||
certificateAuthorities: [data.client_1_issuer_dn.buffer]
|
||||
};
|
||||
}
|
||||
chrome.platformKeys.selectClientCertificates(
|
||||
{ interactive: false, request: requestCA1() },
|
||||
(matches) => {
|
||||
});
|
||||
|
||||
const requestECDSA: chrome.platformKeys.ClientCertificateRequest = {
|
||||
certificateTypes: ['ecdsaSign'],
|
||||
certificateAuthorities: []
|
||||
};
|
||||
chrome.platformKeys.selectClientCertificates(
|
||||
{ interactive: false, request: requestECDSA },
|
||||
(matches) => {
|
||||
return matches.length;
|
||||
});
|
||||
|
||||
if (chrome.platformKeys.subtleCrypto &&
|
||||
chrome.platformKeys.subtleCrypto() &&
|
||||
chrome.platformKeys.subtleCrypto().sign &&
|
||||
chrome.platformKeys.subtleCrypto().exportKey) {
|
||||
console.log('Subtle crypto working (Y)')
|
||||
}
|
||||
|
||||
var keyParams = {
|
||||
// Algorithm names are case-insensitive.
|
||||
name: 'RSASSA-Pkcs1-V1_5',
|
||||
hash: { name: 'sha-1' }
|
||||
};
|
||||
chrome.platformKeys.getKeyPair(
|
||||
data.client_1_issuer_dn.buffer, keyParams,
|
||||
(publicKey, privateKey) => {
|
||||
let expectedAlgorithm = {
|
||||
modulusLength: 2048,
|
||||
name: "RSASSA-PKCS1-v1_5",
|
||||
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
||||
hash: { name: 'SHA-1' }
|
||||
};
|
||||
|
||||
if (expectedAlgorithm === publicKey.algorithm &&
|
||||
privateKey &&
|
||||
expectedAlgorithm === privateKey.algorithm) {
|
||||
if (publicKey.type === 'public' && privateKey.type === 'private') {
|
||||
console.log('All okay!');
|
||||
}
|
||||
}
|
||||
chrome.platformKeys.subtleCrypto()
|
||||
.exportKey('spki', publicKey)
|
||||
.then((actualPublicKeySpki) => {
|
||||
if (new ArrayBuffer(100) === actualPublicKeySpki) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
var details = {
|
||||
serverCertificateChain: [data.client_1_issuer_dn.buffer],
|
||||
hostname: "l1_leaf"
|
||||
};
|
||||
chrome.platformKeys.verifyTLSServerCertificate(
|
||||
details, (result) => {
|
||||
return result.trusted;
|
||||
});
|
||||
// #endregion
|
||||
|
||||
// #region chrome.permissions
|
||||
|
||||
chrome.permissions.request({ permissions: ['storage'] }, (granted) => {
|
||||
return granted && 'It was granted';
|
||||
});
|
||||
|
||||
chrome.permissions.getAll((permissions) => {
|
||||
if (chrome.runtime.lastError || !permissions.permissions) {
|
||||
return;
|
||||
}
|
||||
for (const permission of permissions.permissions) {
|
||||
if (permission === 'alarms') {
|
||||
return 'I knew it!';
|
||||
}
|
||||
chrome.permissions.remove({ permissions: [permission] }, (removed) => {
|
||||
return removed ? 'It was removed' : 'It was not removed';
|
||||
});
|
||||
}
|
||||
chrome.permissions.contains({ origins: ['chrome://favicon/'] }, (doIHaveIt) => doIHaveIt ? 'yes' : 'neh');
|
||||
chrome.permissions.request(
|
||||
{ permissions: ['audio'] },
|
||||
() => { });
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region chrome.power
|
||||
|
||||
@ -1360,9 +1473,58 @@ chrome.virtualKeyboard.restrictFeatures(
|
||||
);
|
||||
// #endregion
|
||||
|
||||
chrome.vpnProvider; // @todo TODO Tests
|
||||
chrome.wallpaper; // @todo TODO Tests
|
||||
chrome.webViewRequest; // @todo TODO Tests
|
||||
// #region chrome.vpnProvider
|
||||
|
||||
const vpnParams = {
|
||||
address: '127.0.0.1/32',
|
||||
mtu: '1500',
|
||||
exclusionList: ['127.0.0.1/32'],
|
||||
inclusionList: ['0.0.0.0/0'],
|
||||
dnsServers: ['1.1.1.1', '1.0.0.1', '8.8.8.8'],
|
||||
reconnect: true
|
||||
};
|
||||
chrome.vpnProvider.onConfigCreated.addListener((id, name, data) => {
|
||||
console.log('Connected: ', id.toLowerCase(), name.toUpperCase(), JSON.stringify(data));
|
||||
});
|
||||
chrome.vpnProvider.createConfig('Local VPN', (id) => {
|
||||
chrome.vpnProvider.setParameters(vpnParams, () => {
|
||||
if (chrome.runtime.lastError) {
|
||||
chrome.vpnProvider.notifyConnectionStateChanged('failure');
|
||||
throw chrome.runtime.lastError;
|
||||
}
|
||||
chrome.vpnProvider.notifyConnectionStateChanged('connected', () => {
|
||||
chrome.vpnProvider.onPacketReceived.addListener(data => {
|
||||
return data.byteLength > 0 ? data : undefined;
|
||||
});
|
||||
chrome.vpnProvider.onConfigRemoved.addListener(id => id.toUpperCase());
|
||||
chrome.vpnProvider.onPlatformMessage.addListener((id, message) => {
|
||||
if (typeof id === 'string') {
|
||||
return message === 'connected';
|
||||
}
|
||||
});
|
||||
chrome.vpnProvider.onUIEvent.addListener((event, id) => {
|
||||
if (event === 'showAddDialog') {
|
||||
return id;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
// #endregion
|
||||
|
||||
// #region chrome.wallpaper
|
||||
chrome.wallpaper.setWallpaper({
|
||||
url: 'chrome://favicon/iconurl/https://www.google.com/favicon.ico',
|
||||
layout: 'CENTER_CROPPED',
|
||||
filename: 'test_wallpaper'
|
||||
}, (thumbnail) => {
|
||||
const imageUrl = thumbnail;
|
||||
});
|
||||
chrome.wallpaper.setWallpaper({
|
||||
layout: chrome.wallpaper.WallpaperLayout.STRETCH,
|
||||
filename: 'test_wallpaper2'
|
||||
}, () => { });
|
||||
// #endregion
|
||||
|
||||
// #region chrome.webViewRequest & WebView
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user