<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>XMLHttpRequest: setRequestHeader() value argument checks</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <!-- Test based on http://w3c-test.org/web-platform-tests/master/XMLHttpRequest/setrequestheader-bogus-value.htm This test should be removed once wpt XMLHttpRequest is imported if both tests are in sync -->
  </head>
  <body>
    <div id="log"></div>
    <script>
      function try_value(value, expectError, isDOMError) {
        test(function() {
          var client = new XMLHttpRequest()
          client.open("GET", "...")
          if (expectError && isDOMError)
              assert_throws_dom(expectError, function() { client.setRequestHeader("x-test", value) }, ' given value ' + value+', ')
          else if (expectError)
              assert_throws_js(expectError, function() { client.setRequestHeader("x-test", value) }, ' given value ' + value+', ')
          else
              client.setRequestHeader("x-test", value)  
          })
      }

      try_value("t\rt", 'SyntaxError', true)
      try_value("t\nt", 'SyntaxError', true)
      try_value("ﾃｽﾄ", TypeError, false)
      try_value("t\bt")
      try_value("t\vt")
      try_value("t\tt")
      try_value("t t")
      try_value("\xd0\xa1")
      try_value("\x7f")
      test(function() {
        var client = new XMLHttpRequest()
        client.open("GET", "...")
        assert_throws_js(TypeError, function() { client.setRequestHeader("x-test") })
      })
    </script>
  </body>
</html>
