summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/xhr/resources/workerxhr-origin-referrer.js
blob: e378de289046dbd9a034e0c47a32f40492daf35e (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
importScripts("/resources/testharness.js")

async_test(function() {
    var expected = 'Referer: ' +
                   location.href.replace(/[^/]*$/, '') +
                   "workerxhr-origin-referrer.js\n"

    var xhr = new XMLHttpRequest()
    xhr.onreadystatechange = this.step_func(function() {
        if (xhr.readyState == 4) {
            assert_equals(xhr.responseText, expected)
            this.done()
        }
    })
    xhr.open('GET', 'inspect-headers.py?filter_name=referer', true)
    xhr.send()
}, 'Referer header')

async_test(function() {
    var expected = 'Origin: ' +
                   location.protocol +
                   '//' +
                   location.hostname +
                   (location.port === "" ? "" : ":" + location.port) +
                   '\n'

    var xhr = new XMLHttpRequest()
    xhr.onreadystatechange = this.step_func(function() {
        if (xhr.readyState == 4) {
            assert_equals(xhr.responseText, expected)
            this.done()
        }
    })
    var url = location.protocol +
              '//www2.' +
              location.hostname +
              (location.port === "" ? "" : ":" + location.port) +
              location.pathname.replace(/[^/]*$/, '') +
              'inspect-headers.py?filter_name=origin&cors'
    xhr.open('GET', url, true)
    xhr.send()
}, 'Origin header')

async_test(function() {
    // If "origin" / base URL is the origin of this JS file, we can load files
    // from the server it originates from.. and requri.py will be able to tell us
    // what the requested URL was

    var expected = location.href.replace(/[^/]*$/, '') +
                   'requri.py?full'

    var xhr = new XMLHttpRequest()
    xhr.onreadystatechange = this.step_func(function() {
        if (xhr.readyState == 4) {
            assert_equals(xhr.responseText, expected)
            this.done()
        }
    })
    xhr.open('GET', 'requri.py?full', true)
    xhr.send()
}, 'Request URL test')

done()