summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/eventsource/request-credentials.htm
blob: c3c178a77914e1c87b4beee019ca7808162c0355 (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
<!DOCTYPE html>
<html>
  <head>
    <title>EventSource: credentials</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
  </head>
  <body>
    <div id="log"></div>
    <script>
      var crossdomain = location.href
                    .replace('://', '://www2.')
                    .replace(/\/[^\/]*$/, '/')

      function testCookie(desc, success, props, id) {
        var test = async_test(document.title + ': credentials ' + desc)
        test.step(function() {
          var source = new EventSource(crossdomain + "resources/cors-cookie.py?ident=" + id, props)

          source.onmessage = test.step_func(function(e) {
            if(e.data.indexOf("first") == 0) {
              assert_equals(e.data, "first NO_COOKIE", "cookie status")
            }
            else if(e.data.indexOf("second") == 0) {
              if (success)
                assert_equals(e.data, "second COOKIE", "cookie status")
              else
                assert_equals(e.data, "second NO_COOKIE", "cookie status")

              source.close()
              test.done()
            }
            else {
              assert_unreached("unrecognized data returned: " + e.data)
              source.close()
              test.done()
            }
          })
        })
      }

      testCookie('enabled',  true,  { withCredentials: true  }, '1_' + new Date().getTime())
      testCookie('disabled', false, { withCredentials: false }, '2_' + new Date().getTime())
      testCookie('default',  false, { },                        '3_' + new Date().getTime())

    </script>
  </body>
</html>