1
- // More helper functions here!
1
+ /*
2
+ Functions and helpers to run the "Head(er)s Up!" browser tests and store the final results in the database
3
+ */
4
+ // Scheme and host of the top-level file (original scheme/host)
2
5
var org_scheme = location . port == 9000 ? "http2" : location . protocol == "http:" ? "http" : "https" ;
3
6
var org_host = location . hostname ;
4
7
8
+ // String to search for on the page; Only necessary for manual debugging of the COEP bug
5
9
let search = urlParams . get ( 'search' ) || undefined ;
6
10
7
11
// We always visit the testpages at http://sub.headers.websec.saarland or https://sub.headers.websec.saarland
8
- // We then create tests for http, https, ~~and http2~~ for the following cases :
9
- // same-org, 2x same-site (parent-domain + sub-domain), cross-site
12
+ // We then create tests for the following origins :
13
+ // (https and https) X same-org, 2x same-site (parent-domain + sub-domain), cross-site
10
14
function get_test_origins ( resp_type ) {
11
15
const same_host = 'sub.{{host}}' ;
12
16
const parent = '{{host}}' ;
@@ -24,13 +28,16 @@ function get_test_origins(resp_type) {
24
28
origins . push ( `http://${ host } ` ) ;
25
29
}
26
30
origins . push ( `https://${ host } ` ) ;
27
- // H2 has a process leak? after a while 7k+ processes are open and everything crashes
31
+
32
+ // The WPT HTTP/2 server has a process leak: after a while 7k+ processes are open and everything crashes
28
33
// Occurs for both with/without settings to allow for invalid responses
34
+ // For now do not test HTTP/2
29
35
//origins.push(`https://${host}:{{ports[h2][0]}}`);
30
36
}
31
37
return origins ;
32
38
} ;
33
39
40
+ // Helper to wait for a postMessage from a specific frame
34
41
function waitForMessageFrom ( frame , test ) {
35
42
return new Promise ( resolve => {
36
43
window . addEventListener ( "message" , test . step_func ( e => {
@@ -41,32 +48,38 @@ function waitForMessageFrom(frame, test) {
41
48
} ) ;
42
49
}
43
50
44
- // Run all tests for origin relations and similar!
51
+ // Run all declared tests for the specified origins
45
52
function run_tests ( test_declarations , path , label , origins ) {
46
- const resp_type = urlParams . get ( "resp_type" ) || "debug" ; // Default resp_type is debug
53
+ // Which tests to run: debug (default), basic, parsing
54
+ const resp_type = urlParams . get ( "resp_type" ) || "debug" ;
55
+ // Which tests to run (from first_id to last_id)
47
56
const first_id = parseInt ( urlParams . get ( "first_id" ) , 10 ) || null ;
48
57
const last_id = parseInt ( urlParams . get ( "last_id" ) , 10 ) || null ;
58
+ // If tests open popups, which to run (from first_popup to last_popup)
49
59
const first_popup = parseInt ( urlParams . get ( "first_popup" ) , 10 ) || 0 ;
50
60
const last_popup = parseInt ( urlParams . get ( "last_popup" ) , 10 ) || Infinity ;
61
+ // Do not run any popup tests
51
62
const run_no_popup = urlParams . get ( "run_no_popup" ) || 'yes' ;
52
63
53
- // Manual confirmation mode
64
+ // Settings for the manual confirmation mode
65
+ // Only run this exact test instance
54
66
const t_resp_id = parseInt ( urlParams . get ( "t_resp_id" ) , 10 ) || null ;
55
67
const t_resp_origin = urlParams . get ( "t_resp_origin" ) || null ;
56
68
const element_relation = urlParams . get ( "t_element_relation" ) || null ;
57
69
58
- // Fetch origin relations if not specified
70
+ // If no origin relations are specified, run for the default origins of the `resp_type`
59
71
if ( ! origins ) {
60
72
origins = get_test_origins ( resp_type ) ;
61
73
}
62
74
63
- // If &first_id=<first_id>&last_id=<last_id>; run on the specified ids
75
+ // For automated testing run on the specified ids ( &first_id=<first_id>&last_id=<last_id>;)
64
76
let popup_count = 0 ;
65
77
if ( first_id && last_id ) {
66
78
for ( var response_id = first_id ; response_id < last_id + 1 ; response_id ++ ) {
67
79
for ( var origin of origins ) {
68
80
for ( let test of test_declarations ) {
69
- // Only run exactly one test in the manual confirmation mode (the manual confirmation mode has to use clean_urls without popup_settings!)
81
+ // Only run exactly one test in the manual confirmation mode
82
+ // (the manual confirmation mode has to use clean_urls without popup_settings!)
70
83
if ( t_resp_id ) {
71
84
if ( t_resp_id != response_id ) {
72
85
continue
@@ -108,6 +121,7 @@ function run_tests(test_declarations, path, label, origins) {
108
121
console . log ( `All popups: ${ popup_count } ` ) ;
109
122
}
110
123
124
+ // Helper to create nested tests
111
125
function nested_test ( frame_element , sandbox , url , response_id , element , test_info , test_name ) {
112
126
async_test ( t => {
113
127
t . set_test_info ( url , test_info ) ;
@@ -145,19 +159,20 @@ function nested_test(frame_element, sandbox, url, response_id, element, test_inf
145
159
} , test_name ) ;
146
160
}
147
161
148
- // Store result helpers!
162
+ // Store all the results on our database
149
163
async function save_result ( tests , status ) {
150
164
console . log ( tests ) ;
165
+ // Convert the WPT test results to our format
151
166
var test_results = tests . map ( function ( x ) {
152
167
return {
153
168
name : x . name , outcome : x . outcome , status : x . status , message : x . message , stack : x . stack ,
154
169
resp_scheme : x . resp_scheme , resp_host : x . resp_host , relation : x . relation
155
170
}
156
171
} ) ;
157
172
var data = {
158
- // Results for the individual tests + metainfo (which browser)
173
+ // Results for the individual tests + metainfo (e.g., which browser)
159
174
tests : test_results ,
160
- browser_id : urlParams . get ( 'browser_id' ) || 1 , // One is the unknown browser!
175
+ browser_id : urlParams . get ( 'browser_id' ) || 1 , // "1" is the unknown browser!
161
176
// Other metadata (status etc. of the complete test file run)
162
177
test : window . location . href ,
163
178
status : status . status ,
@@ -167,6 +182,7 @@ async function save_result(tests, status) {
167
182
org_host : org_host ,
168
183
full_url : document . location . href
169
184
} ;
185
+ // Store the results at the database
170
186
await fetch ( 'https://{{host}}:{{ports[https][0]}}/_hp/server/store_results.py' , {
171
187
method : 'POST' ,
172
188
body : JSON . stringify ( data ) ,
@@ -181,12 +197,13 @@ async function save_result(tests, status) {
181
197
d . id = "finished" ;
182
198
document . body . appendChild ( d ) ;
183
199
184
- // Try to stop the page runner
200
+ // Stop the run_id page runner by notifying the runner via postgres
185
201
let run_id = urlParams . get ( 'run_id' ) || undefined ;
186
202
if ( run_id ) {
187
203
await fetch ( `${ location . origin } /_hp/server/notify_runner_clients.py?run_id=${ run_id } ` ) ;
188
204
}
189
205
206
+ // For manual debugging of the COEP test only
190
207
if ( search ) {
191
208
// Get the content of the webpage
192
209
const webpageContent = document . body . innerText ;
@@ -209,10 +226,11 @@ async function save_result(tests, status) {
209
226
try {
210
227
window . opener . postMessage ( "finished" , "*" ) ;
211
228
} catch ( e ) {
212
- // Openere page does not exist; test opened directly
229
+ // Opener page does not exist; test opened directly
213
230
console . log ( e ) ;
214
231
}
215
232
216
233
217
234
} ;
218
- add_completion_callback ( save_result ) ;
235
+ // Save the results if the tests are finished
236
+ add_completion_callback ( save_result ) ;
0 commit comments