Update WPT tests for embedded content
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / html / semantics / embedded-content / the-iframe-element / support / iframe_sandbox_download_helper.js
1 function StreamDownloadFinishDelay() {
2     return 1000;
3 }
4
5 function DownloadVerifyDelay() {
6     return 1000;
7 }
8
9 function VerifyDownload(test_obj, token, timeout, expect_download) {
10     var verify_token = test_obj.step_func(function () {
11         var xhr = new XMLHttpRequest();
12         xhr.open('GET', 'support/download_stash.py?verify-token&token=' + token);
13         xhr.onload = test_obj.step_func(function(e) {
14             if (expect_download) {
15               if (xhr.response != "TOKEN_SET") {
16                 // Always retry, and rely on the test timeout to conclude that
17                 // download didn't happen and to fail the test.
18                 test_obj.step_timeout(verify_token, DownloadVerifyDelay());
19                 return;
20               }
21             } else {
22               assert_equals(xhr.response, "TOKEN_NOT_SET", "Expect no download to happen, but got one.");
23             }
24             test_obj.done();
25         });
26         xhr.send();
27     });
28     test_obj.step_timeout(verify_token, timeout);
29 }
30
31 function AssertDownloadSuccess(test_obj, token, timeout) {
32     VerifyDownload(test_obj, token, timeout, true);
33 }
34
35 function AssertDownloadFailure(test_obj, token, timeout) {
36     VerifyDownload(test_obj, token, timeout, false);
37 }