summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/embedded-content/the-iframe-element/support/iframe_sandbox_download_helper.js
blob: 7090e7662ca8e2f5cd0e732a8ea3c386abc273b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function StreamDownloadFinishDelay() {
    return 1000;
}

function DownloadVerifyDelay() {
    return 1000;
}

function VerifyDownload(test_obj, token, timeout, expect_download) {
    var verify_token = test_obj.step_func(function () {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', 'support/download_stash.py?verify-token&token=' + token);
        xhr.onload = test_obj.step_func(function(e) {
            if (expect_download) {
              if (xhr.response != "TOKEN_SET") {
                // Always retry, and rely on the test timeout to conclude that
                // download didn't happen and to fail the test.
                test_obj.step_timeout(verify_token, DownloadVerifyDelay());
                return;
              }
            } else {
              assert_equals(xhr.response, "TOKEN_NOT_SET", "Expect no download to happen, but got one.");
            }
            test_obj.done();
        });
        xhr.send();
    });
    test_obj.step_timeout(verify_token, timeout);
}

function AssertDownloadSuccess(test_obj, token, timeout) {
    VerifyDownload(test_obj, token, timeout, true);
}

function AssertDownloadFailure(test_obj, token, timeout) {
    VerifyDownload(test_obj, token, timeout, false);
}