[sinon-chrome] Support plugins

This commit is contained in:
kobanyan 2018-03-12 01:26:35 +09:00
parent 9bb6dc2f8b
commit 6596fb459b
2 changed files with 67 additions and 0 deletions

View File

@ -2,6 +2,7 @@
// Project: https://github.com/vitalets/sinon-chrome
// Definitions by: Tim Perry <https://github.com/pimterry>
// CRIMX <https://github.com/crimx>
// kobanyan <https://github.com/kobanyan>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
@ -37,6 +38,8 @@ declare namespace SinonChrome {
*/
export function reset(): void;
export function registerPlugin(plugin: SinonChrome.plugins.Plugin): void;
export var csi: Sinon.SinonSpy;
export var loadTimes: Sinon.SinonSpy;
}
@ -353,6 +356,23 @@ declare namespace SinonChrome.permissions {
export var request: SinonChromeStub;
}
declare namespace SinonChrome.plugins {
export interface Plugin {}
export interface Translation {
message: string;
placeholders?: object;
}
export interface Translations {
[key: string]: Translation;
}
export class I18nPlugin implements Plugin {
constructor(translations: Translations);
}
export class CookiePlugin implements Plugin {
constructor(state?: Array<chrome.cookies.Cookie>);
}
}
declare namespace SinonChrome.power {
export var releaseKeepAwake: SinonChromeStub;
export var requestKeepAwake: SinonChromeStub;

View File

@ -32,3 +32,50 @@ var id: string = chromeStub.runtime.id;
chromeStub.proxy.settings.set({value: { }, scope: 'regular'});
chromeStub.proxy.settings.onChange.trigger();
chromeStub.registerPlugin(new chromeStub.plugins.I18nPlugin({
one: {
message: 'Hi!'
},
two: {
message: 'Hi $first_name$ $last_name$!',
placeholders: {
first_name: {
content: '$1'
},
last_name: {
content: '$2'
}
}
}
}));
chromeStub.registerPlugin(new chromeStub.plugins.CookiePlugin());
chromeStub.registerPlugin(new chromeStub.plugins.CookiePlugin(
[
{
domain: '.domain.com',
expirationDate: 1511612273,
hostOnly: false,
httpOnly: false,
name: 'COOKIE_NAME',
path: '/data',
secure: false,
session: false,
storeId: '0',
value: 'COOKIE_VALUE'
},
{
domain: 'other-domain.com',
hostOnly: false,
httpOnly: false,
name: 'other-cookie',
path: '/',
secure: false,
session: true,
storeId: '0',
value: '123'
}
]
));