10
10
< script >
11
11
12
12
const { ORIGIN , REMOTE_ORIGIN , HTTP_NOTSAMESITE_ORIGIN } = get_host_info ( ) ;
13
- const origins = {
14
- "same origin" : ORIGIN ,
15
- "same site" : REMOTE_ORIGIN ,
16
- "different site" : HTTP_NOTSAMESITE_ORIGIN
17
- }
18
13
const loaders = {
19
14
image : {
20
15
file : '../../images/green.png' ,
59
54
}
60
55
} ;
61
56
62
- async function test_prefetch_document ( { origin, as} , expected ) {
63
- promise_test ( async t => {
64
- const { href, uid} = await prefetch ( {
65
- file : "prefetch-exec.html" ,
66
- type : "text/html" ,
67
- corssOrigin : "anonymous" ,
68
- origin : origins [ origin ] ,
69
- as} ) ;
57
+ async function prefetch_document_and_count_fetches ( options , t ) {
58
+ const { href, uid} = await prefetch ( {
59
+ file : "prefetch-exec.html" ,
60
+ type : "text/html" ,
61
+ corssOrigin : "anonymous" ,
62
+ ...options } ) ;
63
+ const popup = window . open ( href ) ;
64
+ const remoteContext = new RemoteContext ( uid ) ;
65
+ t . add_cleanup ( ( ) => popup . close ( ) ) ;
66
+ const result = await remoteContext . execute_script ( ( ) => "OK" ) ;
67
+ assert_equals ( result , "OK" ) ;
68
+ const requests = await get_prefetch_info ( href ) ;
69
+ return requests . length ;
70
+ }
70
71
71
- const popup = window . open ( href ) ;
72
- const remoteContext = new RemoteContext ( uid ) ;
73
- t . add_cleanup ( ( ) => popup . close ( ) ) ;
74
- const result = await remoteContext . execute_script ( ( ) => "OK" ) ;
75
- assert_equals ( result , "OK" ) ;
72
+ promise_test ( async t => {
73
+ assert_equals ( await prefetch_document_and_count_fetches ( { origin : ORIGIN } , t ) , 1 ) ;
74
+ } , "same origin document prefetch without 'as' should be consumed" ) ;
76
75
77
- const requests = await get_prefetch_info ( href ) ;
78
- const did_consume = requests . length === 1 ? "consumed" : "not consumed" ;
79
- assert_equals ( did_consume , expected ) ;
80
- } , `Prefetching a document (${ origin } , as="${ as } ") should be ${ expected } ` ) ;
81
- }
76
+ promise_test ( async t => {
77
+ assert_equals ( await prefetch_document_and_count_fetches ( { origin : REMOTE_ORIGIN } , t ) , 1 ) ;
78
+ } , "same-site different-origin document prefetch without 'as' should be consumed" ) ;
82
79
83
- test_prefetch_document ( { origin : "same origin" } , "consumed" ) ;
84
- test_prefetch_document ( { origin : "same site" } , "consumed" ) ;
85
- test_prefetch_document ( { as : "document" , origin : "different site" } , "not consumed" ) ;
80
+ promise_test ( async t => {
81
+ assert_equals ( await prefetch_document_and_count_fetches ( { origin : HTTP_NOTSAMESITE_ORIGIN } , t ) , 2 ) ;
82
+ } , "different-site document prefetch without 'as' should not be consumed" ) ;
83
+
84
+ promise_test ( async t => {
85
+ assert_equals ( await prefetch_document_and_count_fetches ( { origin : HTTP_NOTSAMESITE_ORIGIN , as : "document" } , t ) , 2 ) ;
86
+ } , "different-site document prefetch without 'as' should not be consumed" ) ;
86
87
87
88
promise_test ( async t => {
88
89
const { href, uid} = await prefetch ( {
98
99
assert_equals ( results . length , 2 ) ;
99
100
assert_equals ( results [ 0 ] . headers . accept , results [ 1 ] . headers . accept ) ;
100
101
} , "Document prefetch should send the exact Accept header as navigation" )
101
-
102
102
</ script >
103
103
</ body >
0 commit comments