@@ -195,7 +195,8 @@ test.each([['edge_v2'], ['chrome_v3'], ['firefox_v2']])(
195195 '[%s] - Modify Response' ,
196196 async browserKey =>
197197 runTest ( browserKey , async browser => {
198- const key = String ( Math . random ( ) ) . replace ( '.' , '' ) ;
198+ const key1 = String ( Math . random ( ) ) . replace ( '.' , '' ) ;
199+ const key2 = String ( Math . random ( ) ) . replace ( '.' , '' ) ;
199200
200201 await callBackgroundApi ( browser . popup , {
201202 method : 'set_pref' ,
@@ -213,19 +214,57 @@ test.each([['edge_v2'], ['chrome_v3'], ['firefox_v2']])(
213214 } ,
214215 body : {
215216 stage : 'Response' ,
216- value : `document.getElementById("value").value='${ key } ';` ,
217+ value : `document.getElementById("value").value='${ key1 } ';` ,
217218 } ,
218219 encoding : 'UTF-8' ,
219220 } ) ;
220221
221222 const value1 = await getPageValue ( browser . browser , 'js-src.php' ) ;
222- expect ( value1 ) . toBe ( key ) ;
223+ expect ( value1 ) . toBe ( key1 ) ;
223224
224225 const value2 = await getPageValue (
225226 browser . browser ,
226- `js-src.php?value=${ key } ` ,
227+ `js-src.php?value=${ key2 } ` ,
228+ ) ;
229+ expect ( value2 ) . toBe ( key2 ) ;
230+
231+ await remove ( ) ;
232+ } ) ,
233+ ) ;
234+
235+ test . each ( [ [ 'edge_v2' ] , [ 'firefox_v2' ] ] ) (
236+ '[%s] - Modify Response - Custom Function' ,
237+ async browserKey =>
238+ runTest ( browserKey , async browser => {
239+ const key1 = String ( Math . random ( ) ) . replace ( '.' , '' ) ;
240+ const key2 = String ( Math . random ( ) ) . replace ( '.' , '' ) ;
241+
242+ await callBackgroundApi ( browser . popup , {
243+ method : 'set_pref' ,
244+ key : 'modify-body' ,
245+ value : true ,
246+ } ) ;
247+
248+ const { remove } = await saveRule ( browser . popup , {
249+ enable : true ,
250+ ruleType : 'modifyReceiveBody' ,
251+ isFunction : true ,
252+ name : 'test modify response with custom function' ,
253+ condition : {
254+ urlPrefix : `${ testServer } mock-js.php` ,
255+ } ,
256+ body : {
257+ stage : 'Response' ,
258+ } ,
259+ code : `return val.replace(/'(.*?)'/, '"${ key1 } $1${ key1 } $1"');` ,
260+ encoding : 'UTF-8' ,
261+ } ) ;
262+
263+ const value = await getPageValue (
264+ browser . browser ,
265+ `js-src.php?value=${ key2 } ` ,
227266 ) ;
228- expect ( value2 ) . toBe ( JSON . stringify ( { value : key } ) ) ;
267+ expect ( value ) . toBe ( ` ${ key1 } ${ key2 } ${ key1 } ${ key2 } ` ) ;
229268
230269 await remove ( ) ;
231270 } ) ,
0 commit comments