@@ -79,4 +79,35 @@ describe('quicklink tests', function () {
7979 expect ( responseURLs ) . to . be . an ( 'array' ) ;
8080 expect ( responseURLs ) . to . include ( `${ server } /main.css` ) ;
8181 } ) ;
82+
83+ it ( 'should only prefetch links if allowed in origins list' , async function ( ) {
84+ const responseURLs = [ ] ;
85+ page . on ( 'response' , resp => {
86+ responseURLs . push ( resp . url ( ) ) ;
87+ } ) ;
88+ await page . goto ( `${ server } /test-allow-origin.html` ) ;
89+
90+ await page . waitFor ( 1000 ) ;
91+
92+ expect ( responseURLs ) . to . be . an ( 'array' ) ;
93+ //=> origins: ['github.githubassets.com']
94+ expect ( responseURLs ) . to . not . include ( `${ server } /2.html` ) ;
95+ expect ( responseURLs ) . to . include ( 'https://example.com/1.html' ) ;
96+ expect ( responseURLs ) . to . include ( 'https://github.githubassets.com/images/spinners/octocat-spinner-32.gif' ) ;
97+ } ) ;
98+
99+ it ( 'should only prefetch links of same origin' , async function ( ) {
100+ const responseURLs = [ ] ;
101+ page . on ( 'response' , resp => {
102+ responseURLs . push ( resp . url ( ) ) ;
103+ } ) ;
104+ await page . goto ( `${ server } /test-same-origin.html` ) ;
105+
106+ await page . waitFor ( 1000 ) ;
107+ expect ( responseURLs ) . to . be . an ( 'array' ) ;
108+ //=> sameOrigin: true
109+ expect ( responseURLs ) . to . include ( `${ server } /2.html` ) ;
110+ expect ( responseURLs ) . to . not . include ( 'https://example.com/1.html' ) ;
111+ expect ( responseURLs ) . to . not . include ( 'https://github.githubassets.com/images/spinners/octocat-spinner-32.gif' ) ;
112+ } ) ;
82113} ) ;
0 commit comments