@@ -5,6 +5,7 @@ import { ExtVersion } from "@App/app/const";
5
5
import { initTestEnv } from "@Tests/utils" ;
6
6
import { describe , expect , it } from "vitest" ;
7
7
import type { GMInfoEnv } from "./types" ;
8
+ import { ScriptLoadInfo } from "../service_worker/types" ;
8
9
9
10
initTestEnv ( ) ;
10
11
@@ -183,3 +184,54 @@ describe("none this", () => {
183
184
expect ( ret ) . toEqual ( "ok" ) ;
184
185
} ) ;
185
186
} ) ;
187
+
188
+ describe ( "@grant GM" , ( ) => {
189
+ it ( "GM_" , async ( ) => {
190
+ const script = Object . assign ( { } , scriptRes2 ) as ScriptLoadInfo ;
191
+ script . metadata . grant = [ "GM_getValue" , "GM_getTab" , "GM_saveTab" ] ;
192
+ // @ts -ignore
193
+ const exec = new ExecScript ( script , undefined , undefined , undefined , envInfo ) ;
194
+ script . code = `return {
195
+ ["GM.getValue"]: GM.getValue,
196
+ ["GM.getTab"]: GM.getTab,
197
+ ["GM.setTab"]: GM.setTab,
198
+ GM_getValue: this.GM_getValue,
199
+ GM_getTab: this.GM_getTab,
200
+ GM_saveTab: this.GM_saveTab,
201
+ }` ;
202
+ exec . scriptFunc = compileScript ( compileScriptCode ( script ) ) ;
203
+ const ret = await exec . exec ( ) ;
204
+ expect ( ret ) . toEqual ( {
205
+ "GM.getValue" : undefined ,
206
+ "GM.getTab" : undefined ,
207
+ "GM.setTab" : undefined ,
208
+ GM_getValue : expect . any ( Function ) ,
209
+ GM_getTab : expect . any ( Function ) ,
210
+ GM_saveTab : expect . any ( Function ) ,
211
+ } ) ;
212
+ } ) ;
213
+ it ( "GM.*" , async ( ) => {
214
+ const script = Object . assign ( { } , scriptRes2 ) as ScriptLoadInfo ;
215
+ script . metadata . grant = [ "GM.getValue" , "GM.getTab" , "GM.saveTab" ] ;
216
+ // @ts -ignore
217
+ const exec = new ExecScript ( script , undefined , undefined , undefined , envInfo ) ;
218
+ script . code = `return {
219
+ ["GM.getValue"]: GM.getValue,
220
+ ["GM.getTab"]: GM.getTab,
221
+ ["GM.saveTab"]: GM.saveTab,
222
+ GM_getValue: this.GM_getValue,
223
+ GM_getTab: this.GM_getTab,
224
+ GM_saveTab: this.GM_saveTab,
225
+ }` ;
226
+ exec . scriptFunc = compileScript ( compileScriptCode ( script ) ) ;
227
+ const ret = await exec . exec ( ) ;
228
+ expect ( ret ) . toEqual ( {
229
+ "GM.getValue" : expect . any ( Function ) ,
230
+ "GM.getTab" : expect . any ( Function ) ,
231
+ "GM.setTab" : expect . any ( Function ) ,
232
+ GM_getValue : undefined ,
233
+ GM_getTab : undefined ,
234
+ GM_setTab : undefined ,
235
+ } ) ;
236
+ } ) ;
237
+ } ) ;
0 commit comments